diff --git a/codeforces/1027/.clang-format b/codeforces/1027/.clang-format new file mode 100644 index 0000000..99733d1 --- /dev/null +++ b/codeforces/1027/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false diff --git a/codeforces/1027/a.cc b/codeforces/1027/a.cc new file mode 100644 index 0000000..9a08503 --- /dev/null +++ b/codeforces/1027/a.cc @@ -0,0 +1,73 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i16 = int16_t; +using u16 = uint16_t; +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); +#endif + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n; + cin >> n; + + u32 root = sqrt(n); + while (root * root < n) { + ++root; + } + + if (root * root == n) { + println("{} 0", root); + } else { + println("-1"); + } +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + u32 tc = 1; + std::cin >> tc; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} +// }}} diff --git a/codeforces/17/.clang-format b/codeforces/17/.clang-format new file mode 100644 index 0000000..99733d1 --- /dev/null +++ b/codeforces/17/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false diff --git a/codeforces/498/1006a.cc b/codeforces/17/a.cc similarity index 91% rename from codeforces/498/1006a.cc rename to codeforces/17/a.cc index f68b3b3..e758599 100644 --- a/codeforces/498/1006a.cc +++ b/codeforces/17/a.cc @@ -39,16 +39,14 @@ constexpr T MAX = std::numeric_limits::max(); // }}} void solve() { - u32 n; + u32 n, a; cin >> n; - u32 a; + i32 total = 0; for (u32 i = 0; i < n; ++i) { cin >> a; - if (a % 2 == 0) { - --a; - } - print("{}{}", a, " \n"[i==n-1]); + total += (i & 1) ? -a : a; } + println("{}", total); } int main() { // {{{ @@ -61,7 +59,7 @@ int main() { // {{{ std::cin.tie(nullptr)->sync_with_stdio(false); #endif u32 tc = 1; - // std::cin >> tc; + std::cin >> tc; for (u32 t = 0; t < tc; ++t) { solve(); } diff --git a/codeforces/498/.clang-format b/codeforces/498/.clang-format new file mode 100644 index 0000000..99733d1 --- /dev/null +++ b/codeforces/498/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false diff --git a/codeforces/498/a.cc b/codeforces/498/a.cc new file mode 100644 index 0000000..7dbb4e2 --- /dev/null +++ b/codeforces/498/a.cc @@ -0,0 +1,68 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i16 = int16_t; +using u16 = uint16_t; +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template constexpr T MIN = std::numeric_limits::min(); + +template constexpr T MAX = std::numeric_limits::max(); +#endif + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n; + cin >> n; + u32 a; + for (u32 i = 0; i < n; ++i) { + cin >> a; + if (a % 2 == 0) { + --a; + } + print("{}{}", a, " \n"[i == n - 1]); + } +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + u32 tc = 1; + // std::cin >> tc; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} +// }}} diff --git a/codeforces/501/1015a.cc b/codeforces/501/1015a.cc index e6a9ef3..3134ea6 100644 --- a/codeforces/501/1015a.cc +++ b/codeforces/501/1015a.cc @@ -1,4 +1,4 @@ -#include // {{{ +#include // {{{ #include #ifdef __cpp_lib_ranges_enumerate @@ -22,11 +22,9 @@ using f64 = double; using f128 = long double; #if __cplusplus >= 202002L -template -constexpr T MIN = std::numeric_limits::min(); +template constexpr T MIN = std::numeric_limits::min(); -template -constexpr T MAX = std::numeric_limits::max(); +template constexpr T MAX = std::numeric_limits::max(); #endif #ifdef LOCAL @@ -42,7 +40,7 @@ void solve() { u32 n, m; cin >> n >> m; vector> a(n); - for (auto& e : a) { + for (auto &e : a) { cin >> e.first >> e.second; } sort(begin(a), end(a)); @@ -56,11 +54,13 @@ void solve() { ans.push_back(i); } } - println("{}", ans.size(); - for (auto& e : ans) print("{} ", e); println(); + println("{}", ans.size()); + for (auto &e : ans) + print("{} ", e); + println(); } -int main() { // {{{ +int main() { // {{{ std::cin.exceptions(std::cin.failbit); #ifdef LOCAL std::cerr.rdbuf(std::cout.rdbuf()); diff --git a/codeforces/570/.clang-format b/codeforces/570/.clang-format new file mode 100644 index 0000000..99733d1 --- /dev/null +++ b/codeforces/570/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false diff --git a/codeforces/570/a.cc b/codeforces/570/a.cc new file mode 100644 index 0000000..4ec28f0 --- /dev/null +++ b/codeforces/570/a.cc @@ -0,0 +1,77 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i16 = int16_t; +using u16 = uint16_t; +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); +#endif + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n; + cin >> n; + + auto dsum = [](u32 N) { + u32 dsum = 0; + while (N > 0) { + dsum += N % 10; + N /= 10; + } + return dsum; + }; + + while (dsum(n) % 4 != 0) { + ++n; + } + + println("{}", n); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + u32 tc = 1; + // std::cin >> tc; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} +// }}} diff --git a/codeforces/575/.clang-format b/codeforces/575/.clang-format new file mode 100644 index 0000000..99733d1 --- /dev/null +++ b/codeforces/575/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false diff --git a/codeforces/575/a.cc b/codeforces/575/a.cc new file mode 100644 index 0000000..02d223d --- /dev/null +++ b/codeforces/575/a.cc @@ -0,0 +1,71 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i16 = int16_t; +using u16 = uint16_t; +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); +#endif + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + vector a(3); + for (auto& e : a) cin >> e; + + sort(begin(a), end(a)); + + u64 diff = min(a[2], a[1] - a[0]); + a[0] += diff; + a[2] -= diff; + a[0] += a[2] / 2; + + println("{}", a[0]); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + u32 tc = 1; + std::cin >> tc; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} +// }}} diff --git a/codeforces/943/.clang-format b/codeforces/943/.clang-format new file mode 100644 index 0000000..99733d1 --- /dev/null +++ b/codeforces/943/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false diff --git a/codeforces/943/a.cc b/codeforces/943/a.cc new file mode 100644 index 0000000..d71fbec --- /dev/null +++ b/codeforces/943/a.cc @@ -0,0 +1,68 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i16 = int16_t; +using u16 = uint16_t; +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); +#endif + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 x; + cin >> x; + array ans{0, 0}; + for (u32 y = 1; y < x; ++y) { + ans = max(ans, {gcd(x, y) + y, y}); + } + + println("{}", ans[1]); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + u32 tc = 1; + std::cin >> tc; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} +// }}} diff --git a/codeforces/950/.clang-format b/codeforces/950/.clang-format new file mode 100644 index 0000000..99733d1 --- /dev/null +++ b/codeforces/950/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false diff --git a/codeforces/950/a.cc b/codeforces/950/a.cc new file mode 100644 index 0000000..2afdc4b --- /dev/null +++ b/codeforces/950/a.cc @@ -0,0 +1,77 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i16 = int16_t; +using u16 = uint16_t; +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); +#endif + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +vector f('G' - 'A' + 1); + +void solve() { + u32 n, m; + cin >> n >> m; + f.assign(f.size(), 0); + char c; + for (u32 i = 0; i < n; ++i) { + cin >> c; + ++f[c - 'A']; + } + + u32 ans = 0; + for (auto freq : f) { + ans += m - min(m, freq); + } + + println("{}", ans); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + u32 tc = 1; + std::cin >> tc; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} +// }}} diff --git a/codeforces/954/.clang-format b/codeforces/954/.clang-format new file mode 100644 index 0000000..99733d1 --- /dev/null +++ b/codeforces/954/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false diff --git a/codeforces/954/a.cc b/codeforces/954/a.cc new file mode 100644 index 0000000..2c8526a --- /dev/null +++ b/codeforces/954/a.cc @@ -0,0 +1,72 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i16 = int16_t; +using u16 = uint16_t; +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); +#endif + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + vector a(3); + for (auto& e : a) cin >> e; + sort(begin(a), end(a)); + + u32 ans = 1e9; + for (i32 c = 1; c <= 10; ++c) { + u32 diff = 0; + for (auto e : a) diff += abs(c - e); + ans = min(ans, diff); + } + + println("{}", ans); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + u32 tc = 1; + std::cin >> tc; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} +// }}}