buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC095_C {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]); //それぞれのピザの金額
int B = int.Parse(input[1]);
int AB = int.Parse(input[2]);
int needA = int.Parse(input[3]); //ピザの必要枚数
int needB = int.Parse(input[4]);
int common = Math.Min(needA, needB); // AとBが両方存在しているとき
int single = Math.Abs(needA - needB); //残りがAとBのどちらかのとき
int moreNeed = needA > needB ? A : B; //要求数の多いほうをの金額を代入
int total = Math.Min((A + B) * common, AB * common * 2) +
Math.Min(moreNeed * single, AB * single * 2);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC095_C {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]); //それぞれのピザの金額
int B = int.Parse(input[1]);
int AB = int.Parse(input[2]);
int needA = int.Parse(input[3]); //ピザの必要枚数
int needB = int.Parse(input[4]);
int common = Math.Min(needA, needB); // AとBが両方存在しているとき
int single = Math.Abs(needA - needB); //残りがAとBのどちらかのとき
int moreNeed = needA > needB ? A : B; //要求数の多いほうをの金額を代入
int total = Math.Min((A + B) * common, AB * common * 2) +
Math.Min(moreNeed * single, AB * single * 2);
Console.WriteLine(total);
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 206
| 7
|
using System;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections.Generic;
class Myon
{
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
void calc() {
int A, B, C, X, Y;
A = cin.nextInt();
B = cin.nextInt();
C = cin.nextInt();
X = cin.nextInt();
Y = cin.nextInt();
int ab = 0;
if (A + B > 2 * C) {
ab = Math.Min(X, Y);
}
int ans = (X - ab) * A + (Y - ab) * B + 2 * ab * C;
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections.Generic;
class Myon
{
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
void calc() {
int A, B, C, X, Y;
A = cin.nextInt();
B = cin.nextInt();
C = cin.nextInt();
X = cin.nextInt();
Y = cin.nextInt();
int ab = 0;
if (A + B > 2 * C) {
ab = Math.Min(X, Y);
}
int ans = (X - ab) * A + (Y - ab) * B + 2 * ab * C;
int abmax = Math.Max(X, Y);
ans = Math.Min(ans, abmax * 2 * C);
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 533
| 27
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
long[] abcxy = Console.ReadLine().Split().Select(long.Parse).ToArray();
var a = abcxy[0];
var b = abcxy[1];
var c = abcxy[2];
var d = abcxy[3];
var e = abcxy[4];
// ABピザを使わない場合
var ans = a * d + b * e;
// ABピザを使う場合
if (a > c) {
var tmp = c * d * 2;
if (e > d) {
tmp += b * (e - d);
}
ans = Math.Min(ans, tmp);
}
if (b > c) {
var tmp = c * e * 2;
if (d > e) {
tmp += a * (d - e);
}
ans = Math.Min(ans, tmp);
}
if (a > c && b > c) {
if (d > e) {
ans = Math.Min(ans, c * d * 2);
} else {
ans = Math.Min(ans, c * e * 2);
}
}
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) {
// 入力
long[] abcxy = Console.ReadLine().Split().Select(long.Parse).ToArray();
var a = abcxy[0];
var b = abcxy[1];
var c = abcxy[2];
var d = abcxy[3];
var e = abcxy[4];
// ABピザを使わない場合
var ans = a * d + b * e;
// ABピザを使う場合
// if (a > c)
//{
var tmp1 = c * d * 2;
if (e > d) {
tmp1 += b * (e - d);
}
ans = Math.Min(ans, tmp1);
//}
// if (b > c)
//{
var tmp2 = c * e * 2;
if (d > e) {
tmp2 += a * (d - e);
}
ans = Math.Min(ans, tmp2);
//}
// if (a > c && b > c)
//{
if (d > e) {
ans = Math.Min(ans, c * d * 2);
} else {
ans = Math.Min(ans, c * e * 2);
}
//}
Console.WriteLine(ans);
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 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, 75, 196, 0, 46]]
| 8
| 272
| 40
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp92 {
class Program {
static void Main(string[] args) {
var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = st[0];
int B = st[1];
int C = st[2];
int X = st[3];
int Y = st[4];
//係数の調整
X *= 2;
Y *= 2;
long ans = 0;
int minCombine = Math.Min(A + B, 2 * C);
if (X > Y) {
ans += (Y / 2) * minCombine;
ans += (X - Y) / 2 * A;
} else {
ans += (X / 2) * minCombine;
ans += (Y - X) / 2 * B;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp92 {
class Program {
static void Main(string[] args) {
var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = st[0];
int B = st[1];
int C = st[2];
int X = st[3];
int Y = st[4];
//係数の調整
X *= 2;
Y *= 2;
long ans = 0;
int minCombine = Math.Min(A + B, 2 * C);
if (X > Y) {
ans += (Y / 2) * minCombine;
ans += Math.Min((X - Y) / 2 * A, (X - Y) * C);
} else {
ans += (X / 2) * minCombine;
ans += Math.Min((Y - X) / 2 * B, (Y - X) * C);
}
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 202
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static int a, b, c, x, y, i, cost, cost2, answer;
static int Main() {
string[] nyu = new string[5];
nyu = Console.ReadLine().Split(' ');
a = int.Parse(nyu[0]);
b = int.Parse(nyu[1]);
c = int.Parse(nyu[2]);
x = int.Parse(nyu[3]);
y = int.Parse(nyu[4]);
cost = a * x + b * y;
answer = cost;
for (i = 1; i <= Math.Max(int.Parse(nyu[3]), int.Parse(nyu[4])) * 2 - 1;
i++) {
if (x > 0)
x -= 1;
if (y > 0)
y -= 1;
cost = a * x + b * y + c * 2 * i;
if (cost < answer) {
answer = cost;
} else {
break;
}
}
Console.Write("{0}, x={1}, y={2}, i={3}", answer, x, y, i);
return 0;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static int a, b, c, x, y, i, cost, cost2, answer;
static int Main() {
string[] nyu = new string[5];
nyu = Console.ReadLine().Split(' ');
a = int.Parse(nyu[0]);
b = int.Parse(nyu[1]);
c = int.Parse(nyu[2]);
x = int.Parse(nyu[3]);
y = int.Parse(nyu[4]);
cost = a * x + b * y;
answer = cost;
for (i = 1; i <= Math.Max(int.Parse(nyu[3]), int.Parse(nyu[4])) * 2; i++) {
if (x > 0)
x -= 1;
if (y > 0)
y -= 1;
cost = a * x + b * y + c * 2 * i;
if (cost < answer) {
answer = cost;
} else {
break;
}
}
Console.Write("{0}", answer);
return 0;
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 261
| 10
|
using System;
using System.Linq;
namespace atcoder {
class Program {
static void Main(string[] args) {
int A, B, C, X, Y;
string[] str = Console.ReadLine().Split(' ');
A = int.Parse(str[0]);
B = int.Parse(str[1]);
C = int.Parse(str[2]);
X = int.Parse(str[3]);
Y = int.Parse(str[4]);
int totalPlice = 0;
// 組み換えがやすい場合
if (A + B > C * 2) {
// 少ないピザを生成
int minPizzaNumber = (X > Y) ? Y : X;
totalPlice += minPizzaNumber * C * 2;
// 残ったピザを生成
totalPlice +=
(A < C * 2) ? (X - minPizzaNumber) * A : (X - minPizzaNumber) * C * 2;
totalPlice +=
(B < C * 2) ? (Y - minPizzaNumber) * B : (Y - minPizzaNumber) * C * 2;
} else {
// A
totalPlice += A * X;
Console.WriteLine(totalPlice);
// B
totalPlice += B * Y;
Console.WriteLine(totalPlice);
}
Console.WriteLine(totalPlice);
}
}
}
|
using System;
using System.Linq;
namespace atcoder {
class Program {
static void Main(string[] args) {
int A, B, C, X, Y;
string[] str = Console.ReadLine().Split(' ');
A = int.Parse(str[0]);
B = int.Parse(str[1]);
C = int.Parse(str[2]);
X = int.Parse(str[3]);
Y = int.Parse(str[4]);
int totalPlice = 0;
// 組み換えがやすい場合
if (A + B > C * 2) {
// 少ないピザを生成
int minPizzaNumber = (X > Y) ? Y : X;
totalPlice += minPizzaNumber * C * 2;
// 残ったピザを生成
totalPlice +=
(A < C * 2) ? (X - minPizzaNumber) * A : (X - minPizzaNumber) * C * 2;
totalPlice +=
(B < C * 2) ? (Y - minPizzaNumber) * B : (Y - minPizzaNumber) * C * 2;
} else {
// A
totalPlice += A * X;
// B
totalPlice += B * Y;
}
Console.WriteLine(totalPlice);
}
}
}
|
[["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 251
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;
public class Hello {
public static void Main() {
int[] n = SpRead(' ').Select(_ => int.Parse(_)).ToArray();
int A = n[0], B = n[1], AB = n[2], X = n[3], Y = n[4];
int h_A = A / 2, h_B = B / 2;
int O_AB = h_A + h_B;
long ans = 0;
ans = Math.Min(X, Y) * Math.Min(O_AB, AB) * 2;
ans += (Math.Max(X, Y) - Math.Min(X, Y)) *
Math.Min((Math.Max(X, Y) == X ? A : B), AB * 2);
Console.WriteLine(ans);
}
}
public class Atcoder {
static void Swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
public static int LCM(int a, int b) {
int c = a * b;
if (a < b)
Swap(ref a, ref b);
int d = a % b;
while (d != 0) {
a = b;
b = d;
d = a % b;
}
return c / b;
}
public static string strReverce(string s) {
return new string(s.Reverse().ToArray());
}
public static int intRead() { return int.Parse(Console.ReadLine()); }
public static bool IsPrime(int n) {
if (n < 2)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
// double sqrtNum = Math.Sqrt(n);
for (int i = 3; i < n; i += 2) {
if (n % i == 0)
return false;
}
return true;
}
public static string[] SpRead(char c) { return Console.ReadLine().Split(c); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;
public class Hello {
public static void Main() {
int[] n = SpRead(' ').Select(_ => int.Parse(_)).ToArray();
int A = n[0], B = n[1], AB = n[2], X = n[3], Y = n[4];
int O_AB = A + B;
long ans = 0;
ans = Math.Min(X, Y) * Math.Min(O_AB, AB * 2);
ans += (Math.Max(X, Y) - Math.Min(X, Y)) *
Math.Min((Math.Max(X, Y) == X ? A : B), AB * 2);
Console.WriteLine(ans);
}
}
public class Atcoder {
static void Swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
public static int LCM(int a, int b) {
int c = a * b;
if (a < b)
Swap(ref a, ref b);
int d = a % b;
while (d != 0) {
a = b;
b = d;
d = a % b;
}
return c / b;
}
public static string strReverce(string s) {
return new string(s.Reverse().ToArray());
}
public static int intRead() { return int.Parse(Console.ReadLine()); }
public static bool IsPrime(int n) {
if (n < 2)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
// double sqrtNum = Math.Sqrt(n);
for (int i = 3; i < n; i += 2) {
if (n % i == 0)
return false;
}
return true;
}
public static string[] SpRead(char c) { return Console.ReadLine().Split(c); }
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 12, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 454
| 19
|
using System;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int x = int.Parse(input[3]);
int y = int.Parse(input[4]);
long cost = 0;
long minCost = 0;
for (int i = 0; i <= x + y; i++) // ABピザをいくつ買うか決める
{
cost += 2 * c * i; // ABピザの購入
if (x - i > 0)
cost += a * (x - i); // Aピザの追加購入
if (y - i > 0)
cost += b * (y - i); // Aピザの追加購入
if (cost < minCost || minCost == 0)
minCost = cost; //最小金額の更新確認
}
Console.WriteLine(minCost);
}
}
|
using System;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int x = int.Parse(input[3]);
int y = int.Parse(input[4]);
long minCost = 0;
for (int i = 0; i <= x + y; i++) // ABピザをいくつ買うか決める
{
long cost = 0;
cost += 2 * c * i; // ABピザの購入
if (x - i > 0)
cost += a * (x - i); // Aピザの追加購入
if (y - i > 0)
cost += b * (y - i); // Aピザの追加購入
if (cost < minCost || minCost == 0)
minCost = cost; //最小金額の更新確認
}
Console.WriteLine(minCost);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35]]
| 8
| 196
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Practice {
class Program {
static void Main(string[] args) {
string row = Console.ReadLine();
string[] szArr = row.Split(' ');
int a = int.Parse(szArr[0]);
int b = int.Parse(szArr[1]);
int c = int.Parse(szArr[2]);
long x = int.Parse(szArr[3]);
long y = int.Parse(szArr[4]);
long minPrice = long.MaxValue;
long maxZ = Math.Max(x, y) * 2; // 適当に大きう
for (int z = 0; z <= maxZ; z += 2) {
long price = c * z + a * (x - z / 2) + b * (y - z / 2);
if (price < minPrice) {
minPrice = price;
}
}
Console.WriteLine(minPrice);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Practice {
class Program {
static void Main(string[] args) {
string row = Console.ReadLine();
string[] szArr = row.Split(' ');
int a = int.Parse(szArr[0]);
int b = int.Parse(szArr[1]);
int c = int.Parse(szArr[2]);
long x = int.Parse(szArr[3]);
long y = int.Parse(szArr[4]);
long minPrice = long.MaxValue;
long maxZ = Math.Max(x, y) * 2; // 適当に大きう
for (int z = 0; z <= maxZ; z += 2) {
long price =
c * z + a * Math.Max(0, (x - z / 2)) + b * Math.Max(0, (y - z / 2));
if (price < minPrice) {
minPrice = price;
}
}
Console.WriteLine(minPrice);
}
}
}
|
[["+", 31, 16, 12, 16, 12, 213, 63, 214, 205, 22], ["+", 31, 16, 12, 16, 12, 213, 63, 214, 0, 131], ["+", 31, 16, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 31, 16, 12, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 23, 0, 25], ["+", 0, 16, 12, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 16, 12, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 16, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 12, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 16, 12, 16, 12, 213, 3, 4, 0, 21]]
| 8
| 219
| 14
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() {
var array = Array();
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
public long[] LongArray() {
var array = Array();
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
}
class Program {
private int A, B, C, X, Y;
private void Scan() {
var sc = new Scanner();
A = sc.NextInt();
B = sc.NextInt();
C = sc.NextInt();
X = sc.NextInt();
Y = sc.NextInt();
}
public void Solve() {
Scan();
long ans = 0;
if (A + B > C * 2) {
int min = Math.Min(X, Y);
ans += C * 2 * min;
X -= min;
Y -= min;
}
ans += A * Math.Min(X, C * 2);
ans += B * Math.Min(Y, C * 2);
Console.WriteLine(ans);
}
static void Main(string[] args) { new Program().Solve(); }
}
}
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() {
var array = Array();
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
public long[] LongArray() {
var array = Array();
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
}
class Program {
private long A, B, C, X, Y;
private void Scan() {
var sc = new Scanner();
A = sc.NextInt();
B = sc.NextInt();
C = sc.NextInt();
X = sc.NextInt();
Y = sc.NextInt();
}
public void Solve() {
Scan();
long ans = 0;
if (A + B > C * 2) {
long min = Math.Min(X, Y);
ans += C * 2 * min;
X -= min;
Y -= min;
}
ans += Math.Min(A, C * 2) * X;
ans += Math.Min(B, C * 2) * Y;
Console.WriteLine(ans);
}
static void Main(string[] args) { new Program().Solve(); }
}
}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 508
| 16
|
using System;
using System.Linq;
namespace arc096_a {
class Program {
static void Main(string[] args) {
long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
long ret = long.MaxValue;
for (int i = 0; i <= Math.Min(x[3], x[4]); i++) {
long now = (x[3] - i) * x[0] + (x[4] - i) * x[1] + (i * 2) * x[2];
ret = Math.Min(ret, now);
}
Console.WriteLine(ret);
}
}
}
|
using System;
using System.Linq;
namespace arc096_a {
class Program {
static void Main(string[] args) {
long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
long ret = long.MaxValue;
for (int i = 0; i <= Math.Max(x[3], x[4]); i++) {
long now = Math.Max(0, (x[3] - i)) * x[0] +
Math.Max(0, (x[4] - i)) * x[1] + (i * 2) * x[2];
ret = Math.Min(ret, now);
}
Console.WriteLine(ret);
}
}
}
|
[["-", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 31, 213, 3, 4, 0, 21], ["+", 31, 213, 3, 4, 0, 28, 0, 23, 0, 25], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 31, 16, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 31, 213, 3, 4, 0, 28, 0, 23, 0, 24]]
| 8
| 149
| 16
|
using System;
namespace ARC096_D___Static_Sushi {
class Program {
static void Main(string[] args) {
var NC = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var N = NC[0];
var C = NC[1];
var x = new long[N];
var v = new long[N];
for (int i = 0; i < N; i++) {
var xv = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
x[i] = xv[0];
v[i] = xv[1];
}
var rx = new long[N];
for (int i = 0; i < N; i++)
rx[i] = C - x[N - i - 1];
var cumV = new long[N + 1];
var cumRV = new long[N + 1];
for (int i = 1; i < N + 1; i++) {
cumV[i] = cumV[i - 1] + v[i - 1];
cumRV[i] = cumRV[i - 1] + v[N - i];
}
var max = new long[N + 1];
var maxX = new long[N + 1];
var maxR = new long[N + 1];
var maxRX = new long[N + 1];
for (int i = 1; i < N + 1; i++) {
max[i] = Math.Max(max[i - 1], cumV[i] - x[i - 1]);
maxX[i] = max[i] == max[i - 1] ? max[i - 1] : x[i - 1];
maxR[i] = Math.Max(maxR[i - 1], cumRV[i] - rx[i - 1]);
maxRX[i] = maxR[i] == maxR[i - 1] ? maxR[i - 1] : rx[i - 1];
}
long result = 0;
for (int i = 1; i < N; i++) {
result = Math.Max(result, max[i] + maxR[N - i] - maxX[i]);
result = Math.Max(result, max[i] + maxR[N - i] - maxRX[N - i]);
}
Console.WriteLine(result);
}
}
}
|
using System;
namespace ARC096_D___Static_Sushi {
class Program {
static void Main(string[] args) {
var NC = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var N = NC[0];
var C = NC[1];
var x = new long[N];
var v = new long[N];
for (int i = 0; i < N; i++) {
var xv = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
x[i] = xv[0];
v[i] = xv[1];
}
var rx = new long[N];
for (int i = 0; i < N; i++)
rx[i] = C - x[N - i - 1];
var cumV = new long[N + 1];
var cumRV = new long[N + 1];
for (int i = 1; i < N + 1; i++) {
cumV[i] = cumV[i - 1] + v[i - 1];
cumRV[i] = cumRV[i - 1] + v[N - i];
}
var max = new long[N + 1];
var maxX = new long[N + 1];
var maxR = new long[N + 1];
var maxRX = new long[N + 1];
for (int i = 1; i < N + 1; i++) {
max[i] = Math.Max(max[i - 1], cumV[i] - x[i - 1]);
maxX[i] = max[i] == max[i - 1] ? max[i - 1] : x[i - 1];
maxR[i] = Math.Max(maxR[i - 1], cumRV[i] - rx[i - 1]);
maxRX[i] = maxR[i] == maxR[i - 1] ? maxR[i - 1] : rx[i - 1];
}
long result = 0;
for (int i = 1; i < N + 1; i++) {
result = Math.Max(result, max[i] + maxR[N - i] - maxX[i]);
result = Math.Max(result, max[i] + maxR[N - i] - maxRX[N - i]);
result = Math.Max(result, max[i]);
result = Math.Max(result, maxR[i]);
}
Console.WriteLine(result);
}
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
| 8
| 523
| 30
|
using System;
using System.Collections.Generic;
namespace AtCoder.ARC096 {
public struct Sushi {
public long Distance { get; set; }
public long CounterclockwiseDistance { get; set; }
public int Calorie { get; set; }
}
public struct EfficientCandidate {
public int Index { get; set; }
public long CalorieSum { get; set; }
}
public class ARC096D {
private int SushiNum { get; set; }
private long LengthOfCounter { get; set; }
private Sushi[] Sushis { get; set; }
public static void Main(string[] args) {
string[] lineArgs = Console.ReadLine().Split(' ');
int sushiNum = int.Parse(lineArgs[0]);
long lengthOfCounter = long.Parse(lineArgs[1]);
Sushi[] sushis = new Sushi[sushiNum];
for (int index = 0; index < sushiNum; index++) {
lineArgs = Console.ReadLine().Split(' ');
sushis[index] = new Sushi() {
Distance = long.Parse(lineArgs[0]),
Calorie = int.Parse(lineArgs[1]),
};
sushis[index].CounterclockwiseDistance =
lengthOfCounter - sushis[index].Distance;
}
Array.Sort(sushis,
(Sushi x, Sushi y) => x.Distance.CompareTo(y.Distance));
Console.WriteLine(
new ARC096D(sushiNum, lengthOfCounter, sushis).GetMaxCal());
}
public ARC096D(int sushiNum, long lengthOfCounter, Sushi[] sushis) {
this.SushiNum = sushiNum;
this.LengthOfCounter = lengthOfCounter;
this.Sushis = sushis;
}
public long GetMaxCal() {
// 時計まわりにどこまで行ってよいかを決め、その中で最も効率的な候補をキャッシュしておく
// 先に進んでもカロリーが見合わないなら行く意味がない
Dictionary<int, EfficientCandidate> leftEfficient =
new Dictionary<int, EfficientCandidate>();
long calorieSum = 0;
long caloriePrediction = 0;
EfficientCandidate mostEfficient =
new EfficientCandidate() { Index = -1, CalorieSum = 0 };
for (int index = 0; index < this.SushiNum; index++) {
caloriePrediction = calorieSum + this.Sushis[index].Calorie -
this.Sushis[index].Distance;
calorieSum += this.Sushis[index].Calorie;
if (mostEfficient.CalorieSum -
(mostEfficient.Index == -1
? 0
: this.Sushis[mostEfficient.Index].Distance) <=
caloriePrediction) {
mostEfficient.Index = index;
mostEfficient.CalorieSum = calorieSum;
}
leftEfficient[index] =
new EfficientCandidate() { Index = mostEfficient.Index,
CalorieSum = mostEfficient.CalorieSum };
}
// 反時計まわりにどこまで行くかを決め、そこまで行くと仮定して時計始まりと
// 反時計はじまりのどちらがお得か決める
calorieSum = 0;
caloriePrediction = 0;
mostEfficient = new EfficientCandidate() { Index = -1, CalorieSum = 0 };
long maxCalorie = 0;
long calorie = 0;
long cost = 0;
int leftIndex = 0;
for (int index = this.SushiNum - 1; 0 <= index; index--) {
caloriePrediction = calorieSum + this.Sushis[index].Calorie -
this.Sushis[index].CounterclockwiseDistance;
calorieSum += this.Sushis[index].Calorie;
if (mostEfficient.CalorieSum - (mostEfficient.Index == -1
? 0
: this.Sushis[mostEfficient.Index]
.CounterclockwiseDistance) <=
caloriePrediction) {
mostEfficient.Index = index;
mostEfficient.CalorieSum = calorieSum;
}
leftIndex = index - 1;
calorie = 0;
if (0 <= leftIndex && 0 <= leftEfficient[leftIndex].Index)
calorie += leftEfficient[leftIndex].CalorieSum;
if (0 <= mostEfficient.Index)
calorie += mostEfficient.CalorieSum;
cost = 0;
if (0 <= leftIndex && 0 <= leftEfficient[leftIndex].Index)
cost += this.Sushis[leftEfficient[leftIndex].Index].Distance * 2;
if (0 <= mostEfficient.Index)
cost += this.Sushis[mostEfficient.Index].CounterclockwiseDistance;
maxCalorie = Math.Max(maxCalorie, calorie - cost);
cost = 0;
if (0 <= leftIndex && 0 <= leftEfficient[leftIndex].Index)
cost += this.Sushis[leftEfficient[leftIndex].Index].Distance;
if (0 <= mostEfficient.Index)
cost += this.Sushis[mostEfficient.Index].CounterclockwiseDistance * 2;
maxCalorie = Math.Max(maxCalorie, calorie - cost);
}
return maxCalorie;
}
private void DebugLog(string format, params object[] objects) {
#if DEBUG
Console.Error.WriteLine(string.Format(format, objects));
#endif
}
}
}
|
using System;
using System.Collections.Generic;
namespace AtCoder.ARC096 {
public struct Sushi {
public long Distance { get; set; }
public long CounterclockwiseDistance { get; set; }
public int Calorie { get; set; }
}
public struct EfficientCandidate {
public int Index { get; set; }
public long CalorieSum { get; set; }
}
public class ARC096D {
private int SushiNum { get; set; }
private long LengthOfCounter { get; set; }
private Sushi[] Sushis { get; set; }
public static void Main(string[] args) {
string[] lineArgs = Console.ReadLine().Split(' ');
int sushiNum = int.Parse(lineArgs[0]);
long lengthOfCounter = long.Parse(lineArgs[1]);
Sushi[] sushis = new Sushi[sushiNum];
for (int index = 0; index < sushiNum; index++) {
lineArgs = Console.ReadLine().Split(' ');
sushis[index] = new Sushi() {
Distance = long.Parse(lineArgs[0]),
Calorie = int.Parse(lineArgs[1]),
};
sushis[index].CounterclockwiseDistance =
lengthOfCounter - sushis[index].Distance;
}
Array.Sort(sushis,
(Sushi x, Sushi y) => x.Distance.CompareTo(y.Distance));
Console.WriteLine(
new ARC096D(sushiNum, lengthOfCounter, sushis).GetMaxCal());
}
public ARC096D(int sushiNum, long lengthOfCounter, Sushi[] sushis) {
this.SushiNum = sushiNum;
this.LengthOfCounter = lengthOfCounter;
this.Sushis = sushis;
}
public long GetMaxCal() {
// 時計まわりにどこまで行ってよいかを決め、その中で最も効率的な候補をキャッシュしておく
// 先に進んでもカロリーが見合わないなら行く意味がない
Dictionary<int, EfficientCandidate> leftEfficient =
new Dictionary<int, EfficientCandidate>();
long calorieSum = 0;
long caloriePrediction = 0;
EfficientCandidate mostEfficient =
new EfficientCandidate() { Index = -1, CalorieSum = 0 };
for (int index = 0; index < this.SushiNum; index++) {
caloriePrediction = calorieSum + this.Sushis[index].Calorie -
this.Sushis[index].Distance;
calorieSum += this.Sushis[index].Calorie;
if (mostEfficient.CalorieSum -
(mostEfficient.Index == -1
? 0
: this.Sushis[mostEfficient.Index].Distance) <
caloriePrediction) {
mostEfficient.Index = index;
mostEfficient.CalorieSum = calorieSum;
}
leftEfficient[index] =
new EfficientCandidate() { Index = mostEfficient.Index,
CalorieSum = mostEfficient.CalorieSum };
}
// 反時計まわりにどこまで行くかを決め、そこまで行くと仮定して時計始まりと
// 反時計はじまりのどちらがお得か決める
calorieSum = 0;
caloriePrediction = 0;
mostEfficient = new EfficientCandidate() { Index = -1, CalorieSum = 0 };
long maxCalorie = 0;
long calorie = 0;
long cost = 0;
int leftIndex = 0;
for (int index = this.SushiNum; 0 <= index; index--) {
if (index < this.SushiNum) {
caloriePrediction = calorieSum + this.Sushis[index].Calorie -
this.Sushis[index].CounterclockwiseDistance;
calorieSum += this.Sushis[index].Calorie;
if (mostEfficient.CalorieSum - (mostEfficient.Index == -1
? 0
: this.Sushis[mostEfficient.Index]
.CounterclockwiseDistance) <
caloriePrediction) {
mostEfficient.Index = index;
mostEfficient.CalorieSum = calorieSum;
}
}
leftIndex = index - 1;
calorie = 0;
if (0 <= leftIndex && 0 <= leftEfficient[leftIndex].Index)
calorie += leftEfficient[leftIndex].CalorieSum;
if (0 <= mostEfficient.Index)
calorie += mostEfficient.CalorieSum;
cost = 0;
if (0 <= leftIndex && 0 <= leftEfficient[leftIndex].Index)
cost += this.Sushis[leftEfficient[leftIndex].Index].Distance * 2;
if (0 <= mostEfficient.Index)
cost += this.Sushis[mostEfficient.Index].CounterclockwiseDistance;
maxCalorie = Math.Max(maxCalorie, calorie - cost);
cost = 0;
if (0 <= leftIndex && 0 <= leftEfficient[leftIndex].Index)
cost += this.Sushis[leftEfficient[leftIndex].Index].Distance;
if (0 <= mostEfficient.Index)
cost += this.Sushis[mostEfficient.Index].CounterclockwiseDistance * 2;
maxCalorie = Math.Max(maxCalorie, calorie - cost);
}
return maxCalorie;
}
private void DebugLog(string format, params object[] objects) {
#if DEBUG
Console.Error.WriteLine(string.Format(format, objects));
#endif
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 214, 205, 273, 0, 274], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 880
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC094A {
class Program {
static void Main(string[] args) {
var word = Console.ReadLine().Split();
int a = int.Parse(word[0]);
int b = int.Parse(word[1]);
int c = int.Parse(word[2]);
if (a > c)
Console.WriteLine("NO");
else if (a - c > b)
Console.WriteLine("NO");
else
Console.WriteLine("YES");
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC094A {
class Program {
static void Main(string[] args) {
var word = Console.ReadLine().Split();
int a = int.Parse(word[0]);
int b = int.Parse(word[1]);
int c = int.Parse(word[2]);
if (a > c)
Console.WriteLine("NO");
else if (a - c > b)
Console.WriteLine("NO");
else if (a + b < c)
Console.WriteLine("NO");
else
Console.WriteLine("YES");
Console.ReadKey();
}
}
}
|
[["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 95]]
| 8
| 147
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Console = System.Console;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var f = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
string ret = "NO";
if (f[0] + f[1] >= f[2]) {
ret = "YES";
}
Console.WriteLine(ret);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Console = System.Console;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var f = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
string ret = "NO";
if (f[0] + f[1] >= f[2] && f[0] <= f[2]) {
ret = "YES";
}
Console.WriteLine(ret);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 128
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int A = int.Parse(s[0]);
int B = int.Parse(s[1]);
int X = int.Parse(s[0]);
Console.WriteLine((X >= A && X >= A + B) ? "YES" : "NO");
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int A = int.Parse(s[0]);
int B = int.Parse(s[1]);
int X = int.Parse(s[2]);
Console.WriteLine((A + B >= X && X >= A) ? "YES" : "NO");
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 41, 15, 23, 0, 16, 31, 16, 31, 22], ["-", 0, 41, 15, 23, 0, 16, 31, 16, 17, 20], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 20], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 22], ["-", 15, 23, 0, 16, 12, 16, 12, 16, 17, 72], ["-", 15, 23, 0, 16, 12, 16, 12, 16, 12, 22]]
| 8
| 112
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if (str[1] >= str[2] && str[2] >= str[0]) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if (str[2] - str[0] >= 0 && str[2] - str[0] <= str[1]) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
|
[["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 104
| 15
|
using System;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
string[] cmds = Console.ReadLine().Split(' ');
int cat = Convert.ToInt32(cmds[0]);
int unk = Convert.ToInt32(cmds[1]);
int allcat = Convert.ToInt32(cmds[2]);
int needcat = allcat - cat;
if (needcat <= 0) {
System.Console.WriteLine("NO");
return;
}
if (needcat < unk) {
System.Console.WriteLine("YES");
return;
}
System.Console.WriteLine("NO");
}
}
}
|
using System;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
string[] cmds = Console.ReadLine().Split(' ');
int cat = Convert.ToInt32(cmds[0]);
int unk = Convert.ToInt32(cmds[1]);
int allcat = Convert.ToInt32(cmds[2]);
int needcat = allcat - cat;
if (needcat == 0) {
System.Console.WriteLine("YES");
return;
}
if (needcat < 0) {
System.Console.WriteLine("NO");
return;
}
if (needcat <= unk) {
System.Console.WriteLine("YES");
return;
}
System.Console.WriteLine("NO");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 139
| 25
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var N = IO.GetInt();
var X = IO.GetIntList().OrderByDescending(x => x).ToList();
var bigB = X[N / 2];
var smallB = X[N / 2 - 1];
for (int i = 0; i < N; i++) {
if (i <= N / 2) {
Console.WriteLine(bigB);
} else {
Console.WriteLine(smallB);
}
}
// Console.Write(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var N = IO.GetInt();
var X = IO.GetIntList();
var sortedX = X.OrderByDescending(x => x).ToList();
double B = (1.0 * sortedX[N / 2] + sortedX[N / 2 - 1]) / 2;
for (int i = 0; i < N; i++) {
if (X[i] <= B) {
Console.WriteLine(sortedX[N / 2 - 1]);
} else {
Console.WriteLine(sortedX[N / 2]);
}
}
// Console.Write(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 250], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 31, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 85], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 85]]
| 8
| 387
| 47
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var b = a.Clone() as int[];
Array.Sort(a);
var t = a[n / 2];
for (int i = 0; i < n; i++) {
Console.WriteLine(b[i] >= t ? a[(n - 1) / 2] : a[n - 1]);
}
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var b = a.Clone() as int[];
Array.Sort(a);
var t = a[n / 2];
for (int i = 0; i < n; i++) {
Console.WriteLine(b[i] >= t ? a[n / 2 - 1] : a[n / 2]);
}
}
}
|
[["-", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 64, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 64, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 75, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 75, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 75, 204, 206, 207, 0, 28, 0, 16, 17, 85], ["+", 75, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 137
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
int[] Xs = new int[N];
for (int i = 0; i < N; i++) {
Xs[i] = int.Parse(s[i]);
}
Array.Sort(Xs);
for (int i = 1; i <= N; i++) {
if (i <= N / 2) {
Console.WriteLine(Xs[N / 2]);
} else {
Console.WriteLine(Xs[N / 2 - 1]);
}
}
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
int[] Xs = new int[N];
for (int i = 0; i < N; i++) {
Xs[i] = int.Parse(s[i]);
}
Array.Sort(Xs);
for (int i = 0; i < N; i++) {
if (int.Parse(s[i]) <= Xs[N / 2 - 1]) {
Console.WriteLine(Xs[N / 2]);
} else {
Console.WriteLine(Xs[(N / 2) - 1]);
}
}
Console.ReadLine();
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25]]
| 8
| 181
| 19
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] As = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long l = As.Max();
long[] ans = new long[2] { l, As[0] == l ? As[1] : As[0] };
long score = 0;
for (int i = 0; i < As.Length; i++) {
if (As[i] != l) {
long test = Math.Abs(l - 2 * As[i]);
if (test < score) {
ans = new long[2] { l, As[i] };
score = test;
}
}
}
Console.WriteLine(ans[0] + " " + ans[1]);
Console.ReadLine();
}
#region Reader
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrN() { return Console.ReadLine().Split(' '); }
static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); }
static int[] ReadIntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); }
static long[] ReadLongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
static long[,] ReadLongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = ReadLongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
static Tuple<string, string>[] ReadTupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = ReadStrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<long, long>[] ReadTupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<int, int>[] ReadTupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = ReadIntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<double, double>[] ReadTupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
static Dictionary<int, HashSet<int>> ReadAdjacencyList(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 = ReadIntN();
dict[ab[0]].Add(ab[1]);
dict[ab[1]].Add(ab[0]);
}
return dict;
}
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] As = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long l = As.Max();
long[] ans = new long[2] { l, As[0] == l ? As[1] : As[0] };
long score = Math.Abs(l - 2 * ans[1]);
for (int i = 0; i < As.Length; i++) {
if (As[i] != l) {
long test = Math.Abs(l - 2 * As[i]);
if (test < score) {
ans = new long[2] { l, As[i] };
score = test;
}
}
}
Console.WriteLine(ans[0] + " " + ans[1]);
Console.ReadLine();
}
#region Reader
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrN() { return Console.ReadLine().Split(' '); }
static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); }
static int[] ReadIntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); }
static long[] ReadLongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
static long[,] ReadLongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = ReadLongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
static Tuple<string, string>[] ReadTupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = ReadStrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<long, long>[] ReadTupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<int, int>[] ReadTupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = ReadIntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<double, double>[] ReadTupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
static Dictionary<int, HashSet<int>> ReadAdjacencyList(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 = ReadIntN();
dict[ab[0]].Add(ab[1]);
dict[ab[1]].Add(ab[0]);
}
return dict;
}
#endregion
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 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], ["+", 0, 28, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 989
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var A = sc.ReadIntArray(N);
var l = A.Max();
var r = -1;
var d = int.MinValue;
for (int i = 0; i < N; i++) {
var cur = Math.Min(A[i], l - A[i]);
if (d < cur) {
r = A[i];
d = cur;
}
}
Console.WriteLine($"{l} {r}");
}
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 A = sc.ReadIntArray(N);
var l = A.Max();
var r = -1;
var d = int.MinValue;
for (int i = 0; i < N; i++) {
if (A[i] == l)
continue;
var cur = Math.Min(A[i], l - A[i]);
if (d < cur) {
r = A[i];
d = cur;
}
}
Console.WriteLine($"{l} {r}");
}
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, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
| 8
| 1,112
| 11
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
//入力を受け取る
var N = long.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var C = A.Max();
var r = 0L;
double distance = double.MaxValue;
for (int i = 0; i < A.Length; i++) {
var num = A[i];
//組む合わせの定理を使い標準化
if (num > (C / 2)) {
num = C - num;
}
//(n+1)/2との近さ
if (Math.Abs(((C + 1) / 2) - num) < distance) {
distance = ((C + 1) / 2) - num;
r = A[i];
}
}
Console.WriteLine(C + " " + r);
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
//入力を受け取る
var N = long.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var C = A.Max();
var r = 0L;
double distance = double.MaxValue;
for (int i = 0; i < A.Length; i++) {
var num = A[i];
//組む合わせの定理を使い標準化
if (num > (C / 2)) {
num = C - num;
}
//(n+1)/2との近さ
if (A[i] != C) {
if (Math.Abs(((C + 1) / 2) - num) < distance) {
distance = ((C + 1) / 2) - num;
r = A[i];
}
}
}
Console.WriteLine(C + " " + r);
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 215
| 11
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static System.Math;
using System.Text;
namespace Program {
public static class ABC094D {
static public void Solve() {
var n = NN;
var aList = NNList(n).OrderByRand().OrderByDescending(e => e).ToArray();
var max = aList.First();
var absMin = long.MaxValue;
var real1 = max / 2;
var real2 = max / 2 + 1;
var act = 0L;
foreach (var item in aList.Skip(1)) {
var abs1 = Abs(real1 - item);
var abs2 = Abs(real2 - item);
if (absMin > Min(abs1, abs2)) {
absMin = Min(abs1, abs2);
act = item;
}
}
Console.WriteLine($"{max} {act}");
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
Solve();
Console.Out.Flush();
}
static Random rand = new Random();
static class Console_ {
private static Queue<string> param = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void RevSort<T>(T[] l)
where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void RevSort<T>(T[] l, Comparison<T> comp)
where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static T Pow<T>(T x, long y) {
T a = (dynamic)1;
while (y != 0) {
if ((y & 1) == 1)
a *= (dynamic)x;
x *= (dynamic)x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
class PQ<T>
where T : IComparable {
private List<T> h;
private Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV>
where TK : IComparable {
private PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
private long[] d;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsSame(long x, long y) => Root(x) == Root(y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Count(long x) => -d[Root(d[x])];
}
struct Mod : IEquatable<object> {
static public long _mod = 1000000007;
private long _val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mod(long x) {
if (x < _mod && x >= 0)
_val = x;
else if ((_val = x % _mod) < 0)
_val += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator long(Mod x) => x._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(Mod x, Mod y) => x._val + y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(Mod x, Mod y) => x._val - y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator *(Mod x, Mod y) => x._val * y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(Mod x, Mod y) => x._val == y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(Mod x, Mod y) => x._val != y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IEquatable<object>.Equals(object obj) => obj == null
? false
: Equals((Mod)obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object obj) => obj == null ? false
: Equals((Mod)obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Mod obj) => obj == null ? false : _val == obj._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode() => _val.GetHashCode();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => _val.ToString();
static private List<Mod> _fact = new List<Mod>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static private void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
struct Mat<T> {
private T[,] m;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mat(T[,] v) { m = (T[,])v.Clone(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
public T this[int r, int c] {
get { return m[r, c]; }
set { m[r, c] = value; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)b[r, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)b[r, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] *= (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, Mat<T> b) {
var nr = a.m.GetLength(0);
var nc = b.m.GetLength(1);
var tm = new T[nr, nc];
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j)
tm[i, j] = (dynamic)0;
for (int r = 0; r < nr; ++r)
for (int c = 0; c < nc; ++c)
for (int i = 0; i < a.m.GetLength(1); ++i)
tm[r, c] += a[r, i] * (dynamic)b[i, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> Pow(Mat<T> x, long y) {
var n = x.m.GetLength(0);
var t = (Mat<T>)new T[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i, j] = (dynamic)(i == j ? 1 : 0);
while (y != 0) {
if ((y & 1) == 1)
t *= x;
x *= x;
y >>= 1;
}
return t;
}
}
class Tree {
private long N;
private int l;
private List<long>[] p;
private int[] d;
private long[][] pr;
private long r;
private Tuple<long, long, int>[] e;
private Tuple<long, long>[] b;
private bool lca;
private bool euler;
private bool bfs;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<long, long>[] FromRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<long, long>[] FromLeaf() => FromRoot().Reverse().ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class BT<T>
where T : IComparable {
private class Node {
public Node left;
public Node right;
public T val;
public bool isBlack;
}
private Comparison<T> c;
private Node root;
private bool change;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
private bool Red(Node n) => n != null && !n.isBlack;
private bool Black(Node n) => n != null && n.isBlack;
private Node RotateL(Node n) {
Node m = n.right, t = m.left;
m.left = n;
n.right = t;
return m;
}
private Node RotateR(Node n) {
Node m = n.left, t = m.right;
m.right = n;
n.left = t;
return m;
}
private Node RotateLR(Node n) {
n.left = RotateL(n.left);
return RotateR(n);
}
private Node RotateRL(Node n) {
n.right = RotateR(n.right);
return RotateL(n);
}
public void Add(T x) {
root = Add(root, x);
root.isBlack = true;
}
private Node Add(Node n, T x) {
if (n == null) {
change = true;
return new Node() { val = x };
}
var r = c(x, n.val);
if (r < 0) {
n.left = Add(n.left, x);
return Balance(n);
}
if (r > 0) {
n.right = Add(n.right, x);
return Balance(n);
}
change = false;
return n;
}
private Node Balance(Node n) {
if (!change)
return n;
if (!Black(n))
return n;
if (Red(n.left) && Red(n.left.left)) {
n = RotateR(n);
n.left.isBlack = true;
} else if (Red(n.left) && Red(n.left.right)) {
n = RotateLR(n);
n.left.isBlack = true;
} else if (Red(n.right) && Red(n.right.left)) {
n = RotateRL(n);
n.right.isBlack = true;
} else if (Red(n.right) && Red(n.right.right)) {
n = RotateL(n);
n.right.isBlack = true;
} else {
change = false;
}
return n;
}
public void Remove(T x) {
root = Remove(root, x);
if (root != null)
root.isBlack = true;
}
private Node Remove(Node n, T x) {
if (n == null) {
change = false;
return n;
}
var r = c(x, n.val);
if (r < 0) {
n.left = Remove(n.left, x);
return BalanceL(n);
}
if (r > 0) {
n.right = Remove(n.right, x);
return BalanceR(n);
}
if (n.left == null) {
change = n.isBlack;
return n.right;
}
n.left = RemoveMax(n.left);
n.val = lmax;
return BalanceL(n);
}
private T lmax;
private Node RemoveMax(Node n) {
if (n.right != null) {
n.right = RemoveMax(n.right);
return BalanceR(n);
}
lmax = n.val;
change = n.isBlack;
return n.left;
}
private Node BalanceL(Node n) {
if (!change)
return n;
if (Black(n.right) && Red(n.right.left)) {
var b = n.isBlack;
n = RotateRL(n);
n.isBlack = b;
n.left.isBlack = true;
change = false;
} else if (Black(n.right) && Red(n.right.right)) {
var b = n.isBlack;
n = RotateL(n);
n.isBlack = b;
n.right.isBlack = true;
n.left.isBlack = true;
change = false;
} else if (Black(n.right)) {
change = n.isBlack;
n.isBlack = true;
n.right.isBlack = false;
} else {
n = RotateL(n);
n.isBlack = true;
n.left.isBlack = false;
n.left = BalanceL(n.left);
change = false;
}
return n;
}
private Node BalanceR(Node n) {
if (!change)
return n;
if (Black(n.left) && Red(n.left.right)) {
var b = n.isBlack;
n = RotateLR(n);
n.isBlack = b;
n.right.isBlack = true;
change = false;
} else if (Black(n.left) && Red(n.left.left)) {
var b = n.isBlack;
n = RotateR(n);
n.isBlack = b;
n.left.isBlack = true;
n.right.isBlack = true;
change = false;
} else if (Black(n.left)) {
change = n.isBlack;
n.isBlack = true;
n.left.isBlack = false;
} else {
n = RotateR(n);
n.isBlack = true;
n.right.isBlack = false;
n.right = BalanceR(n.right);
change = false;
}
return n;
}
public bool Have(T x) {
var t = FindUpper(x);
return t.Item1 && t.Item2.CompareTo(x) == 0;
}
public Tuple<bool, T> FindUpper(T x) {
var v = FindUpper(root, x);
if (v == null)
return Tuple.Create(false, default(T));
return v;
}
private Tuple<bool, T> FindUpper(Node n, T x) {
if (n == null)
return null;
var r = c(x, n.val);
if (r < 0) {
var v = FindUpper(n.left, x);
if (v == null)
return Tuple.Create(true, n.val);
return v;
} else if (r > 0)
return FindUpper(n.right, x);
else
return Tuple.Create(true, n.val);
}
public Tuple<bool, T> FindLower(T x) {
var v = FindLower(root, x);
if (v == null)
return Tuple.Create(false, default(T));
return v;
}
private Tuple<bool, T> FindLower(Node n, T x) {
if (n == null)
return null;
var r = c(x, n.val);
if (r < 0)
return FindLower(n.left, x);
else if (r > 0) {
var v = FindLower(n.right, x);
if (v == null)
return Tuple.Create(true, n.val);
return v;
} else
return Tuple.Create(true, n.val);
}
public T Min() {
Node n = root, p = null;
while (n != null) {
p = n;
n = n.left;
}
return p == null ? default(T) : p.val;
}
public T Max() {
Node n = root, p = null;
while (n != null) {
p = n;
n = n.right;
}
return p == null ? default(T) : p.val;
}
public bool Any() => root != null;
public int CountSlow() => List(root).Count();
public IEnumerable<T> List() => List(root);
private IEnumerable<T> List(Node n) {
if (n == null)
yield break;
foreach (var i in List(n.left))
yield return i;
yield return n.val;
foreach (var i in List(n.right))
yield return i;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static System.Math;
using System.Text;
namespace Program {
public static class ABC094D {
static public void Solve() {
var n = NN;
var aList = NNList(n).OrderByRand().OrderByDescending(e => e).ToArray();
var max = aList.First();
var absMin = long.MaxValue;
var real1 = max / 2;
var real2 = max / 2 + (max % 2 == 1 ? 1 : 0);
var act = 0L;
foreach (var item in aList.Skip(1)) {
var abs1 = Abs(real1 - item);
var abs2 = Abs(real2 - item);
if (absMin > Min(abs1, abs2)) {
absMin = Min(abs1, abs2);
act = item;
}
}
Console.WriteLine($"{max} {act}");
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
Solve();
Console.Out.Flush();
}
static Random rand = new Random();
static class Console_ {
private static Queue<string> param = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void RevSort<T>(T[] l)
where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void RevSort<T>(T[] l, Comparison<T> comp)
where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static T Pow<T>(T x, long y) {
T a = (dynamic)1;
while (y != 0) {
if ((y & 1) == 1)
a *= (dynamic)x;
x *= (dynamic)x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
class PQ<T>
where T : IComparable {
private List<T> h;
private Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV>
where TK : IComparable {
private PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
private long[] d;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsSame(long x, long y) => Root(x) == Root(y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Count(long x) => -d[Root(d[x])];
}
struct Mod : IEquatable<object> {
static public long _mod = 1000000007;
private long _val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mod(long x) {
if (x < _mod && x >= 0)
_val = x;
else if ((_val = x % _mod) < 0)
_val += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator long(Mod x) => x._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(Mod x, Mod y) => x._val + y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(Mod x, Mod y) => x._val - y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator *(Mod x, Mod y) => x._val * y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(Mod x, Mod y) => x._val == y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(Mod x, Mod y) => x._val != y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IEquatable<object>.Equals(object obj) => obj == null
? false
: Equals((Mod)obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object obj) => obj == null ? false
: Equals((Mod)obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Mod obj) => obj == null ? false : _val == obj._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode() => _val.GetHashCode();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => _val.ToString();
static private List<Mod> _fact = new List<Mod>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static private void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
struct Mat<T> {
private T[,] m;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mat(T[,] v) { m = (T[,])v.Clone(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
public T this[int r, int c] {
get { return m[r, c]; }
set { m[r, c] = value; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)b[r, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)b[r, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] *= (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, Mat<T> b) {
var nr = a.m.GetLength(0);
var nc = b.m.GetLength(1);
var tm = new T[nr, nc];
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j)
tm[i, j] = (dynamic)0;
for (int r = 0; r < nr; ++r)
for (int c = 0; c < nc; ++c)
for (int i = 0; i < a.m.GetLength(1); ++i)
tm[r, c] += a[r, i] * (dynamic)b[i, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> Pow(Mat<T> x, long y) {
var n = x.m.GetLength(0);
var t = (Mat<T>)new T[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i, j] = (dynamic)(i == j ? 1 : 0);
while (y != 0) {
if ((y & 1) == 1)
t *= x;
x *= x;
y >>= 1;
}
return t;
}
}
class Tree {
private long N;
private int l;
private List<long>[] p;
private int[] d;
private long[][] pr;
private long r;
private Tuple<long, long, int>[] e;
private Tuple<long, long>[] b;
private bool lca;
private bool euler;
private bool bfs;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<long, long>[] FromRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<long, long>[] FromLeaf() => FromRoot().Reverse().ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class BT<T>
where T : IComparable {
private class Node {
public Node left;
public Node right;
public T val;
public bool isBlack;
}
private Comparison<T> c;
private Node root;
private bool change;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
private bool Red(Node n) => n != null && !n.isBlack;
private bool Black(Node n) => n != null && n.isBlack;
private Node RotateL(Node n) {
Node m = n.right, t = m.left;
m.left = n;
n.right = t;
return m;
}
private Node RotateR(Node n) {
Node m = n.left, t = m.right;
m.right = n;
n.left = t;
return m;
}
private Node RotateLR(Node n) {
n.left = RotateL(n.left);
return RotateR(n);
}
private Node RotateRL(Node n) {
n.right = RotateR(n.right);
return RotateL(n);
}
public void Add(T x) {
root = Add(root, x);
root.isBlack = true;
}
private Node Add(Node n, T x) {
if (n == null) {
change = true;
return new Node() { val = x };
}
var r = c(x, n.val);
if (r < 0) {
n.left = Add(n.left, x);
return Balance(n);
}
if (r > 0) {
n.right = Add(n.right, x);
return Balance(n);
}
change = false;
return n;
}
private Node Balance(Node n) {
if (!change)
return n;
if (!Black(n))
return n;
if (Red(n.left) && Red(n.left.left)) {
n = RotateR(n);
n.left.isBlack = true;
} else if (Red(n.left) && Red(n.left.right)) {
n = RotateLR(n);
n.left.isBlack = true;
} else if (Red(n.right) && Red(n.right.left)) {
n = RotateRL(n);
n.right.isBlack = true;
} else if (Red(n.right) && Red(n.right.right)) {
n = RotateL(n);
n.right.isBlack = true;
} else {
change = false;
}
return n;
}
public void Remove(T x) {
root = Remove(root, x);
if (root != null)
root.isBlack = true;
}
private Node Remove(Node n, T x) {
if (n == null) {
change = false;
return n;
}
var r = c(x, n.val);
if (r < 0) {
n.left = Remove(n.left, x);
return BalanceL(n);
}
if (r > 0) {
n.right = Remove(n.right, x);
return BalanceR(n);
}
if (n.left == null) {
change = n.isBlack;
return n.right;
}
n.left = RemoveMax(n.left);
n.val = lmax;
return BalanceL(n);
}
private T lmax;
private Node RemoveMax(Node n) {
if (n.right != null) {
n.right = RemoveMax(n.right);
return BalanceR(n);
}
lmax = n.val;
change = n.isBlack;
return n.left;
}
private Node BalanceL(Node n) {
if (!change)
return n;
if (Black(n.right) && Red(n.right.left)) {
var b = n.isBlack;
n = RotateRL(n);
n.isBlack = b;
n.left.isBlack = true;
change = false;
} else if (Black(n.right) && Red(n.right.right)) {
var b = n.isBlack;
n = RotateL(n);
n.isBlack = b;
n.right.isBlack = true;
n.left.isBlack = true;
change = false;
} else if (Black(n.right)) {
change = n.isBlack;
n.isBlack = true;
n.right.isBlack = false;
} else {
n = RotateL(n);
n.isBlack = true;
n.left.isBlack = false;
n.left = BalanceL(n.left);
change = false;
}
return n;
}
private Node BalanceR(Node n) {
if (!change)
return n;
if (Black(n.left) && Red(n.left.right)) {
var b = n.isBlack;
n = RotateLR(n);
n.isBlack = b;
n.right.isBlack = true;
change = false;
} else if (Black(n.left) && Red(n.left.left)) {
var b = n.isBlack;
n = RotateR(n);
n.isBlack = b;
n.left.isBlack = true;
n.right.isBlack = true;
change = false;
} else if (Black(n.left)) {
change = n.isBlack;
n.isBlack = true;
n.left.isBlack = false;
} else {
n = RotateR(n);
n.isBlack = true;
n.right.isBlack = false;
n.right = BalanceR(n.right);
change = false;
}
return n;
}
public bool Have(T x) {
var t = FindUpper(x);
return t.Item1 && t.Item2.CompareTo(x) == 0;
}
public Tuple<bool, T> FindUpper(T x) {
var v = FindUpper(root, x);
if (v == null)
return Tuple.Create(false, default(T));
return v;
}
private Tuple<bool, T> FindUpper(Node n, T x) {
if (n == null)
return null;
var r = c(x, n.val);
if (r < 0) {
var v = FindUpper(n.left, x);
if (v == null)
return Tuple.Create(true, n.val);
return v;
} else if (r > 0)
return FindUpper(n.right, x);
else
return Tuple.Create(true, n.val);
}
public Tuple<bool, T> FindLower(T x) {
var v = FindLower(root, x);
if (v == null)
return Tuple.Create(false, default(T));
return v;
}
private Tuple<bool, T> FindLower(Node n, T x) {
if (n == null)
return null;
var r = c(x, n.val);
if (r < 0)
return FindLower(n.left, x);
else if (r > 0) {
var v = FindLower(n.right, x);
if (v == null)
return Tuple.Create(true, n.val);
return v;
} else
return Tuple.Create(true, n.val);
}
public T Min() {
Node n = root, p = null;
while (n != null) {
p = n;
n = n.left;
}
return p == null ? default(T) : p.val;
}
public T Max() {
Node n = root, p = null;
while (n != null) {
p = n;
n = n.right;
}
return p == null ? default(T) : p.val;
}
public bool Any() => root != null;
public int CountSlow() => List(root).Count();
public IEnumerable<T> List() => List(root);
private IEnumerable<T> List(Node n) {
if (n == null)
yield break;
foreach (var i in List(n.left))
yield return i;
yield return n.val;
foreach (var i in List(n.right))
yield return i;
}
}
}
}
|
[["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 0, 102], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 75, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
| 8
| 6,887
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int max = a[n - 1];
double mean = (double)max / 2;
var b = a.Select(x => Math.Abs(x - mean)).ToList();
double min = b.Min();
int m = b.IndexOf(min);
int mm = a[m];
Console.WriteLine($"{max} {mm}");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
a.Sort();
int max = a[n - 1];
a.RemoveAt(n - 1);
double mean = (double)max / 2;
var b = a.Select(x => Math.Abs(x - mean)).ToList();
double min = b.Min();
int m = b.IndexOf(min);
int mm = a[m];
Console.WriteLine($"{max} {mm}");
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
| 8
| 173
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static PB10004.Algorithm.Util;
namespace PB10004.Algorithm {
class Template {
static void Main(string[] args) { new ABC094D().Solve(); }
}
public class ABC094D {
public void Solve() {
var n = ReadInt();
var array = ReadLongArray();
Array.Sort(array);
Array.Reverse(array);
Write(array[0] + " ");
long tmp = long.MaxValue;
for (int i = 1; i < n; i++) {
if (array[i] <= (array[0] + 1) / 2) {
Write(array[i] + "\n");
return;
}
}
Write(array[n - 1] + "\n");
}
}
public static class Util {
/// <summary>
/// 標準入力をint型にパースする
/// </summary>
/// <returns></returns>
public static int ReadInt() { return int.Parse(ReadLine()); }
/// <summary>
/// 標準入力をint型の配列にする
/// </summary>
/// <returns></returns>
public static int[] ReadIntArray() {
return ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
}
/// <summary>
/// 標準入力をlong型にパースする
/// </summary>
/// <returns></returns>
public static long ReadLong() { return long.Parse(ReadLine()); }
/// <summary>
/// 標準入力をlong型の配列にする
/// </summary>
/// <returns></returns>
public static long[] ReadLongArray() {
return ReadLine().Split(' ').Select(long.Parse).ToArray();
}
/// <summary>
/// 一定値の数列を生成する
/// </summary>
/// <param name="value"></param>
/// <param name="length"></param>
/// <returns></returns>
public static IEnumerable<long> ConstSeq(long value, long length) {
for (int i = 0; i < length; i++) {
yield return value;
}
}
/// <summary>
/// int配列の累積和を求める
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
public static IEnumerable<int> CumulativeSum(IEnumerable<int> array) {
int tmp = 0;
foreach (var num in array)
yield return tmp += num;
}
/// <summary>
/// long配列の累積和を求める
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
public static IEnumerable<long> CumulativeSum(IEnumerable<long> array) {
long tmp = 0;
foreach (var num in array)
yield return tmp += num;
}
/// <summary>
/// 最大公約数をユークリッドの互除法で求める
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Gcd(long a, long b) {
return b == 0 ? a : Gcd(b, a % b);
}
/// <summary>
/// 最小公倍数を求める
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Lcm(long a, long b) { return a * b / Gcd(a, b); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static PB10004.Algorithm.Util;
namespace PB10004.Algorithm {
class Template {
static void Main(string[] args) { new ABC094D().Solve(); }
}
public class ABC094D {
public void Solve() {
var n = ReadInt();
var array = ReadLongArray();
Array.Sort(array);
Array.Reverse(array);
Write(array[0] + " ");
long tmp = long.MaxValue;
for (int i = 1; i < n; i++) {
if (array[i] <= (array[0] + 1) / 2) {
if (array[i] + array[i - 1] >= array[0]) {
Write(array[i] + "\n");
} else {
Write(array[i - 1] + "\n");
}
return;
}
}
Write(array[n - 1] + "\n");
}
}
public static class Util {
/// <summary>
/// 標準入力をint型にパースする
/// </summary>
/// <returns></returns>
public static int ReadInt() { return int.Parse(ReadLine()); }
/// <summary>
/// 標準入力をint型の配列にする
/// </summary>
/// <returns></returns>
public static int[] ReadIntArray() {
return ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
}
/// <summary>
/// 標準入力をlong型にパースする
/// </summary>
/// <returns></returns>
public static long ReadLong() { return long.Parse(ReadLine()); }
/// <summary>
/// 標準入力をlong型の配列にする
/// </summary>
/// <returns></returns>
public static long[] ReadLongArray() {
return ReadLine().Split(' ').Select(long.Parse).ToArray();
}
/// <summary>
/// 一定値の数列を生成する
/// </summary>
/// <param name="value"></param>
/// <param name="length"></param>
/// <returns></returns>
public static IEnumerable<long> ConstSeq(long value, long length) {
for (int i = 0; i < length; i++) {
yield return value;
}
}
/// <summary>
/// int配列の累積和を求める
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
public static IEnumerable<int> CumulativeSum(IEnumerable<int> array) {
int tmp = 0;
foreach (var num in array)
yield return tmp += num;
}
/// <summary>
/// long配列の累積和を求める
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
public static IEnumerable<long> CumulativeSum(IEnumerable<long> array) {
long tmp = 0;
foreach (var num in array)
yield return tmp += num;
}
/// <summary>
/// 最大公約数をユークリッドの互除法で求める
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Gcd(long a, long b) {
return b == 0 ? a : Gcd(b, a % b);
}
/// <summary>
/// 最小公倍数を求める
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Lcm(long a, long b) { return a * b / Gcd(a, b); }
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 64, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 44], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 502
| 38
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
double mid = a.Max() / 2.0;
double temp = double.MaxValue;
int ans = -1;
for (int i = 0; i < n; i++) {
if (Math.Abs(a[i] - mid) < temp) {
temp = Math.Abs(a[i] - mid);
ans = a[i];
}
}
Console.WriteLine("{0} {1}", a.Max(), ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
double mid = a.Max() / 2.0;
double temp = double.MaxValue;
int ans = -1;
for (int i = n - 1; i >= 0; i--) {
if (Math.Abs(a[i] - mid) < temp) {
temp = Math.Abs(a[i] - mid);
ans = a[i];
}
}
Console.WriteLine("{0} {1}", a.Max(), ans);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
| 8
| 175
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
#if DEBUG
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
namespace competitive_programming {
public class Program {
static void Main(string[] args) {
#if DEBUG
var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open));
#else
var scanner = new IO.StreamScanner(Console.OpenStandardInput());
#endif
var n = scanner.Integer();
var a = new List<int>();
for (int i = 0; i < n; i++) {
a.Add(scanner.Integer());
}
IO.Printer.Out.WriteLine(GetAns(n, a));
IO.Printer.Out.Flush();
}
public static string GetAns(int n, List<int> a) {
var max = a.Max();
return max.ToString() + " " +
a.OrderBy(v => Math.Abs(v - max / 2.0)).First().ToString();
}
}
#if DEBUG
[TestClass]
public class Test {}
#endif
namespace 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(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
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;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
#if DEBUG
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
namespace competitive_programming {
public class Program {
static void Main(string[] args) {
#if DEBUG
var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open));
#else
var scanner = new IO.StreamScanner(Console.OpenStandardInput());
#endif
var n = scanner.Integer();
var a = new List<int>();
for (int i = 0; i < n; i++) {
a.Add(scanner.Integer());
}
IO.Printer.Out.WriteLine(GetAns(n, a));
IO.Printer.Out.Flush();
}
public static string GetAns(int n, List<int> a) {
var max = a.Max();
a.Remove(max);
return max.ToString() + " " +
a.OrderBy(v => Math.Abs(v - max / 2.0)).First().ToString();
}
}
#if DEBUG
[TestClass]
public class Test {}
#endif
namespace 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(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
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;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 1,076
| 7
|
using System;
using System.Linq;
namespace arc095_b {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int max = x.Max();
int ret = 0;
int nearest = int.MaxValue;
for (int i = 0; i < n; i++) {
if (nearest > Math.Abs(max - (x[i] * 2))) {
nearest = Math.Abs(max - (x[i] * 2));
ret = x[i];
}
}
Console.WriteLine(max + " " + ret);
}
}
}
|
using System;
using System.Linq;
namespace arc095_b {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int max = x.Max();
int ret = 0;
int nearest = int.MaxValue;
for (int i = 0; i < n; i++) {
if (x[i] != max && nearest > Math.Abs(max - (x[i] * 2))) {
nearest = Math.Abs(max - (x[i] * 2));
ret = x[i];
}
}
Console.WriteLine(max + " " + ret);
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 164
| 7
|
using System;
using System.Linq;
using System.Collections.Generic;
public static class Program {
public static void Main() {
int n = int.Parse(Console.ReadLine());
var graph = Enumerable.Range(0, n).Select(_ => new List<int>()).ToArray();
for (int i = 0; i < n - 1; i++) {
var uv = Console.ReadLine().Split().Select(int.Parse).ToArray();
int u = uv[0];
int v = uv[1];
u--;
v--;
graph[u].Add(v);
graph[v].Add(u);
}
for (int u = 0; u < n; u++) {
// Console.Write($"{u}:");
foreach (int v in graph[u]) {
// Console.Write($" {v}");
}
// Console.Write("\n");
}
Func<int, int> far = (int start) => {
var dist = new int[n];
Action<int, int> dfs = null;
dfs = (int x, int p) => {
foreach (int y in graph[x]) {
if (y == p)
continue;
dist[y] = dist[x] + 1;
dfs(y, x);
}
};
dfs(start, start);
int goal = start;
for (int i = 0; i < n; i++) {
if (dist[goal] < dist[i]) {
goal = i;
}
}
return goal;
};
int s = far(0);
int t = far(s);
// Console.WriteLine($"farthest: {s}, {t}");
var deg = new List<int>();
{
Func<int, int, bool> Dfs = null;
Dfs = (int x, int p) => {
if (x == t) {
deg.Add(graph[t].Count);
return true;
}
foreach (int y in graph[x]) {
if (y == p)
continue;
if (Dfs(y, x)) {
deg.Add(graph[x].Count - (x == s ? 0 : 1));
return true;
}
}
return false;
};
Dfs(s, s);
}
var deg_rev = deg.AsEnumerable().Reverse().ToList();
// Console.Write("deg:");
foreach (int x in deg) {
// Console.Write($" {x}");
}
// Console.Write('\n');
// Console.Write("deg_rev:");
foreach (int x in deg_rev) {
// Console.Write($" {x}");
}
// Console.Write('\n');
// check if catapiller
if (deg.Sum() != n) {
Console.WriteLine(-1);
Environment.Exit(0);
}
var perm0 = MakePermutation(deg, n);
// Console.Write("perm0:");
foreach (int x in perm0) {
// Console.Write($" {x}");
}
// Console.Write('\n');
var perm1 = MakePermutation(deg_rev, n);
// Console.Write("perm1:");
foreach (int x in perm1) {
// Console.Write($" {x}");
}
// Console.Write('\n');
var ans = new List<int>();
for (int i = 0; i < n; i++) {
if (perm0[i] < perm1[i]) {
ans = perm0;
break;
} else if (perm0[i] > perm1[i]) {
ans = perm1;
break;
}
}
if (ans.Count == 0) {
ans = perm0;
}
Console.WriteLine($"count: {ans.Count} {perm0.Count} {perm1.Count}");
for (int i = 0; i < n; i++) {
if (0 < i)
Console.Write(' ');
Console.Write(ans[i] + 1);
}
Console.Write('\n');
}
public static List<int> MakePermutation(List<int> a, int n) {
var ans = Enumerable.Range(0, n).ToList();
for (int i = 1; i < a.Count; i++) {
a[i] += a[i - 1];
}
Action<int, int> Rotate = (int l, int r) => {
Console.WriteLine($"rotate {l} {r}");
for (int i = l; i < r - 1; i++) {
Console.WriteLine($" -- swap {i} {i+1}");
ans[i + 1] ^= ans[i];
ans[i] ^= ans[i + 1];
ans[i + 1] ^= ans[i];
}
};
for (int i = 1; i < a.Count; i++) {
Rotate(a[i - 1], a[i]);
}
return ans;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
public static class Program {
public static void Main() {
int n = int.Parse(Console.ReadLine());
var graph = Enumerable.Range(0, n).Select(_ => new List<int>()).ToArray();
for (int i = 0; i < n - 1; i++) {
var uv = Console.ReadLine().Split().Select(int.Parse).ToArray();
int u = uv[0];
int v = uv[1];
u--;
v--;
graph[u].Add(v);
graph[v].Add(u);
}
for (int u = 0; u < n; u++) {
// Console.Write($"{u}:");
foreach (int v in graph[u]) {
// Console.Write($" {v}");
}
// Console.Write("\n");
}
Func<int, int> far = (int start) => {
var dist = new int[n];
Action<int, int> dfs = null;
dfs = (int x, int p) => {
foreach (int y in graph[x]) {
if (y == p)
continue;
dist[y] = dist[x] + 1;
dfs(y, x);
}
};
dfs(start, start);
int goal = start;
for (int i = 0; i < n; i++) {
if (dist[goal] < dist[i]) {
goal = i;
}
}
return goal;
};
int s = far(0);
int t = far(s);
// Console.WriteLine($"farthest: {s}, {t}");
var deg = new List<int>();
{
Func<int, int, bool> Dfs = null;
Dfs = (int x, int p) => {
if (x == t) {
deg.Add(graph[t].Count);
return true;
}
foreach (int y in graph[x]) {
if (y == p)
continue;
if (Dfs(y, x)) {
deg.Add(graph[x].Count - (x == s ? 0 : 1));
return true;
}
}
return false;
};
Dfs(s, s);
}
var deg_rev = deg.AsEnumerable().Reverse().ToList();
// Console.Write("deg:");
foreach (int x in deg) {
// Console.Write($" {x}");
}
// Console.Write('\n');
// Console.Write("deg_rev:");
foreach (int x in deg_rev) {
// Console.Write($" {x}");
}
// Console.Write('\n');
// check if catapiller
if (deg.Sum() != n) {
Console.WriteLine(-1);
Environment.Exit(0);
}
var perm0 = MakePermutation(deg, n);
// Console.Write("perm0:");
foreach (int x in perm0) {
// Console.Write($" {x}");
}
// Console.Write('\n');
var perm1 = MakePermutation(deg_rev, n);
// Console.Write("perm1:");
foreach (int x in perm1) {
// Console.Write($" {x}");
}
// Console.Write('\n');
var ans = new List<int>();
for (int i = 0; i < n; i++) {
if (perm0[i] < perm1[i]) {
ans = perm0;
break;
} else if (perm0[i] > perm1[i]) {
ans = perm1;
break;
}
}
if (ans.Count == 0) {
ans = perm0;
}
for (int i = 0; i < n; i++) {
if (0 < i)
Console.Write(' ');
Console.Write(ans[i] + 1);
}
Console.Write('\n');
}
public static List<int> MakePermutation(List<int> a, int n) {
var ans = Enumerable.Range(0, n).ToList();
for (int i = 1; i < a.Count; i++) {
a[i] += a[i - 1];
}
Action<int, int> Rotate = (int l, int r) => {
// Console.WriteLine($"rotate {l} {r}");
for (int i = l; i < r - 1; i++) {
// Console.WriteLine($" -- swap {i} {i+1}");
ans[i + 1] ^= ans[i];
ans[i] ^= ans[i + 1];
ans[i + 1] ^= ans[i];
}
};
for (int i = 1; i < a.Count; i++) {
Rotate(a[i - 1], a[i]);
}
return ans;
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 205, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 0, 131], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 200, 0, 212, 0, 218, 8, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 0, 212, 0, 218, 8, 196, 0, 1, 0, 35], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 31, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 17, 72], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 948
| 60
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { Solve(); }
static void Solve() {
Scan sc = new Scan();
write wr = new write();
var s = sc.chararr;
Array.Sort(s);
var a = new string(s);
if (a == "abc") {
wr.wri("Yes");
} else
wr.wri("No");
}
}
class Scan {
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 => strarr.Select(char.Parse).ToArray();
}
class write {
public void wri<Type>(Type x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { Solve(); }
static void Solve() {
Scan sc = new Scan();
write wr = new write();
var s = sc.chararr;
Array.Sort(s);
var a = new string(s);
if (a == "abc") {
wr.wri("Yes");
} else
wr.wri("No");
}
}
class Scan {
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();
}
class write {
public void wri<Type>(Type x) { Console.WriteLine(x); }
}
|
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 277, 51, 306, 0, 213, 63, 214, 205, 22]]
| 8
| 230
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC096 {
class Program {
public static void Main(string[] args) {
/*
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int a = input[0];
int b = input[1];
int x = input[2];
string result = "NO";
*/
var str = Console.ReadLine();
var a = str.ToCharArray();
var result =
((a[0] != a[1]) && (a[1] != a[2]) && (a[0] != a[2])) ? "YES" : "NO";
Console.WriteLine(result);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC096 {
class Program {
public static void Main(string[] args) {
/*
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int a = input[0];
int b = input[1];
int x = input[2];
string result = "NO";
*/
var str = Console.ReadLine();
var a = str.ToCharArray();
var result =
((a[0] != a[1]) && (a[1] != a[2]) && (a[0] != a[2])) ? "Yes" : "No";
Console.WriteLine(result);
}
}
}
|
[["-", 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 128
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using static AtCoderer.Comfort;
using static AtCoderer.Math;
using static AtCoderer.Algorithm;
using static System.Math;
namespace AtCoderer {
public class App {
public static void Main(string[] args) {
Console.WriteLine(
Console.ReadLine().OrderBy(c => c).ToString() == "abc" ? "Yes" : "No");
}
}
public static class Comfort {
//ソート
public static int[] OrderBy(this int[] IArr) {
int[] arr = new int[IArr.Length];
Array.Copy(IArr, arr, IArr.Length);
Array.Sort(arr);
return arr;
}
//ソート
public static char[] OrderBy(this string IArr) {
char[] arr = new char[IArr.Length];
Array.Copy(IArr.ToCharArray(), arr, IArr.Length);
Array.Sort(arr);
return arr;
}
// MinとMax
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
//整数入力
public static int Parse() { return int.Parse(Console.ReadLine()); }
//整数列入力
public static int[] ParseArray(this string s) {
return s.Split().Select(v => int.Parse(v)).ToArray();
}
//整数列入力
public static long[] ParseArrayL(this string s) {
return s.Split().Select(v => long.Parse(v)).ToArray();
}
//整数列入力
public static int[] ParseArray() {
return Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
}
//整数列入力
public static long[] ParseArrayL() {
return Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
}
// 2整数入力
public static void ParseArray(out int a, out int b) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
// 3整数入力
public static void ParseArray(out int a, out int b, out int c) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
// 4整数入力
public static void ParseArray(out int a, out int b, out int c, out int d) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
// 2整数入力
public static void ParseArray(out long a, out long b) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
// 3整数入力
public static void ParseArray(out long a, out long b, out long c) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
// 4整数入力
public static void ParseArray(out long a, out long b, out long c,
out long d) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
// char配列のstring化
public static string ToString(this IEnumerable<char> v) {
return string.Join("", v);
}
//配列のstring化
public static string Join<T>(this IEnumerable<T> v, char c) {
return string.Join(c.ToString(), v);
}
//配列のstring化
public static string Join<T>(this IEnumerable<T> v, string s) {
return string.Join(s, v);
}
}
public static class Math {
//自然数判定
public static bool IsNatural(this float v) => v - (int)v == 0;
public static bool IsNatural(this double v) => v - (int)v == 0;
//非重複順列
public static long nCm(long n, long m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * nCm(n - 1, m - 1) / m % 1000000007;
}
//素因数分解
public static IEnumerable<int> Factor(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
//最大公約数
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int x,
int y) => y == 0 ? x : GcdRecursive(y, x % y);
//最大公約数
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long x,
long y) => y == 0 ? x
: GcdRecursive(y, x % y);
//最小公倍数
public static long Lcm(int a, int b) => ((long)a) * b / Gcd(a, b);
}
public static class Algorithm {
// 2値タプル
public class Point {
public int a;
public int b;
public Point(int x, int y) {
a = x;
b = y;
}
}
//全列挙のクラス
public class EnumAll {
bool Over = false;
int UpperValue;
int Dimension;
public int[] Current { private set; get; }
public EnumAll(int Value, int Dimension) {
this.Dimension = Dimension;
UpperValue = Value;
Current = new int[Dimension];
Current[0] = -1;
}
public bool Next() {
if (Over)
return false;
bool flag = false;
for (int i = 0; i < Dimension; i++) {
if (++Current[i] >= UpperValue)
Current[i] = 0;
else {
flag = true;
break;
}
}
if (!flag) {
Over = true;
return false;
}
return true;
}
public bool IsOver() { return Over; }
}
// Union-Find
public class UnionFind {
private int[] Parent;
private int GetRoot(int v) {
if (Parent[v] < 0)
return v;
else
return Parent[v] = GetRoot(Parent[v]);
}
public UnionFind(int size) {
Parent = new int[size];
for (int i = 0; i < size; i++)
Parent[i] = -1;
}
public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); }
public void Connect(int a, int b) {
a = GetRoot(a);
b = GetRoot(b);
if (a == b)
return;
if (Parent[b] < Parent[a]) {
Parent[b] += Parent[a];
Parent[a] = b;
} else {
Parent[a] += Parent[b];
Parent[b] = a;
}
}
public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; }
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static AtCoderer.Comfort;
using static AtCoderer.Math;
using static AtCoderer.Algorithm;
using static System.Math;
namespace AtCoderer {
public class App {
public static void Solve() {
Console.WriteLine(
Console.ReadLine().OrderBy(c => c).Join() == "abc" ? "Yes" : "No");
}
public static void Main(string[] args) {
Solve();
Console.ReadKey();
}
}
public static class Comfort {
//ソート
public static int[] OrderBy(this int[] IArr) {
int[] arr = new int[IArr.Length];
Array.Copy(IArr, arr, IArr.Length);
Array.Sort(arr);
return arr;
}
//ソート
public static char[] OrderBy(this string IArr) {
char[] arr = new char[IArr.Length];
Array.Copy(IArr.ToCharArray(), arr, IArr.Length);
Array.Sort(arr);
return arr;
}
// MinとMax
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
//整数入力
public static int Parse() { return int.Parse(Console.ReadLine()); }
//整数列入力
public static int[] ParseArray(this string s) {
return s.Split().Select(v => int.Parse(v)).ToArray();
}
//整数列入力
public static long[] ParseArrayL(this string s) {
return s.Split().Select(v => long.Parse(v)).ToArray();
}
//整数列入力
public static int[] ParseArray() {
return Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
}
//整数列入力
public static long[] ParseArrayL() {
return Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
}
// 2整数入力
public static void ParseArray(out int a, out int b) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
// 3整数入力
public static void ParseArray(out int a, out int b, out int c) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
// 4整数入力
public static void ParseArray(out int a, out int b, out int c, out int d) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
// 2整数入力
public static void ParseArray(out long a, out long b) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
// 3整数入力
public static void ParseArray(out long a, out long b, out long c) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
// 4整数入力
public static void ParseArray(out long a, out long b, out long c,
out long d) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
// char配列のstring化
public static string Join(this IEnumerable<char> v) {
return string.Join("", v);
}
//配列のstring化
public static string Join<T>(this IEnumerable<T> v, char c) {
return string.Join(c.ToString(), v);
}
//配列のstring化
public static string Join<T>(this IEnumerable<T> v, string s) {
return string.Join(s, v);
}
}
public static class Math {
//自然数判定
public static bool IsNatural(this float v) => v - (int)v == 0;
public static bool IsNatural(this double v) => v - (int)v == 0;
//非重複順列
public static long nCm(long n, long m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * nCm(n - 1, m - 1) / m % 1000000007;
}
//素因数分解
public static IEnumerable<int> Factor(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
//最大公約数
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int x,
int y) => y == 0 ? x : GcdRecursive(y, x % y);
//最大公約数
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long x,
long y) => y == 0 ? x
: GcdRecursive(y, x % y);
//最小公倍数
public static long Lcm(int a, int b) => ((long)a) * b / Gcd(a, b);
}
public static class Algorithm {
// 2値タプル
public class Point {
public int a;
public int b;
public Point(int x, int y) {
a = x;
b = y;
}
}
//全列挙のクラス
public class EnumAll {
bool Over = false;
int UpperValue;
int Dimension;
public int[] Current { private set; get; }
public EnumAll(int Value, int Dimension) {
this.Dimension = Dimension;
UpperValue = Value;
Current = new int[Dimension];
Current[0] = -1;
}
public bool Next() {
if (Over)
return false;
bool flag = false;
for (int i = 0; i < Dimension; i++) {
if (++Current[i] >= UpperValue)
Current[i] = 0;
else {
flag = true;
break;
}
}
if (!flag) {
Over = true;
return false;
}
return true;
}
public bool IsOver() { return Over; }
}
// Union-Find
public class UnionFind {
private int[] Parent;
private int GetRoot(int v) {
if (Parent[v] < 0)
return v;
else
return Parent[v] = GetRoot(Parent[v]);
}
public UnionFind(int size) {
Parent = new int[size];
for (int i = 0; i < size; i++)
Parent[i] = -1;
}
public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); }
public void Connect(int a, int b) {
a = GetRoot(a);
b = GetRoot(b);
if (a == b)
return;
if (Parent[b] < Parent[a]) {
Parent[b] += Parent[a];
Parent[a] = b;
} else {
Parent[a] += Parent[b];
Parent[b] = a;
}
}
public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; }
}
}
}
|
[["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 70], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 0, 41, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 41, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 54, 55, 0, 220, 39, 224, 225, 226, 0, 70], ["+", 54, 55, 0, 220, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
| 8
| 1,676
| 32
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6 {
class Program {
static void Main(string[] args) {
var Source = Console.ReadLine().Split();
Console.WriteLine(new List<string> { "a", "b", "c" }
.Select(s => Source.Contains(s))
.Aggregate((b, b1) => b && b1)
? "Yes"
: "No");
}
public static int countWordInArray(IEnumerable<string> sourcelist,
string TargetWord) {
return sourcelist.Count(s => s == TargetWord);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6 {
class Program {
static void Main(string[] args) {
var Source = Console.ReadLine().ToList();
Console.WriteLine(new List<char> { 'a', 'b', 'c' }
.Select(s => Source.Contains(s))
.Aggregate((b, b1) => b && b1)
? "Yes"
: "No");
}
public static int countWordInArray(IEnumerable<string> sourcelist,
string TargetWord) {
return sourcelist.Count(s => s == TargetWord);
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 63, 214, 205, 230, 39, 236, 237, 238, 0, 199], ["+", 63, 214, 205, 230, 39, 236, 237, 238, 0, 199], ["-", 63, 214, 205, 230, 10, 229, 0, 5, 0, 62], ["+", 63, 214, 205, 230, 10, 229, 0, 252, 0, 104]]
| 8
| 163
| 16
|
using static System.Math;
using static System.Console;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Net;
using System.Dynamic;
class Program {
static void Main(string[] args) {
var a = ReadLine();
var c = a.ToCharArray().Distinct();
WriteLine(c.Count());
}
}
|
using static System.Math;
using static System.Console;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Net;
using System.Dynamic;
class Program {
static void Main(string[] args) {
var a = ReadLine();
var c = a.ToCharArray().Distinct();
WriteLine(c.Count() == 3 ? "Yes" : "No");
}
}
|
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 98
| 10
|
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = ReadLine().Split();
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int k = int.Parse(input[2]);
List<int> ans = new List<int>();
for (int i = a; i < a + Math.Min(k, b - a); i++) {
if (!ans.Contains(i)) {
ans.Add(i);
}
}
for (int i = b - Math.Min(k, b - a) + 1; i <= b; i++) {
if (!ans.Contains(i)) {
ans.Add(i);
}
}
for (int i = 0; i < ans.Count; i++) {
WriteLine(ans[i]);
}
}
}
|
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = ReadLine().Split();
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int k = int.Parse(input[2]);
List<int> ans = new List<int>();
for (int i = a; i < a + Math.Min(k, b - a); i++) {
if (!ans.Contains(i)) {
ans.Add(i);
}
}
for (int i = b - Math.Min(k, b - a) + 1; i <= b; i++) {
if (!ans.Contains(i)) {
ans.Add(i);
}
}
ans.Sort();
if (ans.Count == 0) {
ans.Add(a);
}
for (int i = 0; i < ans.Count; i++) {
WriteLine(ans[i]);
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 222
| 23
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
int A;
int B;
int K;
Multi(out A, out B, out K);
var array = Enumerable.Range(A, K).ToList();
array.AddRange(Enumerable.Range(B - K + 1, K).ToList());
array = array.Distinct().OrderBy(a => a).ToList();
foreach (var a in array) {
Console.WriteLine(a);
}
// Console.WriteLine(ans);
}
static public string GetStr() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
int A;
int B;
int K;
Multi(out A, out B, out K);
var array = Enumerable.Range(A, K).ToList();
array.AddRange(Enumerable.Range(B - K + 1, K).ToList());
array = array.Where(a => A <= a && a <= B).ToList();
array = array.Distinct().OrderBy(a => a).ToList();
foreach (var a in array) {
Console.WriteLine(a);
}
// Console.WriteLine(ans);
}
static public string GetStr() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
}
}
|
[["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 19], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 98], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 17, 19], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 12, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131]]
| 8
| 753
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp64 {
class Program {
static void Main(string[] args) {
var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = st[0];
int B = st[1];
int K = st[2];
List<int> ans = new List<int>();
for (int i = 0; i < K; i++) {
ans.Add(A + i);
ans.Add(B - i);
}
var ans_new = ans.Distinct().OrderBy(x => x);
foreach (var element in ans_new) {
Console.WriteLine(element);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp64 {
class Program {
static void Main(string[] args) {
var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = st[0];
int B = st[1];
int K = st[2];
List<int> ans = new List<int>();
for (int i = 0; i < K; i++) {
if (A + i <= B) {
ans.Add(A + i);
}
if (B - i >= A) {
ans.Add(B - i);
}
}
var ans_new = ans.Distinct().OrderBy(x => x);
foreach (var element in ans_new) {
Console.WriteLine(element);
}
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 174
| 20
|
using System;
namespace Main {
class Program {
static void Main(string[] args) {
var lines = Console.ReadLine().Split(' ');
var a = int.Parse(lines[0]);
var b = int.Parse(lines[1]);
var k = int.Parse(lines[2]);
if (b - a < k * 2) {
Console.WriteLine("a");
for (var i = a; i <= b; i++)
if (a <= i && i < a + k || b - k < i && i <= b)
Console.WriteLine(i);
} else {
Console.WriteLine("b");
for (var i = a; i < a + k; i++)
Console.WriteLine(i);
for (var i = b - k + 1; i <= b; i++)
Console.WriteLine(i);
}
}
}
}
|
using System;
namespace Main {
class Program {
static void Main(string[] args) {
var lines = Console.ReadLine().Split(' ');
var a = int.Parse(lines[0]);
var b = int.Parse(lines[1]);
var k = int.Parse(lines[2]);
if (b - a < k * 2) {
for (var i = a; i <= b; i++)
if (a <= i && i < a + k || b - k < i && i <= b)
Console.WriteLine(i);
} else {
for (var i = a; i < a + k; i++)
Console.WriteLine(i);
for (var i = b - k + 1; i <= b; i++)
Console.WriteLine(i);
}
}
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 201
| 18
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder {
class Program {
static void Main(string[] args) { MainStream(); }
static void MainStream() {
Scan sc = new Scan();
write wr = new write();
int[] abk = sc.intarr;
int a = abk[0];
int b = abk[1];
int k = abk[2];
if ((b - a) / 2 <= k) {
for (int i = a; i <= b; i++) {
wr.wri(i);
}
return;
}
List<int> ans = new List<int>();
for (int i = 0; i < k; i++) {
ans.Add(a + i);
}
for (int i = k - 1; i >= 0; i--) {
ans.Add(b - i);
}
foreach (var num in ans) {
wr.wri(num);
}
}
}
class Scan {
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();
}
class write {
public void wri<Type>(Type x) { Console.WriteLine(x); }
}
class Method {
static public int max(params int[] nums) {
int maxx = nums[0];
for (int i = 1; i < nums.Length; i++) {
maxx = Math.Max(maxx, nums[i]);
}
return maxx;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder {
class Program {
static void Main(string[] args) { MainStream(); }
static void MainStream() {
Scan sc = new Scan();
write wr = new write();
int[] abk = sc.intarr;
int a = abk[0];
int b = abk[1];
int k = abk[2];
if (a == b) {
wr.wri(a);
return;
}
if ((b - a + 1) / 2 < k) {
for (int i = a; i <= b; i++) {
wr.wri(i);
}
return;
}
List<int> ans = new List<int>();
for (int i = 0; i < k; i++) {
ans.Add(a + i);
}
for (int i = k - 1; i >= 0; i--) {
ans.Add(b - i);
}
foreach (var num in ans) {
wr.wri(num);
}
}
}
class Scan {
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();
}
class write {
public void wri<Type>(Type x) { Console.WriteLine(x); }
}
class Method {
static public int max(params int[] nums) {
int maxx = nums[0];
for (int i = 1; i < nums.Length; i++) {
maxx = Math.Max(maxx, nums[i]);
}
return maxx;
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 377
| 21
|
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
var A = NextInt();
var B = NextInt();
var K = NextInt();
var L = new List<int>();
for (var i = 0; i < K; i++) {
L.Add(A + i);
}
for (var j = 0; j < K; j++) {
var tmp = B - j;
if (!L.Contains(tmp)) {
L.Add(tmp);
}
}
L.Sort();
foreach (var x in L) {
WriteLine(x);
}
}
static int NextInt() { return int.Parse(NextString()); }
static string NextString() {
var result = new List<char>();
while (true) {
int next = Read();
if (next < 0)
break;
var nextChar = (char)next;
if (!char.IsWhiteSpace(nextChar))
result.Add(nextChar);
else if (nextChar != '\r')
break;
}
return string.Join("", result);
}
}
|
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
var A = NextInt();
var B = NextInt();
var K = NextInt();
var L = new List<int>();
for (var i = 0; i < K; i++) {
L.Add(A + i);
}
for (var j = 0; j < K; j++) {
var tmp = B - j;
if (!L.Contains(tmp)) {
L.Add(tmp);
}
}
L.Sort();
foreach (var x in L) {
if (A <= x && x <= B) {
WriteLine(x);
}
}
}
static int NextInt() { return int.Parse(NextString()); }
static string NextString() {
var result = new List<char>();
while (true) {
int next = Read();
if (next < 0)
break;
var nextChar = (char)next;
if (!char.IsWhiteSpace(nextChar))
result.Add(nextChar);
else if (nextChar != '\r')
break;
}
return string.Join("", result);
}
}
|
[["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 246
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
// using System.Text;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
// using System.Numerics;
// using static System.Math;
// using pair = Pair<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;
void solve() {
int A = cin.nextint;
int B = cin.nextint;
int K = cin.nextint;
for (int i = A; i < A + K; i++) {
WriteLine(i);
}
for (int i = Math.Max(A + K, B - K + 1); i <= B; i++) {
WriteLine(i);
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan {
get { return ReadLine().Split(); }
}
public int[] scanint {
get { return Array.ConvertAll(scan, int.Parse); }
}
public long[] scanlong {
get { return Array.ConvertAll(scan, long.Parse); }
}
public double[] scandouble {
get { return Array.ConvertAll(scan, double.Parse); }
}
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint {
get { return int.Parse(next); }
}
public long nextlong {
get { return long.Parse(next); }
}
public double nextdouble {
get { return double.Parse(next); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
// using System.Text;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
// using System.Numerics;
// using static System.Math;
// using pair = Pair<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;
void solve() {
int A = cin.nextint;
int B = cin.nextint;
int K = cin.nextint;
for (int i = A; i < Math.Min(A + K, B + 1); i++) {
WriteLine(i);
}
for (int i = Math.Max(A + K, B - K + 1); i <= B; i++) {
WriteLine(i);
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan {
get { return ReadLine().Split(); }
}
public int[] scanint {
get { return Array.ConvertAll(scan, int.Parse); }
}
public long[] scanlong {
get { return Array.ConvertAll(scan, long.Parse); }
}
public double[] scandouble {
get { return Array.ConvertAll(scan, double.Parse); }
}
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint {
get { return int.Parse(next); }
}
public long nextlong {
get { return long.Parse(next); }
}
public double nextdouble {
get { return double.Parse(next); }
}
}
|
[["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 419
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProgrammingContest {
class Writer : IDisposable {
private System.IO.TextWriter writer;
private StringBuilder sb;
private bool isReactive;
public Writer(string path) : this(new System.IO.StreamWriter(path)) {}
public Writer(bool isReactive) : this(null, isReactive) {}
public Writer(System.IO.TextWriter writer = null, bool isReactive = false) {
this.writer = (writer ?? Console.Out);
this.isReactive = isReactive;
if (!this.isReactive) {
this.sb = new StringBuilder();
}
}
public void Dispose() {
if (!this.isReactive) {
this.writer.Write(sb.ToString());
}
if (!this.writer.Equals(Console.Out)) {
this.writer.Dispose();
}
}
public void Write(object val) {
if (this.isReactive) {
this.writer.Write(val.ToString());
this.writer.Flush();
} else {
this.sb.Append(val.ToString());
}
}
public void Write(string format, params object[] vals) {
if (this.isReactive) {
this.writer.Write(format, vals);
this.writer.Flush();
} else {
this.sb.AppendFormat(format, vals);
}
}
public void WriteLine(object val = null) {
this.Write((val ?? string.Empty).ToString() + System.Environment.NewLine);
}
public void WriteLine(int val) { this.WriteLine(val.ToString()); }
public void WriteLine(long val) { this.WriteLine(val.ToString()); }
public void WriteLine(string val) { this.WriteLine((object)val); }
public void WriteLine(string format, params object[] vals) {
this.Write(format + System.Environment.NewLine, vals);
}
}
class Scanner : IDisposable {
private Queue<string> buffer;
private char[] sep;
private System.IO.TextReader reader;
public Scanner(string path, char[] sep = null)
: this(new System.IO.StreamReader(path), sep) {}
public Scanner(System.IO.TextReader reader = null, char[] sep = null) {
this.buffer = new Queue<string>();
this.sep = (sep ?? new char[] { ' ' });
this.reader = (reader ?? Console.In);
}
private void CheckBuffer() {
if (this.buffer.Count == 0 && this.reader.Peek() != -1) {
string str = string.Empty;
for (; string.IsNullOrEmpty(str); str = this.reader.ReadLine())
;
str.Split(this.sep).ToList().ForEach(el => this.buffer.Enqueue(el));
}
}
public void Dispose() {
if (!this.reader.Equals(Console.In)) {
this.reader.Dispose();
}
}
public string Next {
get {
this.CheckBuffer();
return this.buffer.Dequeue();
}
}
public string[] GetStringArray(int N) {
return Enumerable.Range(0, N).Select(e => this.Next).ToArray();
}
public int NextInt {
get { return int.Parse(this.Next); }
}
public int[] GetIntArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextInt).ToArray();
}
public double NextDouble {
get { return double.Parse(this.Next); }
}
public double[] GetdoubleArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextDouble).ToArray();
}
public long NextLong {
get { return long.Parse(this.Next); }
}
public long[] GetLongArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextLong).ToArray();
}
public bool IsEnd {
get {
this.CheckBuffer();
return this.buffer.Count == 0;
}
}
}
class MainClass : IDisposable {
Scanner sc;
Writer wr;
const string backPath = "..";
char dirSep = System.IO.Path.DirectorySeparatorChar;
string inFilePath = string.Empty;
string outFilePath = string.Empty;
public MainClass() {
this.inFilePath = MainClass.backPath + this.dirSep + MainClass.backPath +
this.dirSep + "in.txt";
this.outFilePath = MainClass.backPath + this.dirSep + MainClass.backPath +
this.dirSep + "out.txt";
this.wr = new Writer(this.IsReactive);
// this.wr = new Writer(this.outFilePath);
#if DEBUG
if (!this.IsReactive) {
this.sc = new Scanner(this.inFilePath);
} else {
this.sc = new Scanner();
}
#else
this.sc = new Scanner();
#endif
}
static void Main(string[] args) {
using (var mainClass = new MainClass()) { mainClass.Solve(); }
}
public void Dispose() {
if (this.sc != null) {
this.sc.Dispose();
this.sc = null;
}
if (this.wr != null) {
this.wr.Dispose();
this.wr = null;
}
#if DEBUG
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
void MakeTestCase() {
var rand = new Random();
if (this.wr != null) {
this.wr.Dispose();
}
this.wr = new Writer(inFilePath);
}
void Solve() {
int A = sc.NextInt;
int B = sc.NextInt;
int K = sc.NextInt;
wr.WriteLine(string.Join(Environment.NewLine,
Enumerable.Range(0, K)
.Select(e => new int[] { e + A, B - e })
.SelectMany(e => e)
.Distinct()
.OrderBy(e => e)));
}
private bool IsReactive { get; } = false; // TODO: reactive check !!
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProgrammingContest {
class Writer : IDisposable {
private System.IO.TextWriter writer;
private StringBuilder sb;
private bool isReactive;
public Writer(string path) : this(new System.IO.StreamWriter(path)) {}
public Writer(bool isReactive) : this(null, isReactive) {}
public Writer(System.IO.TextWriter writer = null, bool isReactive = false) {
this.writer = (writer ?? Console.Out);
this.isReactive = isReactive;
if (!this.isReactive) {
this.sb = new StringBuilder();
}
}
public void Dispose() {
if (!this.isReactive) {
this.writer.Write(sb.ToString());
}
if (!this.writer.Equals(Console.Out)) {
this.writer.Dispose();
}
}
public void Write(object val) {
if (this.isReactive) {
this.writer.Write(val.ToString());
this.writer.Flush();
} else {
this.sb.Append(val.ToString());
}
}
public void Write(string format, params object[] vals) {
if (this.isReactive) {
this.writer.Write(format, vals);
this.writer.Flush();
} else {
this.sb.AppendFormat(format, vals);
}
}
public void WriteLine(object val = null) {
this.Write((val ?? string.Empty).ToString() + System.Environment.NewLine);
}
public void WriteLine(int val) { this.WriteLine(val.ToString()); }
public void WriteLine(long val) { this.WriteLine(val.ToString()); }
public void WriteLine(string val) { this.WriteLine((object)val); }
public void WriteLine(string format, params object[] vals) {
this.Write(format + System.Environment.NewLine, vals);
}
}
class Scanner : IDisposable {
private Queue<string> buffer;
private char[] sep;
private System.IO.TextReader reader;
public Scanner(string path, char[] sep = null)
: this(new System.IO.StreamReader(path), sep) {}
public Scanner(System.IO.TextReader reader = null, char[] sep = null) {
this.buffer = new Queue<string>();
this.sep = (sep ?? new char[] { ' ' });
this.reader = (reader ?? Console.In);
}
private void CheckBuffer() {
if (this.buffer.Count == 0 && this.reader.Peek() != -1) {
string str = string.Empty;
for (; string.IsNullOrEmpty(str); str = this.reader.ReadLine())
;
str.Split(this.sep).ToList().ForEach(el => this.buffer.Enqueue(el));
}
}
public void Dispose() {
if (!this.reader.Equals(Console.In)) {
this.reader.Dispose();
}
}
public string Next {
get {
this.CheckBuffer();
return this.buffer.Dequeue();
}
}
public string[] GetStringArray(int N) {
return Enumerable.Range(0, N).Select(e => this.Next).ToArray();
}
public int NextInt {
get { return int.Parse(this.Next); }
}
public int[] GetIntArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextInt).ToArray();
}
public double NextDouble {
get { return double.Parse(this.Next); }
}
public double[] GetdoubleArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextDouble).ToArray();
}
public long NextLong {
get { return long.Parse(this.Next); }
}
public long[] GetLongArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextLong).ToArray();
}
public bool IsEnd {
get {
this.CheckBuffer();
return this.buffer.Count == 0;
}
}
}
class MainClass : IDisposable {
Scanner sc;
Writer wr;
const string backPath = "..";
char dirSep = System.IO.Path.DirectorySeparatorChar;
string inFilePath = string.Empty;
string outFilePath = string.Empty;
public MainClass() {
this.inFilePath = MainClass.backPath + this.dirSep + MainClass.backPath +
this.dirSep + "in.txt";
this.outFilePath = MainClass.backPath + this.dirSep + MainClass.backPath +
this.dirSep + "out.txt";
this.wr = new Writer(this.IsReactive);
// this.wr = new Writer(this.outFilePath);
#if DEBUG
if (!this.IsReactive) {
this.sc = new Scanner(this.inFilePath);
} else {
this.sc = new Scanner();
}
#else
this.sc = new Scanner();
#endif
}
static void Main(string[] args) {
using (var mainClass = new MainClass()) { mainClass.Solve(); }
}
public void Dispose() {
if (this.sc != null) {
this.sc.Dispose();
this.sc = null;
}
if (this.wr != null) {
this.wr.Dispose();
this.wr = null;
}
#if DEBUG
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
void MakeTestCase() {
var rand = new Random();
if (this.wr != null) {
this.wr.Dispose();
}
this.wr = new Writer(inFilePath);
}
void Solve() {
int A = sc.NextInt;
int B = sc.NextInt;
int K = sc.NextInt;
wr.WriteLine(string.Join(Environment.NewLine,
Enumerable.Range(0, K)
.Select(e => new int[] { e + A, B - e })
.SelectMany(e => e)
.Distinct()
.Where(e => A <= e && e <= B)
.OrderBy(e => e)));
}
private bool IsReactive { get; } = false; // TODO: reactive check !!
}
}
|
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 19], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 98], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 17, 19], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 12, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131]]
| 8
| 1,300
| 13
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using static System.Console;
using static System.Math;
class Simple {
void Solve() {
var A = io.Int;
var B = io.Int;
var K = io.Int;
var ans = new List<int>();
for (int i = A; i < A + K; ++i)
ans.Add(i);
for (int i = B - K + 1; i <= B; ++i)
ans.Add(i);
foreach (var VARIABLE in ans.Distinct()) {
WriteLine(VARIABLE);
}
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) => new Simple().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class SimpleIO {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public SimpleIO() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
_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 Flush() => Out.Flush();
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using static System.Console;
using static System.Math;
class Simple {
void Solve() {
var A = io.Int;
var B = io.Int;
var K = io.Int;
var ans = new List<int>();
for (int i = A, cnt = 0; i < B && cnt < K; ++i, ++cnt)
ans.Add(i);
for (int i = B, cnt = 0; i >= A && cnt < K; --i, ++cnt)
ans.Add(i);
foreach (var VARIABLE in ans.Distinct().OrderBy(x => x)) {
WriteLine(VARIABLE);
}
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) => new Simple().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class SimpleIO {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public SimpleIO() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
_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 Flush() => Out.Flush();
}
|
[["+", 0, 195, 8, 196, 0, 7, 10, 198, 0, 21], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 98], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 18], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 26, 21], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 241, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 68], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 12, 213, 3, 4, 0, 28, 0, 218, 8, 22]]
| 8
| 417
| 41
|
using System;
using System.Linq;
using System.Collections.Generic;
public class SmallAndLargeIntegers {
public static void Main() {
int[] ABK = ReadIntArray();
List<int> nums = new List<int>(200);
for (int i = 0; i < ABK[2]; i++) {
nums.Add(ABK[0] + i);
nums.Add(ABK[1] - i);
}
foreach (var i in nums.Distinct().OrderBy(i => i))
Console.WriteLine(i);
}
private static int ReadInt() { return int.Parse(Console.ReadLine()); }
private static double ReadDouble() {
return double.Parse(Console.ReadLine());
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static char ReadChar() { return Console.ReadLine()[0]; }
private static string[] ReadStringArray() {
return Console.ReadLine().Split(' ');
}
private static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
private static double[] ReadDoubleArray() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
private static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
private static void WriteArraySingleLine(Object[] array) {
Console.WriteLine(string.Join(" ", array));
}
private static void WriteArrayMultiLine(Object[] array) {
Console.WriteLine(string.Join(Environment.NewLine, array));
}
private static void WriteYesNo(bool b) {
Console.WriteLine((b) ? "Yes" : "No");
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
public class SmallAndLargeIntegers {
public static void Main() {
int[] ABK = ReadIntArray();
if (ABK[2] > ABK[1] - ABK[0] + 1)
ABK[2] = ABK[1] - ABK[0] + 1;
List<int> nums = new List<int>(200);
for (int i = 0; i < ABK[2]; i++) {
nums.Add(ABK[0] + i);
nums.Add(ABK[1] - i);
}
foreach (var i in nums.Distinct().OrderBy(i => i))
Console.WriteLine(i);
}
private static int ReadInt() { return int.Parse(Console.ReadLine()); }
private static double ReadDouble() {
return double.Parse(Console.ReadLine());
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static char ReadChar() { return Console.ReadLine()[0]; }
private static string[] ReadStringArray() {
return Console.ReadLine().Split(' ');
}
private static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
private static double[] ReadDoubleArray() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
private static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
private static void WriteArraySingleLine(Object[] array) {
Console.WriteLine(string.Join(" ", array));
}
private static void WriteArrayMultiLine(Object[] array) {
Console.WriteLine(string.Join(Environment.NewLine, array));
}
private static void WriteYesNo(bool b) {
Console.WriteLine((b) ? "Yes" : "No");
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 15, 16, 12, 16, 31, 16, 12, 204, 205, 22], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 11, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 64, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 431
| 36
|
using System;
class test {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int[] n = new int[3];
int i;
for (i = 0; i < 3; i++) {
n[i] = int.Parse(s[i]);
}
int[] ans;
int size = n[1] - n[0] + 1;
if (size > n[2] * 2) {
ans = new int[n[2] * 2];
for (i = n[0]; i < n[0] + n[2]; i++) {
ans[i] = n[0] + i;
}
for (i = n[1]; i > n[1] - n[2]; i--) {
ans[i] = n[1] - i;
}
} else {
ans = new int[size];
for (i = n[0]; i < size; i++) {
ans[i] = i;
}
}
for (i = 0; i < ans.Length; i++) {
Console.WriteLine(ans[i]);
}
}
}
|
using System;
class test {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int[] n = new int[3];
int i;
for (i = 0; i < 3; i++) {
n[i] = int.Parse(s[i]);
}
int[] ans;
int size = n[1] - n[0] + 1;
if (size > n[2] * 2) {
ans = new int[n[2] * 2];
for (i = 0; i < n[2]; i++) {
ans[i] = n[0] + i;
}
for (i = 0; i < n[2]; i++) {
ans[n[2] * 2 - 1 - i] = n[1] - i;
}
} else {
ans = new int[size];
for (i = 0; i < size; i++) {
ans[i] = n[0] + i;
}
}
for (i = 0; i < ans.Length; i++) {
Console.WriteLine(ans[i]);
}
}
}
|
[["-", 64, 196, 0, 7, 10, 11, 12, 204, 205, 22], ["-", 0, 7, 10, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 7, 10, 11, 12, 204, 206, 207, 0, 73], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 0, 7, 15, 16, 12, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 10, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 64, 196, 0, 7, 10, 11, 12, 203], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["-", 64, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 0, 57, 64, 196, 0, 7, 26, 223, 0, 68], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 16, 31, 16, 31, 204, 205, 22], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 75, 196, 0, 7, 10, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
| 8
| 261
| 39
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Solve {
public Solve() {}
public static int Main() {
new Solve().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
var A = cin.nextInt();
var B = cin.nextInt();
var K = cin.nextInt();
var NumList = new List<int>();
for (int i = 0; i < K; i++) {
if (A + i <= B)
NumList.Add(A + i);
if (A - i >= A)
NumList.Add(B - i);
}
NumList.Sort();
var result = NumList.Distinct();
// for (int i = 0; i < NumList.Count; i++){
// //Console.WriteLine(NumList[i].ToString());
//}
foreach (var res in result) {
Console.WriteLine(res);
}
}
}
public class Point {
public int X, Y;
public Point(int x, int y) {
X = x;
Y = y;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Solve {
public Solve() {}
public static int Main() {
new Solve().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
var A = cin.nextInt();
var B = cin.nextInt();
var K = cin.nextInt();
var NumList = new List<int>();
for (int i = 0; i < K; i++) {
if (A + i <= B)
NumList.Add(A + i);
if (B - i >= A)
NumList.Add(B - i);
}
NumList.Sort();
var result = NumList.Distinct();
foreach (var res in result) {
Console.WriteLine(res);
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["-", 36, 36, 0, 208, 0, 235, 0, 251, 0, 259], ["-", 36, 36, 36, 36, 0, 208, 0, 235, 0, 269], ["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 36, 36, 0, 208, 0, 235, 8, 201, 0, 45], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 259], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 0, 21], ["-", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 263, 0, 251, 0, 259], ["-", 0, 208, 0, 235, 8, 201, 0, 263, 141, 22], ["-", 0, 235, 8, 201, 0, 263, 54, 55, 0, 24], ["-", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["-", 8, 201, 0, 263, 54, 55, 0, 220, 141, 22], ["-", 0, 235, 8, 201, 0, 263, 54, 55, 0, 21], ["-", 0, 235, 8, 201, 0, 263, 54, 55, 0, 25], ["-", 0, 235, 8, 201, 0, 263, 8, 196, 0, 45], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35]]
| 8
| 588
| 32
|
using System;
using System.Linq;
namespace arc094_a {
class Program {
static void Main(string[] args) {
var ABC =
(Console.ReadLine().Split().Select(x => decimal.Parse(x))).ToList();
ABC.Sort();
decimal r = 0;
decimal A = Math.Floor((ABC[2] - ABC[0]) / 2);
r += A;
ABC[0] += A * 2;
decimal B = Math.Floor((ABC[2] - ABC[1]) / 2);
r += B;
ABC[1] += B * 2;
if (ABC[0] == ABC[1] && ABC[1] == ABC[2]) {
} else if (ABC[1] == ABC[2]) {
r += 2;
} else {
r += 1;
}
Console.WriteLine(r);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace arc094_a {
class Program {
static void Main(string[] args) {
var ABC =
(Console.ReadLine().Split().Select(x => decimal.Parse(x))).ToList();
ABC.Sort();
decimal r = 0;
decimal A = Math.Floor((ABC[2] - ABC[0]) / 2);
r += A;
ABC[0] += A * 2;
decimal B = Math.Floor((ABC[2] - ABC[1]) / 2);
r += B;
ABC[1] += B * 2;
if (ABC[0] == ABC[1] && ABC[1] == ABC[2]) {
} else if (ABC[0] != ABC[1]) {
r += 2;
} else {
r += 1;
}
Console.WriteLine(r);
}
}
}
|
[["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 79], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 196
| 25
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharpSample01 {
class Program {
static void Main(string[] args) {
int[] data =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
Array.Sort(data);
Array.Reverse(data);
int cost = 0;
if ((data[0] % 2 == 0 && data[1] % 2 == 0 && data[2] % 2 == 0) ||
(data[0] % 2 == 1 && data[1] % 2 == 1 && data[2] % 2 == 1)) {
int dai = data[0];
int chu = data[1];
int sho = data[2];
cost = (dai - chu) / 2 + (dai - sho) / 2;
Console.WriteLine(cost);
} else {
int even = 0;
for (int i = 0; i < data.Length; i++) {
if (data[i] % 2 == 0)
even++;
}
if (even == 2) {
for (int i = 0; i < data.Length; i++) {
if (data[i] % 2 == 0)
data[i]++;
Console.WriteLine($"{data[i]}");
}
cost++;
int dai = data[0];
int chu = data[1];
int sho = data[2];
cost += (dai - chu) / 2 + (dai - sho) / 2;
Console.WriteLine(cost);
} else {
for (int i = 0; i < data.Length; i++) {
if (data[i] % 2 == 1)
data[i]++;
}
cost++;
int dai = data[0];
int chu = data[1];
int sho = data[2];
cost += (dai - chu) / 2 + (dai - sho) / 2;
Console.WriteLine(cost);
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharpSample01 {
class Program {
static void Main(string[] args) {
int[] data =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
Array.Sort(data);
Array.Reverse(data);
int cost = 0;
if ((data[0] % 2 == 0 && data[1] % 2 == 0 && data[2] % 2 == 0) ||
(data[0] % 2 == 1 && data[1] % 2 == 1 && data[2] % 2 == 1)) {
int dai = data[0];
int chu = data[1];
int sho = data[2];
cost = (dai - chu) / 2 + (dai - sho) / 2;
Console.WriteLine(cost);
} else {
int even = 0;
for (int i = 0; i < data.Length; i++) {
if (data[i] % 2 == 0)
even++;
}
if (even == 2) {
for (int i = 0; i < data.Length; i++) {
if (data[i] % 2 == 0)
data[i]++;
}
cost++;
int dai = data[0];
int chu = data[1];
int sho = data[2];
cost += (dai - chu) / 2 + (dai - sho) / 2;
Console.WriteLine(cost);
} else {
for (int i = 0; i < data.Length; i++) {
if (data[i] % 2 == 1)
data[i]++;
}
cost++;
int dai = data[0];
int chu = data[1];
int sho = data[2];
cost += (dai - chu) / 2 + (dai - sho) / 2;
Console.WriteLine(cost);
}
}
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 0, 28, 0, 283, 0, 284, 0, 204, 205, 22], ["-", 0, 283, 0, 284, 0, 204, 206, 207, 0, 70], ["-", 0, 284, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 283, 0, 284, 0, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 437
| 14
|
using System;
class test {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int[] n = new int[3];
for (int i = 0; i < 3; i++) {
n[i] = int.Parse(s[i]);
}
Array.Sort(n);
for (int i = 0; i < 3; i++) {
Console.WriteLine(n[i]);
}
int ans = 0;
while (n[0] != n[1] || n[0] != n[2]) {
ans++;
if (n[0] != n[1]) {
n[0] += 2;
} else {
n[0]++;
n[1]++;
}
Array.Sort(n);
}
Console.WriteLine(ans);
}
}
|
using System;
class test {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int[] n = new int[3];
for (int i = 0; i < 3; i++) {
n[i] = int.Parse(s[i]);
}
Array.Sort(n);
int ans = 0;
while (n[0] != n[1] || n[0] != n[2]) {
ans++;
if (n[0] != n[1]) {
n[0] += 2;
} else {
n[0]++;
n[1]++;
}
Array.Sort(n);
}
Console.WriteLine(ans);
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 189
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
public class Contest {
static void Swap<T>(ref T lhs, ref T rhs) {
T temp;
temp = lhs;
lhs = rhs;
rhs = temp;
}
public const long MOD1 = 1000000007L; // 10^9+7
public static void Main() {
int n;
VT<int, int>[] abl;
MyIO.ReadMulti(out n);
MyIO.ReadLines(n, out abl);
foreach (var e in abl) {
int i1 = Math.Min(e.Item1, e.Item2);
int i2 = Math.Max(e.Item1, e.Item2);
int ans = 0;
if (i2 <= i1 + 1) {
ans = 2 * i1 - 2;
} else {
long ab = (long)i1 * (long)i2;
long c = (long)Math.Sqrt(ab);
// while(c*c<ab)c++;
// c--;
if (ab <= c * (c + 1)) {
ans = (int)c * 2 - 2;
} else {
ans = (int)c * 2 - 1;
}
}
MyIO.WriteMulti(ans);
}
}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.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 static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(int n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(int n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(int n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(int n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(int n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
public class Contest {
static void Swap<T>(ref T lhs, ref T rhs) {
T temp;
temp = lhs;
lhs = rhs;
rhs = temp;
}
public const long MOD1 = 1000000007L; // 10^9+7
public static void Main() {
int n;
VT<int, int>[] abl;
MyIO.ReadMulti(out n);
MyIO.ReadLines(n, out abl);
foreach (var e in abl) {
int i1 = Math.Min(e.Item1, e.Item2);
int i2 = Math.Max(e.Item1, e.Item2);
int ans = 0;
if (i2 <= i1 + 1) {
ans = 2 * i1 - 2;
} else {
long ab = (long)i1 * (long)i2;
long c = (long)Math.Sqrt(ab);
while (c * c < ab)
c++;
c--;
if (ab <= c * (c + 1)) {
ans = (int)c * 2 - 2;
} else {
ans = (int)c * 2 - 1;
}
}
MyIO.WriteMulti(ans);
}
}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.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 static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(int n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(int n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(int n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(int n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(int n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
[["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 24], ["+", 75, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 75, 196, 0, 52, 15, 16, 31, 16, 17, 48], ["+", 75, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 25], ["+", 75, 196, 0, 52, 8, 1, 0, 223, 0, 22], ["+", 75, 196, 0, 52, 8, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 196, 0, 52, 8, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 2,024
| 14
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
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() {
int A = NextInt(), B = NextInt(), C = NextInt();
var box = new[] {A, B, C}.OrderByDescending(x => x).ToArray();
var ans = (box[0] - box[1]) / 2;
box[1] += ans * 2;
var ac = (box[0] - box[2]) / 2;
box[2] += ac * 2;
ans += ac;
if (box[0]==box[1]&&box[1]==box[2]) {
ans.WL();
}
else {
(ans+2).WL();
}
return;
}
}
}
}
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 e) => Seq(0, e, 1);
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 Li NextIntList(int n) => Enumerable.Repeat(0, n).Select(x => ReadLine()).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);
public static T[,] GetBox<T>(int h, int w, Func<int, int, T> getFunc) {
var rt = new T[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
rt[i, j] = getFunc(i, j);
}
}
return rt;
}
}
}
namespace CS_Contest.Utils {
using Li = List<int>;
using Ll = List<long>;
[DebuggerStepThrough]
public static class Utils {
public static bool AnyOf<T>(this T @this, params T[] these) where T:IComparable {
return these.Contains(@this);
}
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 Map<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) {
var dic = new Map<TKey, int>();
foreach (var item in l) {
dic[item]++;
}
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 static int LowerBound<T>(this T[] @this, T x) where T : IComparable
{
int lb = -1, ub = @this.Length;
while (ub - lb > 1)
{
int mid = (ub + lb) >> 1;
if (@this[mid].CompareTo(x) >= 0) ub = mid;
else lb = mid;
}
return ub;
}
public static int UpperBound<T>(this T[] @this, T x) where T : IComparable
{
int lb = -1, ub = @this.Length;
while (ub - lb > 1)
{
int mid = (ub + lb) >> 1;
if (@this[mid].CompareTo(x) > 0) ub = mid;
else lb = mid;
}
return ub;
}
}
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.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
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() {
int A = NextInt(), B = NextInt(), C = NextInt();
var box = new[] {A, B, C}.OrderByDescending(x => x).ToArray();
var ans = (box[0] - box[1]) / 2;
//ans.WL();
box[1] += ans * 2;
var ac = (box[0] - box[2]) / 2;
//ac.WL();
box[2] += ac * 2;
ans += ac;
if (box[0]==box[1]&&box[1]==box[2]) {
ans.WL();
}else if (box[1]==box[2]) {
(ans+1).WL();
}
else {
(ans+2).WL();
}
return;
}
}
}
}
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 e) => Seq(0, e, 1);
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 Li NextIntList(int n) => Enumerable.Repeat(0, n).Select(x => ReadLine()).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);
public static T[,] GetBox<T>(int h, int w, Func<int, int, T> getFunc) {
var rt = new T[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
rt[i, j] = getFunc(i, j);
}
}
return rt;
}
}
}
namespace CS_Contest.Utils {
using Li = List<int>;
using Ll = List<long>;
[DebuggerStepThrough]
public static class Utils {
public static bool AnyOf<T>(this T @this, params T[] these) where T:IComparable {
return these.Contains(@this);
}
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 Map<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) {
var dic = new Map<TKey, int>();
foreach (var item in l) {
dic[item]++;
}
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 static int LowerBound<T>(this T[] @this, T x) where T : IComparable
{
int lb = -1, ub = @this.Length;
while (ub - lb > 1)
{
int mid = (ub + lb) >> 1;
if (@this[mid].CompareTo(x) >= 0) ub = mid;
else lb = mid;
}
return ub;
}
public static int UpperBound<T>(this T[] @this, T x) where T : IComparable
{
int lb = -1, ub = @this.Length;
while (ub - lb > 1)
{
int mid = (ub + lb) >> 1;
if (@this[mid].CompareTo(x) > 0) ub = mid;
else lb = mid;
}
return ub;
}
}
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, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 1, 0, 213, 63, 214, 205, 23, 0, 24], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 31, 22], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 17, 72], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 213, 63, 214, 205, 23, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45]]
| 8
| 2,087
| 25
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Channels;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() {
var array = Array();
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
public long[] LongArray() {
var array = Array();
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
}
class Program {
private int[] A;
public void Solve() {
var sc = new Scanner();
A = sc.IntArray();
Array.Sort(A);
int ans = 0;
ans += A[2] - A[1];
A[0] += ans;
var aa = (A[2] - A[0]) / 2;
A[0] += 2 * aa;
ans += aa;
Console.WriteLine(ans);
}
static void Main(string[] args) { new Program().Solve(); }
}
}
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Channels;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() {
var array = Array();
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
public long[] LongArray() {
var array = Array();
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
}
class Program {
private int[] A;
public void Solve() {
var sc = new Scanner();
A = sc.IntArray();
Array.Sort(A);
int ans = 0;
var bb = A[2] - A[1];
A[0] += bb;
A[1] = A[2];
var aa = (A[2] - A[0]) / 2;
A[0] += 2 * aa;
ans = aa + bb;
if (A[2] - A[0] == 1) {
ans += 2;
}
Console.WriteLine(ans);
}
static void Main(string[] args) { new Program().Solve(); }
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 436
| 41
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
string S = re.s();
if (S.Length <= 4) {
sb.Append(SolveSimple(S) + "\n");
return;
}
{
bool AllSame = true;
for (int i = 0; i < S.Length - 1; i++) {
AllSame &= S[i] == S[i + 1];
}
if (AllSame) {
sb.Append("1\n");
return;
}
}
long[,,,] DP = new long[S.Length, 3, 3, 2];
DP[0, 0, 0, 0] = 1;
DP[0, 1, 1, 0] = 1;
DP[0, 2, 2, 0] = 1;
for (int i = 0; i < S.Length - 1; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
for (int l = 0; l < 3; l++) {
DP[i + 1, l, (k + l) % 3, j == l ? 1 : 0] =
(DP[i + 1, l, (k + l) % 3, j == l ? 1 : 0] + DP[i, j, k, 0]) %
Define.mod;
DP[i + 1, l, (k + l) % 3, 1] =
(DP[i + 1, l, (k + l) % 3, 1] + DP[i, j, k, 1]) % Define.mod;
}
}
}
}
bool alldiff = true;
int c = 0;
for (int i = 0; i < S.Length - 1; i++) {
alldiff &= S[i] != S[i + 1];
c += S[i] - 'a';
}
c %= 3;
long count = DP[S.Length - 1, 0, c, 1] + DP[S.Length - 1, 1, c, 1] +
DP[S.Length - 1, 2, c, 1];
if (alldiff) {
count++;
}
count %= Define.mod;
sb.Append(count + "\n");
}
int SolveSimple(string s) {
int N = s.Length;
int pow = 1;
int c = 0;
for (int i = 0; i < N; i++) {
c *= 3;
if (s[i] == 'a') {
} else if (s[i] == 'b') {
c++;
} else {
c += 2;
}
pow *= 3;
}
bool[] OK = new bool[pow];
dfs(OK, c, N);
int count = 0;
for (int i = 0; i < pow; i++) {
if (OK[i]) {
count++;
// string ans = "";
// int d = i;
// for(int j=0;j<N;j++){
// char ax = (char)('a' + d % 3);
// d /= 3;
// ans = ax + ans;
// }
// Console.WriteLine(ans);
}
}
return count;
}
void dfs(bool[] OK, int c, int N) {
if (OK[c]) {
return;
}
OK[c] = true;
int[] S = new int[N];
int cc = c;
for (int i = N - 1; i >= 0; i--) {
S[i] = cc % 3;
cc /= 3;
}
int pow = 1;
for (int i = N - 1; i > 0; i--) {
if (S[i] != S[i - 1]) {
bool[] used = new bool[3];
used[S[i]] = true;
used[S[i - 1]] = true;
int a = -1;
for (int j = 0; j < 3; j++) {
if (!used[j]) {
a = j;
}
}
int newc = c - pow * S[i] - pow * 3 * S[i - 1] + pow * 4 * a;
dfs(OK, newc, N);
}
pow *= 3;
}
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 998244353; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
string S = re.s();
if (S.Length <= 4) {
sb.Append(SolveSimple(S) + "\n");
return;
}
{
bool AllSame = true;
for (int i = 0; i < S.Length - 1; i++) {
AllSame &= S[i] == S[i + 1];
}
if (AllSame) {
sb.Append("1\n");
return;
}
}
long[,,,] DP = new long[S.Length, 3, 3, 2];
DP[0, 0, 0, 0] = 1;
DP[0, 1, 1, 0] = 1;
DP[0, 2, 2, 0] = 1;
for (int i = 0; i < S.Length - 1; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
for (int l = 0; l < 3; l++) {
DP[i + 1, l, (k + l) % 3, j == l ? 1 : 0] =
(DP[i + 1, l, (k + l) % 3, j == l ? 1 : 0] + DP[i, j, k, 0]) %
Define.mod;
DP[i + 1, l, (k + l) % 3, 1] =
(DP[i + 1, l, (k + l) % 3, 1] + DP[i, j, k, 1]) % Define.mod;
}
}
}
}
bool alldiff = true;
int c = 0;
for (int i = 0; i < S.Length - 1; i++) {
alldiff &= S[i] != S[i + 1];
}
for (int i = 0; i < S.Length; i++) {
c += S[i] - 'a';
}
c %= 3;
long count = DP[S.Length - 1, 0, c, 1] + DP[S.Length - 1, 1, c, 1] +
DP[S.Length - 1, 2, c, 1];
if (alldiff) {
count++;
}
count %= Define.mod;
sb.Append(count + "\n");
}
int SolveSimple(string s) {
int N = s.Length;
int pow = 1;
int c = 0;
for (int i = 0; i < N; i++) {
c *= 3;
if (s[i] == 'a') {
} else if (s[i] == 'b') {
c++;
} else {
c += 2;
}
pow *= 3;
}
bool[] OK = new bool[pow];
dfs(OK, c, N);
int count = 0;
for (int i = 0; i < pow; i++) {
if (OK[i]) {
count++;
// string ans = "";
// int d = i;
// for(int j=0;j<N;j++){
// char ax = (char)('a' + d % 3);
// d /= 3;
// ans = ax + ans;
// }
// Console.WriteLine(ans);
}
}
return count;
}
void dfs(bool[] OK, int c, int N) {
if (OK[c]) {
return;
}
OK[c] = true;
int[] S = new int[N];
int cc = c;
for (int i = N - 1; i >= 0; i--) {
S[i] = cc % 3;
cc /= 3;
}
int pow = 1;
for (int i = N - 1; i > 0; i--) {
if (S[i] != S[i - 1]) {
bool[] used = new bool[3];
used[S[i]] = true;
used[S[i - 1]] = true;
int a = -1;
for (int j = 0; j < 3; j++) {
if (!used[j]) {
a = j;
}
}
int newc = c - pow * S[i] - pow * 3 * S[i - 1] + pow * 4 * a;
dfs(OK, newc, N);
}
pow *= 3;
}
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 998244353; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45]]
| 8
| 2,524
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass {
static void Main() {
var S = ReadLine();
var C = new List<char>();
for (int i = 0; i < 26; i++) {
C.Add((char)('a' + i));
}
foreach (var i in S) {
C.Remove(i);
}
if (C.Count > 0) {
WriteLine(S + C[0]);
} else {
if (S != "")
WriteLine(next(S.ToCharArray()));
}
}
static string next(char[] S) {
var list = new List<char>();
for (int i = S.Length - 1; i >= 0; i--) {
foreach (var j in list) {
if (j > S[i]) {
string ans = string.Join("", S).Substring(0, i);
return ans + j;
}
}
}
return "-1";
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass {
static void Main() {
var S = ReadLine();
var C = new List<char>();
for (int i = 0; i < 26; i++) {
C.Add((char)('a' + i));
}
foreach (var i in S) {
C.Remove(i);
}
if (C.Count > 0) {
WriteLine(S + C[0]);
} else {
if (S != "")
WriteLine(next(S.ToCharArray()));
}
}
static string next(char[] S) {
var list = new List<char>();
for (int i = S.Length - 1; i >= 0; i--) {
foreach (var j in list) {
if (j > S[i]) {
string ans = string.Join("", S).Substring(0, i);
return ans + j;
}
}
list.Add(S[i]);
}
return "-1";
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 238
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
string s = sc.Next();
if (s == "zyxwvutsrqponmlkjihgfedcba") {
Console.WriteLine(-1);
return;
}
bool[] exist = new bool[26];
foreach (var c in s) {
exist[c - 'a'] = true;
}
if (s.Length < 26) {
string answer = s;
for (int i = 0; i < 26; i++) {
if (!exist[i]) {
answer += ((char)('a' + i)).ToString();
break;
}
}
Console.WriteLine(answer);
return;
} else {
List<char> keep = new List<char>();
char[] reverse = s.Reverse().ToArray();
for (int i = 0; i < reverse.Length; i++) {
if (i == 0) {
keep.Add(reverse[i]);
continue;
}
if (reverse[i] < reverse[i - 1]) {
char append = keep.OrderBy(c => c).First();
string before = s.Substring(0, 26 - i - 1);
string answer = before + append.ToString();
Console.WriteLine(answer);
return;
}
keep.Add(reverse[i]);
}
}
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
string s = sc.Next();
if (s == "zyxwvutsrqponmlkjihgfedcba") {
Console.WriteLine(-1);
return;
}
if (s.Length < 26) {
bool[] exist = new bool[26];
foreach (var c in s) {
exist[c - 'a'] = true;
}
string answer = s;
for (int i = 0; i < 26; i++) {
if (!exist[i]) {
answer += ((char)('a' + i)).ToString();
break;
}
}
Console.WriteLine(answer);
return;
} else {
List<char> keep = new List<char>();
char[] reverse = s.Reverse().ToArray();
for (int i = 0; i < reverse.Length; i++) {
if (i == 0) {
keep.Add(reverse[i]);
continue;
}
if (reverse[i] < reverse[i - 1]) {
char append = keep.Where(c => c > reverse[i]).OrderBy(c => c).First();
string before = s.Substring(0, 26 - i - 1);
string answer = before + append.ToString();
Console.WriteLine(answer);
return;
}
keep.Add(reverse[i]);
}
}
}
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();
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 0, 28, 0, 218, 8, 16, 12, 204, 205, 22], ["+", 0, 218, 8, 16, 12, 204, 206, 207, 0, 70], ["+", 8, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 218, 8, 16, 12, 204, 206, 207, 0, 73], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
| 8
| 613
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Numerics;
using System.Threading;
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);
/*var th = new Thread(Run, 1 << 26);
th.Start();
th.Join();*/
Run();
// Console.Out.Flush();
}
static void Run() {
int t = 1;
for (var _ = 0; _ < t; _++)
Solve();
}
static void Solve() {
var s = Str;
if (s == "zyxwvutsrqponmlkjihgfedcba") {
OutL(-1);
return;
}
if (s.Length < 26) {
for (var c = 'a'; c <= 'z'; c++) {
if (!s.Contains(c)) {
OutL(s + c);
return;
}
}
} else {
var used = new int[26];
Initialize(ref used, 1);
for (var i = s.Length - 1; i >= 0; i--) {
for (var c = s[i] - 'a' + 1; c < 26; c++) {
if (used[c] == 0) {
OutL(s.Substring(0, i) + (char)(s[i] + 1));
return;
}
}
used[s[i] - 'a']--;
}
}
}
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 Input<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
d = Conv<W>(q[3]);
e = Conv<X>(q[4]);
}
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 Gcd(long a, long b) {
if (a == 0 || b == 0)
return Max(a, b);
return a % b == 0 ? b : Gcd(b, a % b);
}
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 System.Threading;
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);
/*var th = new Thread(Run, 1 << 26);
th.Start();
th.Join();*/
Run();
// Console.Out.Flush();
}
static void Run() {
int t = 1;
for (var _ = 0; _ < t; _++)
Solve();
}
static void Solve() {
var s = Str;
if (s == "zyxwvutsrqponmlkjihgfedcba") {
OutL(-1);
return;
}
if (s.Length < 26) {
for (var c = 'a'; c <= 'z'; c++) {
if (!s.Contains(c)) {
OutL(s + c);
return;
}
}
} else {
var used = new int[26];
Initialize(ref used, 1);
for (var i = s.Length - 1; i >= 0; i--) {
for (var c = s[i] - 'a' + 1; c < 26; c++) {
if (used[c] == 0) {
OutL(s.Substring(0, i) + (char)(c + 'a'));
return;
}
}
used[s[i] - 'a']--;
}
}
}
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 Input<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
d = Conv<W>(q[3]);
e = Conv<X>(q[4]);
}
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 Gcd(long a, long b) {
if (a == 0 || b == 0)
return Max(a, b);
return a % b == 0 ? b : Gcd(b, a % b);
}
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));
}
}
|
[["-", 12, 74, 51, 23, 0, 16, 31, 204, 205, 22], ["-", 51, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 51, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 16, 12, 74, 51, 23, 0, 16, 31, 22], ["-", 0, 16, 12, 74, 51, 23, 0, 16, 12, 203], ["+", 12, 74, 51, 23, 0, 16, 12, 252, 0, 104], ["+", 12, 74, 51, 23, 0, 16, 12, 252, 0, 253]]
| 8
| 1,915
| 9
|
using System;
using System.Linq;
namespace AGC022 {
class A {
static void Main(string[] args) {
// input
string S = Console.ReadLine();
//文字用の配列と、Sで使われている文字のカウント
int[] C = new int[26];
for (int i = 0; i < S.Length; i++) {
C[S[i] - 'a']++;
}
int sum = C.Sum();
//|S| < 26のとき
////使われていない文字で、一番最小のものを最後につける
if (sum < 26) {
for (int i = 0; i < C.Length; i++) {
if (C[i] == 0) {
Console.WriteLine(S + (char)(i + (int)'a'));
return;
}
}
} else {
int num = 0;
for (int i = S.Length - 1; 0 < i; i--) {
if (S[i] > S[i - 1]) {
num = i;
break;
}
if (i == 1) {
Console.WriteLine(-1);
return;
}
}
int c = int.MaxValue;
string s1 = "";
for (int i = S.Length - 1; num <= i; i--) {
int temp = (int)S[num - 1] - (int)S[i];
if (temp < 0 && temp < c) {
c = temp;
s1 = S[i].ToString();
}
}
string sub = S.Substring(0, num - 1) + s1;
Console.WriteLine(sub);
}
}
}
}
|
using System;
using System.Linq;
namespace AGC022 {
class A {
static void Main(string[] args) {
// input
string S = Console.ReadLine();
//文字用の配列と、Sで使われている文字のカウント
int[] C = new int[26];
for (int i = 0; i < S.Length; i++) {
C[S[i] - 'a']++;
}
int sum = C.Sum();
//|S| < 26のとき
////使われていない文字で、一番最小のものを最後につける
if (sum < 26) {
for (int i = 0; i < C.Length; i++) {
if (C[i] == 0) {
Console.WriteLine(S + (char)(i + (int)'a'));
return;
}
}
} else {
int num = 0;
for (int i = S.Length - 1; 0 < i; i--) {
if (S[i] > S[i - 1]) {
num = i;
break;
}
if (i == 1) {
Console.WriteLine(-1);
return;
}
}
int c = int.MaxValue;
string s1 = "";
for (int i = S.Length - 1; num <= i; i--) {
int temp = (int)S[num - 1] - (int)S[i];
int temp2 = Math.Abs(temp);
if (temp < 0 && temp2 < c) {
c = temp;
s1 = S[i].ToString();
}
}
string sub = S.Substring(0, num - 1) + s1;
Console.WriteLine(sub);
}
}
}
}
|
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
| 8
| 323
| 12
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var S = Console.ReadLine();
var dict = new Dictionary<char, int>();
foreach (var c in S) {
dict[c] = 1;
}
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var ans = "";
if (S.Length == 26) {
if (S[S.Length - 1] == 'a') {
Console.WriteLine(-1);
return;
}
Console.WriteLine(nextString(S));
} else {
foreach (var a in alphabet) {
if (!dict.ContainsKey(a)) {
ans = a.ToString();
break;
}
}
Console.WriteLine(S + ans);
}
}
static string nextString(string s) {
List<char> c = s.ToList();
bool[] isUsed = new bool[26];
for (int i = 0; i < c.Count; i++)
isUsed[c[i] - 'a'] = true;
for (int i = c.Count - 1; i >= 0; i--) {
char item = c[i];
for (int j = item - 'a'; j < isUsed.Length; j++) {
if (!isUsed[j]) {
c[i] = char.ConvertFromUtf32(j + 'a')[0];
goto end;
}
}
isUsed[item - 'a'] = false;
c.RemoveAt(c.Count - 1);
}
end:;
return string.Join("", c);
}
static bool isTasai(string s) => s.Distinct().Count() == s.Count();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var S = Console.ReadLine();
var dict = new Dictionary<char, int>();
foreach (var c in S) {
dict[c] = 1;
}
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var ans = "";
if (S.Length == 26) {
if (S == "zyxwvutsrqponmlkjihgfedcba") {
Console.WriteLine(-1);
return;
}
Console.WriteLine(nextString(S));
} else {
foreach (var a in alphabet) {
if (!dict.ContainsKey(a)) {
ans = a.ToString();
break;
}
}
Console.WriteLine(S + ans);
}
}
static string nextString(string s) {
List<char> c = s.ToList();
bool[] isUsed = new bool[26];
for (int i = 0; i < c.Count; i++)
isUsed[c[i] - 'a'] = true;
for (int i = c.Count - 1; i >= 0; i--) {
char item = c[i];
for (int j = item - 'a'; j < isUsed.Length; j++) {
if (!isUsed[j]) {
c[i] = char.ConvertFromUtf32(j + 'a')[0];
goto end;
}
}
isUsed[item - 'a'] = false;
c.RemoveAt(c.Count - 1);
}
end:;
return string.Join("", c);
}
static bool isTasai(string s) => s.Distinct().Count() == s.Count();
}
}
|
[["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["-", 64, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 64, 196, 0, 57, 15, 16, 12, 5, 0, 62], ["+", 64, 196, 0, 57, 15, 16, 12, 5, 0, 222]]
| 8
| 379
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var s = Console.ReadLine();
Console.WriteLine(WriteMsg(s));
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
static int[] alphabets = Enumerable.Range('a', 26).ToArray();
private static string WriteMsg(string s) {
if (s.Length < 26) {
var suffixChar = alphabets.Where(i => !s.Contains((char)i)).Min();
return s + (char)suffixChar;
}
char pChar = s[25];
for (int i = 24; i >= 0; i--) {
var leftChar = s[i];
if (leftChar > pChar) {
continue;
}
var prefix = s.Take(i).ToArray();
var suffix = s.Skip(i).Where(c => leftChar < c).Min().ToString();
return new string(prefix) + suffix;
}
return "-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 MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
/// <summary>nCr, 組み合わせ</summary>
public static long Combination(int n, int r) {
if (r == 0) {
return 1;
}
// 分子
var moleculeArr =
Enumerable.Range(0, Math.Min(n - r, r)).Select(i => n - i).ToArray();
var moleculeArrLength = moleculeArr.Length;
// 分母
var denominatorArr = Enumerable.Range(1, Math.Max(n - r, r)).ToArray();
for (var m = 0; m < moleculeArrLength; m++) {
while (true) {
var mVal = moleculeArr[m];
var gcds = denominatorArr.Select(b => Gcd(mVal, b));
var maxGcd = gcds.Max();
var maxI = gcds.ToList().IndexOf(maxGcd);
if (maxGcd == 1) {
break;
}
denominatorArr[maxI] /= maxGcd;
moleculeArr[m] /= maxGcd;
}
}
return FullPower(moleculeArr);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static int Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
var mod = a % b;
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return (int)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);
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)value % mod;
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
long value = item1.Value + item2;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
long value = Math.BigMul(item1.Value, item2);
return new ModInt(value, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var s = Console.ReadLine();
Console.WriteLine(WriteMsg(s));
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
static int[] alphabets = Enumerable.Range('a', 26).ToArray();
private static string WriteMsg(string s) {
if (s.Length < 26) {
var suffixChar = alphabets.Where(i => !s.Contains((char)i)).Min();
return s + (char)suffixChar;
}
char pChar = s[25];
for (int i = 24; i >= 0; i--) {
var topChar = pChar;
pChar = s[i];
if (topChar < pChar) {
continue;
}
var prefix = s.Take(i).ToArray();
var suffix = s.Skip(i).Where(c => pChar < c).Min().ToString();
return new string(prefix) + suffix;
}
return "-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 MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
/// <summary>nCr, 組み合わせ</summary>
public static long Combination(int n, int r) {
if (r == 0) {
return 1;
}
// 分子
var moleculeArr =
Enumerable.Range(0, Math.Min(n - r, r)).Select(i => n - i).ToArray();
var moleculeArrLength = moleculeArr.Length;
// 分母
var denominatorArr = Enumerable.Range(1, Math.Max(n - r, r)).ToArray();
for (var m = 0; m < moleculeArrLength; m++) {
while (true) {
var mVal = moleculeArr[m];
var gcds = denominatorArr.Select(b => Gcd(mVal, b));
var maxGcd = gcds.Max();
var maxI = gcds.ToList().IndexOf(maxGcd);
if (maxGcd == 1) {
break;
}
denominatorArr[maxI] /= maxGcd;
moleculeArr[m] /= maxGcd;
}
}
return FullPower(moleculeArr);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static int Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
var mod = a % b;
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return (int)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);
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)value % mod;
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
long value = item1.Value + item2;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
long value = Math.BigMul(item1.Value, item2);
return new ModInt(value, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22]]
| 8
| 1,786
| 12
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
public class A {
public static void Main() {
string S = GetString();
int[] tmp = new int[S.Length];
for (int i = 0; i < S.Length; i++)
tmp[i] = (int)(S[i] - 'a');
if (S.Length < 26) {
int flag = 0;
for (int i = 0; i < S.Length; i++)
flag |= (1 << (int)(S[i] - 'a'));
Console.WriteLine(S + firstChar(flag).ToString());
return;
} else {
int iPivot = S.Length - 2;
for (; iPivot >= 0; iPivot--) {
if (tmp[iPivot] <= tmp[iPivot + 1])
break;
}
if (iPivot < 0) {
Console.WriteLine(-1);
return;
}
int iMin = iPivot + 1;
for (int i = iPivot + 2; i < S.Length; i++)
if (tmp[i] < tmp[iMin])
iMin = i;
Console.WriteLine(S.Substring(0, iPivot) +
((char)(tmp[iMin] + 'a')).ToString());
}
}
private static char firstChar(int flag) {
for (int i = 0; i < 26; i++) {
if (((flag >> i) & 1) == 1)
continue;
return (char)('a' + i);
}
return '\0';
}
}
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 System.Linq;
using static MyIO;
public class A {
public static void Main() {
string S = GetString();
int[] tmp = new int[S.Length];
for (int i = 0; i < S.Length; i++)
tmp[i] = (int)(S[i] - 'a');
if (S.Length < 26) {
int flag = 0;
for (int i = 0; i < S.Length; i++)
flag |= (1 << (int)(S[i] - 'a'));
Console.WriteLine(S + firstChar(flag).ToString());
return;
} else {
int iPivot = S.Length - 2;
for (; iPivot >= 0; iPivot--) {
if (tmp[iPivot] <= tmp[iPivot + 1])
break;
}
if (iPivot < 0) {
Console.WriteLine(-1);
return;
}
int pivot = tmp[iPivot];
int replace = int.MaxValue;
for (int i = iPivot + 1; i < S.Length; i++) {
if (tmp[i] < pivot)
continue;
replace = Math.Min(replace, tmp[i]);
}
Console.WriteLine(S.Substring(0, iPivot) +
((char)(replace + 'a')).ToString());
}
}
private static char firstChar(int flag) {
for (int i = 0; i < 26; i++) {
if (((flag >> i) & 1) == 1)
continue;
return (char)('a' + i);
}
return '\0';
}
}
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(); }
}
|
[["-", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 7, 8, 57, 64, 1, 0, 11, 31, 22], ["-", 8, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 74, 51, 23, 0, 16, 31, 204, 205, 22], ["-", 51, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 51, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 205, 23, 0, 74, 51, 23, 0, 16, 31, 22]]
| 8
| 504
| 40
|
using System;
using System.Collections.Generic;
using System.Linq;
using console = System.Console;
namespace AtCoderTemplate {
public class App {
public static void Main(string[] args) {
args = new string[2];
args[0] = console.ReadLine();
if (args[0].Count() == 26) {
args[1] = (25 - args[0]
.Skip(1)
.Zip(args[0], (a, b) => a - b)
.Reverse()
.TakeWhile(i => i < 0)
.Count())
.ToString();
if (args[1][0] == 0)
console.WriteLine(-1);
else {
var s = args[0].Take(args[1][0]).ToArray();
s[args[1][0] - 1] = args[0].Last(c => c > s[args[1][0] - 1]);
console.WriteLine(s);
}
} else
console.WriteLine(args[0] +
(char)('a' + args[0]
.OrderBy(c => c)
.Where((c, i) => c - i == 'a')
.Count()));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using console = System.Console;
namespace AtCoderTemplate {
public class App {
public static void Main(string[] args) {
args = new string[3];
args[0] = console.ReadLine();
if (args[0].Count() == 26) {
args[1] = ((char)(25 - args[0]
.Skip(1)
.Zip(args[0], (a, b) => a - b)
.Reverse()
.TakeWhile(i => i < 0)
.Count()))
.ToString();
if (args[1][0] == 0)
console.WriteLine(-1);
else {
var s =
args[0]
.Take(args[1][0])
.Select((v, i) =>
i == args[1][0] - 1
? args[0].Last(c => c > args[0][args[1][0] - 1])
: v);
console.WriteLine(string.Join("", s));
}
} else
console.WriteLine(args[0] +
(char)('a' + args[0]
.OrderBy(c => c)
.Where((c, i) => c - i == 'a')
.Count()));
}
}
}
|
[["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 11, 12, 213, 63, 214, 205, 23, 0, 24], ["+", 12, 213, 63, 214, 205, 23, 0, 74, 39, 199], ["+", 12, 213, 63, 214, 205, 23, 0, 74, 0, 25], ["+", 63, 214, 205, 23, 0, 74, 51, 23, 0, 24], ["+", 51, 23, 0, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["-", 64, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["-", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 41, 15, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 41, 15, 16, 17, 60], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 0, 101], ["-", 0, 28, 0, 218, 8, 16, 12, 204, 205, 22], ["+", 0, 218, 8, 16, 12, 204, 205, 204, 205, 22], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 218, 8, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 218, 8, 41, 64, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 75, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 279
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using console = System.Console;
namespace AtCoderTemplate {
public class App {
public static void Main(string[] args) {
args = new string[2];
args[0] = console.ReadLine();
if (args[0].Count() == 26) {
args[1] = (25 - args[0]
.Skip(1)
.Zip(args[0], (a, b) => a - b)
.Reverse()
.TakeWhile(i => i < 0)
.Count())
.ToString();
if (args[1][0] == 0)
console.WriteLine(-1);
else {
var s = args[0].Take(args[1][0]).ToArray();
s[args[1][0] - 1] = args[0].Last(c => c > s[args[1][0] - 1]);
console.WriteLine(s);
}
} else
console.WriteLine(args[0] +
(char)('a' + args[0]
.OrderBy(c => c)
.Where((c, i) => c - i == 'a')
.Count()));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using console = System.Console;
namespace AtCoderTemplate {
public class App {
public static void Main(string[] args) {
args = new string[2];
args[0] = console.ReadLine();
if (args[0].Count() == 26) {
args[1] = ((char)(25 - args[0]
.Skip(1)
.Zip(args[0], (a, b) => a - b)
.Reverse()
.TakeWhile(i => i < 0)
.Count()))
.ToString();
if (args[1][0] == 0)
console.WriteLine(-1);
else {
var s = args[0].Take(args[1][0]).ToArray();
s[args[1][0] - 1] = args[0].Last(c => c > s[args[1][0] - 1]);
console.WriteLine(string.Join("", s));
}
} else
console.WriteLine(args[0] +
(char)('a' + args[0]
.OrderBy(c => c)
.Where((c, i) => c - i == 'a')
.Count()));
}
}
}
|
[["+", 12, 213, 63, 214, 205, 23, 0, 74, 0, 24], ["+", 12, 213, 63, 214, 205, 23, 0, 74, 39, 199], ["+", 12, 213, 63, 214, 205, 23, 0, 74, 0, 25], ["+", 63, 214, 205, 23, 0, 74, 51, 23, 0, 24], ["+", 51, 23, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 279
| 13
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
List<char> usable = new List<char>();
for (int i = 0; i < 26; i++)
usable.Add((char)('a' + i));
foreach (char c in s)
usable.Remove(c);
if (usable.Count > 0)
Console.WriteLine(s + usable[0].ToString());
else {
int i = 25;
while (true) {
usable.Add(s[i]);
usable.Sort();
if (s[i - 1] < usable[0]) {
Console.WriteLine(s.Substring(0, i - 1) + usable[0].ToString());
break;
}
i--;
if (i == 0) {
Console.WriteLine(-1);
break;
}
}
}
}
}
// mcs Main.cs
// mono Main.exe
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
List<char> usable = new List<char>();
for (int i = 0; i < 26; i++)
usable.Add((char)('a' + i));
foreach (char c in s)
usable.Remove(c);
if (usable.Count > 0)
Console.WriteLine(s + usable[0].ToString());
else {
int i = 25;
while (true) {
usable.Add(s[i]);
usable.Sort();
foreach (char c in usable) {
if (s[i - 1] < c) {
Console.WriteLine(s.Substring(0, i - 1) + c.ToString());
return;
}
}
i--;
if (i == 0) {
Console.WriteLine(-1);
break;
}
}
}
}
}
// mcs Main.cs
// mono Main.exe
|
[["+", 75, 196, 0, 52, 8, 196, 0, 210, 0, 266], ["+", 75, 196, 0, 52, 8, 196, 0, 210, 0, 24], ["+", 75, 196, 0, 52, 8, 196, 0, 210, 39, 199], ["+", 75, 196, 0, 52, 8, 196, 0, 210, 31, 22], ["+", 75, 196, 0, 52, 8, 196, 0, 210, 0, 267], ["+", 75, 196, 0, 52, 8, 196, 0, 210, 12, 22], ["+", 75, 196, 0, 52, 8, 196, 0, 210, 0, 25], ["+", 0, 52, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 16, 12, 213, 63, 214, 205, 204, 205, 22], ["-", 12, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["-", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["-", 12, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 212
| 21
|
using System;
using System.Collections.Generic;
namespace Practice {
class Program {
static void Main(string[] args) { Solve(); }
private const int MOD = 1000000007;
static void Solve() {
var s = Console.ReadLine();
if (s == "zyxwvutsrqponmlkjihgfedcba") {
Console.WriteLine(-1);
return;
}
if (s.Length == 26) {
bool[] use = new bool[26];
for (int i = s.Length - 1; i >= 0; --i) {
if (s[i - 1] > s[i]) {
use[s[i] - 'a'] = true;
continue;
}
char p = 'a';
for (int j = 0; j < use.Length; ++j) {
p = (char)(j + 'a');
if (use[i] && s[i - 1] < p) {
break;
}
}
string sub = s.Substring(0, i - 1);
string ans = sub + p;
Console.WriteLine(ans);
return;
}
} else {
bool[] use = new bool[26];
for (int i = 0; i < s.Length; ++i) {
int idx = s[i] - 'a';
use[idx] = true;
}
char c = 'a';
for (int i = 0; i < use.Length; ++i) {
if (!use[i]) {
c = (char)(i + 'a');
break;
}
}
string ans = s + c;
Console.WriteLine(ans);
}
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
namespace Practice {
class Program {
static void Main(string[] args) { Solve(); }
private const int MOD = 1000000007;
static void Solve() {
var s = Console.ReadLine();
if (s == "zyxwvutsrqponmlkjihgfedcba") {
Console.WriteLine(-1);
return;
}
if (s.Length == 26) {
bool[] use = new bool[26];
for (int i = s.Length - 1; i >= 0; --i) {
use[s[i] - 'a'] = true;
if (s[i - 1] > s[i]) {
continue;
}
char p = 'a';
for (int j = 0; j < use.Length; ++j) {
p = (char)(j + 'a');
if (use[j] && s[i - 1] < p) {
break;
}
}
string sub = s.Substring(0, i - 1);
string ans = sub + p;
Console.WriteLine(ans);
return;
}
} else {
bool[] use = new bool[26];
for (int i = 0; i < s.Length; ++i) {
int idx = s[i] - 'a';
use[idx] = true;
}
char c = 'a';
for (int i = 0; i < use.Length; ++i) {
if (!use[i]) {
c = (char)(i + 'a');
break;
}
}
string ans = s + c;
Console.WriteLine(ans);
}
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 206, 207, 0, 28, 0, 16, 12, 252, 0, 104], ["+", 206, 207, 0, 28, 0, 16, 12, 252, 0, 253], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 64, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 206, 207, 0, 28, 0, 16, 12, 252, 0, 104], ["-", 206, 207, 0, 28, 0, 16, 12, 252, 0, 253], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 951
| 30
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
string A = "abcdefghijklmnopqrstuvwxyz";
int[] n = new int[26];
for (var i = 0; i < S.Length; i++) {
n[i] = A.IndexOf(S.Substring(i, 1)) + 1;
}
if (S.Length < 26) {
for (var j = 0; j <= 25; j++) {
if (S.IndexOf(A.Substring(j, 1)) == -1) {
S += A.Substring(j, 1);
break;
}
}
} else {
int t = 0;
for (var i = 24; i >= 0; i--) {
for (var j = i + 1; j < 26; j++) {
if (n[j] > n[i]) {
n[i] += 1;
for (var k = i + 1; k < 26; k++) {
n[k] = 0;
}
t = 1;
break;
}
}
if (t == 1) {
break;
}
}
if (t == 0) {
S = "-1";
} else {
string S2 = "";
for (var i = 0; i < 26; i++) {
if (n[i] > 0) {
S2 += A.Substring(n[i] - 1, 1);
}
}
S = S2;
}
}
Console.WriteLine(S);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
string A = "abcdefghijklmnopqrstuvwxyz";
int[] n = new int[26];
for (var i = 0; i < S.Length; i++) {
n[i] = A.IndexOf(S.Substring(i, 1)) + 1;
}
if (S.Length < 26) {
for (var j = 0; j <= 25; j++) {
if (S.IndexOf(A.Substring(j, 1)) == -1) {
S += A.Substring(j, 1);
break;
}
}
} else {
int t = 0;
for (var i = 24; i >= 0; i--) {
for (var j = i + 1; j < 26; j++) {
if (n[j] > n[i]) {
while (n[i] < 26) {
n[i] += 1;
if (Array.IndexOf(n, n[i]) == i) {
break;
}
}
for (var k = i + 1; k < 26; k++) {
n[k] = 0;
}
t = 1;
break;
}
}
if (t == 1) {
break;
}
}
if (t == 0) {
S = "-1";
} else {
string S2 = "";
for (var i = 0; i < 26; i++) {
if (n[i] > 0) {
S2 += A.Substring(n[i] - 1, 1);
}
}
S = S2;
}
}
Console.WriteLine(S);
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 57, 64, 196, 0, 52, 0, 24], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 52, 0, 25], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 21], ["+", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46]]
| 8
| 332
| 31
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
class Program {
static int[] dx = new int[] { 0, 0, 1, -1 };
static int[] dy = new int[] { 1, -1, 0, 0 };
const int INF = 1010101010;
static void Solve() {
var s = sc.Str();
var used = new bool[30];
if (s == "zyxwvutsrqponmlkjihgfedcba") {
pr.WriteLine(-1);
return;
}
foreach (var c in s)
used[c - 'a'] = true;
if (s.Length == 'z' - 'a' + 1) {
for (var i = s.Length - 2; 0 <= i; i--) {
if (s[i] < s[i + 1]) {
pr.Write(s.Substring(0, i));
pr.WriteLine((char)s.Substring(i + 1).Min());
break;
}
}
} else {
pr.Write(s);
pr.WriteLine((char)('a' + Array.IndexOf(used, false)));
}
}
class Node : IComparable {
public int Id;
public int Cost;
public int CompareTo(object obj) { return ((Node)obj).Cost - Cost; }
public override string ToString() {
return $"Id: {this.Id} - Cost: {this.Cost}";
}
}
class Edge {
public int To;
public int Cost;
}
static double F(double prev, double next, double t) {
return Math.Pow(Math.Exp((next - prev) / t), 2);
}
static int[,] Mul(int[,] a, int[,] b) {
var ret = new int[a.GetLength(0), b.GetLength(1)];
for (int i = 0; i < a.GetLength(0); i++)
for (int j = 0; j < b.GetLength(1); j++)
for (int k = 0; k < a.GetLength(1); k++)
ret[i, j] += a[i, k] * b[k, j];
return ret;
}
static int[,] Pow(int[,] a, int n) {
var b = new int[a.GetLength(1), a.GetLength(0)];
var f = n % 2 == 1;
for (int i = 0; i < a.GetLength(0); i++)
b[i, i] = 1;
while (n > 0) {
if (n % 2 == 1)
b = Mul(a, b);
n >>= 1;
}
return b;
}
class Coord {
public int x;
public int y;
}
static void Main(string[] args) {
pr.AutoFlush = true;
Solve();
pr.Flush();
// Console.ReadKey();
}
static Scanner sc = new Scanner();
static Printer pr = new Printer();
}
class Heap<T>
where T : IComparable {
private List<T> _heap;
private int _last;
private int _cnt;
private IComparer<T> _comparer;
public Heap() {
_heap = new List<T>();
_last = 0;
}
public Heap(IEnumerable<T> e) {
_heap = new List<T>(e);
_cnt = _last = _heap.Count();
for (int i = _last / 2; 0 <= i; i--)
Heapify(i);
}
public Heap(IComparer<T> comparer) { _comparer = comparer; }
public Heap(IEnumerable<T> e, IComparer<T> comparer) : this(e) {
_comparer = comparer;
}
private int Compare(T a, T b) {
if (_comparer == null)
return a.CompareTo(b);
else
return _comparer.Compare(a, b);
}
public bool Empty() { return _last == 0; }
public void Enqueue(T item) {
if (_last < _cnt) {
_heap[_last++] = item;
} else {
_heap.Add(item);
_cnt++;
_last++;
}
var i = _last - 1;
while (0 < i) {
if (0 <= Compare(_heap[(i - 1) / 2], _heap[i]))
break;
swap((i - 1) / 2, i);
i = (i - 1) / 2;
}
}
public T Dequeue() {
if (_last == 0)
throw new Exception("Empty");
var ret = _heap[0];
_heap[0] = _heap[--_last];
Heapify(0);
return ret;
}
public T Peek() { return _heap[0]; }
public int Count() { return _last; }
private void Heapify(int i) {
var max = i;
if (i * 2 + 1 < _last && Compare(_heap[max], _heap[i * 2 + 1]) < 0)
max = i * 2 + 1;
if (i * 2 + 2 < _last && Compare(_heap[max], _heap[i * 2 + 2]) < 0)
max = i * 2 + 2;
if (max == i)
return;
swap(i, max);
Heapify(max);
}
private void swap(int a, int b) {
var t = _heap[a];
_heap[a] = _heap[b];
_heap[b] = t;
}
}
#region IO
class Scanner {
private int _i = 0;
private string[] line = new string[0];
private T[] Enumerate<T>(int n, Func<T> f) {
T[] ret = new T[n];
for (int i = 0; i < n; i++)
ret[i] = f();
return ret;
}
public string Str() {
if (line.Length <= _i) {
line = Console.ReadLine().Split(' ');
_i = 0;
}
return line[_i++];
}
public int Int() => int.Parse(Str());
public long Long() => long.Parse(Str());
public double Double() => double.Parse(Str());
public int[] Int(int n) => Enumerate(n, Int);
public long[] Long(int n) => Enumerate(n, Long);
public double[] Double(int n) => Enumerate(n, Double);
public string[] Str(int n) => Enumerate(n, Str);
}
class Printer : StreamWriter {
public Printer() : base(Console.OpenStandardOutput()) { AutoFlush = false; }
}
#endregion
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
class Program {
static int[] dx = new int[] { 0, 0, 1, -1 };
static int[] dy = new int[] { 1, -1, 0, 0 };
const int INF = 1010101010;
static void Solve() {
var s = sc.Str();
var used = new bool[30];
if (s == "zyxwvutsrqponmlkjihgfedcba") {
pr.WriteLine(-1);
return;
}
foreach (var c in s)
used[c - 'a'] = true;
if (s.Length == 'z' - 'a' + 1) {
for (var i = s.Length - 2; 0 <= i; i--) {
if (s[i] < s[i + 1]) {
pr.Write(s.Substring(0, i));
pr.WriteLine((char)s.Substring(i + 1).Where(c => s[i] < c).Min());
break;
}
}
} else {
pr.Write(s);
pr.WriteLine((char)('a' + Array.IndexOf(used, false)));
}
}
class Node : IComparable {
public int Id;
public int Cost;
public int CompareTo(object obj) { return ((Node)obj).Cost - Cost; }
public override string ToString() {
return $"Id: {this.Id} - Cost: {this.Cost}";
}
}
class Edge {
public int To;
public int Cost;
}
static double F(double prev, double next, double t) {
return Math.Pow(Math.Exp((next - prev) / t), 2);
}
static int[,] Mul(int[,] a, int[,] b) {
var ret = new int[a.GetLength(0), b.GetLength(1)];
for (int i = 0; i < a.GetLength(0); i++)
for (int j = 0; j < b.GetLength(1); j++)
for (int k = 0; k < a.GetLength(1); k++)
ret[i, j] += a[i, k] * b[k, j];
return ret;
}
static int[,] Pow(int[,] a, int n) {
var b = new int[a.GetLength(1), a.GetLength(0)];
var f = n % 2 == 1;
for (int i = 0; i < a.GetLength(0); i++)
b[i, i] = 1;
while (n > 0) {
if (n % 2 == 1)
b = Mul(a, b);
n >>= 1;
}
return b;
}
class Coord {
public int x;
public int y;
}
static void Main(string[] args) {
pr.AutoFlush = true;
Solve();
pr.Flush();
// Console.ReadKey();
}
static Scanner sc = new Scanner();
static Printer pr = new Printer();
}
class Heap<T>
where T : IComparable {
private List<T> _heap;
private int _last;
private int _cnt;
private IComparer<T> _comparer;
public Heap() {
_heap = new List<T>();
_last = 0;
}
public Heap(IEnumerable<T> e) {
_heap = new List<T>(e);
_cnt = _last = _heap.Count();
for (int i = _last / 2; 0 <= i; i--)
Heapify(i);
}
public Heap(IComparer<T> comparer) { _comparer = comparer; }
public Heap(IEnumerable<T> e, IComparer<T> comparer) : this(e) {
_comparer = comparer;
}
private int Compare(T a, T b) {
if (_comparer == null)
return a.CompareTo(b);
else
return _comparer.Compare(a, b);
}
public bool Empty() { return _last == 0; }
public void Enqueue(T item) {
if (_last < _cnt) {
_heap[_last++] = item;
} else {
_heap.Add(item);
_cnt++;
_last++;
}
var i = _last - 1;
while (0 < i) {
if (0 <= Compare(_heap[(i - 1) / 2], _heap[i]))
break;
swap((i - 1) / 2, i);
i = (i - 1) / 2;
}
}
public T Dequeue() {
if (_last == 0)
throw new Exception("Empty");
var ret = _heap[0];
_heap[0] = _heap[--_last];
Heapify(0);
return ret;
}
public T Peek() { return _heap[0]; }
public int Count() { return _last; }
private void Heapify(int i) {
var max = i;
if (i * 2 + 1 < _last && Compare(_heap[max], _heap[i * 2 + 1]) < 0)
max = i * 2 + 1;
if (i * 2 + 2 < _last && Compare(_heap[max], _heap[i * 2 + 2]) < 0)
max = i * 2 + 2;
if (max == i)
return;
swap(i, max);
Heapify(max);
}
private void swap(int a, int b) {
var t = _heap[a];
_heap[a] = _heap[b];
_heap[b] = t;
}
}
#region IO
class Scanner {
private int _i = 0;
private string[] line = new string[0];
private T[] Enumerate<T>(int n, Func<T> f) {
T[] ret = new T[n];
for (int i = 0; i < n; i++)
ret[i] = f();
return ret;
}
public string Str() {
if (line.Length <= _i) {
line = Console.ReadLine().Split(' ');
_i = 0;
}
return line[_i++];
}
public int Int() => int.Parse(Str());
public long Long() => long.Parse(Str());
public double Double() => double.Parse(Str());
public int[] Int(int n) => Enumerate(n, Int);
public long[] Long(int n) => Enumerate(n, Long);
public double[] Double(int n) => Enumerate(n, Double);
public string[] Str(int n) => Enumerate(n, Str);
}
class Printer : StreamWriter {
public Printer() : base(Console.OpenStandardOutput()) { AutoFlush = false; }
}
#endregion
|
[["+", 51, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 51, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 204, 205, 22], ["+", 0, 218, 8, 16, 31, 204, 206, 207, 0, 70], ["+", 8, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 218, 8, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["+", 51, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 74, 51, 213, 63, 214, 0, 131]]
| 8
| 1,437
| 12
|
using System;
namespace agc022_a {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
if (s == "zyxwvutsrqponmlkjihgfedcba")
Console.WriteLine(-1);
else if (s.Length == 26) {
bool found = false;
for (int i = s.Length - 1; !found; i--) {
char a = (char)(s[i] + 1);
if (a <= 'z' && s.Substring(0, i).IndexOf(a) < 0) {
found = true;
Console.WriteLine(s.Substring(0, i) + a);
}
}
} else {
bool[] words = new bool[26];
for (int i = 0; i < s.Length; i++) {
words[s[i] - 'a'] = true;
}
Console.Write(s);
int a = 0;
while (words[a])
a++;
Console.WriteLine((char)('a' + a));
}
}
}
}
|
using System;
namespace agc022_a {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
if (s == "zyxwvutsrqponmlkjihgfedcba")
Console.WriteLine(-1);
else if (s.Length == 26) {
bool found = false;
for (int i = s.Length - 1; !found; i--) {
char j = (char)(s[i] + 1);
for (; j <= 'z'; j++) {
if (s.Substring(0, i).IndexOf(j) < 0)
break;
}
if (j <= 'z' && s.Substring(0, i).IndexOf(j) < 0) {
found = true;
Console.WriteLine(s.Substring(0, i) + j);
}
}
} else {
bool[] words = new bool[26];
for (int i = 0; i < s.Length; i++) {
words[s[i] - 'a'] = true;
}
Console.Write(s);
int a = 0;
while (words[a])
a++;
Console.WriteLine((char)('a' + a));
}
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 64, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 64, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 64, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 7, 15, 16, 12, 252, 0, 253], ["+", 64, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 64, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 227
| 42
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static long mod = (long)(Math.Pow(10, 9) + 7);
public static bool f = false, t = true;
static void Main(string[] args) {
int[] alpha = new int[26];
string a = Console.ReadLine();
for (int i = 0; i < a.Length; i++) {
alpha[a[i] - 'a']++;
}
if (a == "zyxwvutsrqponmlkjihgfedcba") {
Console.WriteLine(-1);
return;
}
for (int i = 0; i < a.Length; i++) {
string u = a.Substring(0, a.Length - i);
if (i != 0) {
alpha[a[a.Length - i] - 'a']--;
}
for (int j = i == 0 ? 0 : a[a.Length - i] - 'a' + 1; j < 26; j++) {
if (alpha[j] == 0) {
Console.WriteLine(u + (char)(j + 'a'));
Console.ReadLine();
return;
}
}
}
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static string Reverse(string s) {
return new string(s.Reverse().ToArray());
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
}
public static class Read {
public static void outl(string n = "") {
Console.WriteLine(n);
return;
}
public static long Long() { return long.Parse(Console.ReadLine()); }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static long mod = (long)(Math.Pow(10, 9) + 7);
public static bool f = false, t = true;
static void Main(string[] args) {
int[] alpha = new int[26];
string a = Console.ReadLine();
for (int i = 0; i < a.Length; i++) {
alpha[a[i] - 'a']++;
}
if (a == "zyxwvutsrqponmlkjihgfedcba") {
Console.WriteLine(-1);
Console.ReadLine();
return;
}
for (int i = 0; i < a.Length; i++) {
string u = a.Substring(0, a.Length - i);
if (i != 0) {
alpha[a[a.Length - i] - 'a']--;
}
for (int j = (i == 0 ? 0 : a[a.Length - i] - 'a' + 1); j < 26; j++) {
if (alpha[j] == 0) {
Console.WriteLine(u + (char)(j + 'a'));
Console.ReadLine();
return;
}
}
}
Console.WriteLine((char)(a[0] + 1));
Console.ReadLine();
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static string Reverse(string s) {
return new string(s.Reverse().ToArray());
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
}
public static class Read {
public static void outl(string n = "") {
Console.WriteLine(n);
return;
}
public static long Long() { return long.Parse(Console.ReadLine()); }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
[["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 10, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["+", 10, 198, 0, 200, 0, 212, 0, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 74, 51, 23, 0, 24], ["+", 0, 74, 51, 23, 0, 16, 31, 204, 205, 22], ["+", 51, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 51, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 74, 51, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 603
| 31
|
using System;
using static System.Console;
using static System.Math;
using System.Linq;
using System.Collections.Generic;
namespace Main {
class Program {
static void Main(string[] args) {
var tmp = new decimal[4];
for (int i = 0; i < 4; i++)
tmp[0] = int.Parse(ReadLine());
WriteLine(Min(tmp[0], tmp[1]) + Min(tmp[2], tmp[3]));
}
}
}
|
using System;
using static System.Console;
using static System.Math;
namespace Main {
class Program {
static void Main(string[] args) {
var tmp = new decimal[4];
for (int i = 0; i < 4; i++)
tmp[i] = int.Parse(ReadLine());
WriteLine(Min(tmp[0], tmp[1]) + Min(tmp[2], tmp[3]));
}
}
}
|
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 112
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace At {
class Program {
static void Main(string[] args) {
var a1 = ReadInt();
var a2 = ReadInt();
var a3 = ReadInt();
var a4 = ReadInt();
var ans = 0;
if (a1 < a2)
ans += a2;
else
ans += a1;
if (a3 < a4)
ans += a3;
else
ans += a4;
WriteLine(ans);
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace At {
class Program {
static void Main(string[] args) {
var a1 = ReadInt();
var a2 = ReadInt();
var a3 = ReadInt();
var a4 = ReadInt();
var ans = 0;
if (a1 < a2)
ans += a1;
else
ans += a2;
if (a3 < a4)
ans += a3;
else
ans += a4;
WriteLine(ans);
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 12, 22]]
| 8
| 291
| 4
|
using System;
namespace abc092B {
class MainClass {
public static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split();
int D = int.Parse(str[0]);
int X = int.Parse(str[1]);
int Ans = 0;
int m = 0;
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = int.Parse(Console.ReadLine());
int B = 0;
while (B <= D) {
B = 1 + m * A[i];
m = m + 1;
Ans = Ans + 1;
}
}
Console.WriteLine(X + Ans);
}
}
}
|
using System;
namespace abc092B {
class MainClass {
public static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split();
int D = int.Parse(str[0]);
int X = int.Parse(str[1]);
int Ans = 0;
int m = 0;
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = int.Parse(Console.ReadLine());
int B = 0;
while (B <= D) {
B = 1 + m * A[i];
m = m + 1;
Ans = Ans + 1;
}
m = 0;
Ans = Ans - 1;
}
Console.WriteLine(X + Ans);
}
}
}
|
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 176
| 10
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6 {
class Program {
static void Main(string[] args) {
var joinPeopleCount = int.Parse(Console.ReadLine());
var DaysCountAndResultChocolateCount =
Console.ReadLine().Split(' ').Select(int.Parse);
var Days = DaysCountAndResultChocolateCount.ElementAt(0);
var ResultChocolateCount = DaysCountAndResultChocolateCount.ElementAt(1);
var BeforeChcolateCount = 0;
for (int i = 0; i < joinPeopleCount; i++) {
var EatInterval = int.Parse(Console.ReadLine());
var eatCount = 0;
var UserDaysCount = 0;
while (Days >= UserDaysCount) {
UserDaysCount += EatInterval;
eatCount++;
}
BeforeChcolateCount += eatCount;
}
Console.WriteLine(ResultChocolateCount + BeforeChcolateCount);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6 {
class Program {
static void Main(string[] args) {
var joinPeopleCount = int.Parse(Console.ReadLine());
var DaysCountAndResultChocolateCount =
Console.ReadLine().Split(' ').Select(int.Parse);
var Days = DaysCountAndResultChocolateCount.ElementAt(0);
var ResultChocolateCount = DaysCountAndResultChocolateCount.ElementAt(1);
var BeforeChcolateCount = 0;
for (int i = 0; i < joinPeopleCount; i++) {
var EatInterval = int.Parse(Console.ReadLine());
var eatCount = 0;
var UserDaysCount = 0;
while (Days > UserDaysCount) {
eatCount++;
UserDaysCount += EatInterval;
}
BeforeChcolateCount += eatCount;
}
Console.WriteLine(ResultChocolateCount + BeforeChcolateCount);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29]]
| 8
| 195
| 8
|
using System;
class Program {
static void Main(string[] args) {
int n, d, x;
int p = 0;
int[] a = new int[1002];
int[] b = new int[1002];
n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
d = int.Parse(input[0]);
x = int.Parse(input[1]);
for (int i = 1; i < n + 1; i++) {
a[i] = int.Parse(Console.ReadLine());
b[i] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= d; j++) {
if (b[i] == j) {
p++;
b[i] += a[i];
Console.WriteLine(j);
}
}
}
p += x;
Console.WriteLine(p);
}
}
|
using System;
class Program {
static void Main(string[] args) {
int n, d, x;
int p = 0;
int[] a = new int[1002];
int[] b = new int[1002];
n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
d = int.Parse(input[0]);
x = int.Parse(input[1]);
for (int i = 1; i < n + 1; i++) {
a[i] = int.Parse(Console.ReadLine());
b[i] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= d; j++) {
if (b[i] == j) {
p++;
b[i] += a[i];
}
}
}
p += x;
Console.WriteLine(p);
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 222
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
var array =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long sum = 0;
for (var j = 0; j <= n; ++j) {
if (j == 0) {
sum += Math.Abs(array[j]);
} else if (j == n) {
sum += Math.Abs(array[j - 1]);
} else {
sum += Math.Abs(array[j] - array[j - 1]);
}
}
Console.WriteLine("before " + sum.ToString());
for (var i = 1; i <= n; ++i) {
var total = sum;
if (i == 1) {
total += Math.Abs(0 - array[1]) - Math.Abs(array[1] - array[0]) -
Math.Abs(0 - array[0]);
} else if (i == n) {
total += Math.Abs(0 - array[n - 2]) -
Math.Abs(array[n - 1] - array[n - 2]) -
Math.Abs(0 - array[n - 1]);
} else {
total += Math.Abs(array[i] - array[i - 2]) -
Math.Abs(array[i - 1] - array[i - 2]) -
Math.Abs(array[i] - array[i - 1]);
}
Console.WriteLine(total.ToString());
}
Console.Out.Flush();
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
var array =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long sum = 0;
for (var j = 0; j <= n; ++j) {
if (j == 0) {
sum += Math.Abs(array[j]);
} else if (j == n) {
sum += Math.Abs(array[j - 1]);
} else {
sum += Math.Abs(array[j] - array[j - 1]);
}
}
for (var i = 1; i <= n; ++i) {
var total = sum;
if (i == 1) {
total += Math.Abs(0 - array[1]) - Math.Abs(array[1] - array[0]) -
Math.Abs(0 - array[0]);
} else if (i == n) {
total += Math.Abs(0 - array[n - 2]) -
Math.Abs(array[n - 1] - array[n - 2]) -
Math.Abs(0 - array[n - 1]);
} else {
total += Math.Abs(array[i] - array[i - 2]) -
Math.Abs(array[i - 1] - array[i - 2]) -
Math.Abs(array[i] - array[i - 1]);
}
Console.WriteLine(total.ToString());
}
Console.Out.Flush();
Console.ReadLine();
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 392
| 15
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = Read.ints();
int sum = 0;
for (int i = 0; i < a.Length; i++) {
if (i == 0) {
sum = Math.Abs(a[0]);
continue;
}
sum += Math.Abs(a[i] - a[i - 1]);
}
sum += Math.Abs(a[a.Length - 1]);
int sumi = sum;
for (int i = 0; i < n; i++) {
sum = sumi;
if (i == 0) {
if ((a[i + 1] - a[i]) * (a[i]) < 0)
sum -=
Math.Abs(a[i]) + Math.Abs(a[i + 1] - a[i]) - (Math.Abs(a[i + 1]));
Console.WriteLine(sum);
continue;
}
if (i == a.Length - 1) {
if ((a[i] - a[i - 1]) * (a[i]) < 0) {
sum -= Math.Abs(a[i] - a[i - 1]) + Math.Abs(a[i]) -
(Math.Abs(a[i] - a[i - 2]));
}
Console.WriteLine(sum);
continue;
}
int come = a[i] - a[i - 1];
int go = a[i + 1] - a[i];
if (come * go < 0) {
sum -= Math.Abs(come) + Math.Abs(go) - (Math.Abs(a[i + 1] - a[i - 1]));
}
Console.WriteLine(sum);
}
Console.ReadLine();
}
public static long gcd(long a, long b) {
while (true) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
a -= b;
} else {
b -= a;
}
}
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static string Reverse(string s) {
return new string(s.Reverse().ToArray());
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
}
public static class Read {
public static void outl(string n = "") {
Console.WriteLine(n);
return;
}
public static long Long() { return long.Parse(Console.ReadLine()); }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = Read.ints();
int sum = 0;
for (int i = 0; i < a.Length; i++) {
if (i == 0) {
sum = Math.Abs(a[0]);
continue;
}
sum += Math.Abs(a[i] - a[i - 1]);
}
sum += Math.Abs(a[a.Length - 1]);
int sumi = sum;
for (int i = 0; i < n; i++) {
sum = sumi;
if (i == 0) {
if ((a[i + 1] - a[i]) * (a[i]) < 0)
sum -=
Math.Abs(a[i]) + Math.Abs(a[i + 1] - a[i]) - (Math.Abs(a[i + 1]));
Console.WriteLine(sum);
continue;
}
if (i == a.Length - 1) {
if ((a[i] - a[i - 1]) * (a[i]) > 0) {
sum -=
Math.Abs(a[i] - a[i - 1]) + Math.Abs(a[i]) - (Math.Abs(a[i - 1]));
}
Console.WriteLine(sum);
continue;
}
int come = a[i] - a[i - 1];
int go = a[i + 1] - a[i];
if (come * go < 0) {
sum -= Math.Abs(come) + Math.Abs(go) - (Math.Abs(a[i + 1] - a[i - 1]));
}
Console.WriteLine(sum);
}
Console.ReadLine();
}
public static long gcd(long a, long b) {
while (true) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
a -= b;
} else {
b -= a;
}
}
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static string Reverse(string s) {
return new string(s.Reverse().ToArray());
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
}
public static class Read {
public static void outl(string n = "") {
Console.WriteLine(n);
return;
}
public static long Long() { return long.Parse(Console.ReadLine()); }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 807
| 9
|
using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
// using System.Numerics;
using static System.Math;
namespace Program {
public class Solver {
Random rnd = new Random(0);
public void Solve() {
var n = ri;
var m = ri;
var X = rl;
var f = new int[m];
var t = new int[m];
var w = new int[m];
var set = new DisjointSet(n);
for (int i = 0; i < m; i++) {
f[i] = ri - 1;
t[i] = ri - 1;
w[i] = ri;
}
var G = Enumerate(n, x => new List<KeyValuePair<int, long>>());
var sum = 0L;
foreach (var id in Enumerate(m, x => x).OrderBy(x => w[x])) {
if (set.Unite(f[id], t[id])) {
sum += w[id];
G[f[id]].Add(new KeyValuePair<int, long>(t[id], w[id]));
G[t[id]].Add(new KeyValuePair<int, long>(f[id], w[id]));
}
}
if (sum > X) {
Console.WriteLine(0);
return;
}
var dist = Enumerate(n, x => new long[n]);
for (int i = 0; i < n; i++) {
Action<int, int, long> dfs = null;
dfs = (prev, cur, v) => {
dist[i][cur] = v;
foreach (var e in G[cur])
if (e.Key != prev)
dfs(cur, e.Key, Max(v, e.Value));
};
dfs(-1, i, 0);
}
var eq = 0;
var over = 0;
for (int i = 0; i < m; i++) {
var d = w[i] - dist[f[i]][t[i]];
if (d == X - sum)
eq++;
else if (d > X - sum)
over++;
}
ModInt ans = 0;
if (X == sum) {
ans += (ModInt.Pow(2, n - 1) - 2) * ModInt.Pow(2, m - (n - 1));
ans += 2 * (ModInt.Pow(2, eq - (n - 1)) - 1) * ModInt.Pow(2, over);
} else {
ans += 2 * ModInt.Pow(2, over);
}
Console.WriteLine(ans);
}
const long INF = 5L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
const string URDL = "URDL";
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < 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(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Program.Solver();
try {
solver.Solve();
Console.Out.Flush();
} catch {
}
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
#region ModInt
public struct ModInt {
public const long Mod = (int)1e9 + 7;
public long num;
public ModInt(long n) { num = n; }
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
#region DisjointSet
public class DisjointSet {
int[] par;
byte[] rank;
public DisjointSet(int n) {
par = new int[n];
for (int i = 0; i < n; i++)
par[i] = -1;
rank = new byte[n];
}
public int this[int id] {
get {
if ((par[id] < 0))
return id;
return par[id] = this[par[id]];
}
}
public bool Unite(int x, int y) {
x = this[x];
y = this[y];
if (x == y)
return false;
if (rank[x] < rank[y]) {
var z = x;
x = y;
y = z;
}
par[x] += par[y];
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
return true;
}
public int Size(int x) { return -par[this[x]]; }
public bool IsUnited(int x, int y) { return this[x] == this[y]; }
}
#endregion
|
using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
// using System.Numerics;
using static System.Math;
namespace Program {
public class Solver {
Random rnd = new Random(0);
public void Solve() {
var n = ri;
var m = ri;
var X = rl;
var f = new int[m];
var t = new int[m];
var w = new int[m];
var set = new DisjointSet(n);
for (int i = 0; i < m; i++) {
f[i] = ri - 1;
t[i] = ri - 1;
w[i] = ri;
}
var G = Enumerate(n, x => new List<KeyValuePair<int, long>>());
var sum = 0L;
foreach (var id in Enumerate(m, x => x).OrderBy(x => w[x])) {
if (set.Unite(f[id], t[id])) {
sum += w[id];
G[f[id]].Add(new KeyValuePair<int, long>(t[id], w[id]));
G[t[id]].Add(new KeyValuePair<int, long>(f[id], w[id]));
}
}
if (sum > X) {
Console.WriteLine(0);
return;
}
var dist = Enumerate(n, x => new long[n]);
for (int i = 0; i < n; i++) {
Action<int, int, long> dfs = null;
dfs = (prev, cur, v) => {
dist[i][cur] = v;
foreach (var e in G[cur])
if (e.Key != prev)
dfs(cur, e.Key, Max(v, e.Value));
};
dfs(-1, i, 0);
}
var eq = 0;
var over = 0;
for (int i = 0; i < m; i++) {
var d = w[i] - dist[f[i]][t[i]];
if (d == X - sum)
eq++;
else if (d > X - sum)
over++;
}
ModInt ans = 0;
if (X == sum) {
ans += (ModInt.Pow(2, n - 1) - 2) * ModInt.Pow(2, m - (n - 1));
ans += 2 * (ModInt.Pow(2, eq - (n - 1)) - 1) * ModInt.Pow(2, over);
} else {
ans += 2 * (ModInt.Pow(2, eq) - 1) * ModInt.Pow(2, over);
}
Console.WriteLine(ans);
}
const long INF = 5L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
const string URDL = "URDL";
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < 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(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Program.Solver();
try {
solver.Solve();
Console.Out.Flush();
} catch {
}
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
#region ModInt
public struct ModInt {
public const long Mod = (int)1e9 + 7;
public long num;
public ModInt(long n) { num = n; }
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
#region DisjointSet
public class DisjointSet {
int[] par;
byte[] rank;
public DisjointSet(int n) {
par = new int[n];
for (int i = 0; i < n; i++)
par[i] = -1;
rank = new byte[n];
}
public int this[int id] {
get {
if ((par[id] < 0))
return id;
return par[id] = this[par[id]];
}
}
public bool Unite(int x, int y) {
x = this[x];
y = this[y];
if (x == y)
return false;
if (rank[x] < rank[y]) {
var z = x;
x = y;
y = z;
}
par[x] += par[y];
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
return true;
}
public int Size(int x) { return -par[this[x]]; }
public bool IsUnited(int x, int y) { return this[x] == this[y]; }
}
#endregion
|
[["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 205, 22]]
| 8
| 1,913
| 13
|
using System;
class Program {
static void Main() {
// Your code here!
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
Console.WriteLine(a);
Console.WriteLine(a + b >= c ? "Yes" : "No");
}
}
|
using System;
class Program {
static void Main() {
// Your code here!
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
Console.WriteLine(a + b >= c ? "Yes" : "No");
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22]]
| 8
| 98
| 7
|
using System;
using System.Linq;
namespace ABC091 {
class Program {
static void Main(string[] args) {
//問題1
int[] input = new int[3];
input = Console.ReadLine()
.Trim()
.Split(' ')
.Select(x => int.Parse(x))
.ToArray();
if (2 * (input[0] + input[1]) >= input[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
Console.ReadLine();
}
}
}
|
using System;
using System.Linq;
namespace ABC091 {
class Program {
static void Main(string[] args) {
//問題1
int[] input = new int[3];
input = Console.ReadLine()
.Trim()
.Split(' ')
.Select(x => int.Parse(x))
.ToArray();
if (input[0] + input[1] >= input[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 124
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var dict = new Dictionary<string, int>();
for (var i = 0; i < N; i++) {
var s = Console.ReadLine();
if (!dict.ContainsKey(s)) {
dict.Add(s, 1);
} else {
dict[s] += 1;
}
}
var M = int.Parse(Console.ReadLine());
for (var i = 0; i < M; i++) {
var s = Console.ReadLine();
if (dict.ContainsKey(s))
dict[s] -= 1;
}
Console.WriteLine(dict.Select(d => d.Value).Max());
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var dict = new Dictionary<string, int>();
for (var i = 0; i < N; i++) {
var s = Console.ReadLine();
if (!dict.ContainsKey(s)) {
dict.Add(s, 1);
} else {
dict[s] += 1;
}
}
var M = int.Parse(Console.ReadLine());
for (var i = 0; i < M; i++) {
var s = Console.ReadLine();
if (dict.ContainsKey(s))
dict[s] -= 1;
}
var max = dict.Select(d => d.Value).Max();
Console.WriteLine(max < 0 ? 0 : max);
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
| 8
| 188
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int n = sc.NextInt();
string[] s = new string[n];
for (int i = 0; i < n; i++) {
s[i] = sc.Next();
}
int m = sc.NextInt();
string[] t = new string[m];
for (int i = 0; i < m; i++) {
t[i] = sc.Next();
}
Dictionary<string, int> dic = new Dictionary<string, int>();
foreach (string str in s) {
if (!dic.ContainsKey(str)) {
dic.Add(str, 0);
}
dic[str]++;
}
foreach (string str in t) {
if (!dic.ContainsKey(str)) {
dic.Add(str, 0);
}
dic[str]--;
}
int answer = 0;
foreach (var item in dic) {
if (item.Value > 0) {
answer += item.Value;
}
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int n = sc.NextInt();
string[] s = new string[n];
for (int i = 0; i < n; i++) {
s[i] = sc.Next();
}
int m = sc.NextInt();
string[] t = new string[m];
for (int i = 0; i < m; i++) {
t[i] = sc.Next();
}
Dictionary<string, int> dic = new Dictionary<string, int>();
foreach (string str in s) {
if (!dic.ContainsKey(str)) {
dic.Add(str, 0);
}
dic[str]++;
}
foreach (string str in t) {
if (!dic.ContainsKey(str)) {
dic.Add(str, 0);
}
dic[str]--;
}
int answer = 0;
foreach (var item in dic) {
answer = Math.Max(answer, item.Value);
}
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();
}
}
|
[["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 555
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
public class QuestionA {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列配列の入力
long n = long.Parse(Console.ReadLine());
List<string> blueList = new List<string>();
for (int i = 0; i < n; ++i) {
blueList.Add(Console.ReadLine());
}
List<string> redList = new List<string>();
for (int i = 0; i < n; ++i) {
redList.Add(Console.ReadLine());
}
List<int> checkCnt = new List<int>();
foreach (var item in blueList) {
var blueItemCnt = blueList.Where(x => x == item).Count();
var redItemCnt = redList.Where(x => x == item).Count();
checkCnt.Add(blueItemCnt - redItemCnt);
}
Console.WriteLine(checkCnt.Max());
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
public class QuestionA {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列配列の入力
long n = long.Parse(Console.ReadLine());
List<string> blueList = new List<string>();
for (int i = 0; i < n; ++i) {
blueList.Add(Console.ReadLine());
}
long m = long.Parse(Console.ReadLine());
List<string> redList = new List<string>();
for (int i = 0; i < m; ++i) {
redList.Add(Console.ReadLine());
}
List<int> checkCnt = new List<int>();
foreach (var item in blueList) {
var blueItemCnt = blueList.Where(x => x == item).Count();
var redItemCnt = redList.Where(x => x == item).Count();
checkCnt.Add(blueItemCnt - redItemCnt);
}
int ans = checkCnt.Max();
if (ans < 0) {
ans = 0;
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 263
| 41
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApp {
class Program {
static void Main(string[] args) {
var nDic = new Dictionary<string, int>();
var num1 = int.Parse(Console.ReadLine());
for (int i = 0; i < num1; i++) {
var txt = Console.ReadLine();
if (nDic.ContainsKey(txt))
nDic[txt] += 1;
else
nDic.Add(txt, 1);
}
var mDic = new Dictionary<string, int>();
var num2 = int.Parse(Console.ReadLine());
for (int i = 0; i < num2; i++) {
var txt = Console.ReadLine();
if (mDic.ContainsKey(txt))
mDic[txt] += 1;
else
mDic.Add(txt, 1);
}
var dic = nDic;
foreach (var item in mDic) {
if (dic.ContainsKey(item.Key))
dic[item.Key] -= item.Value;
}
Console.WriteLine(
dic.OrderByDescending(x => x.Value).FirstOrDefault().Value);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApp {
class Program {
static void Main(string[] args) {
var nDic = new Dictionary<string, int>();
var num1 = int.Parse(Console.ReadLine());
for (int i = 0; i < num1; i++) {
var txt = Console.ReadLine();
if (nDic.ContainsKey(txt))
nDic[txt] += 1;
else
nDic.Add(txt, 1);
}
var mDic = new Dictionary<string, int>();
var num2 = int.Parse(Console.ReadLine());
for (int i = 0; i < num2; i++) {
var txt = Console.ReadLine();
if (mDic.ContainsKey(txt))
mDic[txt] += 1;
else
mDic.Add(txt, 1);
}
var dic = nDic;
foreach (var item in mDic) {
if (dic.ContainsKey(item.Key))
dic[item.Key] -= item.Value;
}
var t = dic.OrderByDescending(x => x.Value).FirstOrDefault().Value;
if (t >= 0)
Console.WriteLine(
dic.OrderByDescending(x => x.Value).FirstOrDefault().Value);
else
Console.WriteLine(0);
Console.ReadLine();
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 212, 0, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 266
| 34
|
using System;
class Program {
static void Main(string[] args) {
string[] ns = new string[110];
string[] ms = new string[110];
bool[] count = new bool[110];
// スペース区切りの整数の入力
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++) {
ns[i] = "";
ns[i] = Console.ReadLine();
}
int M = int.Parse(Console.ReadLine());
for (int i = 0; i < M; i++) {
ms[i] = "";
ms[i] = Console.ReadLine();
}
int lastvalue = 0;
for (int i = 0; i < N; i++) {
int wcount = 0;
if (count[i] == false) {
for (int j = i; j < N; j++) {
if (ns[j] == ns[i]) {
wcount++;
count[j] = true;
}
}
for (int j = 0; j < M; j++) {
if (ms[j] == ns[i]) {
wcount--;
}
}
if (wcount > 0) {
lastvalue += wcount;
}
}
}
Console.WriteLine(lastvalue);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] ns = new string[110];
string[] ms = new string[110];
bool[] count = new bool[110];
// スペース区切りの整数の入力
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++) {
ns[i] = "";
ns[i] = Console.ReadLine();
}
int M = int.Parse(Console.ReadLine());
for (int i = 0; i < M; i++) {
ms[i] = "";
ms[i] = Console.ReadLine();
}
int lastvalue = 0;
for (int i = 0; i < N; i++) {
int wcount = 0;
if (count[i] == false) {
for (int j = i; j < N; j++) {
if (ns[j] == ns[i]) {
wcount++;
count[j] = true;
}
}
for (int j = 0; j < M; j++) {
if (ms[j] == ns[i]) {
wcount--;
}
}
if (wcount > 0) {
if (lastvalue < wcount)
lastvalue = wcount;
}
}
}
Console.WriteLine(lastvalue);
}
}
|
[["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32]]
| 8
| 279
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var dic = new Dictionary<string, int>();
for (int i = 0; i < N; i++) {
var item = Console.ReadLine();
if (dic.ContainsKey(item)) {
dic[item]++;
} else {
dic[item] = 1;
}
}
int M = int.Parse(Console.ReadLine());
for (int i = 0; i < M; i++) {
var item = Console.ReadLine();
if (dic.ContainsKey(item)) {
dic[item]--;
} else {
dic[item] = -1;
}
}
int max = int.MinValue;
foreach (var item in dic) {
max = Math.Max(max, item.Value);
}
Console.WriteLine(max);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var dic = new Dictionary<string, int>();
for (int i = 0; i < N; i++) {
var item = Console.ReadLine();
if (dic.ContainsKey(item)) {
dic[item]++;
} else {
dic[item] = 1;
}
}
int M = int.Parse(Console.ReadLine());
for (int i = 0; i < M; i++) {
var item = Console.ReadLine();
if (dic.ContainsKey(item)) {
dic[item]--;
} else {
dic[item] = -1;
}
}
int max = int.MinValue;
foreach (var item in dic) {
max = Math.Max(max, item.Value);
}
Console.WriteLine(Math.Max(0, max));
}
}
|
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 224
| 7
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
class Program {
static int[] dx = new int[] { 0, 0, 1, -1 };
static int[] dy = new int[] { 1, -1, 0, 0 };
static void Solve() {
var cnt = new Dictionary<string, int>();
var n = sc.Int();
for (int i = 0; i < n; i++) {
var s = sc.Str();
if (cnt.ContainsKey(s))
cnt[s]++;
else
cnt.Add(s, 1);
}
var m = sc.Int();
for (int i = 0; i < m; i++) {
var s = sc.Str();
if (cnt.ContainsKey(s))
cnt[s]--;
}
pr.WriteLine(cnt.Select(x => x.Value).Max());
}
class Node {
public Node Prev;
public Node[] To;
public int cost;
}
static double F(double prev, double next, double t) {
return Math.Pow(Math.Exp((next - prev) / t), 2);
}
static int[,] Mul(int[,] a, int[,] b) {
var ret = new int[a.GetLength(0), b.GetLength(1)];
for (int i = 0; i < a.GetLength(0); i++)
for (int j = 0; j < b.GetLength(1); j++)
for (int k = 0; k < a.GetLength(1); k++)
ret[i, j] += a[i, k] * b[k, j];
return ret;
}
static int[,] Pow(int[,] a, int n) {
var b = new int[a.GetLength(1), a.GetLength(0)];
var f = n % 2 == 1;
for (int i = 0; i < a.GetLength(0); i++)
b[i, i] = 1;
while (n > 0) {
if (n % 2 == 1)
b = Mul(a, b);
n >>= 1;
}
return b;
}
class Coord {
public int x;
public int y;
}
static void Main(string[] args) {
// pr.AutoFlush = true;
Solve();
pr.Flush();
// Console.ReadKey();
}
static Scanner sc = new Scanner();
static Printer pr = new Printer();
}
#region IO
class Scanner {
private int _i = 0;
private string[] line = new string[0];
private T[] Enumerate<T>(int n, Func<T> f) {
T[] ret = new T[n];
for (int i = 0; i < n; i++)
ret[i] = f();
return ret;
}
public string Str() {
if (line.Length <= _i) {
line = Console.ReadLine().Split(' ');
_i = 0;
}
return line[_i++];
}
public int Int() => int.Parse(Str());
public long Long() => long.Parse(Str());
public double Double() => double.Parse(Str());
public int[] Int(int n) => Enumerate(n, Int);
public long[] Long(int n) => Enumerate(n, Long);
public double[] Double(int n) => Enumerate(n, Double);
public string[] Str(int n) => Enumerate(n, Str);
}
class Printer : StreamWriter {
public Printer() : base(Console.OpenStandardOutput()) { AutoFlush = false; }
}
#endregion
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
class Program {
static int[] dx = new int[] { 0, 0, 1, -1 };
static int[] dy = new int[] { 1, -1, 0, 0 };
static void Solve() {
var cnt = new Dictionary<string, int>();
var n = sc.Int();
for (int i = 0; i < n; i++) {
var s = sc.Str();
if (cnt.ContainsKey(s))
cnt[s]++;
else
cnt.Add(s, 1);
}
var m = sc.Int();
for (int i = 0; i < m; i++) {
var s = sc.Str();
if (cnt.ContainsKey(s))
cnt[s]--;
}
var ans = cnt.Select(x => x.Value).Max();
pr.WriteLine(ans >= 0 ? ans : 0);
}
class Node {
public Node Prev;
public Node[] To;
public int cost;
}
static double F(double prev, double next, double t) {
return Math.Pow(Math.Exp((next - prev) / t), 2);
}
static int[,] Mul(int[,] a, int[,] b) {
var ret = new int[a.GetLength(0), b.GetLength(1)];
for (int i = 0; i < a.GetLength(0); i++)
for (int j = 0; j < b.GetLength(1); j++)
for (int k = 0; k < a.GetLength(1); k++)
ret[i, j] += a[i, k] * b[k, j];
return ret;
}
static int[,] Pow(int[,] a, int n) {
var b = new int[a.GetLength(1), a.GetLength(0)];
var f = n % 2 == 1;
for (int i = 0; i < a.GetLength(0); i++)
b[i, i] = 1;
while (n > 0) {
if (n % 2 == 1)
b = Mul(a, b);
n >>= 1;
}
return b;
}
class Coord {
public int x;
public int y;
}
static void Main(string[] args) {
// pr.AutoFlush = true;
Solve();
pr.Flush();
// Console.ReadKey();
}
static Scanner sc = new Scanner();
static Printer pr = new Printer();
}
#region IO
class Scanner {
private int _i = 0;
private string[] line = new string[0];
private T[] Enumerate<T>(int n, Func<T> f) {
T[] ret = new T[n];
for (int i = 0; i < n; i++)
ret[i] = f();
return ret;
}
public string Str() {
if (line.Length <= _i) {
line = Console.ReadLine().Split(' ');
_i = 0;
}
return line[_i++];
}
public int Int() => int.Parse(Str());
public long Long() => long.Parse(Str());
public double Double() => double.Parse(Str());
public int[] Int(int n) => Enumerate(n, Int);
public long[] Long(int n) => Enumerate(n, Long);
public double[] Double(int n) => Enumerate(n, Double);
public string[] Str(int n) => Enumerate(n, Str);
}
class Printer : StreamWriter {
public Printer() : base(Console.OpenStandardOutput()) { AutoFlush = false; }
}
#endregion
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
| 8
| 817
| 19
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var N = int.Parse(Console.ReadLine());
var abi = new Pair[N];
var cdi = new Pair[N];
for (var i = 0; i < N; i++) {
var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
abi[i] = new Pair { X = ab[0], Y = ab[1] };
}
for (var i = 0; i < N; i++) {
var cd = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
cdi[i] = new Pair { X = cd[0], Y = cd[1] };
}
abi = abi.OrderByDescending(x => x.X).ThenByDescending(x => x.Y).ToArray();
cdi = cdi.OrderByDescending(x => x.X).ThenBy(x => x.Y).ToArray();
var answer = 0;
var hash = new HashSet<int>();
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (!hash.Contains(j) && abi[i].X < cdi[j].X && abi[i].Y < cdi[j].Y) {
answer++;
hash.Add(j);
break;
}
}
}
Console.WriteLine(answer);
}
public class Pair {
public int X { get; set; }
public int Y { get; set; }
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var N = int.Parse(Console.ReadLine());
var abi = new Pair[N];
var cdi = new Pair[N];
for (var i = 0; i < N; i++) {
var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
abi[i] = new Pair { X = ab[0], Y = ab[1] };
}
for (var i = 0; i < N; i++) {
var cd = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
cdi[i] = new Pair { X = cd[0], Y = cd[1] };
}
abi = abi.OrderByDescending(x => x.Y).ToArray();
cdi = cdi.OrderBy(x => x.X).ToArray();
var answer = 0;
var hash = new HashSet<int>();
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (!hash.Contains(j) && abi[i].X < cdi[j].X && abi[i].Y < cdi[j].Y) {
answer++;
hash.Add(j);
break;
}
}
}
Console.WriteLine(answer);
}
public class Pair {
public int X { get; set; }
public int Y { get; set; }
}
}
}
|
[["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
| 8
| 444
| 20
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
public class Remainder {
static public void Main() {
var N = long.Parse(Console.ReadLine());
var red = new long [N][];
for (int i = 0; i < N; i++) {
var AB =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
red[i] = AB;
}
Array.Sort(red, StructuralComparisons.StructuralComparer);
// var blue = new long[N][];
var blue = new List<long[]>();
for (int i = 0; i < N; i++) {
var CD =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
blue.Add(CD);
}
blue = blue.OrderBy(a => a[0]).ThenBy(a => a[1]).ToList();
// blue.Sort();
// Array.Sort(blue, StructuralComparisons.StructuralComparer);
var ans = 0;
var bluep = 0;
var flag = false;
for (int x = 0; x < N; x++) {
for (int y = 0; y < blue.Count(); y++) {
if (red[x][0] < blue[y][0] && red[x][1] < blue[y][1]) {
// Console.WriteLine(red[x][0]+","+red[x][1]+"
// "+blue[bluep][0]+","+blue[bluep][1]);
blue.RemoveAt(y);
blue = blue.OrderBy(a => a[0]).ThenBy(a => a[1]).ToList();
// PrintValues(blue);
ans++;
break;
}
}
}
Console.WriteLine(ans);
}
public static void PrintValues(IEnumerable myList) {
foreach (long[] obj in myList)
Console.Write(String.Join(",", obj) + " ");
Console.WriteLine();
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
public class Remainder {
static public void Main() {
var N = int.Parse(Console.ReadLine());
var red = new long [N][];
for (int i = 0; i < N; i++) {
var AB =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
red[i] = AB;
}
Array.Sort(red, StructuralComparisons.StructuralComparer);
var blue = new List<long[]>();
for (int i = 0; i < N; i++) {
var CD =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
blue.Add(CD);
}
blue = blue.OrderBy(a => a[1]).ThenBy(a => a[0]).ToList();
var ans = 0;
var bluep = 0;
var flag = false;
for (int x = N - 1; x >= 0; x--) {
for (int y = 0; y < blue.Count(); y++) {
if (red[x][0] < blue[y][0] && red[x][1] < blue[y][1]) {
blue.RemoveAt(y);
blue = blue.OrderBy(a => a[1]).ThenBy(a => a[0]).ToList();
ans++;
break;
}
}
}
Console.WriteLine(ans);
}
public static void PrintValues(IEnumerable myList) {
foreach (long[] obj in myList)
Console.Write(String.Join(",", obj) + " ");
Console.WriteLine();
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 218, 8, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 218, 8, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
| 8
| 410
| 20
|
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert
#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
namespace UtakaApp {
public partial class Program {
//=========================================================================================
// Answer
//=========================================================================================
public const string SiteName = "AtCoder";
public const string ContestName = "abc091";
public const string ProblemName = "C";
public void Solve() {
int N = cin.ReadInt;
List<Pair> R = new List<Pair>();
List<Pair> B = new List<Pair>();
for (int i = 0; i < N; i++) {
R.Add(new Pair(cin.ReadInt, cin.ReadInt));
}
for (int i = 0; i < N; i++) {
B.Add(new Pair(cin.ReadInt, cin.ReadInt));
}
var pairComparer = new PairComparer();
R.Sort(pairComparer);
B.Sort(pairComparer);
int count = 0;
for (int i = 0; i < N; i++) {
Pair p = B[i];
int x = p.X;
int foundIndex = -1;
int maxY = -1;
for (int j = 0; j < R.Count; j++) {
Pair q = R[j];
if (q.X >= x) {
break;
}
if (q.Y > maxY) {
maxY = q.Y;
foundIndex = j;
}
}
if (foundIndex != -1) {
count++;
R.RemoveAt(foundIndex);
}
}
cou.WriteLine(count);
}
public class PairComparer : IComparer<Pair> {
public int Compare(Pair x, Pair y) {
if (x.X < y.X)
return -1;
if (x.X > y.X)
return 1;
if (x.Y < y.Y)
return -1;
if (x.Y > y.Y)
return 1;
return 0;
}
}
public sealed class Pair : Pair<int, int> {
public Pair(int x, int y) : base(x, y) {}
}
[DebuggerDisplay("({X}, {Y})")]
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>,
IEquatable<Pair<T1, T2>>
where T1 : IComparable<T1>
where T2 : IComparable<T2> {
public Pair(T1 x, T2 y) {
X = x;
Y = y;
}
public T1 X;
public T2 Y;
public int CompareTo(Pair<T1, T2> other) {
if (ReferenceEquals(this, other))
return 0;
if (ReferenceEquals(null, other))
return 1;
var firstComparison = X.CompareTo(other.X);
return firstComparison != 0 ? firstComparison : Y.CompareTo(other.Y);
}
public override string ToString() => $"({X}, {Y})";
public bool Equals(Pair<T1, T2> other) {
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
return EqualityComparer<T1>.Default.Equals(X, other.X) &&
EqualityComparer<T2>.Default.Equals(Y, other.Y);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
return obj.GetType() == this.GetType() && Equals((Pair<T1, T2>)obj);
}
public override int GetHashCode() {
unchecked {
return (EqualityComparer<T1>.Default.GetHashCode(X) * 397) ^
EqualityComparer<T2>.Default.GetHashCode(Y);
}
}
}
}
//=========================================================================================
// Debug IO
//=========================================================================================
public partial class Program {
//=========================================================================================
// Main
//=========================================================================================
private readonly ConsoleInput cin;
private readonly IConsole cou;
public Program(ConsoleInput cin, IConsole cou) {
this.cin = cin;
this.cou = cou;
}
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems();
#else
var cin = new ConsoleInput(System.Console.In);
var console = new MyConsole();
new Program(cin, console).Solve();
console.Flush();
#endif
}
//=========================================================================================
// Library
//=========================================================================================
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[,] Array2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a, b];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
ret[i, j] = defaultValue;
}
}
return ret;
}
/// <summary>
/// 要素数 (a, b) のdefault値で満たされた配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <returns>初期化された配列</returns>
public static T[,] Array2D<T>(int a, int b)
where T : struct {
var ret = new T[a, b];
return ret;
}
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[][] JagArray2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
ret[i] = Enumerable.Repeat(defaultValue, b).ToArray();
}
return ret;
}
/// <summary>
/// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <returns>初期化された配列</returns>
public static T[][] JagArray2D<T>(int a, int b)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
ret[i] = new T[b];
}
return ret;
}
/// <summary>
/// ジャグ配列をコピーして返す。
/// </summary>
public static T[][] CopyJagArray<T>(T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
}
public class ConsoleInput {
private readonly char _separator = ' ';
private readonly TextReader _stream;
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => 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;
}
}
public interface IConsole {
void Flush();
void Write(object obj);
void Write(string str);
void WriteLine(object obj);
void WriteLine(string str);
void WriteLine();
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { Console.WriteLine(str); }
public void WriteLine() { Console.WriteLine(); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// 何もしない
}
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { mSb.Append(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public void WriteLine() { mSb.AppendLine(); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string GetDirectoryPath() {
var problemPart = string.IsNullOrEmpty(Program.ProblemName)
? ""
: $"/{Program.ProblemName}";
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
}
private string GetInputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
}
private string GetOutputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var cin = new ConsoleInput(inputStream);
var debugConsoleWriter = new DebugConsole();
new Program(cin, debugConsoleWriter).Solve();
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems(int targetTestCaseNumber = -1) {
if (targetTestCaseNumber >= 0) {
Console.WriteLine(
$"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
}
bool isSuccessAll = true;
int testCaseNumber = 0;
while (true) {
testCaseNumber++;
if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) {
continue;
}
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
#if UTAKA_LOCAL
public static class Dbg {
public static void WriteLine(string str) { Console.WriteLine(str); }
public static void Write(string str) { Console.Write(str); }
}
#else
public static class Dbg {
public static void WriteLine(string str) {}
public static void Write(string str) {}
}
#endif
}
|
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert
#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
namespace UtakaApp {
public partial class Program {
//=========================================================================================
// Answer
//=========================================================================================
public const string SiteName = "AtCoder";
public const string ContestName = "abc091";
public const string ProblemName = "C";
public void Solve() {
int N = cin.ReadInt;
List<Pair> R = new List<Pair>();
List<Pair> B = new List<Pair>();
for (int i = 0; i < N; i++) {
R.Add(new Pair(cin.ReadInt, cin.ReadInt));
}
for (int i = 0; i < N; i++) {
B.Add(new Pair(cin.ReadInt, cin.ReadInt));
}
var pairComparer = new PairComparer();
R.Sort(pairComparer);
B.Sort(pairComparer);
int count = 0;
for (int i = 0; i < N; i++) {
Pair p = B[i];
int foundIndex = -1;
int maxY = -1;
for (int j = 0; j < R.Count; j++) {
Pair q = R[j];
if (p.X <= q.X) {
break;
}
if (p.Y <= q.Y) {
continue;
}
if (q.Y > maxY) {
maxY = q.Y;
foundIndex = j;
}
}
if (foundIndex != -1) {
count++;
R.RemoveAt(foundIndex);
}
}
cou.WriteLine(count);
}
public class PairComparer : IComparer<Pair> {
public int Compare(Pair x, Pair y) {
if (x.X < y.X)
return -1;
if (x.X > y.X)
return 1;
if (x.Y < y.Y)
return -1;
if (x.Y > y.Y)
return 1;
return 0;
}
}
public sealed class Pair : Pair<int, int> {
public Pair(int x, int y) : base(x, y) {}
}
[DebuggerDisplay("({X}, {Y})")]
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>,
IEquatable<Pair<T1, T2>>
where T1 : IComparable<T1>
where T2 : IComparable<T2> {
public Pair(T1 x, T2 y) {
X = x;
Y = y;
}
public T1 X;
public T2 Y;
public int CompareTo(Pair<T1, T2> other) {
if (ReferenceEquals(this, other))
return 0;
if (ReferenceEquals(null, other))
return 1;
var firstComparison = X.CompareTo(other.X);
return firstComparison != 0 ? firstComparison : Y.CompareTo(other.Y);
}
public override string ToString() => $"({X}, {Y})";
public bool Equals(Pair<T1, T2> other) {
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
return EqualityComparer<T1>.Default.Equals(X, other.X) &&
EqualityComparer<T2>.Default.Equals(Y, other.Y);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
return obj.GetType() == this.GetType() && Equals((Pair<T1, T2>)obj);
}
public override int GetHashCode() {
unchecked {
return (EqualityComparer<T1>.Default.GetHashCode(X) * 397) ^
EqualityComparer<T2>.Default.GetHashCode(Y);
}
}
}
}
//=========================================================================================
// Debug IO
//=========================================================================================
public partial class Program {
//=========================================================================================
// Main
//=========================================================================================
private readonly ConsoleInput cin;
private readonly IConsole cou;
public Program(ConsoleInput cin, IConsole cou) {
this.cin = cin;
this.cou = cou;
}
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems();
#else
var cin = new ConsoleInput(System.Console.In);
var console = new MyConsole();
new Program(cin, console).Solve();
console.Flush();
#endif
}
//=========================================================================================
// Library
//=========================================================================================
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[,] Array2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a, b];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
ret[i, j] = defaultValue;
}
}
return ret;
}
/// <summary>
/// 要素数 (a, b) のdefault値で満たされた配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <returns>初期化された配列</returns>
public static T[,] Array2D<T>(int a, int b)
where T : struct {
var ret = new T[a, b];
return ret;
}
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[][] JagArray2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
ret[i] = Enumerable.Repeat(defaultValue, b).ToArray();
}
return ret;
}
/// <summary>
/// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <returns>初期化された配列</returns>
public static T[][] JagArray2D<T>(int a, int b)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
ret[i] = new T[b];
}
return ret;
}
/// <summary>
/// ジャグ配列をコピーして返す。
/// </summary>
public static T[][] CopyJagArray<T>(T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
}
public class ConsoleInput {
private readonly char _separator = ' ';
private readonly TextReader _stream;
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => 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;
}
}
public interface IConsole {
void Flush();
void Write(object obj);
void Write(string str);
void WriteLine(object obj);
void WriteLine(string str);
void WriteLine();
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { Console.WriteLine(str); }
public void WriteLine() { Console.WriteLine(); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// 何もしない
}
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { mSb.Append(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public void WriteLine() { mSb.AppendLine(); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string GetDirectoryPath() {
var problemPart = string.IsNullOrEmpty(Program.ProblemName)
? ""
: $"/{Program.ProblemName}";
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
}
private string GetInputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
}
private string GetOutputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var cin = new ConsoleInput(inputStream);
var debugConsoleWriter = new DebugConsole();
new Program(cin, debugConsoleWriter).Solve();
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems(int targetTestCaseNumber = -1) {
if (targetTestCaseNumber >= 0) {
Console.WriteLine(
$"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
}
bool isSuccessAll = true;
int testCaseNumber = 0;
while (true) {
testCaseNumber++;
if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) {
continue;
}
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
#if UTAKA_LOCAL
public static class Dbg {
public static void WriteLine(string str) { Console.WriteLine(str); }
public static void Write(string str) { Console.Write(str); }
}
#else
public static class Dbg {
public static void WriteLine(string str) {}
public static void Write(string str) {}
}
#endif
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117]]
| 8
| 2,441
| 27
|
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert
#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif
//#define TOPCODER
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using static UtakaApp.Util;
namespace UtakaApp {
public partial class Program {
/*
https://atcoder.jp/contests/abc089/tasks/abc089_d
*/
public const string SiteName = "AtCoder";
public const string ContestName = "abc089";
public const string ProblemName = "D";
public void Solve() {
int H = cin.ReadInt;
int W = cin.ReadInt;
int D = cin.ReadInt;
int[][] A = JagArray2D<int>(H, W);
for (int i = 0; i < H; i++) {
A[i] = cin.ReadIntArray(W);
}
Pair[] numToPos = new Pair[H * W + 1];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
int num = A[i][j];
numToPos[num] = new Pair(i, j);
}
}
// long[] S = new long[H * W + 1];
//
// for (int i = D + 1; i <= H * W; i++)
// {
// S[i] = S[i - D] + Math.Abs(numToPos[i].First - numToPos[i - D].First)
// + Math.Abs(numToPos[i].Second - numToPos[i - D].Second);
// }
//
// int Q = cin.ReadInt;
//
// for (int i = 0; i < Q; i++)
// {
// int l = cin.ReadInt;
// int r = cin.ReadInt;
//
// long ans = S[r] - S[l];
// cou.WriteLine(ans);
// }
int Q = cin.ReadInt;
int Len = (H * W + D - 1) / D;
// S[i][j] : [Dで割ったあまりがiであるマス][j + 1番目まで]の総和
long[][] S = JagArray2D<long>(D, Len + 2);
for (int k = 0; k < D; k++) {
int currX = -1;
int currY = -1;
int ind = 0;
for (int i = k; i <= H * W; i += D) {
Pair tmp = numToPos[i];
if (tmp != null) {
int nextX = tmp.First;
int nextY = tmp.Second;
if (currX >= 0) {
S[k][ind + 1] =
S[k][ind] + (Math.Abs(nextX - currX) + Math.Abs(nextY - currY));
}
currX = nextX;
currY = nextY;
}
ind++;
}
}
for (int query = 0; query < Q; query++) {
int l = cin.ReadInt;
int r = cin.ReadInt;
int k = l % D;
int start = l / D;
int goal = r / D;
if (k == 0) {
start++;
goal++;
}
long ans = S[k][goal + 1] - S[k][start + 1];
cou.WriteLine(ans);
}
}
public sealed class Pair : Pair<int, int> {
public Pair(int first, int second) : base(first, second) {}
}
[DebuggerDisplay("({First}, {Second})")]
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>,
IEquatable<Pair<T1, T2>>
where T1 : IComparable<T1>
where T2 : IComparable<T2> {
public Pair(T1 first, T2 second) {
First = first;
Second = second;
}
public T1 First;
public T2 Second;
public int CompareTo(Pair<T1, T2> other) {
if (ReferenceEquals(this, other))
return 0;
if (ReferenceEquals(null, other))
return 1;
var firstComparison = First.CompareTo(other.First);
return firstComparison != 0 ? firstComparison
: Second.CompareTo(other.Second);
}
public override string ToString() => $"({First}, {Second})";
public bool Equals(Pair<T1, T2> other) {
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
return EqualityComparer<T1>.Default.Equals(First, other.First) &&
EqualityComparer<T2>.Default.Equals(Second, other.Second);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
return obj.GetType() == this.GetType() && Equals((Pair<T1, T2>)obj);
}
public override int GetHashCode() {
unchecked {
return (EqualityComparer<T1>.Default.GetHashCode(First) * 397) ^
EqualityComparer<T2>.Default.GetHashCode(Second);
}
}
}
}
//=========================================================================================
// Debug IO
//=========================================================================================
public partial class Program {
//=========================================================================================
// Main
//=========================================================================================
private readonly ConsoleInput cin;
private readonly IConsole cou;
public Program(ConsoleInput cin, IConsole cou) {
this.cin = cin;
this.cou = cou;
}
#if !TOPCODER
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems(3);
#else
var cin = new ConsoleInput(System.Console.In);
var console = new MyConsole();
new Program(cin, console).Solve();
console.Flush();
#endif
}
#endif
public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") {
if (!A.Any()) {
return;
}
var sb = new StringBuilder();
foreach (T v in A) {
sb.Append(v);
sb.Append(delimiter);
}
if (sb.Length > 0) {
sb.Length--;
}
cou.WriteLine(sb.ToString());
}
}
public static class Util {
public static int LowerBound<T>(T[] arr, int start, int end, T value,
IComparer<T> comparer) {
int low = start;
int high = end;
while (low < high) {
var 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>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static int UpperBound<T>(T[] arr, int start, int end, T value,
IComparer<T> comparer) {
int low = start;
int high = end;
while (low < high) {
var 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>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static int UpperBound<T>(List<T> list, int start, int end, T value,
IComparer<T> comparer) {
int low = start;
int high = end;
while (low < high) {
var mid = ((high - low) >> 1) + low;
if (comparer.Compare(list[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int UpperBound<T>(List<T> list, T value) {
return UpperBound(list, 0, list.Count, value, Comparer<T>.Default);
}
public static T[] Array1D<T>(int a, T defaultValue)
where T : struct {
var ret = new T[a];
for (int i = 0; i < a; i++) {
ret[i] = defaultValue;
}
return ret;
}
public static T[] Array1D<T>(int a)
where T : struct {
var ret = new T[a];
return ret;
}
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[,] Array2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a, b];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
ret[i, j] = defaultValue;
}
}
return ret;
}
public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue)
where T : struct {
T[,,] ret = new T[a, b, c];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
for (int k = 0; k < c; k++) {
ret[i, j, k] = defaultValue;
}
}
}
return ret;
}
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[][] JagArray2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
var row = new T[b];
ret[i] = row;
for (int j = 0; j < b; j++) {
row[j] = defaultValue;
}
}
return ret;
}
/// <summary>
/// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <returns>初期化された配列</returns>
public static T[][] JagArray2D<T>(int a, int b)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
ret[i] = new T[b];
}
return ret;
}
public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue)
where T : struct {
var ret = new T[a][][];
for (int i = 0; i < a; i++) {
T[][] aRow = new T[b][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[] bRow = new T[c];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
bRow[k] = defaultValue;
}
}
}
return ret;
}
public static T[][][] JagArray3D<T>(int a, int b, int c)
where T : struct {
var ret = new T[a][][];
for (int i = 0; i < a; i++) {
T[][] aRow = new T[b][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[] bRow = new T[c];
aRow[j] = bRow;
}
}
return ret;
}
public static T[][][][] JagArray4D<T>(int a, int b, int c, int d,
T defaultValue)
where T : struct {
var ret = new T[a][][][];
for (int i = 0; i < a; i++) {
T[][][] aRow = new T[b][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][] bRow = new T[c][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[] cRow = new T[d];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
cRow[l] = defaultValue;
}
}
}
}
return ret;
}
public static T[][][][] JagArray4D<T>(int a, int b, int c, int d)
where T : struct {
var ret = new T[a][][][];
for (int i = 0; i < a; i++) {
T[][][] aRow = new T[b][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][] bRow = new T[c][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[] cRow = new T[d];
bRow[k] = cRow;
}
}
}
return ret;
}
public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e,
T defaultValue)
where T : struct {
var ret = new T[a][][][][];
for (int i = 0; i < a; i++) {
T[][][][] aRow = new T[b][][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][][] bRow = new T[c][][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[][] cRow = new T[d][];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
T[] dRow = new T[e];
cRow[l] = dRow;
for (int m = 0; m < e; m++) {
dRow[m] = defaultValue;
}
}
}
}
}
return ret;
}
public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e)
where T : struct {
var ret = new T[a][][][][];
for (int i = 0; i < a; i++) {
T[][][][] aRow = new T[b][][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][][] bRow = new T[c][][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[][] cRow = new T[d][];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
T[] dRow = new T[e];
cRow[l] = dRow;
}
}
}
}
return ret;
}
/// <summary>
/// ジャグ配列をコピーして返す。
/// </summary>
public static T[][] CopyJagArray2D<T>(T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
}
public static class UtakaExtentions {
/// <summary>
/// IList<T>をコピーします
/// </summary>
public static T[] Copy<T>(this IList<T> a) {
T[] ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
/// <summary>
/// 2次元ジャグ配列をコピーして返す。
/// </summary>
public static T[][] Copy<T>(this T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
/// <summary>
/// 昇順にソートされたlong配列で、threshold以上の値をカウントする
/// </summary>
public static int LargerCount(this long[] a, long threshold) {
int ng = -1;
int ok = a.Length;
while (Math.Abs(ng - ok) > 1) {
int mid = (ok + ng) / 2;
if (threshold <= a[mid]) {
ok = mid;
} else {
ng = mid;
}
}
return a.Length - ok;
}
}
public class IntLargeComparer : IComparer<int> {
public static IntLargeComparer Instance = new IntLargeComparer();
public int Compare(int x, int y) { return y - x; }
}
public class LongLargeComparer : IComparer<long> {
public static LongLargeComparer Instance = new LongLargeComparer();
public int Compare(long x, long y) {
if (x > y)
return -1;
if (x < y)
return 1;
return 0;
}
}
public class ConsoleInput {
private readonly char _separator = ' ';
private readonly TextReader _stream;
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => 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 int[] ReadIntArrayMinus1(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadInt - 1;
}
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadLong;
}
return ret;
}
}
public interface IConsole {
void Flush();
void Write(object obj);
void Write(string str);
void WriteLine(object obj);
void WriteLine(string str);
void WriteLine();
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { Console.WriteLine(str); }
public void WriteLine() { Console.WriteLine(); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// 何もしない
}
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { mSb.Append(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public void WriteLine() { mSb.AppendLine(); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string GetDirectoryPath() {
var problemPart = string.IsNullOrEmpty(Program.ProblemName)
? ""
: $"/{Program.ProblemName}";
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
}
private string GetInputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
}
private string GetOutputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var cin = new ConsoleInput(inputStream);
var debugConsoleWriter = new DebugConsole();
new Program(cin, debugConsoleWriter).Solve();
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems(int targetTestCaseNumber = -1) {
if (targetTestCaseNumber >= 0) {
Console.WriteLine(
$"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
}
bool isSuccessAll = true;
int testCaseNumber = 0;
while (true) {
testCaseNumber++;
bool foundTargetTest = targetTestCaseNumber == testCaseNumber;
if (targetTestCaseNumber >= 0 && !foundTargetTest) {
continue;
}
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
if (foundTargetTest) {
break;
}
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
public static class Dbg {
[Conditional("UTAKA_DEBUG")]
public static void WriteLine(string str) { Console.WriteLine(str); }
[Conditional("UTAKA_DEBUG")]
public static void WriteLine() { Console.WriteLine(); }
[Conditional("UTAKA_DEBUG")]
public static void Write(string str) { Console.Write(str); }
}
}
|
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert
#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif
//#define TOPCODER
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using static UtakaApp.Util;
namespace UtakaApp {
public partial class Program {
/*
https://atcoder.jp/contests/abc089/tasks/abc089_d
*/
public const string SiteName = "AtCoder";
public const string ContestName = "abc089";
public const string ProblemName = "D";
public void Solve() {
int H = cin.ReadInt;
int W = cin.ReadInt;
int D = cin.ReadInt;
int[][] A = JagArray2D<int>(H, W);
for (int i = 0; i < H; i++) {
A[i] = cin.ReadIntArray(W);
}
Pair[] numToPos = new Pair[H * W + 1];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
int num = A[i][j];
numToPos[num] = new Pair(i, j);
}
}
// long[] S = new long[H * W + 1];
//
// for (int i = D + 1; i <= H * W; i++)
// {
// S[i] = S[i - D] + Math.Abs(numToPos[i].First - numToPos[i - D].First)
// + Math.Abs(numToPos[i].Second - numToPos[i - D].Second);
// }
//
// int Q = cin.ReadInt;
//
// for (int i = 0; i < Q; i++)
// {
// int l = cin.ReadInt;
// int r = cin.ReadInt;
//
// long ans = S[r] - S[l];
// cou.WriteLine(ans);
// }
int Q = cin.ReadInt;
int Len = (H * W + D - 1) / D;
// S[i][j] : [Dで割ったあまりがiであるマス][j + 1番目まで]の総和
long[][] S = JagArray2D<long>(D, Len + 2);
for (int k = 0; k < D; k++) {
int currX = -1;
int currY = -1;
int ind = 0;
for (int i = k; i <= H * W; i += D) {
Pair tmp = numToPos[i];
if (tmp != null) {
int nextX = tmp.First;
int nextY = tmp.Second;
if (currX >= 0) {
S[k][ind + 1] =
S[k][ind] + (Math.Abs(nextX - currX) + Math.Abs(nextY - currY));
}
currX = nextX;
currY = nextY;
}
ind++;
}
}
for (int query = 0; query < Q; query++) {
int l = cin.ReadInt;
int r = cin.ReadInt;
int k = l % D;
int start = l / D;
int goal = r / D;
// if (k == 0)
// {
// start++;
// goal++;
// }
long ans = S[k][goal + 1] - S[k][start + 1];
cou.WriteLine(ans);
}
}
public sealed class Pair : Pair<int, int> {
public Pair(int first, int second) : base(first, second) {}
}
[DebuggerDisplay("({First}, {Second})")]
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>,
IEquatable<Pair<T1, T2>>
where T1 : IComparable<T1>
where T2 : IComparable<T2> {
public Pair(T1 first, T2 second) {
First = first;
Second = second;
}
public T1 First;
public T2 Second;
public int CompareTo(Pair<T1, T2> other) {
if (ReferenceEquals(this, other))
return 0;
if (ReferenceEquals(null, other))
return 1;
var firstComparison = First.CompareTo(other.First);
return firstComparison != 0 ? firstComparison
: Second.CompareTo(other.Second);
}
public override string ToString() => $"({First}, {Second})";
public bool Equals(Pair<T1, T2> other) {
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
return EqualityComparer<T1>.Default.Equals(First, other.First) &&
EqualityComparer<T2>.Default.Equals(Second, other.Second);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
return obj.GetType() == this.GetType() && Equals((Pair<T1, T2>)obj);
}
public override int GetHashCode() {
unchecked {
return (EqualityComparer<T1>.Default.GetHashCode(First) * 397) ^
EqualityComparer<T2>.Default.GetHashCode(Second);
}
}
}
}
//=========================================================================================
// Debug IO
//=========================================================================================
public partial class Program {
//=========================================================================================
// Main
//=========================================================================================
private readonly ConsoleInput cin;
private readonly IConsole cou;
public Program(ConsoleInput cin, IConsole cou) {
this.cin = cin;
this.cou = cou;
}
#if !TOPCODER
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems(3);
#else
var cin = new ConsoleInput(System.Console.In);
var console = new MyConsole();
new Program(cin, console).Solve();
console.Flush();
#endif
}
#endif
public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") {
if (!A.Any()) {
return;
}
var sb = new StringBuilder();
foreach (T v in A) {
sb.Append(v);
sb.Append(delimiter);
}
if (sb.Length > 0) {
sb.Length--;
}
cou.WriteLine(sb.ToString());
}
}
public static class Util {
public static int LowerBound<T>(T[] arr, int start, int end, T value,
IComparer<T> comparer) {
int low = start;
int high = end;
while (low < high) {
var 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>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static int UpperBound<T>(T[] arr, int start, int end, T value,
IComparer<T> comparer) {
int low = start;
int high = end;
while (low < high) {
var 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>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static int UpperBound<T>(List<T> list, int start, int end, T value,
IComparer<T> comparer) {
int low = start;
int high = end;
while (low < high) {
var mid = ((high - low) >> 1) + low;
if (comparer.Compare(list[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int UpperBound<T>(List<T> list, T value) {
return UpperBound(list, 0, list.Count, value, Comparer<T>.Default);
}
public static T[] Array1D<T>(int a, T defaultValue)
where T : struct {
var ret = new T[a];
for (int i = 0; i < a; i++) {
ret[i] = defaultValue;
}
return ret;
}
public static T[] Array1D<T>(int a)
where T : struct {
var ret = new T[a];
return ret;
}
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[,] Array2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a, b];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
ret[i, j] = defaultValue;
}
}
return ret;
}
public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue)
where T : struct {
T[,,] ret = new T[a, b, c];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
for (int k = 0; k < c; k++) {
ret[i, j, k] = defaultValue;
}
}
}
return ret;
}
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[][] JagArray2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
var row = new T[b];
ret[i] = row;
for (int j = 0; j < b; j++) {
row[j] = defaultValue;
}
}
return ret;
}
/// <summary>
/// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <returns>初期化された配列</returns>
public static T[][] JagArray2D<T>(int a, int b)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
ret[i] = new T[b];
}
return ret;
}
public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue)
where T : struct {
var ret = new T[a][][];
for (int i = 0; i < a; i++) {
T[][] aRow = new T[b][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[] bRow = new T[c];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
bRow[k] = defaultValue;
}
}
}
return ret;
}
public static T[][][] JagArray3D<T>(int a, int b, int c)
where T : struct {
var ret = new T[a][][];
for (int i = 0; i < a; i++) {
T[][] aRow = new T[b][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[] bRow = new T[c];
aRow[j] = bRow;
}
}
return ret;
}
public static T[][][][] JagArray4D<T>(int a, int b, int c, int d,
T defaultValue)
where T : struct {
var ret = new T[a][][][];
for (int i = 0; i < a; i++) {
T[][][] aRow = new T[b][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][] bRow = new T[c][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[] cRow = new T[d];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
cRow[l] = defaultValue;
}
}
}
}
return ret;
}
public static T[][][][] JagArray4D<T>(int a, int b, int c, int d)
where T : struct {
var ret = new T[a][][][];
for (int i = 0; i < a; i++) {
T[][][] aRow = new T[b][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][] bRow = new T[c][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[] cRow = new T[d];
bRow[k] = cRow;
}
}
}
return ret;
}
public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e,
T defaultValue)
where T : struct {
var ret = new T[a][][][][];
for (int i = 0; i < a; i++) {
T[][][][] aRow = new T[b][][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][][] bRow = new T[c][][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[][] cRow = new T[d][];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
T[] dRow = new T[e];
cRow[l] = dRow;
for (int m = 0; m < e; m++) {
dRow[m] = defaultValue;
}
}
}
}
}
return ret;
}
public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e)
where T : struct {
var ret = new T[a][][][][];
for (int i = 0; i < a; i++) {
T[][][][] aRow = new T[b][][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][][] bRow = new T[c][][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[][] cRow = new T[d][];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
T[] dRow = new T[e];
cRow[l] = dRow;
}
}
}
}
return ret;
}
/// <summary>
/// ジャグ配列をコピーして返す。
/// </summary>
public static T[][] CopyJagArray2D<T>(T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
}
public static class UtakaExtentions {
/// <summary>
/// IList<T>をコピーします
/// </summary>
public static T[] Copy<T>(this IList<T> a) {
T[] ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
/// <summary>
/// 2次元ジャグ配列をコピーして返す。
/// </summary>
public static T[][] Copy<T>(this T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
/// <summary>
/// 昇順にソートされたlong配列で、threshold以上の値をカウントする
/// </summary>
public static int LargerCount(this long[] a, long threshold) {
int ng = -1;
int ok = a.Length;
while (Math.Abs(ng - ok) > 1) {
int mid = (ok + ng) / 2;
if (threshold <= a[mid]) {
ok = mid;
} else {
ng = mid;
}
}
return a.Length - ok;
}
}
public class IntLargeComparer : IComparer<int> {
public static IntLargeComparer Instance = new IntLargeComparer();
public int Compare(int x, int y) { return y - x; }
}
public class LongLargeComparer : IComparer<long> {
public static LongLargeComparer Instance = new LongLargeComparer();
public int Compare(long x, long y) {
if (x > y)
return -1;
if (x < y)
return 1;
return 0;
}
}
public class ConsoleInput {
private readonly char _separator = ' ';
private readonly TextReader _stream;
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => 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 int[] ReadIntArrayMinus1(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadInt - 1;
}
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadLong;
}
return ret;
}
}
public interface IConsole {
void Flush();
void Write(object obj);
void Write(string str);
void WriteLine(object obj);
void WriteLine(string str);
void WriteLine();
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { Console.WriteLine(str); }
public void WriteLine() { Console.WriteLine(); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// 何もしない
}
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { mSb.Append(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public void WriteLine() { mSb.AppendLine(); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string GetDirectoryPath() {
var problemPart = string.IsNullOrEmpty(Program.ProblemName)
? ""
: $"/{Program.ProblemName}";
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
}
private string GetInputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
}
private string GetOutputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var cin = new ConsoleInput(inputStream);
var debugConsoleWriter = new DebugConsole();
new Program(cin, debugConsoleWriter).Solve();
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems(int targetTestCaseNumber = -1) {
if (targetTestCaseNumber >= 0) {
Console.WriteLine(
$"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
}
bool isSuccessAll = true;
int testCaseNumber = 0;
while (true) {
testCaseNumber++;
bool foundTargetTest = targetTestCaseNumber == testCaseNumber;
if (targetTestCaseNumber >= 0 && !foundTargetTest) {
continue;
}
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
if (foundTargetTest) {
break;
}
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
public static class Dbg {
[Conditional("UTAKA_DEBUG")]
public static void WriteLine(string str) { Console.WriteLine(str); }
[Conditional("UTAKA_DEBUG")]
public static void WriteLine() { Console.WriteLine(); }
[Conditional("UTAKA_DEBUG")]
public static void Write(string str) { Console.Write(str); }
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 4,741
| 14
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
var n = Console.ReadLine();
// int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
var ans = 0;
var ok = true;
for (int i = n.Length - 1; i >= 0; i--) {
if (n[i] != '9')
ok = false;
if (i != 0) {
ans += 9;
} else {
if (ok)
ans += 9;
else
ans += int.Parse(n[i].ToString()) - 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 s = Console.ReadLine();
var n = Console.ReadLine();
// int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
var ans = 0;
var ok = true;
for (int i = n.Length - 1; i >= 0; i--) {
if (i != 0) {
if (n[i] != '9')
ok = false;
ans += 9;
} else {
if (ok)
ans += int.Parse(n[i].ToString());
else
ans += int.Parse(n[i].ToString()) - 1;
}
}
// 出力
Console.WriteLine(ans);
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 75, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 147
| 28
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
public static List<Pair>[
,
] pairs;
public static int[,] ans;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
char[] n = scan.Scan().ToCharArray();
int[] ruiseki = new int[n.Length];
ruiseki[0] = n[0] - '0';
for (int i = 1; i < n.Length; i++) {
ruiseki[i] = ruiseki[i - 1] + n[i] - '0';
}
int[] ans = new int[n.Length];
for (int i = 0; i < n.Length; i++) {
ans[i] = ruiseki[i] - 1 + 9 * (n.Length - 1 - i);
}
Console.WriteLine(ans.Max());
}
static int[] Togo;
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
public static List<Pair>[
,
] pairs;
public static int[,] ans;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
char[] n = scan.Scan().ToCharArray();
int[] ruiseki = new int[n.Length];
ruiseki[0] = n[0] - '0';
for (int i = 1; i < n.Length; i++) {
ruiseki[i] = ruiseki[i - 1] + n[i] - '0';
}
int[] ans = new int[n.Length + 1];
for (int i = 0; i < n.Length; i++) {
ans[i] = ruiseki[i] - 1 + 9 * (n.Length - 1 - i);
}
ans[n.Length] = ruiseki[n.Length - 1];
Console.WriteLine(ans.Max());
}
static int[] Togo;
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
}
|
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 0, 131], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 141, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 9,532
| 18
|
using System;
namespace agc021a {
class Program {
static void Main(string[] args) {
var N = Console.ReadLine();
var ret = int.Parse(N[0].ToString()) + 9 * (N.Length - 1);
//文字列Nの最上位の桁(0番目)以降の中から9を削除した時のNの長さが0以外の時
//入力値Nから最上位の桁を1引いて他の桁を9にした値の桁の和が最大
if (N.Substring(1).Replace("9", "").Length != 0)
ret -= 1;
Console.WriteLine(ret);
Console.WriteLine(N.Substring(1).Replace("9", ""));
}
}
}
|
using System;
namespace agc021a {
class Program {
static void Main(string[] args) {
var N = Console.ReadLine();
var ret = int.Parse(N[0].ToString()) + 9 * (N.Length - 1);
//文字列Nの最上位の桁(0番目)以降の中から9を削除した時のNの長さが0以外の時
//入力値Nから最上位の桁を1引いて他の桁を9にした値の桁の和が最大
if (N.Substring(1).Replace("9", "").Length != 0)
ret -= 1;
Console.WriteLine(ret);
// Console.WriteLine(N.Substring(1).Replace("9",""));
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 116
| 22
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
public static void Main() {
// 方針
//
var n = rstr();
var t = true;
for (int i = 0; i < n.Length; i++) {
if (n[i] != '9')
t = false;
}
if (t) {
WriteLine(n.Length * 9);
} else {
WriteLine((n.Length - 1) * 9 + int.Parse(n[0].ToString()) - 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
public static void Main() {
// 方針
//
var n = rstr();
var t = true;
for (int i = 1; i < n.Length; i++) {
if (n[i] != '9')
t = false;
}
if (t) {
WriteLine((n.Length - 1) * 9 + int.Parse(n[0].ToString()));
} else {
WriteLine((n.Length - 1) * 9 + int.Parse(n[0].ToString()) - 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 1,269
| 20
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ここから
static void Solve() {
var S = GetStr();
var ans = int.Parse(S[0].ToString()) - 1 + (S.Length - 1) * 9;
Console.WriteLine(ans);
}
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
static public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
static public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
static public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
static public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
static public void WriteObjects<T>(IReadOnlyCollection<T> values) {
var array = values.ToArray();
var num = array.Length;
Console.Write(array[0]);
for (int i = 1; i < num; i++) {
Console.Write(" " + array[i]);
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d,
out X e, out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ここから
static void Solve() {
var S = GetStr();
var ans =
Math.Max(S.ToCharArray().Select(c => int.Parse(c.ToString())).Sum(),
int.Parse(S[0].ToString()) - 1 + (S.Length - 1) * 9);
Console.WriteLine(ans);
}
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
static public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
static public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
static public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
static public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
static public void WriteObjects<T>(IReadOnlyCollection<T> values) {
var array = values.ToArray();
var num = array.Length;
Console.Write(array[0]);
for (int i = 1; i < num; i++) {
Console.Write(" " + array[i]);
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d,
out X e, out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
}
|
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 1,485
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class92 {
static void Main() {
var N = Console.ReadLine().ToCharArray();
var S = string.Join("", N).Substring(1);
if (!S.All(x => x == '9')) {
N[0] = (int.Parse(N[0].ToString()) - 1).ToString()[0];
Console.WriteLine(int.Parse(N[0].ToString()) + 9 * S.Length);
} else {
Console.WriteLine(9 * N.Length);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class92 {
static void Main() {
var N = Console.ReadLine().ToCharArray();
var S = string.Join("", N).Substring(1);
if (!S.All(x => x == '9')) {
N[0] = (int.Parse(N[0].ToString()) - 1).ToString()[0];
Console.WriteLine(int.Parse(N[0].ToString()) + 9 * S.Length);
} else {
Console.WriteLine(int.Parse(N[0].ToString()) + 9 * S.Length);
}
}
}
}
|
[["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 16, 12, 214, 205, 22]]
| 8
| 160
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using static System.Console;
class Program {
static void Main() {
var N = ReadLine();
if (N.Length == 1)
WriteLine(N);
else if (N.Count(x => x == '9') == N.Length)
WriteLine(N.Select(x => int.Parse(x + "")).Sum());
else if (N.First() == '1' && N.Count(x => x == '9') == N.Length - 1)
WriteLine(N);
else {
WriteLine(((int.Parse(N.First() + "") - 1).ToString() +
"99999999999999999999999999999999999999999999".Substring(
0, N.Length - 1))
.Select(x => long.Parse(x + ""))
.Sum());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using static System.Console;
class Program {
static void Main() {
var N = ReadLine();
if (N.Length == 1)
WriteLine(N);
else if (N.Count(x => x == '9') == N.Length)
WriteLine(N.Select(x => int.Parse(x + "")).Sum());
else if (N.First() != '9' && N.Count(x => x == '9') == N.Length - 1)
WriteLine(N.Select(x => int.Parse(x + "")).Sum());
else {
WriteLine(((int.Parse(N.First() + "") - 1).ToString() +
"99999999999999999999999999999999999999999999".Substring(
0, N.Length - 1))
.Select(x => long.Parse(x + ""))
.Sum());
}
}
}
|
[["-", 75, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 79], ["-", 75, 57, 15, 16, 31, 16, 12, 252, 0, 253], ["+", 75, 57, 15, 16, 31, 16, 12, 252, 0, 253], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["+", 8, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 8, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 212
| 23
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var n = Console.ReadLine();
var score = Calculation.Calculate(n);
Console.WriteLine(score);
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class Calculation {
internal static object Calculate(string n) {
if (n.Length == 1)
return n;
var cand1 = int.Parse(n.First().ToString()) - 1 + (n.Length - 1) * 9;
var maxDigit = n.Skip(1).Select(c => int.Parse(c.ToString())).Max();
var cand2 = (n.Length - 2) * 9 + (maxDigit - 1);
return Math.Max(cand1, cand2);
}
}
static class RootedTreeNodesFactory {
public class RootedTreeNode {
public int Id { get; }
public int Parent { get; }
public int Depth { get; set; }
int[] Childs { get; }
public RootedTreeNode(int id, int parent, int[] childs) {
this.Id = id;
this.Parent = parent;
this.Childs = childs;
}
}
}
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>
public static int[] CountingSort(int[] aArr, int k) {
int[] b, c;
var n = aArr.Length;
b = new int[n];
c = Enumerable.Repeat(0, k + 1).ToArray();
for (int i = 0; i < n; i++) {
c[aArr[i]]++;
}
for (int i = 1; i <= k; i++) {
c[i] += c[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
b[c[aArr[i]] - 1] = aArr[i];
c[aArr[i]]--;
}
return b;
}
}
/// <summary>無向グラフ</summary>
class UndirectedGraph {
public Dictionary<int, List<int>> Graph { get; }
/// <param name="graphArr">point1 to point2</param>
/// <param name="n">グラフの全要素数</param>
public UndirectedGraph(int[][] graphArr, int n) {
Graph = new Dictionary<int, List<int>>();
for (int i = 1; i <= n; i++) {
Graph.Add(i, new List<int>());
}
foreach (var arr in graphArr) {
Graph[arr[0]].Add(arr[1]);
Graph[arr[1]].Add(arr[0]);
}
}
}
/// <summary>DeepCopyするクラス</summary>
class DeepCopier {
BinaryFormatter b = new BinaryFormatter();
public T DeepCopy<T>(T obj) {
T result;
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
static class MergeSort {
public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); }
// rightは+1されていることに注意
private static long[] Merge(long[] sArr, int left, int mid, int right) {
var n1 = mid - left;
var n2 = right - mid;
var lArr = new long[n1 + 1];
var rArr = new long[n2 + 1];
for (int i = 0; i < n1; i++) {
lArr[i] = sArr[left + i];
}
lArr[n1] = int.MaxValue;
for (int i = 0; i < n2; i++) {
rArr[i] = sArr[mid + i];
}
rArr[n2] = int.MaxValue;
int l = 0, r = 0;
for (int k = left; k < right; k++) {
if (lArr[l] <= rArr[r]) {
sArr[k] = lArr[l];
l++;
} else {
sArr[k] = rArr[r];
r++;
}
}
return sArr; // 要素数はright - left
}
private static long[] Sort(long[] sArr, int left, int right) {
if (left + 1 < right) {
var mid = (left + right) / 2;
sArr = Sort(sArr, left, mid);
sArr = Sort(sArr, mid, right);
sArr = Merge(sArr, left, mid, right);
}
return sArr;
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
/// <summary>拡張メソッドs</summary>
static class Extention {
/// <summary>iとjを入れ替える</summary>
public static void Swap<T>(this T[] arr, int i, int j) {
var buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
}
/// <summary>
/// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。
/// </summary>
/// <param name="sArr"></param>
/// <param name="p">partitionの先頭の添字</param>
/// <param name="r">partitionの末尾の添字</param>
/// <returns>partitionの基準が存在する添字</returns>
public static int Partition(this int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
/// <summary>深いコピーをする</summary>
public static T DeepCopy<T>(this T obj) {
T result;
var b = new BinaryFormatter();
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var n = Console.ReadLine();
var score = Calculation.Calculate(n);
Console.WriteLine(score);
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class Calculation {
internal static object Calculate(string n) {
if (n.Length == 1)
return n;
var cand1 = int.Parse(n.First().ToString()) - 1 + (n.Length - 1) * 9;
var cand2 = n.Select(i => int.Parse(i.ToString())).Sum();
return Math.Max(cand1, cand2);
}
}
static class RootedTreeNodesFactory {
public class RootedTreeNode {
public int Id { get; }
public int Parent { get; }
public int Depth { get; set; }
int[] Childs { get; }
public RootedTreeNode(int id, int parent, int[] childs) {
this.Id = id;
this.Parent = parent;
this.Childs = childs;
}
}
}
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>
public static int[] CountingSort(int[] aArr, int k) {
int[] b, c;
var n = aArr.Length;
b = new int[n];
c = Enumerable.Repeat(0, k + 1).ToArray();
for (int i = 0; i < n; i++) {
c[aArr[i]]++;
}
for (int i = 1; i <= k; i++) {
c[i] += c[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
b[c[aArr[i]] - 1] = aArr[i];
c[aArr[i]]--;
}
return b;
}
}
/// <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;
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["-", 31, 16, 31, 23, 0, 16, 31, 214, 205, 22], ["-", 31, 16, 31, 23, 0, 16, 31, 214, 141, 22], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 212, 0, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203]]
| 8
| 3,261
| 32
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
if (n < 10) {
Console.WriteLine(n);
return;
}
bool allNine = true;
int count = 0;
for (count = 0; n >= 10; count++) {
if (n % 10 != 9)
allNine = false;
n = n / 10;
}
if (allNine)
Console.WriteLine(9 * count + 9);
else
Console.WriteLine(9 * count + n - 1);
}
}
// mcs Main.cs
// mono Main.exe
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
if (n < 10) {
Console.WriteLine(n);
return;
}
bool allNine = true;
int count = 0;
for (count = 0;; count++) {
if (n % 10 != 9)
allNine = false;
n = n / 10;
if (n < 10)
break;
}
if (allNine)
Console.WriteLine(9 * count + n + 9);
else
Console.WriteLine(9 * count + n + 8);
}
}
// mcs Main.cs
// mono Main.exe
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 130
| 17
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.