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 AtCoder.Abc {
class QuestionB {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数の入力
int num_K = int.Parse(Console.ReadLine());
// 文字列の入力
var str_S = Console.ReadLine();
var num_Length = str_S.Length;
if (num_Length <= num_K) {
Console.WriteLine(str_S);
} else if (num_Length > num_K) {
var str_SS = str_S.Substring(0, 7) + "...";
Console.WriteLine(str_SS);
}
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionB {
/// <summary>
/// https://atcoder.jp/contests/abc168/tasks/abc168_b
/// </summary>
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数の入力
int num_K = int.Parse(Console.ReadLine());
// 文字列の入力
string str_S = Console.ReadLine();
int num_Length = str_S.Length;
if (num_Length <= num_K) {
Console.WriteLine(str_S);
} else if (num_Length > num_K) {
string str_SS = str_S.Substring(0, num_K) + "...";
Console.WriteLine(str_SS);
}
Console.Out.Flush();
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 165
| 8
|
using System;
public class Hello {
public static void Main() {
int n = int.Parse(Console.ReadLine());
string str = Console.ReadLine();
int s = str.Length;
if (s > n) {
Console.WriteLine(str.Substring(0, 7) + "...");
} else {
Console.WriteLine(str);
}
}
}
|
using System;
public class Hello {
public static void Main() {
int n = int.Parse(Console.ReadLine());
string str = Console.ReadLine();
int s = str.Length;
if (s > n) {
Console.WriteLine(str.Substring(0, n) + "...");
} else {
Console.WriteLine(str);
}
}
}
|
[["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 82
| 2
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
int s = int.Parse(Console.ReadLine());
string k = Console.ReadLine();
if (k.Length < s) {
Console.WriteLine(k);
} else {
var span = k.AsSpan().Slice(0, s);
Console.WriteLine(span.ToString() + "...");
}
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
int s = int.Parse(Console.ReadLine());
string k = Console.ReadLine();
if (k.Length <= s) {
Console.WriteLine(k);
} else {
var span = k.AsSpan().Slice(0, s);
Console.WriteLine(span.ToString() + "...");
}
Console.Out.Flush();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 138
| 2
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
string K = Console.ReadLine();
string S = Console.ReadLine();
int Ka = int.Parse(K);
int Sa = S.Length;
if (Ka >= Sa) {
Console.WriteLine(S);
} else if (Ka < Sa) {
Console.WriteLine(S.Substring(0, Ka));
}
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
string K = Console.ReadLine();
string S = Console.ReadLine();
int Ka = int.Parse(K);
int Sa = S.Length;
if (Ka >= Sa) {
Console.WriteLine(S);
} else if (Ka < Sa) {
Console.WriteLine(S.Substring(0, Ka) + "...");
}
}
}
|
[["+", 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, 222]]
| 8
| 94
| 4
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int K = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
int flg = S.Length;
if (K - flg >= 0) {
Console.Write(S);
} else {
for (int i = 0; i < flg - K; i++) {
Console.Write(S[i]);
}
Console.Write("...");
}
}
}
}
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int K = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
int flg = S.Length;
if (K - flg >= 0) {
Console.Write(S);
} else {
for (int i = 0; i < K; i++) {
Console.Write(S[i]);
}
Console.Write("...");
}
}
}
}
|
[["-", 75, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 75, 196, 0, 7, 15, 16, 12, 16, 17, 33]]
| 8
| 109
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
public static class program {
public static void Main() {
var K = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
if (K <= S.Length) {
var ans = "";
for (var i = 0; i < K; i++) {
ans = ans + S[i];
}
ans = ans + "...";
Console.WriteLine(ans);
} else {
Console.WriteLine(S);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
public static class program {
public static void Main() {
var K = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
if (K < S.Length) {
var ans = "";
for (var i = 0; i < K; i++) {
ans = ans + S[i];
}
ans = ans + "...";
Console.WriteLine(ans);
} else {
Console.WriteLine(S);
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 122
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC168_B {
class Program {
static void Main(string[] args) {
int K = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
if (S.Length >= K) {
S = S.Substring(0, K) + "...";
}
Console.WriteLine(S);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC168_B {
class Program {
static void Main(string[] args) {
int K = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
if (S.Length > K) {
S = S.Substring(0, K) + "...";
}
Console.WriteLine(S);
Console.ReadLine();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 107
| 2
|
using System;
namespace _168 {
class Program {
static void Main(string[] args) { B(); }
public static void A() {
int x = int.Parse(Console.ReadLine()) % 10;
if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
Console.WriteLine("hon");
}
if (x == 0 || x == 6 || x == 1 || x == 8) {
Console.WriteLine("pon");
}
if (x == 3) {
Console.WriteLine("bon");
}
}
public static void B() {
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (s.Length > k) {
Console.WriteLine(s.Substring(0, 7) + "...");
} else {
Console.WriteLine(s);
}
}
}
}
|
using System;
namespace _168 {
class Program {
static void Main(string[] args) { B(); }
public static void A() {
int x = int.Parse(Console.ReadLine()) % 10;
if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
Console.WriteLine("hon");
}
if (x == 0 || x == 6 || x == 1 || x == 8) {
Console.WriteLine("pon");
}
if (x == 3) {
Console.WriteLine("bon");
}
}
public static void B() {
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (s.Length > k) {
Console.WriteLine(s.Substring(0, k) + "...");
} else {
Console.WriteLine(s);
}
}
}
}
|
[["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 198
| 2
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace AtCoder {
static class Program_B {
class Solver {
public void Solve() {
var k = Int();
var s = Rl();
if (s.Length < k) {
Wl(s);
return;
}
Wl(s.Substring(0, k) + "...");
}
// ----------------------------------------------------------------------------
void Wl(string mes) { Console.WriteLine(mes); }
string Rl() { return Console.ReadLine(); }
public int Int() { return int.Parse(Console.ReadLine()); }
public int[] Ints(int subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) - subtract)
.ToArray();
}
public Int64[] Int64s(Int64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => Int64.Parse(s) - subtract)
.ToArray();
}
public UInt64[] UInt64s(UInt64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => UInt64.Parse(s) - subtract)
.ToArray();
}
}
static void Main(string[] args) { new Solver().Solve(); }
}
struct ModInt {
const int MOD = 1000000007;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => a.Data + b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => a.Data - b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div;
long p = MOD;
long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace AtCoder {
static class Program_B {
class Solver {
public void Solve() {
var k = Int();
var s = Rl();
if (s.Length <= k) {
Wl(s);
return;
}
Wl(s.Substring(0, k) + "...");
}
// ----------------------------------------------------------------------------
void Wl(string mes) { Console.WriteLine(mes); }
string Rl() { return Console.ReadLine(); }
public int Int() { return int.Parse(Console.ReadLine()); }
public int[] Ints(int subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) - subtract)
.ToArray();
}
public Int64[] Int64s(Int64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => Int64.Parse(s) - subtract)
.ToArray();
}
public UInt64[] UInt64s(UInt64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => UInt64.Parse(s) - subtract)
.ToArray();
}
}
static void Main(string[] args) { new Solver().Solve(); }
}
struct ModInt {
const int MOD = 1000000007;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => a.Data + b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => a.Data - b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div;
long p = MOD;
long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 745
| 2
|
using System;
class Program {
static void Main(string[] args) {
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (s.Length < k) {
Console.WriteLine(s);
} else {
string s2 = s.Remove(k);
Console.WriteLine(s2 + "...");
}
return;
}
}
|
using System;
class Program {
static void Main(string[] args) {
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (s.Length <= k) {
Console.WriteLine(s);
} else {
string s2 = s.Remove(k);
Console.WriteLine(s2 + "...");
}
return;
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 84
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace abc168b {
class Program {
static void Main(string[] args) {
//==========================================================================================================================
// 1) input
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
//==========================================================================================================================
// 2) output
if (s.Length >= k) {
s = s.Substring(0, k) + "...";
}
Console.WriteLine(s);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace abc168b {
class Program {
static void Main(string[] args) {
//==========================================================================================================================
// 1) input
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
//==========================================================================================================================
// 2) output
if (s.Length > k) {
s = s.Substring(0, k) + "...";
}
Console.WriteLine(s);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 93
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static void Main(string[] args) {
var K = int.Parse(Console.ReadLine());
var S = ReadLine();
if (S.Length < K) {
WriteLine(S);
return;
}
WriteLine(S.Substring(0, K) + "...");
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static void Main(string[] args) {
var K = int.Parse(Console.ReadLine());
var S = ReadLine();
if (S.Length <= K) {
WriteLine(S);
return;
}
WriteLine(S.Substring(0, K) + "...");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 182
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace Main {
class Program {
static void Main(string[] args) {
//ここから
// int n=Readint();
// string[] str = Console.ReadLine().Split(' ');
int n = Readint();
string s = Console.ReadLine();
if (s.Length < n)
Console.WriteLine(s);
else {
for (int i = 0; i < n; i++) {
Console.Write(s[i]);
}
Console.WriteLine("...");
}
//ここまで
}
static int Readint() { return int.Parse(Console.ReadLine()); }
static long Readlong() { return long.Parse(Console.ReadLine()); }
static int Min(int a, int b) {
if (a < b)
return a;
return b;
}
static int Max(int a, int b) {
if (a > b)
return a;
return b;
}
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace Main {
class Program {
static void Main(string[] args) {
//ここから
// int n=Readint();
// string[] str = Console.ReadLine().Split(' ');
int n = Readint();
string s = Console.ReadLine();
if (s.Length <= n)
Console.WriteLine(s);
else {
for (int i = 0; i < n; i++) {
Console.Write(s[i]);
}
Console.WriteLine("...");
}
//ここまで
}
static int Readint() { return int.Parse(Console.ReadLine()); }
static long Readlong() { return long.Parse(Console.ReadLine()); }
static int Min(int a, int b) {
if (a < b)
return a;
return b;
}
static int Max(int a, int b) {
if (a > b)
return a;
return b;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 198
| 2
|
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 abhm =
Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
var h = (abhm[2] + (abhm[3] / 60.0)) * 30.0;
var m = abhm[3] * 6.0;
var angle = (Math.Abs(h - m) % 180) * Math.PI / 180.0;
var tmp = (abhm[0] * abhm[0]) + (abhm[1] * abhm[1]) -
(2.0 * abhm[0] * abhm[1] * Math.Cos(angle));
Console.WriteLine(Math.Sqrt(tmp));
}
}
}
|
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 abhm =
Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
var h = (abhm[2] + (abhm[3] / 60.0)) * 30.0;
var m = abhm[3] * 6.0;
var angle = Math.Abs(h - m) * Math.PI / 180.0;
var tmp = (abhm[0] * abhm[0]) + (abhm[1] * abhm[1]) -
(2.0 * abhm[0] * abhm[1] * Math.Cos(angle));
Console.WriteLine(Math.Sqrt(tmp));
}
}
}
|
[["-", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["-", 31, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 109], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203]]
| 8
| 234
| 4
|
using System;
using System.Linq;
namespace _168.C {
internal class Program {
private static void Main(string[] args) {
var i = Console.ReadLine().Split().Select(int.Parse).ToList();
var (a, b, h, m) = (i[0], i[1], i[2], i[3]);
var hd = 360 * h / 12.0 * Math.PI / 180;
var md = 360 * m / 60.0 * Math.PI / 180;
var ax = a * Math.Sin(hd);
var ay = a * Math.Cos(hd);
var bx = b * Math.Sin(md);
var by = b * Math.Cos(md);
Console.WriteLine(Math.Sqrt(Math.Pow(ax - bx, 2) + Math.Pow(ay - by, 2)));
}
}
}
|
using System;
using System.Linq;
namespace _168.C {
internal class Program {
private static void Main(string[] args) {
var i = Console.ReadLine().Split().Select(int.Parse).ToList();
var (a, b, h, m) = (i[0], i[1], i[2], i[3]);
var hd = (360 * h / 12.0 + m / 2.0) * Math.PI / 180;
var md = 360 * m / 60.0 * Math.PI / 180;
var ax = a * Math.Sin(hd);
var ay = a * Math.Cos(hd);
var bx = b * Math.Sin(md);
var by = b * Math.Cos(md);
Console.WriteLine(Math.Sqrt(Math.Pow(ax - bx, 2) + Math.Pow(ay - by, 2)));
}
}
}
|
[["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 17, 85], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 12, 250], ["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 25]]
| 8
| 198
| 6
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) { new Program().Solve(); }
public void Solve() {
string[] input = Console.ReadLine().Split(" ");
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int hour = int.Parse(input[2]);
int minute = int.Parse(input[3]);
double theta_A = ((2 * Math.PI / 12) * hour) + ((Math.PI / 360) * minute);
double theta_B = ((2 * Math.PI / 60) * minute);
double theta = Math.Abs(theta_A - theta_B);
if (theta > Math.PI)
theta = Math.PI - theta;
double distance = Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(theta));
Console.WriteLine(distance);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) { new Program().Solve(); }
public void Solve() {
string[] input = Console.ReadLine().Split(" ");
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int hour = int.Parse(input[2]);
int minute = int.Parse(input[3]);
double theta_A = ((2 * Math.PI / 12) * hour) + ((Math.PI / 360) * minute);
double theta_B = ((2 * Math.PI / 60) * minute);
double theta = Math.Abs(theta_A - theta_B);
if (theta > Math.PI)
theta = 2 * Math.PI - theta;
double distance = Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(theta));
Console.WriteLine(distance);
}
}
}
|
[["+", 64, 1, 0, 11, 12, 16, 31, 16, 31, 203], ["+", 64, 1, 0, 11, 12, 16, 31, 16, 17, 48]]
| 8
| 244
| 2
|
using System;
using System.Linq;
using static System.Console;
namespace C {
internal class Program {
public static void Main(string[] args) {
var input = ReadLine().Split(' ').Select(int.Parse).ToList();
var degA = input[2] * (360 / 12) + 30 * input[3] / 60; // H+M/60
var degB = input[3] * (360 / 60);
// degA = degA >= 180 ? 360 - degA : degA;
// degB = degB >= 180 ? 360 - degB : degB;
var diff = (degA - degB);
var length = Math.Sqrt(Math.Pow(input[0], 2) + Math.Pow(input[1], 2) -
2 * input[0] * input[1] * Math.Cos(Deg2Rad(diff)));
WriteLine($"{length:F20}");
}
static double Deg2Rad(double degree) { return degree * Math.PI / 180; }
}
}
|
using System;
using System.Linq;
using static System.Console;
namespace C {
internal class Program {
public static void Main(string[] args) {
var input = ReadLine().Split(' ').Select(double.Parse).ToList();
var degA = input[2] * (360d / 12) + 30 * input[3] / 60; // H+M/60
var degB = input[3] * (360d / 60);
var diff = degA - degB;
var length = Math.Sqrt(Math.Pow(input[0], 2) + Math.Pow(input[1], 2) -
2 * input[0] * input[1] * Math.Cos(Deg2Rad(diff)));
WriteLine($"{length:F20}");
}
static double Deg2Rad(double degree) { return degree * Math.PI / 180; }
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 31, 250], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 250], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25]]
| 8
| 192
| 8
|
using System;
namespace test {
class MainClass {
public static void Main(string[] args) {
double PI = 3.14159265358979323846264338327950;
string x = Console.ReadLine();
// y[]はchar
//切り分け
string[] y = x.Split();
// int型に直す
int a = int.Parse(y[0]);
int b = int.Parse(y[1]);
int h = int.Parse(y[2]);
int m = int.Parse(y[3]);
double hh, mm;
double kakudo;
double rad;
double c, cc;
hh = 30 * h + m / 2;
mm = 6 * m;
// Console.WriteLine("{0} {1}",hh,mm);
if (Math.Abs(hh - mm) >= 180) {
kakudo = 360 - Math.Abs(hh - mm);
} else {
kakudo = Math.Abs(hh - mm);
}
rad = kakudo * PI / 180;
// Console.WriteLine(kakudo);
// Console.WriteLine(rad);
cc = b * b + a * a - 2 * a * b * Math.Cos(rad);
c = Math.Sqrt(cc);
string text = c.ToString("F20");
Console.WriteLine(text);
}
}
}
|
using System;
namespace test {
class MainClass {
public static void Main(string[] args) {
double PI = 3.14159265358979323846264338327950;
string x = Console.ReadLine();
// y[]はchar
//切り分け
string[] y = x.Split();
// int型に直す
double a = int.Parse(y[0]);
double b = int.Parse(y[1]);
double h = int.Parse(y[2]);
double m = int.Parse(y[3]);
double hh, mm;
double kakudo;
double rad;
double c, cc;
hh = 30 * h + m / 2;
mm = 6 * m;
if (Math.Abs(hh - mm) >= 180) {
kakudo = 360 - Math.Abs(hh - mm);
} else {
kakudo = Math.Abs(hh - mm);
}
rad = kakudo * PI / 180;
// Console.WriteLine(kakudo);
// Console.WriteLine(rad);
cc = b * b + a * a - 2 * a * b * Math.Cos(rad);
c = Math.Sqrt(cc);
string text = c.ToString("F20");
Console.WriteLine(text);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 239
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C {
class Program {
static void Main(string[] args) {
string line = Console.ReadLine();
string[] strs = line.Split(' ');
int A = int.Parse(strs[0]);
int B = int.Parse(strs[1]);
int H = int.Parse(strs[2]);
int M = int.Parse(strs[3]);
// 三角関数必要あり
double 時針角度 = (H * 60 + M) / 2.0;
double 分針角度 = M * 6;
double 角度 = Math.Abs(時針角度 - 分針角度);
if (角度 >= 180.0)
角度 = 角度 - 180;
double 長さ =
Math.Sqrt(A * A + B * B - 2 * A * B * Math.Cos(角度 * Math.PI / 180.0));
Console.WriteLine(長さ);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C {
class Program {
static void Main(string[] args) {
string line = Console.ReadLine();
string[] strs = line.Split(' ');
int A = int.Parse(strs[0]);
int B = int.Parse(strs[1]);
int H = int.Parse(strs[2]);
int M = int.Parse(strs[3]);
// 三角関数必要あり
double 時針角度 = (H * 60 + M) / 2.0;
double 分針角度 = M * 6;
double 角度 = Math.Abs(時針角度 - 分針角度);
if (角度 > 180.0)
角度 = 360 - 角度;
double 長さ =
Math.Sqrt(A * A + B * B - 2 * A * B * Math.Cos(角度 * Math.PI / 180.0));
Console.WriteLine(長さ);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 0, 42, 0, 20], ["+", 0, 195, 8, 196, 0, 57, 0, 42, 0, 47], ["-", 0, 195, 8, 196, 0, 57, 0, 42, 0, 42], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 203], ["-", 8, 196, 0, 57, 64, 1, 0, 241, 0, 203], ["+", 0, 213, 63, 214, 0, 42, 0, 42, 0, 42]]
| 8
| 211
| 6
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class1 {
static void Main(string[] args) {
var X = Console.ReadLine().Trim().Split().Select(float.Parse).ToArray();
var A = X[0];
var B = X[1];
var H = X[2];
var M = X[3];
var angle = 360 * Math.Abs(H / 12 - M / 60 + (M / 60) / 12);
var Ans = A * A + B * B - 2 * A * B * Math.Cos(angle * (Math.PI / 180));
Console.Write(Math.Sqrt(Ans));
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class1 {
static void Main(string[] args) {
var X = Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
var A = X[0];
var B = X[1];
var H = X[2];
var M = X[3];
var angle = 360 * Math.Abs(H / 12 - M / 60 + (M / 60) / 12);
var Ans = A * A + B * B - 2 * A * B * Math.Cos(angle * (Math.PI / 180));
Console.Write(Math.Sqrt(Ans));
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
| 8
| 165
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;
namespace AtCoderTemplate {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
var A = long.Parse(str[0]);
var B = long.Parse(str[1]);
var H = long.Parse(str[2]);
var M = long.Parse(str[3]);
var a = H * 30 + 0.5 + M;
var b = 6 * M;
var c = Math.Abs(a - b);
if (c > 180)
c = 360 - c;
var ans = Math.Sqrt(Math.Pow(A, 2) + Math.Pow(B, 2) -
2 * A * B * Math.Cos(c * Math.PI / 180));
Console.WriteLine(ans);
}
}
class MyLibrary {
// 自作の関数
public static int MyFunction(int n) { return 0; }
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;
namespace AtCoderTemplate {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
var A = long.Parse(str[0]);
var B = long.Parse(str[1]);
var H = long.Parse(str[2]);
var M = long.Parse(str[3]);
var a = H * 30 + 0.5 * M;
var b = 6 * M;
var c = Math.Abs(a - b);
if (c > 180)
c = 360 - c;
var ans = Math.Sqrt(Math.Pow(A, 2) + Math.Pow(B, 2) -
2 * A * B * Math.Cos(c * Math.PI / 180));
Console.WriteLine(ans);
}
}
class MyLibrary {
// 自作の関数
public static int MyFunction(int n) { return 0; }
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48]]
| 8
| 244
| 2
|
using System;
namespace Kznner {
class Program {
static void Main() {
string[] inputABHM = Console.ReadLine().Split(' ');
int A = int.Parse(inputABHM[0]);
int B = int.Parse(inputABHM[1]);
int H = int.Parse(inputABHM[2]);
int M = int.Parse(inputABHM[3]);
double Ax = Math.Sin(TimeToRadianA(H, M)) * A;
double Ay = Math.Cos(TimeToRadianA(H, M)) * A;
double Bx = Math.Sin(TimeToRadianB(H, M)) * B;
double By = Math.Cos(TimeToRadianB(H, M)) * B;
double deltaX = Ax - Bx;
double deltaY = Ay - By;
double distance = Math.Sqrt(deltaX * deltaX + deltaY + deltaY);
Console.WriteLine(distance);
}
static double TimeToRadianA(int hour, int minutes) {
double minutes_factor = 360.0 / 12 / 60;
double hour_factor = 360.0 / 12;
return Math.PI / 180 * (hour_factor * hour + minutes_factor * minutes);
}
static double TimeToRadianB(int hour, int minutes) {
return Math.PI / 180.0 * ((double)minutes / 60 * 360);
}
}
}
|
using System;
namespace Kznner {
class Program {
static void Main() {
string[] inputABHM = Console.ReadLine().Split(' ');
int A = int.Parse(inputABHM[0]);
int B = int.Parse(inputABHM[1]);
int H = int.Parse(inputABHM[2]);
int M = int.Parse(inputABHM[3]);
double Ax = Math.Sin(TimeToRadianA(H, M)) * A;
double Ay = Math.Cos(TimeToRadianA(H, M)) * A;
double Bx = Math.Sin(TimeToRadianB(H, M)) * B;
double By = Math.Cos(TimeToRadianB(H, M)) * B;
double deltaX = Ax - Bx;
double deltaY = Ay - By;
double distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
Console.WriteLine(distance);
}
static double TimeToRadianA(int hour, int minutes) {
double minutes_factor = 360.0 / 12 / 60;
double hour_factor = 360.0 / 12;
return Math.PI / 180 * (hour_factor * hour + minutes_factor * minutes);
}
static double TimeToRadianB(int hour, int minutes) {
return Math.PI / 180.0 * ((double)minutes / 60 * 360);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48]]
| 8
| 268
| 2
|
using System;
using System.Linq;
public class Test {
public static void Main() {
var x = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray();
int a = x[0];
int b = x[1];
int h = x[2];
int m = x[3];
double aa = 30 * h + m / 2;
double bb = 6 * m;
double theta;
if (aa >= bb) {
theta = aa - bb;
} else {
theta = bb - aa;
}
if (theta > 180) {
theta = 360 - theta;
}
double cos = Math.Cos(theta * (Math.PI / 180));
double ans = Math.Sqrt(a * a + b * b - 2 * a * b * cos);
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
public class Test {
public static void Main() {
var x = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray();
int a = x[0];
int b = x[1];
int h = x[2];
int m = x[3];
double aa = 30 * h + 0.5 * m;
double bb = 6 * m;
double theta;
if (aa >= bb) {
theta = aa - bb;
} else {
theta = bb - aa;
}
if (theta > 180) {
theta = 360 - theta;
}
double cos = Math.Cos(theta * (Math.PI / 180));
double ans = Math.Sqrt(a * a + b * b - 2 * a * b * cos);
Console.WriteLine(ans);
}
}
|
[["+", 0, 200, 0, 212, 0, 16, 12, 16, 31, 250], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 17, 85], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203]]
| 8
| 189
| 4
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
var a = (double)Input.NextInt();
var b = (double)Input.NextInt();
var h = (double)Input.NextInt();
var m = (double)Input.NextInt();
#if false
double angle = Math.Abs((h * 60 + m) / 2.0 - m * 60.0);
double d = Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(angle * Math.PI / 180.0));
Console.WriteLine(d);
#else
double angleA = (h * 60 + m) / 2.0 / 180.0 * Math.PI;
double angleB = m * 60.0 / 180.0 * Math.PI;
double xa = a * Math.Sin(angleA);
double ya = a * Math.Cos(angleA);
double xb = b * Math.Sin(angleB);
double yb = b * Math.Cos(angleB);
double d = Math.Sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
Console.WriteLine(d);
#endif
}
#region よく使う便利関数
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
var a = (double)Input.NextInt();
var b = (double)Input.NextInt();
var h = (double)Input.NextInt();
var m = (double)Input.NextInt();
#if false
double angle = Math.Abs((h * 60 + m) / 2.0 - m * 60.0);
double d = Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(angle * Math.PI / 180.0));
Console.WriteLine(d);
#else
double angleA = (h * 60 + m) / 2.0 / 180.0 * Math.PI;
double angleB = m * 6.0 / 180.0 * Math.PI;
double xa = a * Math.Sin(angleA);
double ya = a * Math.Cos(angleA);
double xb = b * Math.Sin(angleB);
double yb = b * Math.Cos(angleB);
double d = Math.Sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
Console.WriteLine(d);
#endif
}
#region よく使う便利関数
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["-", 0, 212, 0, 16, 31, 16, 31, 16, 12, 250], ["+", 0, 212, 0, 16, 31, 16, 31, 16, 12, 250]]
| 8
| 2,617
| 2
|
using System;
using System.Collections.Generic;
using System.Globalization;
namespace cswork {
class Program {
public Program() {}
Scanner cin;
const int MAXIN = 1024;
bool[] used = new bool[MAXIN];
int[] perm = new int[MAXIN];
List<int[]> permList = new List<int[]>();
void Omame() {
cin = new Scanner();
int a = cin.nextInt();
int b = cin.nextInt();
int h = cin.nextInt();
int m = cin.nextInt();
double hKakudo = 90 + 30 * (h + m / 60);
double mKakudo = 90 + 6 * m;
double hx = a * Math.Cos(hKakudo * (Math.PI / 180));
double hy = a * Math.Sin(hKakudo * (Math.PI / 180));
double mx = b * Math.Cos(mKakudo * (Math.PI / 180));
double my = b * Math.Sin(mKakudo * (Math.PI / 180));
double d = Math.Pow(mx - hx, 2) + Math.Pow(my - hy, 2);
d = Math.Pow(d, 0.5);
Console.WriteLine(d);
}
static void Main(string[] args) { new Program().Omame(); }
public void Permutation(int pos, int n, int length) {
if (pos == n) {
permList.Add((int[])perm.Clone());
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
perm[pos] = i;
used[i] = true;
Permutation(pos + 1, n, length);
used[i] = false;
}
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
namespace cswork {
class Program {
public Program() {}
Scanner cin;
const int MAXIN = 1024;
bool[] used = new bool[MAXIN];
int[] perm = new int[MAXIN];
List<int[]> permList = new List<int[]>();
void Omame() {
cin = new Scanner();
double a = cin.nextInt();
double b = cin.nextInt();
double h = cin.nextInt();
double m = cin.nextInt();
double hKakudo = 90 + 30 * (h + m / 60);
double mKakudo = 90 + 6 * m;
double hx = a * Math.Cos(hKakudo * (Math.PI / 180));
double hy = a * Math.Sin(hKakudo * (Math.PI / 180));
double mx = b * Math.Cos(mKakudo * (Math.PI / 180));
double my = b * Math.Sin(mKakudo * (Math.PI / 180));
double d = Math.Pow(mx - hx, 2) + Math.Pow(my - hy, 2);
d = Math.Pow(d, 0.5);
Console.WriteLine(d);
}
static void Main(string[] args) { new Program().Omame(); }
public void Permutation(int pos, int n, int length) {
if (pos == n) {
permList.Add((int[])perm.Clone());
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
perm[pos] = i;
used[i] = true;
Permutation(pos + 1, n, length);
used[i] = false;
}
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 555
| 8
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
namespace AtCoder.Contest.B {
static class Program {
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
var t = new List<char>(cin.Next().ToCharArray());
char now = 'D';
for (int i = 0; i < t.Count - 1; i++) {
if (t[i] == '?') {
if (i != 0 && t[i - 1] == 'P') {
t[i] = 'D';
} else if (i != t.Count - 1 && (t[i + 1] == 'D' || t[i + 1] == '?')) {
t[i] = 'P';
} else {
t[i] = 'D';
}
}
}
Console.WriteLine(string.Concat(t));
Console.Out.Flush();
}
}
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.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
namespace AtCoder.Contest.B {
static class Program {
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
var t = new List<char>(cin.Next().ToCharArray());
char now = 'D';
for (int i = 0; i < t.Count; i++) {
if (t[i] == '?') {
if (i != 0 && t[i - 1] == 'P') {
t[i] = 'D';
} else if (i != t.Count - 1 && (t[i + 1] == 'D' || t[i + 1] == '?')) {
t[i] = 'P';
} else {
t[i] = 'D';
}
}
}
Console.WriteLine(string.Concat(t));
Console.Out.Flush();
}
}
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, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 613
| 2
|
using System;
namespace ABC168_a {
class Program {
static void Main(string[] args) {
//標準入力文字列を数値に変換
long N = long.Parse(Console.ReadLine());
// 1の位を抽出
long N_1st = N % 10;
if (N_1st == 3) {
Console.WriteLine("hon");
} else if (N_1st == 0 || N_1st == 1 || N_1st == 6 || N_1st == 8) {
Console.WriteLine("pon");
} else if (N_1st == 2 || N_1st == 4 || N_1st == 5 || N_1st == 7 ||
N_1st == 9) {
Console.WriteLine("hon");
}
}
}
}
|
using System;
namespace ABC168_a {
class Program {
static void Main(string[] args) {
//標準入力文字列を数値に変換
long N = long.Parse(Console.ReadLine());
// 1の位を抽出
long N_1st = N % 10;
if (N_1st == 3) {
Console.WriteLine("bon");
} else if (N_1st == 0 || N_1st == 1 || N_1st == 6 || N_1st == 8) {
Console.WriteLine("pon");
} else if (N_1st == 2 || N_1st == 4 || N_1st == 5 || N_1st == 7 ||
N_1st == 9) {
Console.WriteLine("hon");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 126
| 2
|
using System;
class Program {
static void Main(string[] args) {
string sa = Console.ReadLine(); //標準入力
string a = sa.Substring(sa.Length - 1, 1);
if (a == "2" || a == "4" || a == "5" || a == "7" || a == "p") {
Console.WriteLine("{0}", "hon");
} else if (a == "3") {
Console.WriteLine("{0}", "bon");
} else {
Console.WriteLine("{0}", "pon");
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
string sa = Console.ReadLine(); //標準入力
string a = sa.Substring(sa.Length - 1, 1);
if (a == "2" || a == "4" || a == "5" || a == "7" || a == "9") {
Console.WriteLine("{0}", "hon");
} else if (a == "3") {
Console.WriteLine("{0}", "bon");
} else {
Console.WriteLine("{0}", "pon");
}
}
}
|
[["-", 0, 57, 15, 16, 12, 16, 12, 5, 0, 222], ["+", 0, 57, 15, 16, 12, 16, 12, 5, 0, 222]]
| 8
| 132
| 2
|
using System;
namespace q1 {
class q2 {
static void Main() {
int a = int.Parse(Console.ReadLine());
int b = a % 10;
if (b == 3) {
Console.WriteLine("bon");
}
if (b == 0 || b == 1 || b == 6 || b == 8) {
Console.WriteLine("pon");
} else {
Console.WriteLine("hon");
}
}
}
}
|
using System;
namespace q1 {
class q2 {
static void Main() {
int a = int.Parse(Console.ReadLine());
int b = a % 10;
if (b == 3) {
Console.WriteLine("bon");
} else if (b == 0 || b == 1 || b == 6 || b == 8) {
Console.WriteLine("pon");
} else {
Console.WriteLine("hon");
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 97
| 1
|
using System;
namespace ConsoleApp108 {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
switch (n) {
case 2:
case 4:
case 5:
case 7:
case 9:
Console.WriteLine("hon");
break;
case 0:
case 1:
case 6:
case 8:
Console.WriteLine("pon");
break;
default:
Console.WriteLine("bon");
break;
}
}
}
}
|
using System;
namespace ConsoleApp108 {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
n = n % 10;
switch (n) {
case 2:
case 4:
case 5:
case 7:
case 9:
Console.WriteLine("hon");
break;
case 0:
case 1:
case 6:
case 8:
Console.WriteLine("pon");
break;
default:
Console.WriteLine("bon");
break;
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 104
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class A_168_Therefore {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string a = Console.ReadLine();
if (a.EndsWith("3")) {
a = "bon";
} else if (a.EndsWith("2") || a.EndsWith("4") || a.EndsWith("5") ||
a.EndsWith("7") || a.EndsWith("9")) {
a = "pon";
} else if (a.EndsWith("0") || a.EndsWith("1") || a.EndsWith("6") ||
a.EndsWith("8")) {
a = "hon";
}
string result = a;
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class A_168_Therefore {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string a = Console.ReadLine();
if (a.EndsWith("3")) {
a = "bon";
} else if (a.EndsWith("2") || a.EndsWith("4") || a.EndsWith("5") ||
a.EndsWith("7") || a.EndsWith("9")) {
a = "hon";
} else if (a.EndsWith("0") || a.EndsWith("1") || a.EndsWith("6") ||
a.EndsWith("8")) {
a = "pon";
}
string result = a;
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
| 8
| 230
| 4
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
String[] arr = Console.ReadLine().Split();
int N;
N = int.Parse(arr[0]);
if (new List<int> { 2, 4, 5, 7, 9 }.Contains(N % 10))
Console.WriteLine("hon");
else if (new List<int> { 1, 4, 6, 8 }.Contains(N % 10))
Console.WriteLine("pon");
else
Console.WriteLine("bon");
return;
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
String[] arr = Console.ReadLine().Split();
int N;
N = int.Parse(arr[0]);
if (new List<int> { 2, 4, 5, 7, 9 }.Contains(N % 10))
Console.WriteLine("hon");
else if (new List<int> { 0, 1, 4, 6, 8 }.Contains(N % 10))
Console.WriteLine("pon");
else
Console.WriteLine("bon");
return;
}
}
|
[["+", 15, 213, 63, 214, 205, 230, 10, 229, 0, 203], ["+", 15, 213, 63, 214, 205, 230, 10, 229, 0, 21]]
| 8
| 132
| 2
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long l = N % 2;
if (l == 2 || l == 4 || l == 5 || l == 7 || l == 9) {
Console.WriteLine("hon");
} else if (l == 0 || l == 1 || l == 6 || l == 8) {
Console.WriteLine("pon");
} else if (l == 3) {
Console.WriteLine("bon");
}
}
}
}
//文字列の入力
// string s = Console.ReadLine();
//整数の入力
// long n = long.Parse(Console.ReadLine());
//文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
// Console.WriteLine();
// Console.ReadKey();
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long l = N % 10;
if (l == 2 || l == 4 || l == 5 || l == 7 || l == 9) {
Console.WriteLine("hon");
} else if (l == 0 || l == 1 || l == 6 || l == 8) {
Console.WriteLine("pon");
} else if (l == 3) {
Console.WriteLine("bon");
}
}
}
}
//文字列の入力
// string s = Console.ReadLine();
//整数の入力
// long n = long.Parse(Console.ReadLine());
//文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
// Console.WriteLine();
// Console.ReadKey();
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 175
| 2
|
using System;
namespace A {
class Program {
static void Main(string[] args) {
var n = Int64.Parse(Console.ReadLine().Trim());
switch (n) {
case 3:
Console.WriteLine("bon");
break;
case 0:
case 1:
case 6:
case 8:
Console.WriteLine("pon");
break;
default:
Console.WriteLine("hon");
break;
}
}
}
}
|
using System;
namespace A {
class Program {
static void Main(string[] args) {
var n = Int64.Parse(Console.ReadLine().Trim());
switch (n % 10) {
case 3:
Console.WriteLine("bon");
break;
case 0:
case 1:
case 6:
case 8:
Console.WriteLine("pon");
break;
default:
Console.WriteLine("hon");
break;
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 99, 51, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 99, 51, 16, 12, 203]]
| 8
| 96
| 2
|
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static System.Console;
using static Program.Input;
using static Program.MyMath;
using static Program.Const;
namespace Program {
public static class Program {
public static void Main() {
var l = new string[] { "pon", "pon", "hon", "bon", "hon",
"hon", "pon", "hon", "pon", "hon" };
var n = ScanInt();
WriteLine($"{n}{l[n%10]}");
}
}
static class Const {
public static string alp = "abcdefghijklmnopqrstuvwxyz";
public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const long MOD = 1000000007;
public static int INF = int.MaxValue;
public static long INFL = long.MaxValue;
}
static class Input {
public static void InputLine(out int a, out int b) {
var input = ScanIntArray();
a = input[0];
b = input[1];
}
public static void InputLine(out int a, out int b, out int c) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out int a, out int b, out int c, out int d) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out long a, out long b) {
var input = ScanLongArray();
a = input[0];
b = input[1];
}
public static void InputLine(out long a, out long b, out long c) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out long a, out long b, out long c, out long d) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out string a, out string b) {
var input = ScanStrArray();
a = input[0];
b = input[1];
}
public static int ScanInt() { return int.Parse(ReadLine()); }
static public uint ScanUint() { return uint.Parse(ReadLine()); }
static public double ScanDouble() { return double.Parse(ReadLine()); }
static public long ScanLong() { return long.Parse(ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(ReadLine()); }
static public int[] ScanIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
static public string RegaxReplace(this string arg1, string pattern,
string replacement) {
return Regex.Replace(arg1, pattern, replacement);
}
}
static class MyMath {
static public int CountBit(this long a) {
if (a == 0)
return 0;
int c = 1;
for (; a > 1; a /= 2)
if (a % 2 == 1)
c++;
return c;
}
static public int Floor2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public long Floor2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public int Ceiling2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N;
}
static public long Ceiling2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N;
}
static public long[] CumSum(this long[] a) {
var res = new long[a.Length];
long s = 0;
for (int i = 0; i < a.Length; i++)
res[i] = (s += a[i]);
return res;
}
static public IEnumerable<int> PrimeFactors(this int n) {
int tmp = n;
for (int i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public IEnumerable<long> PrimeFactors(this long n) {
var tmp = n;
for (long i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public int Digit(this int n, int d) {
if (d < 0)
return 0;
return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d);
}
static public int Length(this int n) {
if (n < 0)
return 0;
return (int)Math.Log10(n) + 1;
}
static public int Top(this int n) { return n.Digit(n.Length() - 1); }
public static bool isPrime(this int p) {
if (p <= 1)
return false;
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static bool isPrime(this long p) {
if (p <= 1)
return false;
for (long i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a / GCD(a, b) * b; }
public static long Inv(this long a, long m = MOD) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
private static void swap(ref long a, ref long b) {
var t = a;
a = b;
b = t;
}
public static long ModPow(long a, long n, long m = MOD) {
long res = 1;
while (n > 0) {
if (n % 2 == 1)
res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
}
static class MyLinq {
public static void Sort(this string[] array) {
Array.Sort(array, StringComparer.OrdinalIgnoreCase);
}
public static void StringSort(this List<string> list) {
list.Sort(StringComparer.OrdinalIgnoreCase);
}
public static string Join<T>(this IEnumerable<T> source, string separator) {
return string.Join(separator, source);
}
public static IEnumerable<TItem>
Distinct<TItem, TKey>(this IEnumerable<TItem> source,
Func<TItem, TKey> keySelector) {
if (source == null)
throw new ArgumentNullException(nameof(source));
if (keySelector == null)
throw new ArgumentNullException(nameof(keySelector));
var set = new HashSet<TKey>();
foreach (var item in source)
if (set.Add(keySelector(item)))
yield return item;
}
}
}
|
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static System.Console;
using static Program.Input;
using static Program.MyMath;
using static Program.Const;
namespace Program {
public static class Program {
public static void Main() {
var l = new string[] { "pon", "pon", "hon", "bon", "hon",
"hon", "pon", "hon", "pon", "hon" };
var n = ScanInt() % 10;
WriteLine(l[n]);
}
}
static class Const {
public static string alp = "abcdefghijklmnopqrstuvwxyz";
public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const long MOD = 1000000007;
public static int INF = int.MaxValue;
public static long INFL = long.MaxValue;
}
static class Input {
public static void InputLine(out int a, out int b) {
var input = ScanIntArray();
a = input[0];
b = input[1];
}
public static void InputLine(out int a, out int b, out int c) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out int a, out int b, out int c, out int d) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out long a, out long b) {
var input = ScanLongArray();
a = input[0];
b = input[1];
}
public static void InputLine(out long a, out long b, out long c) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out long a, out long b, out long c, out long d) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out string a, out string b) {
var input = ScanStrArray();
a = input[0];
b = input[1];
}
public static int ScanInt() { return int.Parse(ReadLine()); }
static public uint ScanUint() { return uint.Parse(ReadLine()); }
static public double ScanDouble() { return double.Parse(ReadLine()); }
static public long ScanLong() { return long.Parse(ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(ReadLine()); }
static public int[] ScanIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
static public string RegaxReplace(this string arg1, string pattern,
string replacement) {
return Regex.Replace(arg1, pattern, replacement);
}
}
static class MyMath {
static public int CountBit(this long a) {
if (a == 0)
return 0;
int c = 1;
for (; a > 1; a /= 2)
if (a % 2 == 1)
c++;
return c;
}
static public int Floor2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public long Floor2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public int Ceiling2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N;
}
static public long Ceiling2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N;
}
static public long[] CumSum(this long[] a) {
var res = new long[a.Length];
long s = 0;
for (int i = 0; i < a.Length; i++)
res[i] = (s += a[i]);
return res;
}
static public IEnumerable<int> PrimeFactors(this int n) {
int tmp = n;
for (int i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public IEnumerable<long> PrimeFactors(this long n) {
var tmp = n;
for (long i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public int Digit(this int n, int d) {
if (d < 0)
return 0;
return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d);
}
static public int Length(this int n) {
if (n < 0)
return 0;
return (int)Math.Log10(n) + 1;
}
static public int Top(this int n) { return n.Digit(n.Length() - 1); }
public static bool isPrime(this int p) {
if (p <= 1)
return false;
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static bool isPrime(this long p) {
if (p <= 1)
return false;
for (long i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a / GCD(a, b) * b; }
public static long Inv(this long a, long m = MOD) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
private static void swap(ref long a, ref long b) {
var t = a;
a = b;
b = t;
}
public static long ModPow(long a, long n, long m = MOD) {
long res = 1;
while (n > 0) {
if (n % 2 == 1)
res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
}
static class MyLinq {
public static void Sort(this string[] array) {
Array.Sort(array, StringComparer.OrdinalIgnoreCase);
}
public static void StringSort(this List<string> list) {
list.Sort(StringComparer.OrdinalIgnoreCase);
}
public static string Join<T>(this IEnumerable<T> source, string separator) {
return string.Join(separator, source);
}
public static IEnumerable<TItem>
Distinct<TItem, TKey>(this IEnumerable<TItem> source,
Func<TItem, TKey> keySelector) {
if (source == null)
throw new ArgumentNullException(nameof(source));
if (keySelector == null)
throw new ArgumentNullException(nameof(keySelector));
var set = new HashSet<TKey>();
foreach (var item in source)
if (set.Add(keySelector(item)))
yield return item;
}
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 109], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62]]
| 8
| 2,027
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class345 {
static void Main() {
int N = int.Parse(Console.ReadLine() [0].ToString());
if (N == 0 || N == 1 || N == 6 || N == 8)
Console.WriteLine("pon");
else if (N == 3)
Console.WriteLine("bon");
else
Console.WriteLine("hon");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class345 {
static void Main() {
int N = int.Parse(Console.ReadLine().Last().ToString());
if (N == 0 || N == 1 || N == 6 || N == 8)
Console.WriteLine("pon");
else if (N == 3)
Console.WriteLine("bon");
else
Console.WriteLine("hon");
}
}
}
|
[["-", 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], ["+", 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, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
| 8
| 116
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// https://atcoder.jp/contests/abc141/tasks/abc141_a
public class QuestionA {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string s = Console.ReadLine();
// string input = ConsoleInput.ReadLine;
string right_one_character = ConsoleInput.Right(s, 1);
string tani = "hon";
if (right_one_character == "0" || right_one_character == "1" ||
right_one_character == "6" || right_one_character == "8") {
tani = "pon";
}
if (right_one_character == "3") {
tani = "bon";
}
Console.WriteLine(s + tani);
//// 整数の入力
// long n = long.Parse(Console.ReadLine());
//// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
//// 整数配列の入力
// var inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
// string result = "";
// Console.WriteLine(result);
Console.Out.Flush();
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
public static string Right(string str, int len) {
return ((str != null && str.Length >= len && str.Length >= 0)
? str.Substring(str.Length - len)
: "");
}
public static string Left(string str, int len) {
return ((str != null && str.Length >= len && str.Length >= 0)
? str.Substring(0, len)
: "");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// https://atcoder.jp/contests/abc141/tasks/abc141_a
public class QuestionA {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string s = Console.ReadLine();
// string input = ConsoleInput.ReadLine;
string right_one_character = ConsoleInput.Right(s, 1);
string tani = "hon";
if (right_one_character == "0" || right_one_character == "1" ||
right_one_character == "6" || right_one_character == "8") {
tani = "pon";
}
if (right_one_character == "3") {
tani = "bon";
}
Console.WriteLine(tani);
//// 整数の入力
// long n = long.Parse(Console.ReadLine());
//// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
//// 整数配列の入力
// var inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
// string result = "";
// Console.WriteLine(result);
Console.Out.Flush();
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
public static string Right(string str, int len) {
return ((str != null && str.Length >= len && str.Length >= 0)
? str.Substring(str.Length - len)
: "");
}
public static string Left(string str, int len) {
return ((str != null && str.Length >= len && str.Length >= 0)
? str.Substring(0, len)
: "");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
| 8
| 617
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static void Main(string[] args) {
try {
Solve.Answer();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var n = ReadLine();
var s = n[n.Length - 1];
int i = int.Parse(s.ToString());
if (i == 2 || s == 4 || s == 5 || s == 7 || s == 9) {
WriteLine("hon");
} else if (i == 3) {
WriteLine("bon");
} else {
WriteLine("pon");
}
}
public class IO {
#region Input
public static string ReadString => ReadLine();
public static int ReadInt => int.Parse(ReadLine());
public static long ReadLong => long.Parse(ReadLine());
public static double ReadDouble => double.Parse(ReadLine());
public static List<string> ReadSplitString => ReadLine().Split().ToList();
public static List<int> ReadSplitInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToList();
public static List<long> ReadSplitLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToList();
public static List<double> ReadSplitdouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToList();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
#endregion
}
public class Mod {
#region
private readonly static long M = 1000000007;
public static long Add(long a, long b) => (a * b) % M;
public static long Sub(long a, long b) => (a - b) % M >= 0
? (a - b) % M
: (a - b) % M + M;
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
public static long GCD(long x, long y) {
#region
if (x < y) {
var tmp = x;
x = y;
y = tmp;
}
while (true)
{
if (x % y == 0) {
return y;
} else {
var tmp = x;
x = y;
y = tmp % y;
}
}
#endregion
}
public static long Choice2(long n) {
#region
if (n <= 1)
return 0;
if (n == 2)
return 1;
else
return n * (n - 1) / 2;
#endregion
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static void Main(string[] args) {
try {
Solve.Answer();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var n = ReadLine();
var s = n[n.Length - 1];
int i = int.Parse(s.ToString());
if (i == 2 || i == 4 || i == 5 || i == 7 || i == 9) {
WriteLine("hon");
} else if (i == 3) {
WriteLine("bon");
} else {
WriteLine("pon");
}
}
public class IO {
#region Input
public static string ReadString => ReadLine();
public static int ReadInt => int.Parse(ReadLine());
public static long ReadLong => long.Parse(ReadLine());
public static double ReadDouble => double.Parse(ReadLine());
public static List<string> ReadSplitString => ReadLine().Split().ToList();
public static List<int> ReadSplitInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToList();
public static List<long> ReadSplitLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToList();
public static List<double> ReadSplitdouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToList();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
#endregion
}
public class Mod {
#region
private readonly static long M = 1000000007;
public static long Add(long a, long b) => (a * b) % M;
public static long Sub(long a, long b) => (a - b) % M >= 0
? (a - b) % M
: (a - b) % M + M;
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
public static long GCD(long x, long y) {
#region
if (x < y) {
var tmp = x;
x = y;
y = tmp;
}
while (true)
{
if (x % y == 0) {
return y;
} else {
var tmp = x;
x = y;
y = tmp % y;
}
}
#endregion
}
public static long Choice2(long n) {
#region
if (n <= 1)
return 0;
if (n == 2)
return 1;
else
return n * (n - 1) / 2;
#endregion
}
}
}
|
[["-", 31, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
| 8
| 635
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// https://atcoder.jp/contests/abc141/tasks/abc141_a
public class QuestionA {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数の入力
int num_N = int.Parse(Console.ReadLine());
switch (num_N % 2) {
case 2:
case 4:
case 5:
case 7:
case 9:
Console.WriteLine("hon");
break;
case 0:
case 1:
case 6:
case 8:
Console.WriteLine("pon");
break;
case 3:
Console.WriteLine("bon");
break;
default:
break;
}
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// https://atcoder.jp/contests/abc141/tasks/abc141_a
public class QuestionA {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数の入力
int num_N = int.Parse(Console.ReadLine());
switch (num_N % 10) {
case 2:
case 4:
case 5:
case 7:
case 9:
Console.WriteLine("hon");
break;
case 0:
case 1:
case 6:
case 8:
Console.WriteLine("pon");
break;
case 3:
Console.WriteLine("bon");
break;
default:
break;
}
Console.Out.Flush();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 99, 51, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 99, 51, 16, 12, 203]]
| 8
| 178
| 2
|
using System;
namespace WelcomeToAtCoder {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
String ret = "";
switch (n) {
case 2:
case 4:
case 5:
case 7:
case 9:
ret = "hon";
break;
case 0:
case 1:
case 6:
case 8:
ret = "pon";
break;
case 3:
ret = "bon";
break;
}
Console.WriteLine(ret);
}
}
}
|
using System;
namespace WelcomeToAtCoder {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
String ret = "";
n = n % 10;
switch (n) {
case 2:
case 4:
case 5:
case 7:
case 9:
ret = "hon";
break;
case 0:
case 1:
case 6:
case 8:
ret = "pon";
break;
case 3:
ret = "bon";
break;
}
Console.WriteLine(ret);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 109
| 6
|
using System;
using System.Linq;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
var n = sc.Next();
switch (n[2]) {
case '3':
Console.WriteLine("bon");
break;
case '0':
case '1':
case '6':
case '8':
Console.WriteLine("pon");
break;
default:
Console.WriteLine("hon");
break;
}
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Linq;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
var n = sc.Next();
switch (n[n.Length - 1]) {
case '3':
Console.WriteLine("bon");
break;
case '0':
case '1':
case '6':
case '8':
Console.WriteLine("pon");
break;
default:
Console.WriteLine("hon");
break;
}
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 99, 51, 204, 206, 207, 0, 28, 0, 203], ["+", 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], ["+", 51, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 51, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 439
| 6
|
using System;
namespace ABC168_A {
class Program {
static void Main(string[] args) {
int i = int.Parse(Console.ReadLine());
i = i % 10;
if (i == 3) {
Console.WriteLine("bon");
} else if (i == 0 && i == 1 && i == 6 && i == 8) {
Console.WriteLine("pon");
} else {
Console.WriteLine("hon");
}
}
}
}
|
using System;
namespace ABC168_A {
class Program {
static void Main(string[] args) {
int i = int.Parse(Console.ReadLine());
i = i % 10;
if (i == 3) {
Console.WriteLine("bon");
} else if (i == 0 || i == 1 || i == 6 || i == 8) {
Console.WriteLine("pon");
} else {
Console.WriteLine("hon");
}
}
}
}
|
[["-", 75, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 17, 106], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 106], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 106]]
| 8
| 101
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.next();
var s = n[n.Length - 1].ToString();
var hon = new string[] { "2", "4,", "5", "7", "9" };
var pon = new string[] { "0", "1", "6", "8" };
var bon = new string[] { "3" };
if (hon.Contains(s)) {
Console.WriteLine("hon");
return;
}
if (pon.Contains(s)) {
Console.WriteLine("pon");
return;
}
if (bon.Contains(s)) {
Console.WriteLine("bon");
return;
}
}
}
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 int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
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 long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.next();
var s = n[n.Length - 1].ToString();
var hon = new string[] { "2", "4", "5", "7", "9" };
var pon = new string[] { "0", "1", "6", "8" };
var bon = new string[] { "3" };
if (hon.Contains(s)) {
Console.WriteLine("hon");
return;
}
if (pon.Contains(s)) {
Console.WriteLine("pon");
return;
}
if (bon.Contains(s)) {
Console.WriteLine("bon");
return;
}
}
}
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 int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
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 long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 0, 212, 0, 227, 0, 229, 0, 5, 0, 222], ["+", 0, 212, 0, 227, 0, 229, 0, 5, 0, 222]]
| 8
| 697
| 2
|
using System;
class p {
static void Main() {
int N = int.Parse(Console.ReadLine());
if (N == 3) {
Console.WriteLine("bon");
return;
} else if (N == 0 || N == 1 || N == 6 || N == 8) {
Console.WriteLine("pon");
return;
} else {
Console.WriteLine("hon");
return;
}
}
}
|
using System;
class p {
static void Main() {
int N = int.Parse(Console.ReadLine()) % 10;
if (N == 3) {
Console.WriteLine("bon");
return;
} else if (N == 0 || N == 1 || N == 6 || N == 8) {
Console.WriteLine("pon");
return;
} else {
Console.WriteLine("hon");
return;
}
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 93
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Runtime.Serialization.Formatters.Binary;
namespace atcorder2 {
[Serializable]
static class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long Gcd(long x, long y) {
if (x < y)
Gcd(y, x);
while (y > 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long Lcm(long x, long y) { return x * y / Lcm(x, y); }
public static bool IsLowercaseAlphabet(char target) {
return new Regex("^[a-z]+$").IsMatch(target.ToString());
}
public static T DeepCopy<T>(this T src) {
using (var memoryStream = new MemoryStream()) {
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, src);
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream);
}
}
public static bool Prime(long n) {
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (int i = 3; i <= Math.Sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var q = Reads();
var n = q[0];
var m = q[1];
var r = new bool[n];
var w = new List<long>[n];
for (int i = 0; i < n; i++) {
w[i] = new List<long>();
}
for (int i = 0; i < n; i++) {
q = Reads();
w[q[0] - 1].Add(q[1] - 1);
w[q[1] - 1].Add(q[0] - 1);
}
var que = new Queue<long>();
que.Enqueue(0);
var ans = new long[n];
var memo = new Dictionary<long, long>();
while (que.Count > 0) {
var s = que.Dequeue();
if (!memo.ContainsKey(s))
memo.Add(s, 1);
else
continue;
r[s] = true;
for (int i = 0; i < w[s].Count; i++) {
que.Enqueue(w[s][i]);
if (ans[w[s][i]] == 0)
ans[w[s][i]] = s + 1;
}
}
var f = true;
for (int i = 0; i < n; i++) {
if (r[i] == false)
f = true;
}
if (f) {
WriteLine("Yes");
for (int i = 1; i < n; i++) {
WriteLine(ans[i]);
}
} else
WriteLine("No");
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Runtime.Serialization.Formatters.Binary;
namespace atcorder2 {
[Serializable]
static class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long Gcd(long x, long y) {
if (x < y)
Gcd(y, x);
while (y > 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long Lcm(long x, long y) { return x * y / Lcm(x, y); }
public static bool IsLowercaseAlphabet(char target) {
return new Regex("^[a-z]+$").IsMatch(target.ToString());
}
public static T DeepCopy<T>(this T src) {
using (var memoryStream = new MemoryStream()) {
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, src);
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream);
}
}
public static bool Prime(long n) {
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (int i = 3; i <= Math.Sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var q = Reads();
var n = q[0];
var m = q[1];
var r = new bool[n];
var w = new List<long>[n];
for (int i = 0; i < n; i++) {
w[i] = new List<long>();
}
for (int i = 0; i < m; i++) {
q = Reads();
w[q[0] - 1].Add(q[1] - 1);
w[q[1] - 1].Add(q[0] - 1);
}
WriteLine();
var que = new Queue<long>();
que.Enqueue(0);
var ans = new long[n];
var memo = new Dictionary<long, long>();
while (que.Count > 0) {
var s = que.Dequeue();
if (!memo.ContainsKey(s))
memo.Add(s, 1);
else
continue;
r[s] = true;
for (int i = 0; i < w[s].Count; i++) {
que.Enqueue(w[s][i]);
if (ans[w[s][i]] == 0)
ans[w[s][i]] = s + 1;
}
}
var f = true;
for (int i = 0; i < n; i++) {
if (r[i] == false)
f = true;
}
if (f) {
WriteLine("Yes");
for (int i = 1; i < n; i++) {
WriteLine(ans[i]);
}
} else
WriteLine("No");
Console.Out.Flush();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 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, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 773
| 6
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace AtCoder.D {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var (N, M) = Read2Longs();
var roots = new List<long>[M + 1];
for (int i = 0; i < M + 1; i++) {
roots[i] = new List<long>();
}
for (int i = 0; i < M; i++) {
var (a, b) = Read2Longs();
roots[a].Add(b);
roots[b].Add(a);
}
var hints = new long[N + 1];
for (int i = 2; i < N + 1; i++) {
hints[i] = -1;
}
var queue = new Queue<long>();
queue.Enqueue(1);
while (queue.Count > 0) {
var from = queue.Dequeue();
foreach (var to in roots[from]) {
if (hints[to] == -1) {
hints[to] = from;
queue.Enqueue(to);
}
}
}
if (hints.Any(x => x == -1))
return "No";
var sb = new StringBuilder();
sb.AppendLine("Yes");
foreach (var hint in hints.Skip(2)) {
sb.AppendLine(hint.ToString());
}
return sb.ToString().Trim();
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace AtCoder.D {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var (N, M) = Read2Longs();
var roots = new List<long>[N + 1];
for (int i = 0; i < N + 1; i++) {
roots[i] = new List<long>();
}
for (int i = 0; i < M; i++) {
var (a, b) = Read2Longs();
roots[a].Add(b);
roots[b].Add(a);
}
var hints = new long[N + 1];
for (int i = 2; i < N + 1; i++) {
hints[i] = -1;
}
var queue = new Queue<long>();
queue.Enqueue(1);
while (queue.Count > 0) {
var from = queue.Dequeue();
foreach (var to in roots[from]) {
if (hints[to] == -1) {
hints[to] = from;
queue.Enqueue(to);
}
}
}
if (hints.Any(x => x == -1))
return "No";
var sb = new StringBuilder();
sb.AppendLine("Yes");
foreach (var hint in hints.Skip(2)) {
sb.AppendLine(hint.ToString());
}
return sb.ToString().Trim();
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22]]
| 8
| 640
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class1 {
static void Main(string[] args) {
var X = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
var G = new List<List<int>>(X[0]);
for (var i = 0; i < X[0]; i++)
G.Add(new List<int>());
for (var i = 0; i < X[1]; i++) {
var a = Console.ReadLine()
.Trim()
.Split()
.Select(x => int.Parse(x) - 1)
.ToArray();
G[a[0]].Add(a[1]);
G[a[1]].Add(a[0]);
}
var Dist = new int[X[0]].Select(x => -1).ToArray();
Dist[0] = 0;
Queue<int> Q = new Queue<int>();
Q.Enqueue(0);
while (Q.Count != 0) {
var a = Q.Dequeue();
foreach (var g in G[a]) {
if (Dist[g] != -1)
continue;
Dist[g] = Dist[a] + 1;
Q.Enqueue(g);
}
}
if (Dist.Contains(-1)) {
Console.Write("No");
} else {
Console.WriteLine("Yes");
for (var i = 1; i < X[0]; i++)
Console.WriteLine("{0}", Dist[i]);
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class1 {
static void Main(string[] args) {
var X = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
var G = new List<List<int>>(X[0]);
for (var i = 0; i < X[0]; i++)
G.Add(new List<int>());
for (var i = 0; i < X[1]; i++) {
var a = Console.ReadLine()
.Trim()
.Split()
.Select(x => int.Parse(x) - 1)
.ToArray();
G[a[0]].Add(a[1]);
G[a[1]].Add(a[0]);
}
var Dist = new int[X[0]].Select(x => -1).ToArray();
Dist[0] = 0;
Queue<int> Q = new Queue<int>();
Q.Enqueue(0);
while (Q.Count != 0) {
var a = Q.Dequeue();
foreach (var g in G[a]) {
if (Dist[g] != -1)
continue;
Dist[g] = a + 1;
Q.Enqueue(g);
}
}
if (Dist.Contains(-1)) {
Console.Write("No");
} else {
Console.WriteLine("Yes");
for (var i = 1; i < X[0]; i++)
Console.WriteLine("{0}", Dist[i]);
}
}
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73]]
| 8
| 375
| 3
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P {
public static void Main() {
var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = nm[0];
var m = nm[1];
Console.WriteLine("Yes");
List<int>[] graph =
Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
for (int i = 0; i < m; i++) {
var st =
Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
graph[st[0]].Add(st[1]);
graph[st[1]].Add(st[0]);
}
int[] res = new int[n];
res[0] = -1;
Stack<int> stack = new Stack<int>();
stack.Push(0);
while (stack.Count != 0) {
var elem = stack.Pop();
foreach (var item in graph[elem]) {
if (res[item] != 0)
continue;
res[item] = elem + 1;
stack.Push(item);
}
}
Console.WriteLine(string.Join("\n", res.Skip(1)));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P {
public static void Main() {
var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = nm[0];
var m = nm[1];
Console.WriteLine("Yes");
List<int>[] graph =
Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
for (int i = 0; i < m; i++) {
var st =
Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
graph[st[0]].Add(st[1]);
graph[st[1]].Add(st[0]);
}
int[] res = new int[n];
res[0] = -1;
Queue<int> stack = new Queue<int>();
stack.Enqueue(0);
while (stack.Count != 0) {
var elem = stack.Dequeue();
foreach (var item in graph[elem]) {
if (res[item] != 0)
continue;
res[item] = elem + 1;
stack.Enqueue(item);
}
}
Console.WriteLine(string.Join("\n", res.Skip(1)));
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 355
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_F.Lib_IO;
using static Contest_F.Lib_Minifunc;
namespace Contest_F {
public static class Entry {
public static void Main() {
checked {
long n, m;
Lib_IO.rm(out n, out m);
P<ll, ll, ll>[] abc, def;
rl(n, out abc);
rl(m, out def);
Dictionary<ll, List<P<ll, ll>>> dlmx =
new Dictionary<ll, List<P<ll, ll>>>();
Dictionary<ll, List<P<ll, ll>>> dlmy =
new Dictionary<ll, List<P<ll, ll>>>();
ll[] rxi, ryi;
P<ll, ll> range, start;
{
ll[] xi = new ll[2 * n + m];
ll[] yi = new ll[2 * m + n];
Dictionary<ll, List<P<ll, ll>>> dlx =
new Dictionary<ll, List<P<ll, ll>>>();
Dictionary<ll, List<P<ll, ll>>> dly =
new Dictionary<ll, List<P<ll, ll>>>();
for (int i = 0; i < n; i++) {
xi[2 * i] = abc[i].A;
xi[2 * i + 1] = abc[i].B;
yi[2 * m + i] = abc[i].C;
if (!dlx.ContainsKey(abc[i].C))
dlx[abc[i].C] = new List<P<ll, ll>>();
dlx[abc[i].C].Add(new P<ll, ll>(abc[i].A, abc[i].B));
}
for (int i = 0; i < m; i++) {
yi[2 * i] = def[i].B;
yi[2 * i + 1] = def[i].C;
xi[2 * n + i] = def[i].A;
if (!dly.ContainsKey(def[i].A))
dly[def[i].A] = new List<P<ll, ll>>();
dly[def[i].A].Add(new P<ll, ll>(def[i].B, def[i].C));
}
xi.sort(1);
yi.sort(1);
Dictionary<ll, ll> dxi = new Dictionary<ll, ll>();
Dictionary<ll, ll> dyi = new Dictionary<ll, ll>();
int kx = 0;
int sx = 0;
for (int i = 0; i < xi.Length; i++) {
var e = xi[i];
if (0 < i && xi[i - 1] < 0 && 0 <= e)
sx = i;
if (!dxi.ContainsKey(e))
dxi[e] = kx++;
}
rxi = new ll[kx];
foreach (var e in dxi)
rxi[e.Value] = e.Key;
int ky = 0;
int sy = 0;
for (int i = 0; i < yi.Length; i++) {
var e = yi[i];
if (0 < i && yi[i - 1] < 0 && 0 <= e)
sy = i;
if (!dyi.ContainsKey(e))
dyi[e] = ky++;
}
ryi = new ll[ky];
foreach (var e in dyi)
ryi[e.Value] = e.Key;
range = new P<ll, ll>(kx, ky);
start = new P<ll, ll>(sx, sy);
foreach (var e in dxi.Keys) {
if (!dly.ContainsKey(e))
continue;
var l = new List<P<ll, ll>>();
foreach (var w in dly[e]) {
l.Add(new P<ll, ll>(dyi[w.A], dyi[w.B]));
}
l.Sort((x, y) => x.A.CompareTo(y.A));
dlmy[dxi[e]] = l;
}
foreach (var e in dyi.Keys) {
if (!dlx.ContainsKey(e))
continue;
var l = new List<P<ll, ll>>();
foreach (var w in dlx[e]) {
l.Add(new P<ll, ll>(dxi[w.A], dxi[w.B]));
}
l.Sort((x, y) => x.A.CompareTo(y.A));
dlmx[dyi[e]] = l;
}
}
Func<ll, ll, int, bool> wall = (x, y, d) => {
if (d == 1) { // y+
if (!dlmx.ContainsKey(y))
return false;
var i = (int)BS(dlmx[y], x);
return i < dlmx[y].Count && dlmx[y][i].A < x;
} else if (d == 2) { // x+
if (!dlmy.ContainsKey(x))
return false;
var i = (int)BS(dlmy[x], y);
return i < dlmy[x].Count && dlmy[x][i].A < y;
} else if (d == 3) { // y-
if (!dlmx.ContainsKey(y - 1))
return false;
var i = (int)BS(dlmx[y - 1], x);
return i < dlmx[y - 1].Count && dlmx[y - 1][i].A < x;
} else { // x-
if (!dlmy.ContainsKey(x - 1))
return false;
var i = (int)BS(dlmy[x - 1], y);
return i < dlmy[x - 1].Count && dlmy[x - 1][i].A < y;
}
};
Func<ll, ll, ll> bfs = (sx, sy) => {
Queue<P<ll, ll>> que = new Queue<P<ll, ll>>();
que.Enqueue(new P<ll, ll>(sx, sy));
ll sum = 0;
bool[][] visit = inita(range.A, range.B, false);
while (0 < que.Count) {
var q = que.Dequeue();
if (q.A <= 0 || q.A >= range.A || q.B <= 0 || q.B >= range.B)
return -1;
if (visit[q.A][q.B])
continue;
visit[q.A][q.B] = true;
sum += (rxi[q.A] - rxi[q.A - 1]) * (ryi[q.B] - ryi[q.B - 1]);
if (!wall(q.A, q.B, 4))
que.Enqueue(new P<ll, ll>(q.A - 1, q.B));
if (!wall(q.A, q.B, 2))
que.Enqueue(new P<ll, ll>(q.A + 1, q.B));
if (!wall(q.A, q.B, 3))
que.Enqueue(new P<ll, ll>(q.A, q.B - 1));
if (!wall(q.A, q.B, 1))
que.Enqueue(new P<ll, ll>(q.A, q.B + 1));
}
return sum;
};
long ans = bfs(start.A, start.B);
Lib_IO.wm(ans == -1 ? "INF" : ans.ToString());
}
}
public static long BS<T>(IList<P<T, T>> seq, T value)
where T : IComparable<T> {
int left = -1;
int right = seq.Count;
while (right - left > 1) {
int mid = left + (right - left) / 2;
if (0 <= seq[mid].B.CompareTo(value))
right = mid;
else
left = mid;
}
return right;
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == 1))
a = b;
return r;
} // b の方が小さければ a を更新
[CS.MethodImpl(256)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == -1))
a = b;
return r;
} // b の方が大きければ a を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e, out Y f) {
var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_F.Lib_IO;
using static Contest_F.Lib_Minifunc;
namespace Contest_F {
public static class Entry {
public static void Main() {
checked {
long n, m;
Lib_IO.rm(out n, out m);
P<ll, ll, ll>[] abc, def;
rl(n, out abc);
rl(m, out def);
Dictionary<ll, List<P<ll, ll>>> dlmx =
new Dictionary<ll, List<P<ll, ll>>>();
Dictionary<ll, List<P<ll, ll>>> dlmy =
new Dictionary<ll, List<P<ll, ll>>>();
ll[] rxi, ryi;
P<ll, ll> range, start;
{
ll[] xi = new ll[2 * n + m];
ll[] yi = new ll[2 * m + n];
Dictionary<ll, List<P<ll, ll>>> dlx =
new Dictionary<ll, List<P<ll, ll>>>();
Dictionary<ll, List<P<ll, ll>>> dly =
new Dictionary<ll, List<P<ll, ll>>>();
for (int i = 0; i < n; i++) {
xi[2 * i] = abc[i].A;
xi[2 * i + 1] = abc[i].B;
yi[2 * m + i] = abc[i].C;
if (!dlx.ContainsKey(abc[i].C))
dlx[abc[i].C] = new List<P<ll, ll>>();
dlx[abc[i].C].Add(new P<ll, ll>(abc[i].A, abc[i].B));
}
for (int i = 0; i < m; i++) {
yi[2 * i] = def[i].B;
yi[2 * i + 1] = def[i].C;
xi[2 * n + i] = def[i].A;
if (!dly.ContainsKey(def[i].A))
dly[def[i].A] = new List<P<ll, ll>>();
dly[def[i].A].Add(new P<ll, ll>(def[i].B, def[i].C));
}
xi.sort(1);
yi.sort(1);
Dictionary<ll, ll> dxi = new Dictionary<ll, ll>();
Dictionary<ll, ll> dyi = new Dictionary<ll, ll>();
int kx = 0;
int sx = 0;
for (int i = 0; i < xi.Length; i++) {
var e = xi[i];
if (0 < i && xi[i - 1] < 0 && 0 <= e)
sx = kx;
if (!dxi.ContainsKey(e))
dxi[e] = kx++;
}
rxi = new ll[kx];
foreach (var e in dxi)
rxi[e.Value] = e.Key;
int ky = 0;
int sy = 0;
for (int i = 0; i < yi.Length; i++) {
var e = yi[i];
if (0 < i && yi[i - 1] < 0 && 0 <= e)
sy = ky;
if (!dyi.ContainsKey(e))
dyi[e] = ky++;
}
ryi = new ll[ky];
foreach (var e in dyi)
ryi[e.Value] = e.Key;
range = new P<ll, ll>(kx, ky);
start = new P<ll, ll>(sx, sy);
foreach (var e in dxi.Keys) {
if (!dly.ContainsKey(e))
continue;
var l = new List<P<ll, ll>>();
foreach (var w in dly[e]) {
l.Add(new P<ll, ll>(dyi[w.A], dyi[w.B]));
}
l.Sort((x, y) => x.A.CompareTo(y.A));
dlmy[dxi[e]] = l;
}
foreach (var e in dyi.Keys) {
if (!dlx.ContainsKey(e))
continue;
var l = new List<P<ll, ll>>();
foreach (var w in dlx[e]) {
l.Add(new P<ll, ll>(dxi[w.A], dxi[w.B]));
}
l.Sort((x, y) => x.A.CompareTo(y.A));
dlmx[dyi[e]] = l;
}
}
Func<ll, ll, int, bool> wall = (x, y, d) => {
if (d == 1) { // y+
if (!dlmx.ContainsKey(y))
return false;
var i = (int)BS(dlmx[y], x);
return i < dlmx[y].Count && dlmx[y][i].A < x;
} else if (d == 2) { // x+
if (!dlmy.ContainsKey(x))
return false;
var i = (int)BS(dlmy[x], y);
return i < dlmy[x].Count && dlmy[x][i].A < y;
} else if (d == 3) { // y-
if (!dlmx.ContainsKey(y - 1))
return false;
var i = (int)BS(dlmx[y - 1], x);
return i < dlmx[y - 1].Count && dlmx[y - 1][i].A < x;
} else { // x-
if (!dlmy.ContainsKey(x - 1))
return false;
var i = (int)BS(dlmy[x - 1], y);
return i < dlmy[x - 1].Count && dlmy[x - 1][i].A < y;
}
};
Func<ll, ll, ll> bfs = (sx, sy) => {
Queue<P<ll, ll>> que = new Queue<P<ll, ll>>();
que.Enqueue(new P<ll, ll>(sx, sy));
ll sum = 0;
bool[][] visit = inita(range.A, range.B, false);
while (0 < que.Count) {
var q = que.Dequeue();
if (q.A <= 0 || q.A >= range.A || q.B <= 0 || q.B >= range.B)
return -1;
if (visit[q.A][q.B])
continue;
visit[q.A][q.B] = true;
sum += (rxi[q.A] - rxi[q.A - 1]) * (ryi[q.B] - ryi[q.B - 1]);
if (!wall(q.A, q.B, 4))
que.Enqueue(new P<ll, ll>(q.A - 1, q.B));
if (!wall(q.A, q.B, 2))
que.Enqueue(new P<ll, ll>(q.A + 1, q.B));
if (!wall(q.A, q.B, 3))
que.Enqueue(new P<ll, ll>(q.A, q.B - 1));
if (!wall(q.A, q.B, 1))
que.Enqueue(new P<ll, ll>(q.A, q.B + 1));
}
return sum;
};
long ans = bfs(start.A, start.B);
Lib_IO.wm(ans == -1 ? "INF" : ans.ToString());
}
}
public static long BS<T>(IList<P<T, T>> seq, T value)
where T : IComparable<T> {
int left = -1;
int right = seq.Count;
while (right - left > 1) {
int mid = left + (right - left) / 2;
if (0 <= seq[mid].B.CompareTo(value))
right = mid;
else
left = mid;
}
return right;
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == 1))
a = b;
return r;
} // b の方が小さければ a を更新
[CS.MethodImpl(256)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == -1))
a = b;
return r;
} // b の方が大きければ a を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e, out Y f) {
var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
[["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22]]
| 8
| 5,892
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_F.Lib_IO;
using static Contest_F.Lib_Minifunc;
namespace Contest_F {
public static class Entry {
public static void Main() {
checked {
long n, m;
Lib_IO.rm(out n, out m);
P<int, int, int>[] abc, def;
rl(n, out abc);
rl(m, out def);
MatMD<bool> wall;
int[] rxi, ryi;
P<int, int> range, start;
{
int[] xi = new int[2 * n + m];
int[] yi = new int[2 * m + n];
var dlx = new Dictionary<int, List<P<int, int>>>();
var dly = new Dictionary<int, List<P<int, int>>>();
for (int i = 0; i < n; i++) {
xi[2 * i] = abc[i].A;
xi[2 * i + 1] = abc[i].B;
yi[2 * m + i] = abc[i].C;
if (!dlx.ContainsKey(abc[i].C))
dlx[abc[i].C] = new List<P<int, int>>();
dlx[abc[i].C].Add(new P<int, int>(abc[i].A, abc[i].B));
}
for (int i = 0; i < m; i++) {
yi[2 * i] = def[i].B;
yi[2 * i + 1] = def[i].C;
xi[2 * n + i] = def[i].A;
if (!dly.ContainsKey(def[i].A))
dly[def[i].A] = new List<P<int, int>>();
dly[def[i].A].Add(new P<int, int>(def[i].B, def[i].C));
}
xi.sort(1);
yi.sort(1);
var dxi = new Dictionary<int, int>();
var dyi = new Dictionary<int, int>();
int kx = 0;
int sx = 0;
for (int i = 0; i < xi.Length; i++) {
var e = xi[i];
if (0 < i && xi[i - 1] <= 0 && 0 < e)
sx = kx;
if (!dxi.ContainsKey(e))
dxi[e] = kx++;
}
rxi = new int[kx];
foreach (var e in dxi)
rxi[e.Value] = e.Key;
int ky = 0;
int sy = 0;
for (int i = 0; i < yi.Length; i++) {
var e = yi[i];
if (0 < i && yi[i - 1] <= 0 && 0 < e)
sy = ky;
if (!dyi.ContainsKey(e))
dyi[e] = ky++;
}
ryi = new int[ky];
foreach (var e in dyi)
ryi[e.Value] = e.Key;
range = new P<int, int>(kx + 1, ky + 1);
start = new P<int, int>(sx, sy);
wall = new MatMD<bool>(range.A, range.B, 2, false);
foreach (var w in dly) {
foreach (var v in w.Value) {
for (int i = dyi[v.A] + 1; i <= dyi[v.B]; i++)
wall[dxi[w.Key], i, 1] = true;
}
}
foreach (var w in dlx) {
foreach (var v in w.Value) {
for (int i = dxi[v.A] + 1; i <= dxi[v.B]; i++)
wall[i, dyi[w.Key], 0] = true;
}
}
/*
char[][] dbg =
inita(2*range.B,2*range.A,' '); for (int i = 0; i < range.A; i++)
{
for (int j = 0; j < range.B;
j++)
{
if(i==sx&&j==sy)
dbg[2*j][2*i] = '◯'; if(wall[i,j,0]) dbg[2*j+1][2*i] = '-';
if(wall[i,j,1])
dbg[2*j][2*i+1] = '|';
}
}
wg(dbg);
*/
}
Func<int, int, ll> bfs = (sx, sy) => {
var que = new Queue<P<int, int, int>>();
que.Enqueue(new P<int, int, int>(sx, sy, 0));
ll sum = 0;
bool[][] visit = inita(range.A, range.B, false);
while (0 < que.Count) {
var q = que.Dequeue();
if (q.A <= 0 || q.A >= range.A || q.B <= 0 || q.B >= range.B)
return -1;
if (visit[q.A][q.B])
continue;
visit[q.A][q.B] = true;
sum += (ll)(rxi[q.A] - rxi[q.A - 1]) * (ll)(ryi[q.B] - ryi[q.B - 1]);
if (q.C != 2 && !wall[q.A - 1, q.B, 1])
que.Enqueue(new P<int, int, int>(q.A - 1, q.B, 4));
if (q.C != 4 && !wall[q.A, q.B, 1])
que.Enqueue(new P<int, int, int>(q.A + 1, q.B, 2));
if (q.C != 1 && !wall[q.A, q.B - 1, 0])
que.Enqueue(new P<int, int, int>(q.A, q.B - 1, 3));
if (q.C != 3 && !wall[q.A, q.B, 0])
que.Enqueue(new P<int, int, int>(q.A, q.B + 1, 1));
}
return sum;
};
long ans = bfs(start.A, start.B);
Lib_IO.wm(ans == -1 ? "INF" : ans.ToString());
}
}
public class MatMD<T>
where T : IComparable {
public readonly int Dimension;
public readonly int Length1, Length2, Length3, Length4, Length5, Length6,
Length7, Length8;
T[] data;
public MatMD(long l1, long l2, T ival) {
Dimension = 2;
Length1 = (int)l1;
Length2 = (int)l2;
data = Enumerable.Repeat(ival, (int)(l1 * l2)).ToArray();
}
public MatMD(long l1, long l2, long l3, T ival) {
Dimension = 3;
Length1 = (int)l1;
Length2 = (int)l2;
Length3 = (int)l3;
data = Enumerable.Repeat(ival, (int)(l1 * l2 * l3)).ToArray();
}
public MatMD(long l1, long l2, long l3, long l4, T ival) {
Dimension = 4;
Length1 = (int)l1;
Length2 = (int)l2;
Length3 = (int)l3;
Length4 = (int)l4;
data = Enumerable.Repeat(ival, (int)(l1 * l2 * l3 * l4)).ToArray();
}
public T this[int i1, int i2] {
get { return data[i1 * Length2 + i2]; }
set { data[i1 * Length2 + i2] = value; }
}
public T this[int i1, int i2, int i3] {
get { return data[(i1 * Length2 + i2) * Length3 + i3]; }
set { data[(i1 * Length2 + i2) * Length3 + i3] = value; }
}
public T this[int i1, int i2, int i3, int i4] {
get { return data[((i1 * Length2 + i2) * Length3 + i3) * Length4 + i4]; }
set { data[((i1 * Length2 + i2) * Length3 + i3) * Length4 + i4] = value; }
}
[CS.MethodImpl(256)]
public bool Chmin(int i1, int i2, T v) {
bool r;
if (r = (this[i1, i2].CompareTo(v) == 1))
this[i1, i2] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmax(int i1, int i2, T v) {
bool r;
if (r = (this[i1, i2].CompareTo(v) == -1))
this[i1, i2] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmin(int i1, int i2, int i3, T v) {
bool r;
if (r = (this[i1, i2, i3].CompareTo(v) == 1))
this[i1, i2, i3] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmax(int i1, int i2, int i3, T v) {
bool r;
if (r = (this[i1, i2, i3].CompareTo(v) == -1))
this[i1, i2, i3] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmin(int i1, int i2, int i3, int i4, T v) {
bool r;
if (r = (this[i1, i2, i3, i4].CompareTo(v) == 1))
this[i1, i2, i3, i4] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmax(int i1, int i2, int i3, int i4, T v) {
bool r;
if (r = (this[i1, i2, i3, i4].CompareTo(v) == -1))
this[i1, i2, i3, i4] = v;
return r;
}
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == 1))
a = b;
return r;
} // b の方が小さければ a を更新
[CS.MethodImpl(256)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == -1))
a = b;
return r;
} // b の方が大きければ a を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e, out Y f) {
var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_F.Lib_IO;
using static Contest_F.Lib_Minifunc;
namespace Contest_F {
public static class Entry {
public static void Main() {
checked {
long n, m;
Lib_IO.rm(out n, out m);
P<int, int, int>[] abc, def;
rl(n, out abc);
rl(m, out def);
MatMD<bool> wall;
int[] rxi, ryi;
P<int, int> range, start;
{
int[] xi = new int[2 * n + m];
int[] yi = new int[2 * m + n];
var dlx = new Dictionary<int, List<P<int, int>>>();
var dly = new Dictionary<int, List<P<int, int>>>();
for (int i = 0; i < n; i++) {
xi[2 * i] = abc[i].A;
xi[2 * i + 1] = abc[i].B;
yi[2 * m + i] = abc[i].C;
if (!dlx.ContainsKey(abc[i].C))
dlx[abc[i].C] = new List<P<int, int>>();
dlx[abc[i].C].Add(new P<int, int>(abc[i].A, abc[i].B));
}
for (int i = 0; i < m; i++) {
yi[2 * i] = def[i].B;
yi[2 * i + 1] = def[i].C;
xi[2 * n + i] = def[i].A;
if (!dly.ContainsKey(def[i].A))
dly[def[i].A] = new List<P<int, int>>();
dly[def[i].A].Add(new P<int, int>(def[i].B, def[i].C));
}
xi.sort(1);
yi.sort(1);
var dxi = new Dictionary<int, int>();
var dyi = new Dictionary<int, int>();
int kx = 0;
int sx = 0;
for (int i = 0; i < xi.Length; i++) {
var e = xi[i];
if (0 < i && xi[i - 1] <= 0 && 0 < e)
sx = kx;
if (!dxi.ContainsKey(e))
dxi[e] = kx++;
}
rxi = new int[kx];
foreach (var e in dxi)
rxi[e.Value] = e.Key;
int ky = 0;
int sy = 0;
for (int i = 0; i < yi.Length; i++) {
var e = yi[i];
if (0 < i && yi[i - 1] <= 0 && 0 < e)
sy = ky;
if (!dyi.ContainsKey(e))
dyi[e] = ky++;
}
ryi = new int[ky];
foreach (var e in dyi)
ryi[e.Value] = e.Key;
range = new P<int, int>(kx, ky);
start = new P<int, int>(sx, sy);
wall = new MatMD<bool>(range.A, range.B, 2, false);
foreach (var w in dly) {
foreach (var v in w.Value) {
for (int i = dyi[v.A] + 1; i <= dyi[v.B]; i++)
wall[dxi[w.Key], i, 1] = true;
}
}
foreach (var w in dlx) {
foreach (var v in w.Value) {
for (int i = dxi[v.A] + 1; i <= dxi[v.B]; i++)
wall[i, dyi[w.Key], 0] = true;
}
}
/*
char[][] dbg =
inita(2*range.B,2*range.A,' '); for (int i = 0; i < range.A; i++)
{
for (int j = 0; j < range.B;
j++)
{
if(i==sx&&j==sy)
dbg[2*j][2*i] = '◯'; if(wall[i,j,0]) dbg[2*j+1][2*i] = '-';
if(wall[i,j,1])
dbg[2*j][2*i+1] = '|';
}
}
wg(dbg);
*/
}
Func<int, int, ll> bfs = (sx, sy) => {
var que = new Queue<P<int, int, int>>();
que.Enqueue(new P<int, int, int>(sx, sy, 0));
ll sum = 0;
bool[][] visit = inita(range.A, range.B, false);
while (0 < que.Count) {
var q = que.Dequeue();
if (q.A <= 0 || q.A >= range.A || q.B <= 0 || q.B >= range.B)
return -1;
if (visit[q.A][q.B])
continue;
visit[q.A][q.B] = true;
sum += (ll)(rxi[q.A] - rxi[q.A - 1]) * (ll)(ryi[q.B] - ryi[q.B - 1]);
if (q.C != 2 && !wall[q.A - 1, q.B, 1])
que.Enqueue(new P<int, int, int>(q.A - 1, q.B, 4));
if (q.C != 4 && !wall[q.A, q.B, 1])
que.Enqueue(new P<int, int, int>(q.A + 1, q.B, 2));
if (q.C != 1 && !wall[q.A, q.B - 1, 0])
que.Enqueue(new P<int, int, int>(q.A, q.B - 1, 3));
if (q.C != 3 && !wall[q.A, q.B, 0])
que.Enqueue(new P<int, int, int>(q.A, q.B + 1, 1));
}
return sum;
};
long ans = bfs(start.A, start.B);
Lib_IO.wm(ans == -1 ? "INF" : ans.ToString());
}
}
public class MatMD<T>
where T : IComparable {
public readonly int Dimension;
public readonly int Length1, Length2, Length3, Length4, Length5, Length6,
Length7, Length8;
T[] data;
public MatMD(long l1, long l2, T ival) {
Dimension = 2;
Length1 = (int)l1;
Length2 = (int)l2;
data = Enumerable.Repeat(ival, (int)(l1 * l2)).ToArray();
}
public MatMD(long l1, long l2, long l3, T ival) {
Dimension = 3;
Length1 = (int)l1;
Length2 = (int)l2;
Length3 = (int)l3;
data = Enumerable.Repeat(ival, (int)(l1 * l2 * l3)).ToArray();
}
public MatMD(long l1, long l2, long l3, long l4, T ival) {
Dimension = 4;
Length1 = (int)l1;
Length2 = (int)l2;
Length3 = (int)l3;
Length4 = (int)l4;
data = Enumerable.Repeat(ival, (int)(l1 * l2 * l3 * l4)).ToArray();
}
public T this[int i1, int i2] {
get { return data[i1 * Length2 + i2]; }
set { data[i1 * Length2 + i2] = value; }
}
public T this[int i1, int i2, int i3] {
get { return data[(i1 * Length2 + i2) * Length3 + i3]; }
set { data[(i1 * Length2 + i2) * Length3 + i3] = value; }
}
public T this[int i1, int i2, int i3, int i4] {
get { return data[((i1 * Length2 + i2) * Length3 + i3) * Length4 + i4]; }
set { data[((i1 * Length2 + i2) * Length3 + i3) * Length4 + i4] = value; }
}
[CS.MethodImpl(256)]
public bool Chmin(int i1, int i2, T v) {
bool r;
if (r = (this[i1, i2].CompareTo(v) == 1))
this[i1, i2] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmax(int i1, int i2, T v) {
bool r;
if (r = (this[i1, i2].CompareTo(v) == -1))
this[i1, i2] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmin(int i1, int i2, int i3, T v) {
bool r;
if (r = (this[i1, i2, i3].CompareTo(v) == 1))
this[i1, i2, i3] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmax(int i1, int i2, int i3, T v) {
bool r;
if (r = (this[i1, i2, i3].CompareTo(v) == -1))
this[i1, i2, i3] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmin(int i1, int i2, int i3, int i4, T v) {
bool r;
if (r = (this[i1, i2, i3, i4].CompareTo(v) == 1))
this[i1, i2, i3, i4] = v;
return r;
}
[CS.MethodImpl(256)]
public bool Chmax(int i1, int i2, int i3, int i4, T v) {
bool r;
if (r = (this[i1, i2, i3, i4].CompareTo(v) == -1))
this[i1, i2, i3, i4] = v;
return r;
}
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == 1))
a = b;
return r;
} // b の方が小さければ a を更新
[CS.MethodImpl(256)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == -1))
a = b;
return r;
} // b の方が大きければ a を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e, out Y f) {
var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
[["-", 12, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 230, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 6,193
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class A_167_Registration {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string s = Console.ReadLine();
string t = Console.ReadLine();
// if (t.Contains(s) == true &&
// s.Length + 1 == t.Length)
//{
// Console.WriteLine("yes");
//}
// else
//{
// Console.WriteLine("no");
//}
string result = "YES";
if (t.Length - s.Length != 1) {
result = "NO";
} else {
for (int i = 0; i < s.Length; i++) {
if (s[i] != t[i]) {
result = "NO";
break;
}
}
}
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class A_167_Registration {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string s = Console.ReadLine();
string t = Console.ReadLine();
// if (t.Contains(s) == true &&
// s.Length + 1 == t.Length)
//{
// Console.WriteLine("yes");
//}
// else
//{
// Console.WriteLine("no");
//}
string result = "Yes";
if (t.Length - s.Length != 1) {
result = "No";
} else {
for (int i = 0; i < s.Length; i++) {
if (s[i] != t[i]) {
result = "No";
break;
}
}
}
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
| 8
| 191
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class A_167_Registration {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string a = Console.ReadLine();
string b = Console.ReadLine();
if (Regex.IsMatch(b, a)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class A_167_Registration {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string a = Console.ReadLine();
string b = Console.ReadLine();
if (Regex.IsMatch(b, a + ".")) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
Console.Out.Flush();
}
}
}
|
[["+", 15, 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, 222]]
| 8
| 146
| 4
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
if (T.Contains(S) && T.Length == S.Length + 1) {
Console.WriteLine("Yes");
} else
Console.WriteLine("No");
}
}
}
//文字列の入力
// string s = Console.ReadLine();
//整数の入力
// long n = long.Parse(Console.ReadLine());
//文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
// Console.WriteLine();
// Console.ReadKey();
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
if (T.IndexOf(S) == 0 && T.Length == S.Length + 1) {
Console.WriteLine("Yes");
} else
Console.WriteLine("No");
}
}
}
//文字列の入力
// string s = Console.ReadLine();
//整数の入力
// long n = long.Parse(Console.ReadLine());
//文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
// Console.WriteLine();
// Console.ReadKey();
|
[["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 131
| 4
|
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static System.Console;
using static Program.Input;
using static Program.MyMath;
using static Program.Const;
namespace Program {
public static class Program {
public static void Main() {
var s = ReadLine();
var t = ReadLine().Substring(0, s.Length - 1);
WriteLine(s == t ? "Yes" : "No");
}
}
static class Const {
public static string alp = "abcdefghijklmnopqrstuvwxyz";
public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const long MOD = 1000000007;
public static int INF = int.MaxValue;
public static long INFL = long.MaxValue;
}
static class Input {
public static void InputLine(out int a, out int b) {
var input = ScanIntArray();
a = input[0];
b = input[1];
}
public static void InputLine(out int a, out int b, out int c) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out int a, out int b, out int c, out int d) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out long a, out long b) {
var input = ScanLongArray();
a = input[0];
b = input[1];
}
public static void InputLine(out long a, out long b, out long c) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out long a, out long b, out long c, out long d) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out string a, out string b) {
var input = ScanStrArray();
a = input[0];
b = input[1];
}
public static int ScanInt() { return int.Parse(ReadLine()); }
static public uint ScanUint() { return uint.Parse(ReadLine()); }
static public double ScanDouble() { return double.Parse(ReadLine()); }
static public long ScanLong() { return long.Parse(ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(ReadLine()); }
static public int[] ScanIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
static public string RegaxReplace(this string arg1, string pattern,
string replacement) {
return Regex.Replace(arg1, pattern, replacement);
}
}
static class MyMath {
static public int CountBit(this long a) {
if (a == 0)
return 0;
int c = 1;
for (; a > 1; a /= 2)
if (a % 2 == 1)
c++;
return c;
}
static public int Floor2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public long Floor2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public int Ceiling2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N;
}
static public long Ceiling2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N;
}
static public long[] CumSum(this long[] a) {
var res = new long[a.Length];
long s = 0;
for (int i = 0; i < a.Length; i++)
res[i] = (s += a[i]);
return res;
}
static public IEnumerable<int> PrimeFactors(this int n) {
int tmp = n;
for (int i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public IEnumerable<long> PrimeFactors(this long n) {
var tmp = n;
for (long i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public int Digit(this int n, int d) {
if (d < 0)
return 0;
return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d);
}
static public int Length(this int n) {
if (n < 0)
return 0;
return (int)Math.Log10(n) + 1;
}
static public int Top(this int n) { return n.Digit(n.Length() - 1); }
public static bool isPrime(this int p) {
if (p <= 1)
return false;
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static bool isPrime(this long p) {
if (p <= 1)
return false;
for (long i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a / GCD(a, b) * b; }
public static long Inv(this long a, long m = MOD) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
private static void swap(ref long a, ref long b) {
var t = a;
a = b;
b = t;
}
public static long ModPow(long a, long n, long m = MOD) {
long res = 1;
while (n > 0) {
if (n % 2 == 1)
res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
}
static class MyLinq {
public static void Sort(this string[] array) {
Array.Sort(array, StringComparer.OrdinalIgnoreCase);
}
public static void StringSort(this List<string> list) {
list.Sort(StringComparer.OrdinalIgnoreCase);
}
public static string Join<T>(this IEnumerable<T> source, string separator) {
return string.Join(separator, source);
}
public static IEnumerable<TItem>
Distinct<TItem, TKey>(this IEnumerable<TItem> source,
Func<TItem, TKey> keySelector) {
if (source == null)
throw new ArgumentNullException(nameof(source));
if (keySelector == null)
throw new ArgumentNullException(nameof(keySelector));
var set = new HashSet<TKey>();
foreach (var item in source)
if (set.Add(keySelector(item)))
yield return item;
}
}
}
|
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static System.Console;
using static Program.Input;
using static Program.MyMath;
using static Program.Const;
namespace Program {
public static class Program {
public static void Main() {
var s = ReadLine();
var t = ReadLine().Substring(0, s.Length);
WriteLine(s == t ? "Yes" : "No");
}
}
static class Const {
public static string alp = "abcdefghijklmnopqrstuvwxyz";
public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const long MOD = 1000000007;
public static int INF = int.MaxValue;
public static long INFL = long.MaxValue;
}
static class Input {
public static void InputLine(out int a, out int b) {
var input = ScanIntArray();
a = input[0];
b = input[1];
}
public static void InputLine(out int a, out int b, out int c) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out int a, out int b, out int c, out int d) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out long a, out long b) {
var input = ScanLongArray();
a = input[0];
b = input[1];
}
public static void InputLine(out long a, out long b, out long c) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out long a, out long b, out long c, out long d) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out string a, out string b) {
var input = ScanStrArray();
a = input[0];
b = input[1];
}
public static int ScanInt() { return int.Parse(ReadLine()); }
static public uint ScanUint() { return uint.Parse(ReadLine()); }
static public double ScanDouble() { return double.Parse(ReadLine()); }
static public long ScanLong() { return long.Parse(ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(ReadLine()); }
static public int[] ScanIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
static public string RegaxReplace(this string arg1, string pattern,
string replacement) {
return Regex.Replace(arg1, pattern, replacement);
}
}
static class MyMath {
static public int CountBit(this long a) {
if (a == 0)
return 0;
int c = 1;
for (; a > 1; a /= 2)
if (a % 2 == 1)
c++;
return c;
}
static public int Floor2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public long Floor2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public int Ceiling2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N;
}
static public long Ceiling2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N;
}
static public long[] CumSum(this long[] a) {
var res = new long[a.Length];
long s = 0;
for (int i = 0; i < a.Length; i++)
res[i] = (s += a[i]);
return res;
}
static public IEnumerable<int> PrimeFactors(this int n) {
int tmp = n;
for (int i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public IEnumerable<long> PrimeFactors(this long n) {
var tmp = n;
for (long i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public int Digit(this int n, int d) {
if (d < 0)
return 0;
return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d);
}
static public int Length(this int n) {
if (n < 0)
return 0;
return (int)Math.Log10(n) + 1;
}
static public int Top(this int n) { return n.Digit(n.Length() - 1); }
public static bool isPrime(this int p) {
if (p <= 1)
return false;
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static bool isPrime(this long p) {
if (p <= 1)
return false;
for (long i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a / GCD(a, b) * b; }
public static long Inv(this long a, long m = MOD) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
private static void swap(ref long a, ref long b) {
var t = a;
a = b;
b = t;
}
public static long ModPow(long a, long n, long m = MOD) {
long res = 1;
while (n > 0) {
if (n % 2 == 1)
res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
}
static class MyLinq {
public static void Sort(this string[] array) {
Array.Sort(array, StringComparer.OrdinalIgnoreCase);
}
public static void StringSort(this List<string> list) {
list.Sort(StringComparer.OrdinalIgnoreCase);
}
public static string Join<T>(this IEnumerable<T> source, string separator) {
return string.Join(separator, source);
}
public static IEnumerable<TItem>
Distinct<TItem, TKey>(this IEnumerable<TItem> source,
Func<TItem, TKey> keySelector) {
if (source == null)
throw new ArgumentNullException(nameof(source));
if (keySelector == null)
throw new ArgumentNullException(nameof(keySelector));
var set = new HashSet<TKey>();
foreach (var item in source)
if (set.Add(keySelector(item)))
yield return item;
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 1,994
| 2
|
using System;
namespace First {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
string t = Console.ReadLine();
if (t.Substring(s.Length) == s) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
namespace First {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
string t = Console.ReadLine();
if (t.Substring(0, s.Length) == s) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 21]]
| 8
| 76
| 2
|
using System;
using System.Collections.Generic;
class main {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
if (S.Equals(T.Substring(0, T.Length - 1))) {
Console.Write("YES");
} else {
Console.Write("NO");
}
}
}
|
using System;
using System.Collections.Generic;
class main {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
if (S.Equals(T.Substring(0, T.Length - 1))) {
Console.Write("Yes");
} else {
Console.Write("No");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 86
| 4
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
string S = Console.ReadLine();
string T = Console.ReadLine();
int Sa = S.Length;
int Ta = T.Length;
int An = Ta - Sa;
if (An == 1 && T.Contains(S) == true) {
Console.WriteLine("Yes");
} else
Console.WriteLine("No");
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
string S = Console.ReadLine();
string T = Console.ReadLine();
int Sa = S.Length;
int Ta = T.Length;
int An = Ta - Sa;
if (An == 1 && T.Substring(0, Sa) == S) {
Console.WriteLine("Yes");
} else
Console.WriteLine("No");
}
}
|
[["-", 15, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 96
| 8
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine().ToCharArray();
var t = Console.ReadLine().ToCharArray();
for (int i = 0; i < s.Length; i++) {
if (s[i] == t[i])
continue;
Console.WriteLine("No");
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine().ToCharArray();
var t = Console.ReadLine().ToCharArray();
for (int i = 0; i < s.Length; i++) {
if (s[i] == t[i])
continue;
Console.WriteLine("No");
return;
}
Console.WriteLine("Yes");
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 7, 8, 196, 0, 37, 0, 35]]
| 8
| 103
| 2
|
using System;
public class Hello {
public static void Main() {
var s = Console.ReadLine().Trim();
var t = Console.ReadLine().Trim();
var a = s + t[t.Length - 1];
Console.WriteLine(s == a ? "Yes" : "No");
}
}
|
using System;
public class Hello {
public static void Main() {
var s = Console.ReadLine().Trim();
var t = Console.ReadLine().Trim();
var a = s + t[t.Length - 1];
Console.WriteLine(a == t ? "Yes" : "No");
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22]]
| 8
| 73
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace program {
public class ABC167 {
public static void Main(string[] args) {
var s = Console.ReadLine();
var t = Console.ReadLine();
if (t.Contains(s) && t.Length - s.Length == 1) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace program {
public class ABC167 {
public static void Main(string[] args) {
var s = Console.ReadLine();
var t = Console.ReadLine();
if (t.IndexOf(s) == 0 && t.Length - s.Length == 1) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 96
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
string[] string2 = Console.ReadLine().Split(' ');
bool checker = false;
int cost = 0;
if (string2[0].Count() - 1 == input[0].Count()) {
if (Equals(string2[0].Substring(0, input[0].Count()), input[0])) {
checker = true;
}
}
Console.WriteLine(checker == true ? "yes" : "no");
checker = false;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
string[] string2 = Console.ReadLine().Split(' ');
bool checker = false;
int cost = 0;
if (string2[0].Count() - 1 == input[0].Count()) {
if (Equals(string2[0].Substring(0, input[0].Count()), input[0])) {
checker = true;
}
}
Console.WriteLine(checker == true ? "Yes" : "No");
checker = false;
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 172
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.AtCoder_Begginer_Contest_167 {
class A {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
if (!T.Substring(0, T.Length - 1).Equals(S)) {
Console.WriteLine("No");
}
if (T.Length - 1 != S.Length) {
Console.WriteLine("No");
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.AtCoder_Begginer_Contest_167 {
class A {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
if (!T.Substring(0, T.Length - 1).Equals(S)) {
Console.WriteLine("No");
return;
}
if (T.Length - 1 != S.Length) {
Console.WriteLine("No");
return;
}
Console.WriteLine("Yes");
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 130
| 4
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
string s = Console.ReadLine();
string t = Console.ReadLine();
string result = t.Contains(s) ? "Yes" : "No";
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
string s = Console.ReadLine();
string t = Console.ReadLine();
string result = t.StartsWith(s) ? "Yes" : "No";
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
[["-", 0, 212, 0, 41, 15, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 41, 15, 213, 63, 214, 141, 22]]
| 8
| 102
| 2
|
using System;
using System.Linq;
using System.Xml.Schema;
class IDONTKNOWCSHARP {
public static void Main() {
string[] values = GetLines();
int value = 0;
int A = int.Parse(values[0]);
int B = int.Parse(values[1]);
int C = int.Parse(values[2]);
int K = int.Parse(values[3]);
if (K - A > 0) {
value += A;
K -= A;
if (K - B > 0) {
K -= B;
if (K - C > 0) {
// error
} else {
value -= K;
}
} else {
value += K;
}
} else {
value += K;
}
Console.WriteLine(value);
}
static string[] GetLines() {
return Console.ReadLine().Split(new string[] { " " },
StringSplitOptions.RemoveEmptyEntries);
}
}
|
using System;
using System.Linq;
using System.Xml.Schema;
class IDONTKNOWCSHARP {
public static void Main() {
string[] values = GetLines();
int value = 0;
int A = int.Parse(values[0]);
int B = int.Parse(values[1]);
int C = int.Parse(values[2]);
int K = int.Parse(values[3]);
if (K - A > 0) {
value += A;
K -= A;
if (K - B > 0) {
K -= B;
if (K - C > 0) {
// error
} else {
value -= K;
}
} else {
// value += K;
}
} else {
value += K;
}
Console.WriteLine(value);
}
static string[] GetLines() {
return Console.ReadLine().Split(new string[] { " " },
StringSplitOptions.RemoveEmptyEntries);
}
}
|
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["-", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 197
| 4
|
using System;
using System.Threading;
namespace ConsoleApp26 {
class Program {
static void Main(string[] args) {
//入力
string line = Console.ReadLine();
string[] array = line.Split(' ');
int a = int.Parse(array[0]);
int b = int.Parse(array[1]);
int c = int.Parse(array[2]);
int k = int.Parse(array[3]);
if (a > k) {
Console.WriteLine(k);
} else if (a + b >= k) {
Console.WriteLine(a);
} else {
Console.WriteLine(a + (k - (a + b)));
}
}
}
}
|
using System;
using System.Threading;
namespace ConsoleApp26 {
class Program {
static void Main(string[] args) {
//入力
string line = Console.ReadLine();
string[] array = line.Split(' ');
int a = int.Parse(array[0]);
int b = int.Parse(array[1]);
int c = int.Parse(array[2]);
int k = int.Parse(array[3]);
if (a > k) {
Console.WriteLine(k);
} else if (a + b >= k) {
Console.WriteLine(a);
} else {
Console.WriteLine(a - (k - (a + b)));
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
| 8
| 156
| 2
|
using System;
using System.Collections.Generic;
namespace test {
class MainClass {
public static void Main(string[] args) {
//問題167
string[] line = Console.ReadLine().Split(' ');
int A = int.Parse(line[0]);
int B = int.Parse(line[1]);
int C = int.Parse(line[2]);
int K = int.Parse(line[3]);
int ans = 0;
// for (int i = 0; i < K; i++)
//{
// if (A > 0)
// {
// ans += 1;
// A--;
// }
// else if (B > 0)
// {
// B--;
// }
// else
// {
// ans--;
// C--;
// }
//}
if (A - K >= 0) {
ans += A;
} else {
ans += A;
if (A + B - K >= 0) {
} else {
ans -= K - A - B;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
namespace test {
class MainClass {
public static void Main(string[] args) {
//問題167
string[] line = Console.ReadLine().Split(' ');
int A = int.Parse(line[0]);
int B = int.Parse(line[1]);
int C = int.Parse(line[2]);
int K = int.Parse(line[3]);
int ans = 0;
// for (int i = 0; i < K; i++)
//{
// if (A > 0)
// {
// ans += 1;
// A--;
// }
// else if (B > 0)
// {
// B--;
// }
// else
// {
// ans--;
// C--;
// }
//}
if (A - K >= 0) {
ans += K;
} else {
ans += A;
if (A + B - K >= 0) {
} else {
ans -= K - A - B;
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 174
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoderMake.ABC167 {
class ABC167D {
static void Main(string[] args) {
var nk =
Console.ReadLine().Split().Select((x) => long.Parse(x)).ToArray();
var a =
Console.ReadLine().Split().Select((x) => int.Parse(x) - 1).ToArray();
Dictionary<int, int> teledic = new Dictionary<int, int>();
int ordinal = 0;
int nextT = 0;
int start = 0;
int T = 0;
int res = 0;
while (1 == 1) {
if (teledic.ContainsKey(nextT) == false) {
teledic.Add(nextT, ordinal);
} else {
start = teledic[nextT];
T = ordinal - start;
break;
}
ordinal++;
nextT = a[nextT];
}
if (nk[1] < start) {
res = teledic.Keys.ToArray()[nk[1]];
} else {
var loopdic = new int[T];
Array.Copy(teledic.Keys.ToArray(), start, loopdic, 0, T);
res = loopdic[(nk[1] - start) % T];
}
Console.WriteLine(res);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoderMake.ABC167 {
class ABC167D {
static void Main(string[] args) {
var nk =
Console.ReadLine().Split().Select((x) => long.Parse(x)).ToArray();
var a =
Console.ReadLine().Split().Select((x) => int.Parse(x) - 1).ToArray();
Dictionary<int, int> teledic = new Dictionary<int, int>();
int ordinal = 0;
int nextT = 0;
int start = 0;
int T = 0;
int res = 0;
while (1 == 1) {
if (teledic.ContainsKey(nextT) == false) {
teledic.Add(nextT, ordinal);
} else {
start = teledic[nextT];
T = ordinal - start;
break;
}
ordinal++;
nextT = a[nextT];
}
if (nk[1] < start) {
res = teledic.Keys.ToArray()[nk[1]];
} else {
var loopdic = new int[T];
Array.Copy(teledic.Keys.ToArray(), start, loopdic, 0, T);
res = loopdic[(nk[1] - start) % T];
}
Console.WriteLine(res + 1);
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 284
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder.Contests.ABC167 {
/// <summary>
///
/// </summary>
static class D {
static void Main(string[] args) {
var n = NextInt();
var k = NextLong();
var aas = ReadIntArray();
var visited = Enumerable.Repeat(-1, n).ToArray();
//ループを探す
var count = 0;
var machi = 0;
visited[0] = 0;
while (true) {
machi = aas[machi] - 1;
count++;
if (count == k) {
Console.WriteLine(machi);
return;
}
if (visited[machi] >= 0) {
//その値が最初の定数回
// count と の差がループの回数
var f = visited[machi];
var loop = count - f;
k = k - f;
k = k % loop;
for (int i = 0; i < k; i++) {
machi = aas[machi] - 1;
}
Console.WriteLine(machi + 1);
return;
}
visited[machi] = count;
}
}
#region Console
static int _index = 0;
static string[] _buffer;
static string Next() {
if (_buffer == null || _index >= _buffer.Length) {
_buffer = Console.ReadLine().Split();
_index = 0;
}
return _buffer[_index++];
}
static int NextInt() { return int.Parse(Next()); }
static long NextLong() { return long.Parse(Next()); }
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
#endregion
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder.Contests.ABC167 {
/// <summary>
///
/// </summary>
static class D {
static void Main(string[] args) {
var n = NextInt();
var k = NextLong();
var aas = ReadIntArray();
var visited = Enumerable.Repeat(-1, n).ToArray();
//ループを探す
var count = 0;
var machi = 0;
visited[0] = 0;
while (true) {
machi = aas[machi] - 1;
count++;
if (count == k) {
Console.WriteLine(machi + 1);
return;
}
if (visited[machi] >= 0) {
//その値が最初の定数回
// count と の差がループの回数
var f = visited[machi];
var loop = count - f;
k = k - f;
k = k % loop;
for (int i = 0; i < k; i++) {
machi = aas[machi] - 1;
}
Console.WriteLine(machi + 1);
return;
}
visited[machi] = count;
}
}
#region Console
static int _index = 0;
static string[] _buffer;
static string Next() {
if (_buffer == null || _index >= _buffer.Length) {
_buffer = Console.ReadLine().Split();
_index = 0;
}
return _buffer[_index++];
}
static int NextInt() { return int.Parse(Next()); }
static long NextLong() { return long.Parse(Next()); }
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
#endregion
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 666
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_D.Lib_IO;
using static Contest_D.Lib_Minifunc;
public static class Contest_D
{
public static void Main() {
checked{
long n, k;
Lib_IO.rm(out n, out k);
ll[]a;
ra(out a);
Dictionary<ll,P<ll,ll>> d = new Dictionary<ll, P<ll,ll>>();
ll i = 0;
ll j = 0;
while(!d.ContainsKey(i)){
ll ni = a[i]-1;
d[i] = new P<ll, ll>(ni,j);
i = ni;
j++;
}
long l = k<d.Count? j : (k-d[i].B)%(d.Count-d[i].B)+d[i].B;
ll ans = 0;
for (int r = 0; r < l; r++)
{
ans = d[ans].A;
}
Lib_IO.wm(ans+1);
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換
[MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新
[MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c);
[MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
public struct P<T,U>
{
public T A; public U B;
public P(T a,U b) { A = a; B = b; }
public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B);
public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value);
}
public struct P<T,U,V>
{
public T A; public U B; public V C;
public P(T a,U b,V c) { A = a; B = b; C = c; }
}
public struct P<T,U,V,W>
{
public T A; public U B; public V C; public W D;
public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; }
}
public static class Lib_IO
{
class Prt : System.IO.StreamWriter
{
public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {}
public Prt(System.IO.Stream s,Encoding e) : base(s,e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[MethodImpl(256)] static T cv<T>(string s) =>
eq<T,int>() ? ct<T,int>(int.Parse(s))
: eq<T,long>() ? ct<T,long>(long.Parse(s))
: eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture))
: eq<T,char>() ? ct<T,char>(s[0])
: ct<T,string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T,U>(out T a,out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T,U,V>(out T a,out U b,out V c) {
var z = rm<T,U>(out a,out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) {
var z = rm<T,U,V>(out a,out b,out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) {
var z = rm<T,U,V,W>(out a,out b,out c,out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) {
var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = z.Select(cv<T>).ToArray();
return z;
}
public static string[][] rl<T>(long n,out T[] a) {
a = new T[n];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T,U>(long n,out P<T,U>[] a) {
a = new P<T,U>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p;
y[i] = rm(out o,out p);
a[i] = new P<T,U>(o,p);
}
return y;
}
public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) {
a = new P<T,U,V>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q;
y[i] = rm(out o,out p,out q);
a[i] = new P<T,U,V>(o,p,q);
}
return y;
}
public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) {
a = new P<T,U,V,W>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q; W r;
y[i] = rm(out o,out p,out q,out r);
a[i] = new P<T,U,V,W>(o,p,q,r);
}
return y;
}
public static string[][] rx<T>(long n,out T[][] a) {
a = new T[n][];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act){
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(()=>{
for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]);
Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); }
public static void wl<T>(IList<T> a) {
wwp(()=>{
var f = wfm(typeof(T));
foreach(T x in a) Console.WriteLine(f,x);
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(()=>{
var f = wfm(typeof(T));
var g = f + s;
foreach(var b in a) {
for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]);
Console.WriteLine(f,b[b.Count-1]);
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_D.Lib_IO;
using static Contest_D.Lib_Minifunc;
public static class Contest_D
{
public static void Main() {
checked{
long n, k;
Lib_IO.rm(out n, out k);
ll[]a;
ra(out a);
Dictionary<ll,P<ll,ll>> d = new Dictionary<ll, P<ll,ll>>();
ll i = 0;
ll j = 0;
while(!d.ContainsKey(i)){
ll ni = a[i]-1;
d[i] = new P<ll, ll>(ni,j);
i = ni;
j++;
}
long l = k<d.Count? k : (k-d[i].B)%(d.Count-d[i].B)+d[i].B;
ll ans = 0;
for (int r = 0; r < l; r++)
{
ans = d[ans].A;
}
Lib_IO.wm(ans+1);
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換
[MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新
[MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c);
[MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
public struct P<T,U>
{
public T A; public U B;
public P(T a,U b) { A = a; B = b; }
public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B);
public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value);
}
public struct P<T,U,V>
{
public T A; public U B; public V C;
public P(T a,U b,V c) { A = a; B = b; C = c; }
}
public struct P<T,U,V,W>
{
public T A; public U B; public V C; public W D;
public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; }
}
public static class Lib_IO
{
class Prt : System.IO.StreamWriter
{
public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {}
public Prt(System.IO.Stream s,Encoding e) : base(s,e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[MethodImpl(256)] static T cv<T>(string s) =>
eq<T,int>() ? ct<T,int>(int.Parse(s))
: eq<T,long>() ? ct<T,long>(long.Parse(s))
: eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture))
: eq<T,char>() ? ct<T,char>(s[0])
: ct<T,string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T,U>(out T a,out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T,U,V>(out T a,out U b,out V c) {
var z = rm<T,U>(out a,out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) {
var z = rm<T,U,V>(out a,out b,out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) {
var z = rm<T,U,V,W>(out a,out b,out c,out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) {
var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = z.Select(cv<T>).ToArray();
return z;
}
public static string[][] rl<T>(long n,out T[] a) {
a = new T[n];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T,U>(long n,out P<T,U>[] a) {
a = new P<T,U>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p;
y[i] = rm(out o,out p);
a[i] = new P<T,U>(o,p);
}
return y;
}
public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) {
a = new P<T,U,V>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q;
y[i] = rm(out o,out p,out q);
a[i] = new P<T,U,V>(o,p,q);
}
return y;
}
public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) {
a = new P<T,U,V,W>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q; W r;
y[i] = rm(out o,out p,out q,out r);
a[i] = new P<T,U,V,W>(o,p,q,r);
}
return y;
}
public static string[][] rx<T>(long n,out T[][] a) {
a = new T[n][];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act){
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(()=>{
for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]);
Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); }
public static void wl<T>(IList<T> a) {
wwp(()=>{
var f = wfm(typeof(T));
foreach(T x in a) Console.WriteLine(f,x);
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(()=>{
var f = wfm(typeof(T));
var g = f + s;
foreach(var b in a) {
for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]);
Console.WriteLine(f,b[b.Count-1]);
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 41, 64, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 22]]
| 8
| 3,066
| 2
|
using System;
using static System.Console;
namespace abc167 {
class Program {
const int keyNum = 998244353;
static void Main() {
var nmk = ReadLine().Split(' ');
var n = int.Parse(nmk[0]);
var m = int.Parse(nmk[1]);
var k = int.Parse(nmk[2]);
WriteLine(CB(n, m, k));
}
static int CB(int n, int m, int k) {
if (m == 1) {
if (k == n - 1) {
return 1;
} else {
return 0;
}
}
int[] facts = null;
int[] revFacts = null;
GetFactorialsDiv(n, keyNum, out facts, out revFacts);
var total = 0L;
for (var i = 0; i <= k; ++i) {
var subTotal =
((long)NCRDiv(n - 1, i, facts, revFacts, keyNum) * m) % keyNum;
subTotal = (subTotal * Exp(m - 1, n - i - 1, keyNum)) % keyNum;
total = (total + subTotal) % keyNum;
}
return (int)total;
}
static void GetFactorialsDiv(int n, int keyNum, out int[] facts,
out int[] revFacts) {
facts = new int[n + 1];
revFacts = new int[n + 1];
facts[0] = 1;
var tmp = 1L;
for (var i = 1; i <= n; ++i) {
tmp = (tmp * i) % keyNum;
facts[i] = (int)tmp;
}
// n!^-1 = n!^(m-2) (mod m)
tmp = Exp(facts[n], keyNum - 2, keyNum);
revFacts[n] = (int)tmp;
for (var i = n; i > 1; --i) {
tmp = (tmp * i) % keyNum;
revFacts[i - 1] = (int)tmp;
}
}
static long Exp(int n, int k, int keyNum) {
if (k == 0) {
return 1;
}
if (k == 1) {
return n;
}
var half = Exp(n, k / 2, keyNum);
var result = (half * half) % keyNum;
return ((k % 2) == 0) ? result : ((result * n) % keyNum);
}
static int NCRDiv(int n, int r, int[] facts, int[] revFacts, int keyNum) {
if (r == 0) {
return 1;
}
if (r == 1) {
return n;
}
var result = 1L;
result = (result * facts[n]) % keyNum;
result = (result * revFacts[r]) % keyNum;
result = (result * revFacts[n - r]) % keyNum;
return (int)result;
}
}
}
|
using System;
using static System.Console;
namespace abc167 {
class Program {
const int keyNum = 998244353;
static void Main() {
var nmk = ReadLine().Split(' ');
var n = int.Parse(nmk[0]);
var m = int.Parse(nmk[1]);
var k = int.Parse(nmk[2]);
WriteLine(CB(n, m, k));
}
static int CB(int n, int m, int k) {
if (m == 1) {
if (k == n - 1) {
return 1;
} else {
return 0;
}
}
int[] facts = null;
int[] revFacts = null;
GetFactorialsDiv(n, keyNum, out facts, out revFacts);
var total = 0L;
for (var i = 0; i <= k; ++i) {
var subTotal =
((long)NCRDiv(n - 1, i, facts, revFacts, keyNum) * m) % keyNum;
subTotal = (subTotal * Exp(m - 1, n - i - 1, keyNum)) % keyNum;
total = (total + subTotal) % keyNum;
}
return (int)total;
}
static void GetFactorialsDiv(int n, int keyNum, out int[] facts,
out int[] revFacts) {
facts = new int[n + 1];
revFacts = new int[n + 1];
facts[0] = 1;
var tmp = 1L;
for (var i = 1; i <= n; ++i) {
tmp = (tmp * i) % keyNum;
facts[i] = (int)tmp;
}
// n!^-1 = n!^(m-2) (mod m)
tmp = Exp(facts[n], keyNum - 2, keyNum);
revFacts[n] = (int)tmp;
for (var i = n; i > 1; --i) {
tmp = (tmp * i) % keyNum;
revFacts[i - 1] = (int)tmp;
}
}
static long Exp(int n, int k, int keyNum) {
if (k == 0) {
return 1;
}
if (k == 1) {
return n;
}
var half = Exp(n, k / 2, keyNum);
var result = (half * half) % keyNum;
return ((k % 2) == 0) ? result : ((result * n) % keyNum);
}
static int NCRDiv(int n, int r, int[] facts, int[] revFacts, int keyNum) {
if (r == 0 || r == n) {
return 1;
}
if (r == 1) {
return n;
}
var result = 1L;
result = (result * facts[n]) % keyNum;
result = (result * revFacts[r]) % keyNum;
result = (result * revFacts[n - r]) % keyNum;
return (int)result;
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 592
| 4
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Contest.E {
class Program {
const long MOD = 998244353;
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Scanner cin = new Scanner();
int n = cin.nextInt();
int m = cin.nextInt();
int k = cin.nextInt();
long ans = 0;
long now = 1;
for (int i = 1; i <= k; i++) {
now *= n - i;
now %= MOD;
now *= modinv(i, MOD);
now %= MOD;
}
now *= m;
now %= MOD;
for (int i = 0; i < n - k - 1; i++) {
now *= m - 1;
now %= MOD;
}
ans += now;
for (int i = 0; i <= k; i++) {
now *= k - i;
now %= MOD;
now *= modinv(n - k - i, MOD);
now %= MOD;
now *= m - 1;
now %= MOD;
ans += now;
ans %= MOD;
}
Console.WriteLine(ans);
Console.Out.Flush();
}
static long modinv(long a, long m) {
long b = m, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
static void swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
}
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.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Contest.E {
class Program {
const long MOD = 998244353;
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Scanner cin = new Scanner();
int n = cin.nextInt();
int m = cin.nextInt();
int k = cin.nextInt();
long ans = 0;
long now = 1;
for (int i = 1; i <= k; i++) {
now *= n - i;
now %= MOD;
now *= modinv(i, MOD);
now %= MOD;
}
now *= m;
now %= MOD;
for (int i = 0; i < n - k - 1; i++) {
now *= m - 1;
now %= MOD;
}
ans += now;
for (int i = 0; i <= k; i++) {
now *= k - i;
now %= MOD;
now *= modinv(n - k + i, MOD);
now %= MOD;
now *= m - 1;
now %= MOD;
ans += now;
ans %= MOD;
}
Console.WriteLine(ans);
Console.Out.Flush();
}
static long modinv(long a, long m) {
long b = m, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
static void swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
}
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;
}
}
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
| 8
| 756
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace contest_Csharp {
class Program {
static long power(long a, long b, long modulo) {
long result = 1;
long buff = a;
for (long i = 1; i <= b; i *= 2) {
result = result * ((b / i % (2) == 1) ? buff : 1) % modulo;
buff = (buff * buff) % modulo;
}
return result % modulo;
}
static long binomal(long n, long r, long modulo) {
long result = 1;
for (long i = 0; i < r; i++) {
result = (result * (n - i)) % modulo;
result = (result * power(i + 1, modulo - 1, modulo)) % modulo;
}
return result;
}
static void Main(string[] args) {
var vals =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
var N = vals[0];
var M = vals[1];
var K = vals[2];
long ans = 0;
long mod = 998244353;
long bin = 1;
for (int i = 0; i < K + 1; i++) {
ans =
(ans + ((M * bin) % mod) * power(M - 1, N - i - 1, mod) % mod) % mod;
bin = (bin * (N - 1 - i)) % mod;
bin = (bin * power(i + 1, mod - 1, mod)) % mod;
}
Console.WriteLine(ans);
}
}
class PriorityQueue<T>
where T : IComparable<T> {
private List<T> heap = new List<T>();
private int lastindex = -1;
private void swap(int n, int m) {
T wait = heap[n];
heap[n] = heap[m];
heap[m] = wait;
}
public int Count() { return lastindex + 1; }
public void Enqueue(T data) {
int p;
if (lastindex + 1 < heap.Count()) {
heap[lastindex + 1] = data;
} else {
heap.Add(data);
}
lastindex++;
p = lastindex;
while (true) {
if (p > 0 && heap[p].CompareTo(heap[(p - 1) / 2]) <= -1) {
swap(p, (p - 1) / 2);
p = (p - 1) / 2;
} else {
break;
}
}
}
public T Peek() { return heap[0]; }
public T Dequeue() {
T result = Peek();
heap[0] = default(T);
swap(0, lastindex);
lastindex--;
int p = 0;
while (true) {
int np;
if (2 * p + 1 > lastindex) {
break;
} else {
np = ((2 * p + 1 == lastindex) ||
heap[2 * p + 1].CompareTo(heap[2 * p + 2]) <= -1)
? (2 * p + 1)
: (2 * p + 2);
}
if (heap[p].CompareTo(heap[np]) >= 1) {
swap(p, np);
p = np;
} else {
break;
}
}
return result;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace contest_Csharp {
class Program {
static long power(long a, long b, long modulo) {
long result = 1;
long buff = a;
for (long i = 1; i <= b; i *= 2) {
result = result * ((b / i % (2) == 1) ? buff : 1) % modulo;
buff = (buff * buff) % modulo;
}
return result % modulo;
}
static long binomal(long n, long r, long modulo) {
long result = 1;
for (long i = 0; i < r; i++) {
result = (result * (n - i)) % modulo;
result = (result * power(i + 1, modulo - 1, modulo)) % modulo;
}
return result;
}
static void Main(string[] args) {
var vals =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
var N = vals[0];
var M = vals[1];
var K = vals[2];
long ans = 0;
long mod = 998244353;
long bin = 1;
for (int i = 0; i < K + 1; i++) {
ans =
(ans + ((M * bin) % mod) * power(M - 1, N - i - 1, mod) % mod) % mod;
bin = (bin * (N - 1 - i)) % mod;
bin = (bin * power(i + 1, mod - 2, mod)) % mod;
}
Console.WriteLine(ans);
}
}
class PriorityQueue<T>
where T : IComparable<T> {
private List<T> heap = new List<T>();
private int lastindex = -1;
private void swap(int n, int m) {
T wait = heap[n];
heap[n] = heap[m];
heap[m] = wait;
}
public int Count() { return lastindex + 1; }
public void Enqueue(T data) {
int p;
if (lastindex + 1 < heap.Count()) {
heap[lastindex + 1] = data;
} else {
heap.Add(data);
}
lastindex++;
p = lastindex;
while (true) {
if (p > 0 && heap[p].CompareTo(heap[(p - 1) / 2]) <= -1) {
swap(p, (p - 1) / 2);
p = (p - 1) / 2;
} else {
break;
}
}
}
public T Peek() { return heap[0]; }
public T Dequeue() {
T result = Peek();
heap[0] = default(T);
swap(0, lastindex);
lastindex--;
int p = 0;
while (true) {
int np;
if (2 * p + 1 > lastindex) {
break;
} else {
np = ((2 * p + 1 == lastindex) ||
heap[2 * p + 1].CompareTo(heap[2 * p + 2]) <= -1)
? (2 * p + 1)
: (2 * p + 2);
}
if (heap[p].CompareTo(heap[np]) >= 1) {
swap(p, np);
p = np;
} else {
break;
}
}
return result;
}
}
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 728
| 2
|
using System;
namespace E {
class Program {
static void Main(string[] args) {
var NMK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var N = NMK[0];
var M = NMK[1];
var K = NMK[2];
long MOD = 998244353;
Combination.combInit(100000000, MOD);
long result = 0;
for (int i = 0; i <= K; i++) {
long subtotal = M;
subtotal *= modpow(M - 1, N - i - 1, MOD);
subtotal %= MOD;
subtotal *= Combination.combination(N - 1, i);
subtotal %= MOD;
result += subtotal;
result %= MOD;
}
Console.WriteLine(result);
}
static long modpow(long a, long n, long mod) {
long result = 1;
while (n > 0) {
if ((n & 1) > 0)
result = (result * a) % mod;
a = (a * a) % mod;
n >>= 1;
}
return result;
}
}
static class Combination {
static long combMax;
static long combMOD;
static long[] factorial;
static long[] inverse;
static long[] factInv;
public static void combInit(long _max, long _mod) {
combMax = _max;
combMOD = _mod;
factorial = new long[combMax];
inverse = new long[combMax];
factInv = new long[combMax];
factorial[0] = factorial[1] = 1;
factInv[0] = factInv[1] = 1;
inverse[1] = 1;
for (int i = 2; i < combMax; i++) {
factorial[i] = factorial[i - 1] * i % combMOD;
inverse[i] = combMOD - inverse[combMOD % i] * (combMOD / i) % combMOD;
factInv[i] = factInv[i - 1] * inverse[i] % combMOD;
}
}
public static long combination(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return factorial[n] * (factInv[k] * factInv[n - k] % combMOD) % combMOD;
}
}
}
|
using System;
namespace E {
class Program {
static void Main(string[] args) {
var NMK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var N = NMK[0];
var M = NMK[1];
var K = NMK[2];
long MOD = 998244353;
Combination.combInit(1000000, MOD);
long result = 0;
for (int i = 0; i <= K; i++) {
long subtotal = M;
subtotal *= modpow(M - 1, N - i - 1, MOD);
subtotal %= MOD;
subtotal *= Combination.combination(N - 1, i);
subtotal %= MOD;
result += subtotal;
result %= MOD;
}
Console.WriteLine(result);
}
static long modpow(long a, long n, long mod) {
long result = 1;
while (n > 0) {
if ((n & 1) > 0)
result = (result * a) % mod;
a = (a * a) % mod;
n >>= 1;
}
return result;
}
}
static class Combination {
static long combMax;
static long combMOD;
static long[] factorial;
static long[] inverse;
static long[] factInv;
public static void combInit(long _max, long _mod) {
combMax = _max;
combMOD = _mod;
factorial = new long[combMax];
inverse = new long[combMax];
factInv = new long[combMax];
factorial[0] = factorial[1] = 1;
factInv[0] = factInv[1] = 1;
inverse[1] = 1;
for (int i = 2; i < combMax; i++) {
factorial[i] = factorial[i - 1] * i % combMOD;
inverse[i] = combMOD - inverse[combMOD % i] * (combMOD / i) % combMOD;
factInv[i] = factInv[i - 1] * inverse[i] % combMOD;
}
}
public static long combination(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return factorial[n] * (factInv[k] * factInv[n - k] % combMOD) % combMOD;
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 468
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class E {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() {
long N = GetLong();
long M = GetLong();
long K = GetLong();
if (M == 1) {
WriteLine(0);
return;
}
MInt.InitTable(N);
var ans = new MInt(0);
for (long k = 0; k <= K; k++)
ans += MInt.MComb(N - 1, N - 1 - k) * M * MInt.MPow((M - 1), N - 1 - k);
WriteLine(ans.Val);
}
}
public struct MInt {
private const long MOD = 998244353;
private static MInt[] f = null;
private static MInt[] g = null;
public long Val { get; private set; }
public MInt(long v) { Val = (v + MOD) % MOD; }
public static void InitTable(int N) => InitTable((long)N);
public static void InitTable(long N) {
f = new MInt[N + 1];
f[0] = new MInt(1);
for (long i = 1; i <= N; i++)
f[i] = f[i - 1] * i;
g = new MInt[N + 1];
g[N] = MPow(f[N], MOD - 2);
for (long i = N; i > 0; i--)
g[i - 1] = g[i] * i;
}
public static MInt MComb(long n, long k) {
if (n < 0 || n < k)
return new MInt(0);
return f[n] * g[k] * g[n - k];
}
public static MInt operator +(MInt x, long y) => x + new MInt(y);
public static MInt operator +(long x, MInt y) => new MInt(x) + y;
public static MInt operator +(MInt x, MInt y) {
long tmp = x.Val + y.Val;
if (tmp >= MOD)
tmp -= MOD;
return new MInt(tmp);
}
public static MInt operator -(MInt x, long y) => x - new MInt(y);
public static MInt operator -(long x, MInt y) => new MInt(x) - y;
public static MInt operator -(MInt x, MInt y) {
long tmp = x.Val;
if (tmp < y.Val)
tmp += MOD;
tmp -= y.Val;
return new MInt(tmp);
}
public static MInt operator *(MInt x,
MInt y) => new MInt((x.Val * y.Val) % MOD);
public static MInt operator *(MInt x, long y) => x * new MInt(y);
public static MInt operator *(long x, MInt y) => new MInt(x) * y;
public static MInt operator /(MInt x, MInt y) => x * MPow(y, MOD - 2);
public static MInt operator /(MInt x, long y) => x * MPow(y, MOD - 2);
public static MInt operator /(long x, MInt y) => x * MPow(y, MOD - 2);
public static MInt MPow(MInt x, MInt y) => MPow(x.Val, y.Val);
public static MInt MPow(MInt x, long y) => MPow(x.Val, y);
public static MInt MPow(long x, MInt y) => MPow(x, y.Val);
public static MInt MPow(long x, long y) {
long exp = y;
long xx = x;
long res = 1;
while (exp > 0) {
if ((exp & 1) == 1)
res = (res * xx) % MOD;
xx = (xx * xx) % MOD;
exp >>= 1;
}
return new MInt(res);
}
}
public static class MyIO {
private static string[] args = new string[0];
private static int cnt = 0;
private static IEnumerable<string>
getArgs(long N) => Range(0, N).Select(_ => getArg());
private static string getArg() {
if (cnt == args.Length) {
args = Console.ReadLine().Split();
cnt = 0;
}
return args[cnt++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static decimal GetDecimal() => decimal.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
public static long[] GetLongs(long N) =>
getArgs(N).Select(long.Parse).ToArray();
public static double[] GetDoubles(long N) =>
getArgs(N).Select(double.Parse).ToArray();
public static decimal[] GetDecimals(long N) =>
getArgs(N).Select(decimal.Parse).ToArray();
public static string[] GetStrings(long N) => getArgs(N).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
public static long rightShift(long x, long y) => (x >> (int)y);
public static long leftShift(long x, long y) => (x << (int)y);
public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
public static long lcm(long x, long y) => (x / gcd(x, y)) * y;
public static IEnumerable<int>
Range(long start, long count) => Enumerable.Range((int)start, (int)count);
public static void
Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class E {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() {
long N = GetLong();
long M = GetLong();
long K = GetLong();
if (N == 1) {
WriteLine(M);
return;
}
MInt.InitTable(N);
var ans = new MInt(0);
for (long k = 0; k <= K; k++)
ans += MInt.MComb(N - 1, N - 1 - k) * M * MInt.MPow((M - 1), N - 1 - k);
WriteLine(ans.Val);
}
}
public struct MInt {
private const long MOD = 998244353;
private static MInt[] f = null;
private static MInt[] g = null;
public long Val { get; private set; }
public MInt(long v) { Val = (v + MOD) % MOD; }
public static void InitTable(int N) => InitTable((long)N);
public static void InitTable(long N) {
f = new MInt[N + 1];
f[0] = new MInt(1);
for (long i = 1; i <= N; i++)
f[i] = f[i - 1] * i;
g = new MInt[N + 1];
g[N] = MPow(f[N], MOD - 2);
for (long i = N; i > 0; i--)
g[i - 1] = g[i] * i;
}
public static MInt MComb(long n, long k) {
if (n < 0 || n < k)
return new MInt(0);
return f[n] * g[k] * g[n - k];
}
public static MInt operator +(MInt x, long y) => x + new MInt(y);
public static MInt operator +(long x, MInt y) => new MInt(x) + y;
public static MInt operator +(MInt x, MInt y) {
long tmp = x.Val + y.Val;
if (tmp >= MOD)
tmp -= MOD;
return new MInt(tmp);
}
public static MInt operator -(MInt x, long y) => x - new MInt(y);
public static MInt operator -(long x, MInt y) => new MInt(x) - y;
public static MInt operator -(MInt x, MInt y) {
long tmp = x.Val;
if (tmp < y.Val)
tmp += MOD;
tmp -= y.Val;
return new MInt(tmp);
}
public static MInt operator *(MInt x,
MInt y) => new MInt((x.Val * y.Val) % MOD);
public static MInt operator *(MInt x, long y) => x * new MInt(y);
public static MInt operator *(long x, MInt y) => new MInt(x) * y;
public static MInt operator /(MInt x, MInt y) => x * MPow(y, MOD - 2);
public static MInt operator /(MInt x, long y) => x * MPow(y, MOD - 2);
public static MInt operator /(long x, MInt y) => x * MPow(y, MOD - 2);
public static MInt MPow(MInt x, MInt y) => MPow(x.Val, y.Val);
public static MInt MPow(MInt x, long y) => MPow(x.Val, y);
public static MInt MPow(long x, MInt y) => MPow(x, y.Val);
public static MInt MPow(long x, long y) {
long exp = y;
long xx = x;
long res = 1;
while (exp > 0) {
if ((exp & 1) == 1)
res = (res * xx) % MOD;
xx = (xx * xx) % MOD;
exp >>= 1;
}
return new MInt(res);
}
}
public static class MyIO {
private static string[] args = new string[0];
private static int cnt = 0;
private static IEnumerable<string>
getArgs(long N) => Range(0, N).Select(_ => getArg());
private static string getArg() {
if (cnt == args.Length) {
args = Console.ReadLine().Split();
cnt = 0;
}
return args[cnt++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static decimal GetDecimal() => decimal.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
public static long[] GetLongs(long N) =>
getArgs(N).Select(long.Parse).ToArray();
public static double[] GetDoubles(long N) =>
getArgs(N).Select(double.Parse).ToArray();
public static decimal[] GetDecimals(long N) =>
getArgs(N).Select(decimal.Parse).ToArray();
public static string[] GetStrings(long N) => getArgs(N).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
public static long rightShift(long x, long y) => (x >> (int)y);
public static long leftShift(long x, long y) => (x << (int)y);
public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
public static long lcm(long x, long y) => (x / gcd(x, y)) * y;
public static IEnumerable<int>
Range(long start, long count) => Enumerable.Range((int)start, (int)count);
public static void
Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 1,485
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_167 {
class E {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
long[] nmk = ReadLongs();
long n = nmk[0];
long m = nmk[1];
long k = nmk[2];
if (n == 1) {
WriteLine(m);
}
long mask = 998244353;
CaseCalculator calculator = new CaseCalculator(mask, n);
long res = 0;
long[] pows = new long[n];
pows[0] = 1;
for (int i = 1; i < n; i++) {
pows[i] = pows[i - 1] * (m - 1);
pows[i] %= mask;
}
for (long i = n - 1; n - 1 - i <= k; i--) {
long tmp = m * pows[i];
tmp %= mask;
tmp *= calculator.Combination(n - 1, i);
tmp %= mask;
res += tmp;
res %= mask;
}
WriteLine(res);
}
class CaseCalculator {
long mask;
long[] allPermutations;
long[] allInverses;
public CaseCalculator(long mask, long permutationCnt) {
this.mask = mask;
allPermutations = AllPermutations(permutationCnt);
allInverses = AllInverses(permutationCnt);
}
public long Combination(long n, long m) {
if (n < m)
return 0;
if (n - m < m)
m = n - m;
return Multi(allPermutations[n], allInverses[n - m], allInverses[m]);
}
public long Permutation(long n, long m) {
if (n < m)
return 0;
return Multi(allPermutations[n], allInverses[n - m]);
}
long[] AllPermutations(long n) {
var perms = new long[n + 1];
perms[0] = 1;
for (int i = 1; i <= n; i++) {
perms[i] = Multi(perms[i - 1], i);
}
return perms;
}
long[] AllInverses(long n) {
var inverses = new long[n + 1];
inverses[1] = 1;
var permInverses = new long[n + 1];
permInverses[0] = 1;
permInverses[1] = 1;
for (int i = 2; i <= n; i++) {
inverses[i] = mask - inverses[mask % i] * (mask / i) % mask;
permInverses[i] = Multi(permInverses[i - 1], inverses[i]);
}
return permInverses;
}
public long Multi(params long[] vals) {
if (vals.Length == 0) {
return 0;
}
long val = vals[0] % mask;
for (int i = 1; i < vals.Length; i++) {
val *= (vals[i] % mask);
val %= mask;
}
return val;
}
public long Inverse(long val) {
long a = mask;
long b = val % mask;
long x = 1;
long x1 = 0;
long y = 0;
long y1 = 1;
while (b > 0) {
long q = a / b;
long r = a % b;
long x2 = (mask + x - q * x1) % mask;
long y2 = (mask + y - q * y1) % mask;
a = b;
b = r;
x = x1;
x1 = x2;
y = y1;
y1 = y2;
}
return y;
}
long DeprecatedInverse(long val) { return Pow(val, mask - 2); }
long Pow(long a, long exp) {
if (exp == 0)
return 1;
else if (exp == 1)
return a % mask;
else {
long halfMod = Pow(a, exp / 2);
long nextMod = Multi(halfMod, halfMod);
if (exp % 2 == 0) {
return nextMod;
} else {
return Multi(nextMod, a);
}
}
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
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 AtTest.ABC_167 {
class E {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
long[] nmk = ReadLongs();
long n = nmk[0];
long m = nmk[1];
long k = nmk[2];
if (n == 1) {
WriteLine(m);
return;
}
long mask = 998244353;
CaseCalculator calculator = new CaseCalculator(mask, n);
long res = 0;
long[] pows = new long[n];
pows[0] = 1;
for (int i = 1; i < n; i++) {
pows[i] = pows[i - 1] * (m - 1);
pows[i] %= mask;
}
for (long i = n - 1; n - 1 - i <= k; i--) {
long tmp = m * pows[i];
tmp %= mask;
tmp *= calculator.Combination(n - 1, i);
tmp %= mask;
res += tmp;
res %= mask;
}
WriteLine(res);
}
class CaseCalculator {
long mask;
long[] allPermutations;
long[] allInverses;
public CaseCalculator(long mask, long permutationCnt) {
this.mask = mask;
allPermutations = AllPermutations(permutationCnt);
allInverses = AllInverses(permutationCnt);
}
public long Combination(long n, long m) {
if (n < m)
return 0;
if (n - m < m)
m = n - m;
return Multi(allPermutations[n], allInverses[n - m], allInverses[m]);
}
public long Permutation(long n, long m) {
if (n < m)
return 0;
return Multi(allPermutations[n], allInverses[n - m]);
}
long[] AllPermutations(long n) {
var perms = new long[n + 1];
perms[0] = 1;
for (int i = 1; i <= n; i++) {
perms[i] = Multi(perms[i - 1], i);
}
return perms;
}
long[] AllInverses(long n) {
var inverses = new long[n + 1];
inverses[1] = 1;
var permInverses = new long[n + 1];
permInverses[0] = 1;
permInverses[1] = 1;
for (int i = 2; i <= n; i++) {
inverses[i] = mask - inverses[mask % i] * (mask / i) % mask;
permInverses[i] = Multi(permInverses[i - 1], inverses[i]);
}
return permInverses;
}
public long Multi(params long[] vals) {
if (vals.Length == 0) {
return 0;
}
long val = vals[0] % mask;
for (int i = 1; i < vals.Length; i++) {
val *= (vals[i] % mask);
val %= mask;
}
return val;
}
public long Inverse(long val) {
long a = mask;
long b = val % mask;
long x = 1;
long x1 = 0;
long y = 0;
long y1 = 1;
while (b > 0) {
long q = a / b;
long r = a % b;
long x2 = (mask + x - q * x1) % mask;
long y2 = (mask + y - q * y1) % mask;
a = b;
b = r;
x = x1;
x1 = x2;
y = y1;
y1 = y2;
}
return y;
}
long DeprecatedInverse(long val) { return Pow(val, mask - 2); }
long Pow(long a, long exp) {
if (exp == 0)
return 1;
else if (exp == 1)
return a % mask;
else {
long halfMod = Pow(a, exp / 2);
long nextMod = Multi(halfMod, halfMod);
if (exp % 2 == 0) {
return nextMod;
} else {
return Multi(nextMod, a);
}
}
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
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, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 1,083
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Abc167F {
struct Bracket {
public long BraN;
public long KetN;
}
public static void Main() {
var n = int.Parse(Console.ReadLine());
long braN = 0;
long ketN = 0;
long m = 0;
var bracket = new List<Bracket>();
for (int i = 0; i < n; i++) {
var s = Console.ReadLine();
m += s.Length;
var x = new Bracket { BraN = 0, KetN = 0 };
for (int j = 0; j < s.Length; j++) {
x.BraN += s[j] == '(' ? 1 : -1;
if (x.KetN > x.BraN)
x.KetN = x.BraN;
}
x.KetN = -x.KetN;
x.BraN += x.KetN;
if (x.BraN == 0)
ketN += x.KetN;
else if (x.KetN == 0)
braN += x.BraN;
else
bracket.Add(x);
}
var sorted = bracket.OrderBy(x => x.KetN).OrderByDescending(x => x.BraN);
foreach (var item in sorted) {
braN -= item.KetN;
if (braN < 0) {
Console.WriteLine("No");
return;
}
braN += item.BraN;
}
Console.WriteLine(braN == ketN ? "Yes" : "No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Abc167F {
struct Bracket {
public long BraN;
public long KetN;
}
public static void Main() {
var n = int.Parse(Console.ReadLine());
long braN = 0;
long ketN = 0;
long m = 0;
var bracket = new List<Bracket>();
for (int i = 0; i < n; i++) {
var s = Console.ReadLine();
m += s.Length;
var x = new Bracket { BraN = 0, KetN = 0 };
for (int j = 0; j < s.Length; j++) {
x.BraN += s[j] == '(' ? 1 : -1;
if (x.KetN > x.BraN)
x.KetN = x.BraN;
}
x.KetN = -x.KetN;
x.BraN += x.KetN;
if (x.BraN == 0)
ketN += x.KetN;
else if (x.KetN == 0)
braN += x.BraN;
else
bracket.Add(x);
}
var sorted =
bracket.OrderBy(x => x.KetN).OrderByDescending(x => x.BraN - x.KetN);
foreach (var item in sorted) {
braN -= item.KetN;
if (braN < 0) {
Console.WriteLine("No");
return;
}
braN += item.BraN;
}
Console.WriteLine(braN == ketN ? "Yes" : "No");
}
}
}
|
[["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 33], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22]]
| 8
| 317
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_167 {
class F {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
int n = ReadInt();
string[] ss = new string[n];
for (int i = 0; i < n; i++) {
ss[i] = Read();
}
int[][] remAdds = new int [n][];
for (int i = 0; i < n; i++) {
int left = 0;
int right = 0;
for (int j = 0; j < ss[i].Length; j++) {
if (ss[i][j] == ')') {
if (right > 0) {
right--;
} else {
left++;
}
} else {
right++;
}
}
remAdds[i] = new int[2] { left, right };
}
int tmp = 0;
for (int i = 0; i < n; i++) {
if (remAdds[i][0] == 0 && remAdds[i][1] > 0) {
tmp += remAdds[i][1];
}
}
Array.Sort(remAdds, (a, b) => b[0] - a[0]);
for (int i = 0; i < n; i++) {
if (remAdds[i][0] > 0 && remAdds[i][1] > 0 &&
remAdds[i][0] <= remAdds[i][1]) {
if (tmp < remAdds[i][0]) {
WriteLine("No");
return;
}
tmp -= remAdds[i][0];
tmp += remAdds[i][1];
}
}
Array.Sort(remAdds, (a, b) => {
if (a[0] == b[0]) {
return b[1] - a[1];
} else {
return a[0] - b[0];
}
});
for (int i = 0; i < n; i++) {
if (remAdds[i][0] > 0 && remAdds[i][1] > 0 &&
remAdds[i][0] > remAdds[i][1]) {
if (tmp < remAdds[i][0]) {
WriteLine("No");
return;
}
tmp -= remAdds[i][0];
tmp += remAdds[i][1];
}
}
for (int i = 0; i < n; i++) {
if (remAdds[i][1] == 0) {
tmp -= remAdds[i][0];
}
}
if (tmp == 0) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
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.Runtime.InteropServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_167 {
class F {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
int n = ReadInt();
string[] ss = new string[n];
for (int i = 0; i < n; i++) {
ss[i] = Read();
}
int[][] remAdds = new int [n][];
for (int i = 0; i < n; i++) {
int left = 0;
int right = 0;
for (int j = 0; j < ss[i].Length; j++) {
if (ss[i][j] == ')') {
if (right > 0) {
right--;
} else {
left++;
}
} else {
right++;
}
}
remAdds[i] = new int[2] { left, right };
}
int tmp = 0;
for (int i = 0; i < n; i++) {
if (remAdds[i][0] == 0 && remAdds[i][1] > 0) {
tmp += remAdds[i][1];
}
}
Array.Sort(remAdds, (a, b) => a[0] - b[0]);
for (int i = 0; i < n; i++) {
if (remAdds[i][0] > 0 && remAdds[i][1] > 0 &&
remAdds[i][0] <= remAdds[i][1]) {
if (tmp < remAdds[i][0]) {
WriteLine("No");
return;
}
tmp -= remAdds[i][0];
tmp += remAdds[i][1];
}
}
Array.Sort(remAdds, (a, b) => {
if (a[0] == b[0]) {
return b[1] - a[1];
} else {
return b[0] - a[0];
}
});
for (int i = 0; i < n; i++) {
if (remAdds[i][0] > 0 && remAdds[i][1] > 0 &&
remAdds[i][0] > remAdds[i][1]) {
if (tmp < remAdds[i][0]) {
WriteLine("No");
return;
}
tmp -= remAdds[i][0];
tmp += remAdds[i][1];
}
}
for (int i = 0; i < n; i++) {
if (remAdds[i][1] == 0) {
tmp -= remAdds[i][0];
}
}
if (tmp == 0) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 0, 28, 0, 218, 8, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 204, 205, 22], ["-", 75, 196, 0, 37, 0, 16, 31, 204, 205, 22], ["+", 75, 196, 0, 37, 0, 16, 31, 204, 205, 22], ["-", 75, 196, 0, 37, 0, 16, 12, 204, 205, 22], ["+", 75, 196, 0, 37, 0, 16, 12, 204, 205, 22]]
| 8
| 845
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P {
public static void Main() {
int n = int.Parse(Console.ReadLine());
Bracket[] brackets = new Bracket[n];
for (int i = 0; i < n; i++) {
var s = Console.ReadLine();
int depth = 0;
int minDepth = 0;
for (int j = 0; j < s.Length; j++) {
if (s[j] == '(')
depth++;
else
depth--;
minDepth = Min(minDepth, depth);
}
brackets[i] = new Bracket() { FinalDepth = depth, MinDepth = minDepth };
}
{
int depth = 0;
foreach (var item in brackets.Where(x => x.FinalDepth >= 0)
.OrderByDescending(x => x.MinDepth)) {
if (depth + item.MinDepth < 0) {
Console.WriteLine("No");
return;
}
depth += item.FinalDepth;
}
foreach (var item in brackets.Where(x => x.FinalDepth < 0)
.OrderBy(x => x.MinDepth)) {
if (depth + item.MinDepth < 0) {
Console.WriteLine("No");
return;
}
depth += item.FinalDepth;
}
if (depth != 0) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
struct Bracket {
public int FinalDepth;
public int MinDepth;
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P {
public static void Main() {
int n = int.Parse(Console.ReadLine());
Bracket[] brackets = new Bracket[n];
for (int i = 0; i < n; i++) {
var s = Console.ReadLine();
int depth = 0;
int minDepth = 0;
for (int j = 0; j < s.Length; j++) {
if (s[j] == '(')
depth++;
else
depth--;
minDepth = Min(minDepth, depth);
}
brackets[i] = new Bracket() { FinalDepth = depth, MinDepth = minDepth };
}
{
int depth = 0;
//先に深い方からやった方が得することがあるかというとそんなことはなくて、そんな暇があったら浅いのをやれてしまうので
//最初は途中での深さが浅いのから
foreach (var item in brackets.Where(x => x.FinalDepth >= 0)
.OrderByDescending(x => x.MinDepth)) {
if (depth + item.MinDepth < 0) {
Console.WriteLine("No");
return;
}
depth += item.FinalDepth;
}
//先に浅いのをやることが得になりうるか
//さっきのの逆、なので途中での深さが深いのから
foreach (var item in brackets.Where(x => x.FinalDepth < 0)
.OrderBy(x => x.MinDepth - x.FinalDepth)) {
if (depth + item.MinDepth < 0) {
Console.WriteLine("No");
return;
}
depth += item.FinalDepth;
}
if (depth != 0) {
Console.WriteLine("No");
return;
}
}
//弾かなくて良いものを弾いている
// throw new Exception();
Console.WriteLine("Yes");
}
}
struct Bracket {
public int FinalDepth;
public int MinDepth;
}
|
[["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 33], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22]]
| 8
| 361
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// 問題:https://atcoder.jp/contests/abc166/tasks/abc166_a
class A_166_A_C {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string s = Console.ReadLine();
if (s == "ABC") {
string result = "ARC";
Console.WriteLine(result);
} else {
string result = "ARC";
Console.WriteLine(result);
}
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// 問題:https://atcoder.jp/contests/abc166/tasks/abc166_a
class A_166_A_C {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string s = Console.ReadLine();
if (s == "ABC") {
string result = "ARC";
Console.WriteLine(result);
} else {
string result = "ABC";
Console.WriteLine(result);
}
Console.Out.Flush();
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
| 8
| 138
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class A_A_C_166 {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string s = Console.ReadLine();
string result = "";
if (s == "abc") {
result = "arc";
} else {
result = "abc";
}
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class A_A_C_166 {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
string s = Console.ReadLine();
string result = "";
if (s == "ABC") {
result = "ARC";
} else {
result = "ABC";
}
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
| 8
| 134
| 6
|
using System;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
if (S == "ABC") {
Console.WriteLine("ARC");
} else {
Console.WriteLine("ARC");
}
}
}
}
|
using System;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
if (S == "ABC") {
Console.WriteLine("ARC");
} else {
Console.WriteLine("ABC");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 67
| 2
|
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static System.Console;
using static Program.Input;
using static Program.MyMath;
using static Program.Const;
namespace Program {
public static class Program {
public static void Main() {
var s = ReadLine();
WriteLine(s.Contains('B') ? "ABC" : "ARC");
}
}
static class Const {
public static string alp = "abcdefghijklmnopqrstuvwxyz";
public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const long MOD = 1000000007;
public static int INF = int.MaxValue;
public static long INFL = long.MaxValue;
}
static class Input {
public static void InputLine(out int a, out int b) {
var input = ScanIntArray();
a = input[0];
b = input[1];
}
public static void InputLine(out int a, out int b, out int c) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out int a, out int b, out int c, out int d) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out long a, out long b) {
var input = ScanLongArray();
a = input[0];
b = input[1];
}
public static void InputLine(out long a, out long b, out long c) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out long a, out long b, out long c, out long d) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out string a, out string b) {
var input = ScanStrArray();
a = input[0];
b = input[1];
}
public static int ScanInt() { return int.Parse(ReadLine()); }
static public uint ScanUint() { return uint.Parse(ReadLine()); }
static public double ScanDouble() { return double.Parse(ReadLine()); }
static public long ScanLong() { return long.Parse(ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(ReadLine()); }
static public int[] ScanIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
static public string RegaxReplace(this string arg1, string pattern,
string replacement) {
return Regex.Replace(arg1, pattern, replacement);
}
}
static class MyMath {
static public int CountBit(this long a) {
if (a == 0)
return 0;
int c = 1;
for (; a > 1; a /= 2)
if (a % 2 == 1)
c++;
return c;
}
static public int Floor2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public long Floor2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public int Ceiling2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N;
}
static public long Ceiling2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N;
}
static public long[] CumSum(this long[] a) {
var res = new long[a.Length];
long s = 0;
for (int i = 0; i < a.Length; i++)
res[i] = (s += a[i]);
return res;
}
static public IEnumerable<int> PrimeFactors(this int n) {
int tmp = n;
for (int i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public IEnumerable<long> PrimeFactors(this long n) {
var tmp = n;
for (long i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public int Digit(this int n, int d) {
if (d < 0)
return 0;
return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d);
}
static public int Length(this int n) {
if (n < 0)
return 0;
return (int)Math.Log10(n) + 1;
}
static public int Top(this int n) { return n.Digit(n.Length() - 1); }
public static bool isPrime(this int p) {
if (p <= 1)
return false;
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static bool isPrime(this long p) {
if (p <= 1)
return false;
for (long i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a / GCD(a, b) * b; }
public static long Inv(this long a, long m = MOD) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
private static void swap(ref long a, ref long b) {
var t = a;
a = b;
b = t;
}
public static long ModPow(long a, long n, long m = MOD) {
long res = 1;
while (n > 0) {
if (n % 2 == 1)
res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
}
static class MyLinq {
public static void Sort(this string[] array) {
Array.Sort(array, StringComparer.OrdinalIgnoreCase);
}
public static void StringSort(this List<string> list) {
list.Sort(StringComparer.OrdinalIgnoreCase);
}
public static string Join<T>(this IEnumerable<T> source, string separator) {
return string.Join(separator, source);
}
public static IEnumerable<TItem>
Distinct<TItem, TKey>(this IEnumerable<TItem> source,
Func<TItem, TKey> keySelector) {
if (source == null)
throw new ArgumentNullException(nameof(source));
if (keySelector == null)
throw new ArgumentNullException(nameof(keySelector));
var set = new HashSet<TKey>();
foreach (var item in source)
if (set.Add(keySelector(item)))
yield return item;
}
}
}
|
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static System.Console;
using static Program.Input;
using static Program.MyMath;
using static Program.Const;
namespace Program {
public static class Program {
public static void Main() {
var s = ReadLine();
WriteLine(s.Contains('B') ? "ARC" : "ABC");
}
}
static class Const {
public static string alp = "abcdefghijklmnopqrstuvwxyz";
public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const long MOD = 1000000007;
public static int INF = int.MaxValue;
public static long INFL = long.MaxValue;
}
static class Input {
public static void InputLine(out int a, out int b) {
var input = ScanIntArray();
a = input[0];
b = input[1];
}
public static void InputLine(out int a, out int b, out int c) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out int a, out int b, out int c, out int d) {
var input = ScanIntArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out long a, out long b) {
var input = ScanLongArray();
a = input[0];
b = input[1];
}
public static void InputLine(out long a, out long b, out long c) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
}
public static void InputLine(out long a, out long b, out long c, out long d) {
var input = ScanLongArray();
a = input[0];
b = input[1];
c = input[2];
d = input[3];
}
public static void InputLine(out string a, out string b) {
var input = ScanStrArray();
a = input[0];
b = input[1];
}
public static int ScanInt() { return int.Parse(ReadLine()); }
static public uint ScanUint() { return uint.Parse(ReadLine()); }
static public double ScanDouble() { return double.Parse(ReadLine()); }
static public long ScanLong() { return long.Parse(ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(ReadLine()); }
static public int[] ScanIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
static public string RegaxReplace(this string arg1, string pattern,
string replacement) {
return Regex.Replace(arg1, pattern, replacement);
}
}
static class MyMath {
static public int CountBit(this long a) {
if (a == 0)
return 0;
int c = 1;
for (; a > 1; a /= 2)
if (a % 2 == 1)
c++;
return c;
}
static public int Floor2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public long Floor2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public int Ceiling2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N;
}
static public long Ceiling2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N;
}
static public long[] CumSum(this long[] a) {
var res = new long[a.Length];
long s = 0;
for (int i = 0; i < a.Length; i++)
res[i] = (s += a[i]);
return res;
}
static public IEnumerable<int> PrimeFactors(this int n) {
int tmp = n;
for (int i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public IEnumerable<long> PrimeFactors(this long n) {
var tmp = n;
for (long i = 2; i * i <= n; i++)
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
if (tmp != 1)
yield return tmp;
}
static public int Digit(this int n, int d) {
if (d < 0)
return 0;
return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d);
}
static public int Length(this int n) {
if (n < 0)
return 0;
return (int)Math.Log10(n) + 1;
}
static public int Top(this int n) { return n.Digit(n.Length() - 1); }
public static bool isPrime(this int p) {
if (p <= 1)
return false;
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static bool isPrime(this long p) {
if (p <= 1)
return false;
for (long i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a / GCD(a, b) * b; }
public static long Inv(this long a, long m = MOD) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
private static void swap(ref long a, ref long b) {
var t = a;
a = b;
b = t;
}
public static long ModPow(long a, long n, long m = MOD) {
long res = 1;
while (n > 0) {
if (n % 2 == 1)
res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
}
static class MyLinq {
public static void Sort(this string[] array) {
Array.Sort(array, StringComparer.OrdinalIgnoreCase);
}
public static void StringSort(this List<string> list) {
list.Sort(StringComparer.OrdinalIgnoreCase);
}
public static string Join<T>(this IEnumerable<T> source, string separator) {
return string.Join(separator, source);
}
public static IEnumerable<TItem>
Distinct<TItem, TKey>(this IEnumerable<TItem> source,
Func<TItem, TKey> keySelector) {
if (source == null)
throw new ArgumentNullException(nameof(source));
if (keySelector == null)
throw new ArgumentNullException(nameof(keySelector));
var set = new HashSet<TKey>();
foreach (var item in source)
if (set.Add(keySelector(item)))
yield return item;
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 1,981
| 4
|
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
namespace hello_world {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
if (s == "ABC")
Console.WriteLine("ARC");
else if (s == "ABC")
Console.WriteLine("ARC");
}
}
}
|
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
namespace hello_world {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
if (s == "ABC")
Console.WriteLine("ARC");
else if (s == "ARC")
Console.WriteLine("ABC");
}
}
}
|
[["-", 0, 57, 75, 57, 15, 16, 12, 5, 0, 222], ["+", 0, 57, 75, 57, 15, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 96
| 4
|
using System;
using System.IO;
using System.Text;
namespace cswork {
class Program {
static void Main(string[] args) {
string str = Util.ReadFile();
switch (str) {
case "ABC":
Console.WriteLine("ARC");
break;
case "ARC":
Console.WriteLine("ABC");
break;
}
}
}
class Util {
public static string ReadFile() {
StreamReader sr = new StreamReader(@"C:\data\data.txt", Encoding.UTF8);
string str = sr.ReadToEnd();
sr.Close();
return str;
}
}
}
|
using System;
using System.IO;
using System.Text;
namespace cswork {
class Program {
static void Main(string[] args) {
// string str = Util.ReadFile ();
string str = Console.ReadLine();
switch (str) {
case "ABC":
Console.WriteLine("ARC");
break;
case "ARC":
Console.WriteLine("ABC");
break;
}
}
}
class Util {
public static string ReadFile() {
StreamReader sr = new StreamReader(@"C:\data\data.txt", Encoding.UTF8);
string str = sr.ReadToEnd();
sr.Close();
return str;
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 122
| 4
|
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;
class MainClass {
public static void Main(string[] args) {
if (LnStr() == "ABC")
print("ARC");
else
print("ARC");
}
public static void print(object obj) { Console.WriteLine(obj); }
public static long Gcd(long a, long b) {
if (a > b) {
var r = a % b;
if (r == 0)
return b;
else
return Gcd(b, r);
} else {
var r = b % a;
if (r == 0)
return a;
else
return Gcd(a, r);
}
}
public static int Gcd(int a, int b) {
if (a > b) {
var r = a % b;
if (r == 0)
return b;
else
return Gcd(b, r);
} else {
var r = b % a;
if (r == 0)
return a;
else
return Gcd(a, r);
}
}
public static int[] LnInts() {
var vs = Console.ReadLine().Trim().Split(
new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var ins = new int[vs.Length];
for (int i = 0; i < vs.Length; i++)
ins[i] = int.Parse(vs[i]);
return ins;
}
public static int LnInt() {
var vs = Console.ReadLine().Trim();
return int.Parse(vs);
}
public static long[] LnLngs() {
var vs = Console.ReadLine().Trim().Split(
new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var ins = new long[vs.Length];
for (int i = 0; i < vs.Length; i++)
ins[i] = long.Parse(vs[i]);
return ins;
}
public static long LnLng() {
var vs = Console.ReadLine().Trim();
return long.Parse(vs);
}
public static string[] LnStrs() {
var vs = Console.ReadLine().Trim().Split(
new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return vs;
}
public static string LnStr() {
var vs = Console.ReadLine().Trim();
return vs;
}
public static List<T[]> AllPermutation<T>(params T[] array)
where T : IComparable {
var a = new List<T>(array).ToArray();
var res = new List<T[]>();
res.Add(new List<T>(a).ToArray());
var n = a.Length;
var next = true;
while (next) {
next = false;
int i;
for (i = n - 2; i >= 0; i--) {
if (a[i].CompareTo(a[i + 1]) < 0)
break;
}
if (i < 0)
break;
var j = n;
do {
j--;
} while (a[i].CompareTo(a[j]) > 0);
if (a[i].CompareTo(a[j]) < 0) {
var tmp = a[i];
a[i] = a[j];
a[j] = tmp;
Array.Reverse(a, i + 1, n - i - 1);
res.Add(new List<T>(a).ToArray());
next = true;
}
}
return res;
}
}
|
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;
class MainClass {
public static void Main(string[] args) {
if (LnStr() == "ABC")
print("ARC");
else
print("ABC");
}
public static void print(object obj) { Console.WriteLine(obj); }
public static long Gcd(long a, long b) {
if (a > b) {
var r = a % b;
if (r == 0)
return b;
else
return Gcd(b, r);
} else {
var r = b % a;
if (r == 0)
return a;
else
return Gcd(a, r);
}
}
public static int Gcd(int a, int b) {
if (a > b) {
var r = a % b;
if (r == 0)
return b;
else
return Gcd(b, r);
} else {
var r = b % a;
if (r == 0)
return a;
else
return Gcd(a, r);
}
}
public static int[] LnInts() {
var vs = Console.ReadLine().Trim().Split(
new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var ins = new int[vs.Length];
for (int i = 0; i < vs.Length; i++)
ins[i] = int.Parse(vs[i]);
return ins;
}
public static int LnInt() {
var vs = Console.ReadLine().Trim();
return int.Parse(vs);
}
public static long[] LnLngs() {
var vs = Console.ReadLine().Trim().Split(
new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var ins = new long[vs.Length];
for (int i = 0; i < vs.Length; i++)
ins[i] = long.Parse(vs[i]);
return ins;
}
public static long LnLng() {
var vs = Console.ReadLine().Trim();
return long.Parse(vs);
}
public static string[] LnStrs() {
var vs = Console.ReadLine().Trim().Split(
new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return vs;
}
public static string LnStr() {
var vs = Console.ReadLine().Trim();
return vs;
}
public static List<T[]> AllPermutation<T>(params T[] array)
where T : IComparable {
var a = new List<T>(array).ToArray();
var res = new List<T[]>();
res.Add(new List<T>(a).ToArray());
var n = a.Length;
var next = true;
while (next) {
next = false;
int i;
for (i = n - 2; i >= 0; i--) {
if (a[i].CompareTo(a[i + 1]) < 0)
break;
}
if (i < 0)
break;
var j = n;
do {
j--;
} while (a[i].CompareTo(a[j]) > 0);
if (a[i].CompareTo(a[j]) < 0) {
var tmp = a[i];
a[i] = a[j];
a[j] = tmp;
Array.Reverse(a, i + 1, n - i - 1);
res.Add(new List<T>(a).ToArray());
next = true;
}
}
return res;
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 787
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace abc166_b {
class Program {
static void Main(string[] args) {
var inputSunukeAndSweets = Console.ReadLine().Split(' ');
var SunukeNum = int.Parse(inputSunukeAndSweets[0]);
var sweetsTypeNum = int.Parse(inputSunukeAndSweets[1]);
var hasSweetsMembers = new List<String>();
for (int i = 0; i < sweetsTypeNum; i++) {
Console.ReadLine();
var hasSweetsMember = Console.ReadLine().Split(' ');
for (int j = 0; i < hasSweetsMember.Length; j++) {
hasSweetsMembers.Add(hasSweetsMember[i]);
}
}
var possessedMember = hasSweetsMembers.Distinct().ToList();
Console.WriteLine(SunukeNum - possessedMember.Count);
Console.Read();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace abc166_b {
class Program {
static void Main(string[] args) {
var inputSunukeAndSweets = Console.ReadLine().Split(' ');
var SunukeNum = int.Parse(inputSunukeAndSweets[0]);
var sweetsTypeNum = int.Parse(inputSunukeAndSweets[1]);
var hasSweetsMembers = new List<String>();
for (int i = 0; i < sweetsTypeNum; i++) {
Console.ReadLine();
var hasSweetsMember = Console.ReadLine().Split(' ');
for (int j = 0; j < hasSweetsMember.Length; j++) {
hasSweetsMembers.Add(hasSweetsMember[j]);
}
}
var possessedMember = hasSweetsMembers.Distinct().ToList();
Console.WriteLine(SunukeNum - possessedMember.Count);
Console.Read();
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 183
| 4
|
namespace ConsoleApplication2 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main() {
var input =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var n = input[0];
var k = input[1];
var man = new bool[n];
for (int i = 0; i < k; i++) {
var d = Console.ReadLine();
var a =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
for (int j = 0; j < a.Count(); j++) {
man[j] = true;
}
}
var ans = man.Count(x => x == false);
Console.WriteLine(ans.ToString());
Console.ReadLine();
}
}
}
|
namespace ConsoleApplication2 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main() {
var input =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var n = input[0];
var k = input[1];
var man = new bool[n];
for (int i = 0; i < k; i++) {
var d = Console.ReadLine();
var a =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
for (int j = 0; j < a.Count(); j++) {
man[a[j] - 1] = true;
}
}
var ans = man.Count(x => x == false);
Console.WriteLine(ans.ToString());
Console.ReadLine();
}
}
}
|
[["+", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 207
| 5
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace cs {
class Program {
static void Main(string[] args) {
var pg = new Program();
pg.Execute();
}
private void Execute() {
var (N, K) = ReadLinesLongList2<long>();
var input = new List<long>();
var count = 0;
for (int i = 1; i <= 2 * K; i++) {
var temp = ReadLinesLongList;
if (i % 2 == 0) {
input = input.Concat(temp).ToList();
}
}
for (long i = 1; i <= N; i++) {
if (input.Contains(i)) {
count++;
}
}
OutputResult($"resurt:{N - count}");
}
private void OutputResult<T>(T result) { Console.WriteLine(result); }
static long ReadLineLong => long.Parse(Console.ReadLine());
static string ReadLineString => Console.ReadLine();
static IEnumerable<long> ReadLinesLongList =>
Console.ReadLine().Split(' ').Select(i => long.Parse(i));
static IEnumerable<string> ReadLinesStringList =>
Console.ReadLine().Split(' ');
public static (T, T) ReadLinesLongList2<T>() {
var input = Console.ReadLine().Split(' ');
return ((T)Convert.ChangeType(input.ElementAt(0), typeof(T)),
(T)Convert.ChangeType(input.ElementAt(1), typeof(T)));
}
public static (T, T, T) ReadLinesLongList3<T>() {
var input = Console.ReadLine().Split(' ');
return ((T)Convert.ChangeType(input.ElementAt(0), typeof(T)),
(T)Convert.ChangeType(input.ElementAt(1), typeof(T)),
(T)Convert.ChangeType(input.ElementAt(2), typeof(T)));
}
public static List<long> ReadLineNTimes() {
var input = new List<long>();
var N = long.Parse(Console.ReadLine());
for (int i = 0; i < N; i++) {
input.Add(long.Parse(Console.ReadLine()));
}
return input;
}
public static List<long> ReadLineNTimes(long N) {
var input = new List<long>();
for (int i = 0; i < N; i++) {
input.Add(long.Parse(Console.ReadLine()));
}
return input;
}
public static List<string> ReadLineNTimesString() {
var input = new List<string>();
var N = long.Parse(Console.ReadLine());
for (int i = 0; i < N; i++) {
input.Add(Console.ReadLine());
}
return input;
}
private int SolveDynamicProgramming(int n) {
var inputList = new List<int>() { 7, -6, 9 };
var dpList = new List<int>() { 0 };
for (int i = 0; i < n; ++i) {
dpList.Add(Math.Max(dpList[i], dpList[i] + inputList[i]));
}
return dpList[n];
}
private int SolveDynamicProgrammingForKnapsack(int n, int weight,
List<int> valueList,
List<int> weightList) {
var dpList = new List<List<int>>();
for (int i = 0; i < n + 1; ++i) {
dpList.Add(Enumerable.Repeat(0, weight + 1).ToList());
}
for (int i = 0; i < n; ++i) {
for (int w = 0; w <= weight; ++w) {
if (w >= weightList[i]) {
dpList[i + 1][w] = Math.Max(
dpList[i][w - weightList[i]] + valueList[i], dpList[i][w]);
} else {
dpList[i + 1][w] = dpList[i][w];
}
}
}
return dpList[n][weight];
}
public static int Gcd(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace cs {
class Program {
static void Main(string[] args) {
var pg = new Program();
pg.Execute();
}
private void Execute() {
var (N, K) = ReadLinesLongList2<long>();
var input = new List<long>();
var count = 0;
for (int i = 1; i <= 2 * K; i++) {
var temp = ReadLinesLongList;
if (i % 2 == 0) {
input = input.Concat(temp).ToList();
}
}
for (long i = 1; i <= N; i++) {
if (input.Contains(i)) {
count++;
}
}
OutputResult(N - count);
}
private void OutputResult<T>(T result) { Console.WriteLine(result); }
static long ReadLineLong => long.Parse(Console.ReadLine());
static string ReadLineString => Console.ReadLine();
static IEnumerable<long> ReadLinesLongList =>
Console.ReadLine().Split(' ').Select(i => long.Parse(i));
static IEnumerable<string> ReadLinesStringList =>
Console.ReadLine().Split(' ');
public static (T, T) ReadLinesLongList2<T>() {
var input = Console.ReadLine().Split(' ');
return ((T)Convert.ChangeType(input.ElementAt(0), typeof(T)),
(T)Convert.ChangeType(input.ElementAt(1), typeof(T)));
}
public static (T, T, T) ReadLinesLongList3<T>() {
var input = Console.ReadLine().Split(' ');
return ((T)Convert.ChangeType(input.ElementAt(0), typeof(T)),
(T)Convert.ChangeType(input.ElementAt(1), typeof(T)),
(T)Convert.ChangeType(input.ElementAt(2), typeof(T)));
}
public static List<long> ReadLineNTimes() {
var input = new List<long>();
var N = long.Parse(Console.ReadLine());
for (int i = 0; i < N; i++) {
input.Add(long.Parse(Console.ReadLine()));
}
return input;
}
public static List<long> ReadLineNTimes(long N) {
var input = new List<long>();
for (int i = 0; i < N; i++) {
input.Add(long.Parse(Console.ReadLine()));
}
return input;
}
public static List<string> ReadLineNTimesString() {
var input = new List<string>();
var N = long.Parse(Console.ReadLine());
for (int i = 0; i < N; i++) {
input.Add(Console.ReadLine());
}
return input;
}
private int SolveDynamicProgramming(int n) {
var inputList = new List<int>() { 7, -6, 9 };
var dpList = new List<int>() { 0 };
for (int i = 0; i < n; ++i) {
dpList.Add(Math.Max(dpList[i], dpList[i] + inputList[i]));
}
return dpList[n];
}
private int SolveDynamicProgrammingForKnapsack(int n, int weight,
List<int> valueList,
List<int> weightList) {
var dpList = new List<List<int>>();
for (int i = 0; i < n + 1; ++i) {
dpList.Add(Enumerable.Repeat(0, weight + 1).ToList());
}
for (int i = 0; i < n; ++i) {
for (int w = 0; w <= weight; ++w) {
if (w >= weightList[i]) {
dpList[i + 1][w] = Math.Max(
dpList[i][w - weightList[i]] + valueList[i], dpList[i][w]);
} else {
dpList[i + 1][w] = dpList[i][w];
}
}
}
return dpList[n][weight];
}
public static int Gcd(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
}
}
|
[["-", 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], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62]]
| 8
| 981
| 5
|
using System;
namespace ABC116B {
class Program {
static void Main(string[] args) {
var aa = Console.ReadLine().Split(' ');
int a = int.Parse(aa[0]);
int b = int.Parse(aa[1]);
int c, v;
int x = 0;
a = a + 1;
int[] d = new int[a];
for (int m = a - 1; m >= 0; m--) {
d[m] = 1;
}
for (int i = 1; i <= b; i++) {
c = int.Parse(Console.ReadLine());
var ab = Console.ReadLine().Split(' ');
for (int n = 1; n <= c; n++) {
v = int.Parse(ab[n - 1]);
d[v] = 0;
}
}
for (int s = a - 1; s >= 0; s--)
x += d[s];
Console.WriteLine(x);
}
}
}
|
using System;
namespace ABC116B {
class Program {
static void Main(string[] args) {
var aa = Console.ReadLine().Split(' ');
int a = int.Parse(aa[0]);
int b = int.Parse(aa[1]);
int c, v;
int x = 0;
a = a + 1;
int[] d = new int[a];
for (int m = a - 1; m >= 0; m--) {
d[m] = 1;
}
for (int i = 1; i <= b; i++) {
c = int.Parse(Console.ReadLine());
var ab = Console.ReadLine().Split(' ');
for (int n = 1; n <= c; n++) {
v = int.Parse(ab[n - 1]);
d[v] = 0;
}
}
for (int s = a - 1; s >= 0; s--)
x += d[s];
Console.WriteLine(x - 1);
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 228
| 2
|
using System;
class Program {
static void Main(string[] args) {
// スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
int[] a = new int[n + 1];
for (int i = 0; i < k; i++) {
int d = int.Parse(Console.ReadLine());
input = Console.ReadLine().Split(' ');
for (int j = 0; j < d; j++) {
a[int.Parse(input[0])]++;
}
}
int count = 0;
for (int i = 1; i < n + 1; i++) {
if (a[i] == 0) {
count++;
}
}
Console.WriteLine(count);
}
}
|
using System;
class Program {
static void Main(string[] args) {
// スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
int[] a = new int[n + 1];
for (int i = 0; i < k; i++) {
int d = int.Parse(Console.ReadLine());
input = Console.ReadLine().Split(' ');
for (int j = 0; j < d; j++) {
a[int.Parse(input[j])]++;
}
}
int count = 0;
for (int i = 1; i < n + 1; i++) {
if (a[i] == 0) {
count++;
}
}
Console.WriteLine(count);
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 195
| 2
|
using System;
namespace hello_world {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(" ");
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
int cnt = 0;
bool[] s = new bool[n];
for (int i = 0; i < k; i++) {
int d = int.Parse(Console.ReadLine());
string[] input2 = Console.ReadLine().Split(" ");
for (int j = 0; j < d; j++) {
s[int.Parse(input[j]) - 1] = true;
}
}
for (int aa = 0; aa < n; aa++) {
if (s[aa] == false)
cnt++;
}
Console.WriteLine(cnt);
}
}
}
|
using System;
namespace hello_world {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(" ");
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
int cnt = 0;
bool[] s = new bool[n];
for (int i = 0; i < k; i++) {
int d = int.Parse(Console.ReadLine());
string[] input2 = Console.ReadLine().Split(" ");
for (int j = 0; j < d; j++) {
s[int.Parse(input2[j]) - 1] = true;
}
}
for (int aa = 0; aa < n; aa++) {
if (s[aa] == false)
cnt++;
}
Console.WriteLine(cnt);
}
}
}
|
[["-", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22]]
| 8
| 198
| 2
|
using System;
using static System.Console;
using System.Linq;
namespace AC {
public class shiokara {
static void Main(string[] args) {
var data = ReadLine().Split(' ').Select(int.Parse).ToArray();
var tester = new int[100];
for (int i = 0; i < data[1]; i++) {
int d = int.Parse(ReadLine());
int[] A = ReadLine().Split(' ').Select(int.Parse).ToArray();
for (int j = 0; j < d; j++) {
tester[A[j] - 1]++;
}
}
int ans = 0;
for (int i = 0; i < data[0] - 1; i++) {
if (tester[i] == 0)
ans++;
}
WriteLine(ans);
}
}
}
|
using System;
using static System.Console;
using System.Linq;
namespace AC {
public class shiokara {
static void Main(string[] args) {
var data = ReadLine().Split(' ').Select(int.Parse).ToArray();
var tester = new int[100];
for (int i = 0; i < data[1]; i++) {
int d = int.Parse(ReadLine());
int[] A = ReadLine().Split(' ').Select(int.Parse).ToArray();
for (int j = 0; j < d; j++) {
tester[A[j] - 1]++;
}
}
int ans = 0;
for (int i = 0; i < data[0]; i++) {
if (tester[i] == 0)
ans++;
}
WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 196
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var inp = Console.ReadLine().Split(' ');
bool[] flg = new bool[int.Parse(inp[0])];
for (int i = 0; i < int.Parse(inp[1]); i++) {
var inpD = Console.ReadLine().Split(' ');
var inpA = Console.ReadLine().Split(' ');
for (int j = 0; j < int.Parse(inpD[0]); j++) {
flg[int.Parse(inpA[j])] = true;
}
}
int cnt = 0;
for (int i = 0; i < flg.Length; i++) {
if (!flg[i]) {
cnt++;
}
}
Console.WriteLine(cnt);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var inp = Console.ReadLine().Split(' ');
bool[] flg = new bool[int.Parse(inp[0])];
for (int i = 0; i < int.Parse(inp[1]); i++) {
var inpD = Console.ReadLine().Split(' ');
var inpA = Console.ReadLine().Split(' ');
for (int j = 0; j < int.Parse(inpD[0]); j++) {
flg[int.Parse(inpA[j]) - 1] = true;
}
}
int cnt = 0;
for (int i = 0; i < flg.Length; i++) {
if (!flg[i]) {
cnt++;
}
}
Console.WriteLine(cnt);
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 203
| 2
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long result = 0;
var a = long.Parse(input[0]);
var b = long.Parse(input[1]);
var c = long.Parse(input[2]);
var k = long.Parse(input[3]);
if (k <= a) {
result = k * a;
} else if (k <= a + b) {
result = a;
} else {
result = a + (k - a - b) * -1;
}
Console.WriteLine(result);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long result = 0;
var a = long.Parse(input[0]);
var b = long.Parse(input[1]);
var c = long.Parse(input[2]);
var k = long.Parse(input[3]);
if (k <= a) {
result = k;
} else if (k <= a + b) {
result = a;
} else {
result = a - (k - a - b);
}
Console.WriteLine(result);
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["-", 0, 11, 12, 16, 12, 16, 12, 241, 0, 33], ["-", 0, 11, 12, 16, 12, 16, 12, 241, 0, 203]]
| 8
| 147
| 7
|
using System;
namespace AtCoder.Question {
public class QuestionB {
public static void Main(string[] args) {
var inputs = Console.ReadLine().Split(' ');
var a = int.Parse(inputs[0]);
var b = int.Parse(inputs[1]);
var c = int.Parse(inputs[2]);
var k = int.Parse(inputs[3]);
if (k <= a) {
Console.WriteLine(k.ToString());
return;
}
if (k <= (a + b)) {
Console.WriteLine(a.ToString());
return;
}
Console.WriteLine((a - c).ToString());
}
}
}
|
using System;
namespace AtCoder.Question {
public class QuestionB {
public static void Main(string[] args) {
var inputs = Console.ReadLine().Split(' ');
var a = int.Parse(inputs[0]);
var b = int.Parse(inputs[1]);
var c = int.Parse(inputs[2]);
var k = int.Parse(inputs[3]);
if (k <= a) {
Console.WriteLine(k.ToString());
return;
}
if (k <= (a + b)) {
Console.WriteLine(a.ToString());
return;
}
Console.WriteLine((2 * a + b - k).ToString());
}
}
}
|
[["+", 205, 23, 0, 16, 31, 16, 31, 16, 31, 203], ["+", 205, 23, 0, 16, 31, 16, 31, 16, 17, 48], ["+", 63, 214, 205, 23, 0, 16, 31, 16, 17, 72], ["+", 63, 214, 205, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 63, 214, 205, 23, 0, 16, 12, 22], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 12, 22]]
| 8
| 155
| 6
|
using System;
namespace Sample {
class Sample {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
int K = int.Parse(input[3]);
if (A >= K) {
Console.WriteLine(K);
} else if ((A + B) >= K) {
Console.WriteLine(A);
} else {
Console.WriteLine(K - A - C);
}
}
}
}
|
using System;
namespace Sample {
class Sample {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
int K = int.Parse(input[3]);
if (A >= K) {
Console.WriteLine(K);
} else if ((A + B) >= K) {
Console.WriteLine(A);
} else {
Console.WriteLine(A - (K - A - B));
}
}
}
}
|
[["+", 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, 23, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 141
| 6
|
using System;
namespace abc167_b {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int k = int.Parse(input[3]);
if (a >= k) {
Console.WriteLine(k);
;
} else if (a < k && k - a <= b) {
Console.WriteLine(a);
} else {
Console.WriteLine(a - c + b);
}
Console.Read();
}
}
}
|
using System;
namespace abc167_b {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int k = int.Parse(input[3]);
if (a >= k) {
Console.WriteLine(k);
;
} else if (a < k && k - a <= b) {
Console.WriteLine(a);
} else {
Console.WriteLine(a * 2 - k + b);
}
Console.Read();
}
}
}
|
[["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
| 8
| 150
| 4
|
using System;
using System.Linq;
namespace _167.B {
internal class Program {
private static void Main(string[] args) {
var i = Console.ReadLine().Split().Select(int.Parse).ToList();
var (a, b, c, k) = (i[0], i[1], i[2], i[3]);
k -= a;
if (k == 0)
Console.WriteLine(k);
else {
k -= b;
if (k <= 0)
Console.WriteLine(a);
else {
Console.WriteLine(a - k);
}
}
}
}
}
|
using System;
using System.Linq;
namespace _167.B {
internal class Program {
private static void Main(string[] args) {
var i = Console.ReadLine().Split().Select(int.Parse).ToList();
var (a, b, c, k) = (i[0], i[1], i[2], i[3]);
k -= a;
if (k <= 0)
Console.WriteLine(k + a);
else {
k -= b;
if (k <= 0)
Console.WriteLine(a);
else {
Console.WriteLine(a - k);
}
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 137
| 4
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class AtCoder {
public static void Main() {
var abck =
Console.ReadLine().Trim().Split().Select(e => int.Parse(e)).ToArray();
var a = abck[0];
var b = abck[1];
var c = abck[2];
var k = abck[3];
int xa = Math.Min(a, k);
k -= a;
int xb = Math.Min(b, k);
k -= b;
int xc = k;
var ans = xa - xc;
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class AtCoder {
public static void Main() {
var abck =
Console.ReadLine().Trim().Split().Select(e => int.Parse(e)).ToArray();
var a = abck[0];
var b = abck[1];
var c = abck[2];
var k = abck[3];
int xa = Math.Min(a, k);
k -= xa;
int xb = Math.Min(b, k);
k -= xb;
int xc = k;
var ans = xa - xc;
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 149
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TOPSIC2 {
class Program {
static void Main(string[] args) {
string[] ABCK = Console.ReadLine().Split(' ');
long A = long.Parse(ABCK[0]);
long B = long.Parse(ABCK[1]);
long C = long.Parse(ABCK[2]);
long K = long.Parse(ABCK[3]);
long ans = 0;
if (A <= K) {
ans += A;
if (A + B <= K) {
ans -= K - A - B;
}
} else {
ans = A;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TOPSIC2 {
class Program {
static void Main(string[] args) {
string[] ABCK = Console.ReadLine().Split(' ');
long A = long.Parse(ABCK[0]);
long B = long.Parse(ABCK[1]);
long C = long.Parse(ABCK[2]);
long K = long.Parse(ABCK[3]);
long ans = 0;
if (A <= K) {
ans += A;
if (A + B <= K) {
ans -= K - A - B;
}
} else {
ans = K;
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 165
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.