description
stringlengths
35
9.39k
solution
stringlengths
7
465k
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; const int MOD = 1e9 + 7; vector<int> g[N + N]; int mat[N][N], p[N + N], sub[N + N], vis[N + N]; int ans[N + N], instack[N + N], go = true, ct = 0; vector<pair<int, int>> extime; void putNumbers(int node) { vis[node] = 1; instack[node] = true; ct...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 5; namespace DSU { int fa[MAXN << 1]; void init(int n) { for (int i = 1; i <= n; i++) fa[i] = i; } int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); } bool Union(int x, int y) { x = Find(x), y = Find(y); if (x == y) return 0; retu...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> using namespace std; char s[1005][1005]; int vis[3 * 1005], fa[3 * 1005], in[3 * 1005], ans[3 * 1005]; vector<int> v[3 * 1005]; int findd(int x) { return x == fa[x] ? x : fa[x] = findd(fa[x]); } int main() { int n, m, i, j; cin >> n >> m; for (i = 0; i < n; i++) { scanf("%s", s[i]); ...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; char mp[N][N]; int sec[N], fir[N]; int num[3]; int b[N + N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { getchar(); scanf("%s", mp[i] + 1); } for (int i = 1; i <= n; i++) ...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 10; char s[MAXN][MAXN]; vector<int> G[MAXN << 1]; int indec[MAXN << 1]; int ans[MAXN << 1]; bool vis[MAXN << 1]; struct DSU { int p[MAXN << 1]; int sz; void init(int n) { sz = n; for (int i = 1; i <= n; i++) { p[i] = i; } } ...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> using namespace std; const long long Mod = 7 + 1e9; const long long INF32 = 5 + 2e9; const long long INF64 = 1 + 1e18; const long long MAX = 5 + 1e3; int N, M, parent[2 * MAX], dp[2 * MAX]; vector<long long> G[2 * MAX]; set<int> GG[2 * MAX]; bool eq[2 * MAX][2 * MAX]; int vis[2 * MAX]; void mer...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) {new Main().run();} FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); void run(){ work(); out.flush(); } long mod=1000000007; long gcd(long a,long b) { return a==0?b:b>=a?gcd(b%...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> #pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math") using namespace std; inline int POW(int a, int b = 1000000007 - 2, int ans = 1) { for (; b; b >>= 1, a = (long long)a * a % 1000000007) if (b & 1) ans = (long long)ans * a ...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 1e3 + 5; int n, m, par[2 * N], sz[2 * N]; int id[2 * N], ans[2 * N]; vector<int> g[2 * N]; bool vis[2 * N], in[2 * N]; char a[N][N]; int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); } void join(int u, int v) { u = ...
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di...
#include <bits/stdc++.h> using namespace std; struct Edge { int v, w; } edge[1000000 * 2 + 10]; int d[1010 * 2], cnt[1010 * 2]; vector<int> G[1010 * 2]; bool vis[1010 * 2]; bool spfa(int n, int m) { memset(cnt, 0, sizeof(cnt)); memset(d, 0, sizeof(d)); memset(vis, true, sizeof(vis)); queue<int> qu; for (int...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long N = 105; long long m; struct node { long long data[N][N]; node operator*(node b) { node t; for (long long i = 0; i <= m; i++) { for (long long j = 0; j <= m; j++) { t.data[i][j] = 0; } } ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int N = 100 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; long long qpow(long long n, long long k) { long long res = 1; while (k) { if (k & 1) res = res * n % mod; n = n * n % mod; k >>= 1; } return res; } struct matrix { long long a...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; struct mint { int n; mint(int n_ = 0) : n(n_ % MOD) { if (n < 0) n += MOD; } }; mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; } mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a....
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int N = 110; const int mo = 1e9 + 7; int n, k, a[N], num[3], nn, f = 0; long long ans, now[N][N], dp[N][N], aa[N]; long long po(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; long long c = po(a, b / 2); if (b & 1) return c * c % mo...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> bool debug = 0; const long long MOD = 1000000007; const double PI = acos(-1.0); const double eps = 1e-9; using namespace std; long long modmul(long long a, long long b) { return (a * b) % MOD; } long long modsum(long long a, long long b) { return ((a % MOD) + (b % MOD)) % MOD; } long long mod...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); long long nn, MOD = 1e9 + 7; vector<vector<long long> > matMul(vector<vector<long long> > &a, vector<vector<long long> > &b) { vector<vector<long long> > c(nn, vector<...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; long long mod(long long n) { if (n < 0) { return (n % MOD + MOD) % MOD; } else { if (n < MOD) return n; else if (n < 2 * MOD) return n - MOD; else return n % MOD; } } long long fp(long lon...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; const int MOD = 1e9 + 7; struct Mat { long long a[MAXN][MAXN]; int n; Mat(int n) : n(n) { memset(a, 0, sizeof(a)); } }; Mat operator*(Mat a, Mat b) { Mat c(a.n); for (int i = 0; i <= a.n; i++) { for (int j = 0; j <= a.n; j++) { for ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; void guan() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const int maxn = 123456; const int mod = 1e9 + 7; int a[maxn]; int dp[110][110][110]; class Matrix { public: long long m[105][105]; Matrix() { memset(m, 0, sizeof(m)); ; } Matrix(in...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.util.*; import java.io.*; public class F553 { public static void main(String[] args) throws Exception { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int n = sc.nextInt(); long k = sc.nextLong(); int [] a...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const double eps = (double)1e-8; const int maxn = (int)2e5 + 20; int n, m; int a[105]; struct mat { int n; int a[105][105]; mat operator*(const mat &t) const { mat res; res.n = n; for (int i = 0; i <= n; i++) for (int j ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 110; struct MAT { long long a[MAXN][MAXN]; MAT() { for (int i = 0; i < MAXN; i++) fo...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int str[101]; int dp[101][101][101]; long long num[51][51]; int n, m; int b, w; namespace MI { void A(long long &a, long long b) { a += b; if (a >= mod) a -= mod; } long long qmul(long long a, long long b) { long long res = 0; while (b) { ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int N = 200; const int mod = 1e9 + 7; int inf = 1000000000; unsigned long long g[N][N], res[N][N]; unsigned long long dp[N]; int a[N]; int n; unsigned long long k; void mul(unsigned long long a[N][N], unsigned long long b[N][N], unsigned long long c[N][N]) { ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f; } inline void read(lo...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int iinf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3f; const int N = 100; const int mod = 1e9 + 7; int n, k, a[N], zn, cn, izn; int Pow(int a, int first) { int res = 1; for (; first; a = 1ll * a * a % mod, first >>= 1) if (first & 1) res = 1ll * res...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.io.*; import java.util.*; public class Main implements Runnable{ public static void main(String[] args){ //new Thread(null,new Main(),"Thread-1",1024*1024*10).start(); new Main().run(); } int[]a; int tot=0; long[]inv; int mod=1000000007; private void solve() thro...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.util.*; import java.io.*; public class EdC { static long[] mods = {1000000007, 998244353, 1000000009}; static long mod = mods[0]; public static MyScanner sc; public static PrintWriter out; static int y; public static void main(String[] omkar) throws Exception{ // TODO Auto-generated method stu...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> #pragma GCC optimize("-O2") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimization("unroll-loops") using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<strin...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> const int M = 105; const int MOD = 1e9 + 7; long long read() { long long x = 0, f = 1; char c; while ((c = getchar()) < '0' || c > '9') { if (c == '-') f = -1; } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return x * f; } long lo...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; long long mod(long long n) { if (n < 0) { return (n % MOD + MOD) % MOD; } else { if (n < MOD) return n; else if (n < (MOD << 1)) return n - MOD; else return n % MOD; } } long long fp(long ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 5; const int MOD = 1e9 + 7; int a[maxn]; long long dp[maxn]; struct mat { long long a[maxn][maxn]; int l, r; void init(int _l, int _r) { memset(a, 0, sizeof(a)); l = _l; r = _r; } }; mat operator*(mat X, mat Y) { mat Z; Z.l = X...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int N = 105; const int mod = 1e9 + 7; int n, k, m, sta, a[N]; int fastpow(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % mod; x = 1ll * x * x % mod; y >>= 1; } return res; } struct mat { int a[N][N]; mat() { memset(a,...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; long long mod(long long n) { if (n < 0) { return (n % MOD + MOD) % MOD; } else { if (n < MOD) return n; else if (n < 2 * MOD) return n - MOD; else return n % MOD; } } long long fp(long lon...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int N = 105, LOGK = 31; const long long MOD = 1e9 + 7; long long n, k, tab[N], l, dp[LOGK][N][N], pocz, ost[N][N], ost2[N][N]; long long pot(long long a, long long p) { if (p == 0) return 1; long long w = pot(a, p / 2); w = w * w % MOD; if (p % 2) w = w * a % ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { static final long MOD = 1_000_000_007 , INF = 1_000_000_000_000_000L; static final int INf = 1_000_000_000; static FastReader reader; static PrintWriter writer; public static void main(String[] args) { ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; class Solution { public: int solve(vector<int>& nums, int k) { int n = nums.size(); if (n < 2) { return 0; } long long P = 0, Q = 0; long long p = invM(n * (n - 1) / 2); int zeros = 0, ones = 0; for (int i = 0; i < n; ++i) { if (nu...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long add(long long a, long long b) { return (a + b) % mod; } long long mul(long long a, long long b) { return a * b % mod; } long long qpow(long long a, long long b = mod - 2) { long long ret = 1; while (b) { if (b & 1) ret = mul(ret, a...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int md = (int)(1e9 + 7); const int N = 110; int a[N], sz; struct mat { int a[N][N]; void init() { memset(a, 0, sizeof(a)); for (int i = 0; i < sz; i++) { a[i][i] = 1; } } void print() { for (int i = 0; i < sz; i++) { for (int j = 0;...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const unsigned long long MOD = 1e9 + 7, N = 100; unsigned long long k, n, c, cnt; int a[110]; struct node { unsigned long long f[110][110]; } t, tt, res; void matrix(node &t) { memset(t.f, 0, sizeof t.f); for (unsigned long long i = 0; i <= N; ++i) t.f[i][i] = 1; } vo...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1000000007; struct Matrix { vector<vector<ll>> v; int n, m; Matrix(vector<vector<ll>>& t) { n = t.size(); m = t[0].size(); v = t; } Matrix(int p, int q) { v = vector<vector<ll>>(p, vector<ll>(q, 0)); n = p, ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int a[105], n, K, sn; struct Mat { int a[105][105]; Mat() { memset(a, 0, sizeof(a)); } Mat operator*(const Mat &b) const { Mat c = Mat(); for (int i = 0; i <= sn; i++) for (int j = 0; j <= sn; j++) for (int k = 0; k <=...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } using ll = long long; const ll mod = 1e9 + 7; const int maxn = 110; using matrix = vector<vector<ll>>; void add(ll& x, ll y) { if (x >= mod) x %= mod; if (y >= mod) y %= mod; x += y; if (x >= mo...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 10; const long long mod = 1e9 + 7; long long qpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } struct Matrix { static const int N = 110; long ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> const int N = 210, MO = 1e9 + 7; int n, K, A[N], fac[N], inv[N], invn[N], a[N][N], ans[N][N], c[N][N], lm; inline void Add(int &a, const int &b) { a += b; if (a >= MO) a -= MO; else if (a < 0) a += MO; return; } inline int qpow(int a, int b) { int ans = 1; while (b) { if...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, M = 1e9 + 7; const long long LINF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1), EPS = 1e-9; const int N = 101; long long b[N]; long long o; int n, k; long long fm(long long a, long long b) { return (-b < a and a < b) ? a : a % b; } template...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> namespace IO { int double_len(6); bool spacebar_can_see(1); template <typename T> class Number { public: unsigned int len; int hex; T number; inline Number(T number = 0, int hex = 10, int len = 0) : number(number), hex(hex), len(len) {} inline operator T() { return number; } };...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int mul(long long a, int b) { return (a * b) % MOD; } int sub(int a, int b) { int c = a - b; if (c < 0) { return c + MOD; } return c; } int add(int a, int b) { int c = a + b; if (c >= MOD) { return c - MOD; } return c; } v...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; namespace IO { const unsigned int Buffsize = 1 << 15, Output = 1 << 24; static char Ch[Buffsize], *S = Ch, *T = Ch; inline char getc() { return ((S == T) && (T = (S = Ch) + fread(Ch, 1, Buffsize, stdin), S == T) ? 0 : *S++); } static char Out[O...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long inf = 0x3f3f3f3f3f3f3f3f; const long long mod = 1e9 + 7; const int N = 110; struct Mat { int a[N][N]; int r, c; Mat(int _r, int _c) { r = _r, c = _c, memset(a, 0, sizeof(a)); } }; Mat operator*(Mat X, Mat Y) { Mat Z(X.r, Y...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<long long>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template <class T> inline bool ckmin(T &a, T b) { return b < a ? a = b, 1 : 0; } template <class T> inline bool ckmax(T &a, T b) { ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> a) { out << a.first << " " << a.second; return out; } t...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; template <int MOD_> struct modnum { static constexpr int MOD = MOD_; static_assert(MOD_ > 0, "MOD must be positive"); private: using ll = long long; int v; static int minv(int a, int m) { a %= m; assert(a); return a == 1 ? 1 : int(m - ll(minv(m, a)) ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int N = 110; const int MOD = 1000000007; inline int add(int u, int v) { u += v; if (u >= MOD) u -= MOD; return u; } inline int sub(int u, int v) { u -= v; if (u < 0) u += MOD; return u; } inline int mul(int u, int v) { return (long long)u * v % MOD; } inli...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Random; public class CFContest { public static void main(String[] args) throws Exception { boolean local = System....
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
//package com.company; // Always comment out package when submitting. import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static class Task { int mod = 1000000007; public class Frac { long a, b; public Frac(long a, long b) { ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<long long>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template <class T> inline bool ckmin(T &a, T b) { return b < a ? a = b, 1 : 0; } template <class T> inline bool ckmax(T &a, T b) { ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int nmax = 2000 * 1000; const int inf = 2000 * 1000 * 1000; const long long infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll; const int mod = 1000 * 1000 * 1000 + 7; const long double pi = acos(-1.0); template <typename T1, typename T2> ostream& operator<<(o...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using ll = long long; struct Matrix { int n, m; vector<vector<ll>> mat; Matrix(int n, int m) : n(n), m(m), mat(n, vector<ll>(m)) {} vector<ll> &operator[](int i) { return mat[i]; } const vector<ll> &operator[](int i) const { return mat[i]; } static Matrix identi...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.io.*; import java.util.*; public class Codeforces1151F { public static void main(String[] args) throws IOException { int P = 1000000007; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(s...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int N = 105; int tot = 0; struct Mat { long long a[N][N]; Mat() { memset(a, 0, sizeof(a)); } Mat operator*(const Mat& tmp) const { Mat ans; for (int i = 0; i < tot; i++) { for (int j = 0; j < tot; j++) { for (...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long M = 1000000007; long long mul(long long a, long long b) { return a * b % M; } long long Pow(long long a, long long b) { long long x = 1; for (; b > 0; b >>= 1) { if (b & 1) x = mul(x, a); a = mul(a, a); } return x; } vector<vector<long long>>...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> struct MI { private: char bb[4096]; FILE *f; char *bs, *be; char e; bool o, l; public: MI() : MI(stdin) {} MI(FILE *f) : f(f), bs(0), be(0), o(0), l(0) {} inline char get() { if (o) { o = 0; return e; } if (bs == be) be = (bs = bb) + fread(bb, 1, sizeo...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; void read(long long &x) { x = 0; long long f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -f; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; x *= f; } void print(long long x) { if (x < 0) putchar('-'), x = -...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Comparator; import java.util.HashSet; import java.util.NoSuchElementException; import java.util.Objects; import java.util.PriorityQueue; import java.util.TreeSet; import java.util.function.B...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; template <typename Tp> void read(Tp &x) { x = 0; long long f = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') { f = -1; } c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.io.*; import java.util.*; public class Main implements Runnable{ public static void main(String[] args){ //new Thread(null,new Main(),"Thread-1",1024*1024*10).start(); new Main().run(); } int[]a; int tot=0; long[]inv; int mod=1000000007; private void solve() thro...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double PI = acos(-1.0); int m, n, x, t, y, a[105], k, l, r, z, all, b[105]; long long en; char c; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long qpow(long long a, long long n, long long p = (long long)10...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } tem...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; char ch = getchar(); bool d = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') d = 0; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return d ? x : -x; } inline unsigned long long rnd() { return ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
// Don't place your source in a package import javax.swing.*; import java.lang.reflect.Array; import java.text.DecimalFormat; import java.util.*; import java.lang.*; import java.io.*; import java.math.*; import java.util.stream.Stream; // Please name your class Main public class Main { static FastScanner fs=new ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int n, num, a[105]; long long k, num1[105], num2[105]; struct Matrix { long long a[105][105]; Matrix() { memset(a, 0, sizeof(a)); } long long* operator[](int i) { return a[i]; } Matrix operator+(Matrix b) { Matrix ans; for (int...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int N, K; struct Matrix { long long a[103][103]; Matrix operator*(Matrix other) const { Matrix ret; int i, j, k; for (i = 0; i <= N; ++i) { for (j = 0; j <= N; ++j) { ret.a[i][j] = 0; for (k = 0; k <= N; +...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long base[101][101], ans[101][101]; long long n, k, maxmisp; long long zc = 0, oc = 0; void mulans() { long long fin[101][101]; memset(fin, 0, sizeof(fin)); for (long long i = 0; i <= 100; i++) for (long long j = 0; j <= 100; j+...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; struct Matrix { int n, m, a[146][146]; Matrix(int _n = 0, int _m = 0, int x = 0) { n = _n, m = _m; memset(a, 0, sizeof a); for (int i = 0; i < min(n, m); ++i) a[i][i] = x; } Matrix operator*(const Matrix& b) { Matrix res = Ma...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
N, T = map(int, raw_input().split()) A = [int(a) for a in raw_input().split()] if sum(A) > N//2: A = [1-a for a in A][::-1] K = sum(A) S = sum(A[-K:]) M = K + 1 P = 10**9+7 inv = pow(N*(N-1)//2, P-2, P) X = [[0]*M for _ in range(M)] for i in range(M): if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P if i < M-1: X[i...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return x * f;...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; struct mint { int n; mint(int n_ = 0) : n(n_ % MOD) { if (n < 0) n += MOD; } }; mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; } mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a....
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using ll = long long; using Matrix = vector<vector<ll>>; const ll MOD = 1e9 + 7; Matrix prod(const Matrix &a, const Matrix &b) { int m = a.size(); Matrix ret(m, vector<ll>(m, 0)); for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { for (int k = 0; k ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7, oo = 1e9; const ll loo = 1e18; ll modpow(ll a, ll b) { ll ans = 1; for (; b; b /= 2, a = a * a % mod) if (b & 1) ans = (ans * a) % mod; return ans; } ll gcd(ll a, ll b) { while (a) b %= a, swap(a, b); return b; } ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; int n, a[110]; long long p, q, k, ansx, ansy; struct mat { long long m[110][110]; mat() { memset(m, 0, sizeof(m)); }; } ans, tmp; inline void add(long long &x, long long y) { if (y >= 1000000007) y -= 1000000007; x += y; if (x >= 1000000007) x -= 1000000007; } inl...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long N = 1e2 + 5; const long long p = 1e9 + 7; long long read() { long long s = 0; char c = getchar(), lc = '+'; while (c < '0' || '9' < c) lc = c, c = getchar(); while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar(); return lc == '-' ? -s : ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, M = 1e9 + 7; const long long LINF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1), EPS = 1e-9; const int N = 101; long long b[N]; long long o; int n, k; long long fastmod(long long a, long long m = M) { return (-m < a and a < m) ? a : a % m; }...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; void add(long long &a, long long b) { a += b; if (a >= ((long long)1e9 + 7)) a -= ((long long)1e9 + 7); if (a < 0) a += ((long long)1e9 + 7); } struct Matrix { int n, m; long long a[105][105]; Matrix() { memset(a, 0, sizeof(a)); } Matrix(int x, int y) : n(x), ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using ll = long long; int const nmax = 100; int const modulo = 1000000007; struct Matrix { int n; int m; vector<vector<int>> mat; Matrix(int n_, int m_) { n = n_; m = m_; mat.resize(n); for (int i = 0; i < n; i++) mat[i].resize(m); } Matrix opera...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> #pragma GCC optimize("-O2") #pragma GCC optimization("unroll-loops") using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\t"; err(++it, a...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007, inv2 = (mod + 1) / 2; long long n; struct mat { long long a[105][105]; mat() { memset(a, 0, sizeof(a)); } mat operator*(const mat& b) const { mat res; for (long long i = 0; i <= n; ++i) for (long long j = 0; j <= n; ++j)...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; constexpr long long int mod = 1e9 + 7; template <class T> struct Mat { vector<vector<T>> A; Mat() {} Mat(size_t n, size_t m) : A(n, vector<T>(m, 0)) {} Mat(size_t n) : A(n, vector<T>(n, 0)){}; size_t height() const { return A.size()...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; struct matrix { int a[105][105]; } b; int tot, st, a[105], ans[105]; int read() { char c = getchar(); int x = 0, f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long Mod = 1000000007; struct Matrix { long long n, m, a[146][146]; Matrix(long long _n = 0, long long _m = 0, long long x = 0) { n = _n, m = _m; memset(a, 0, sizeof a); for (long long i = 0; i < min(n, m); ++i) a[i][i] = x; } Matrix operator*...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int md = 1000000007; int n, m, K, i, j, k, a[105], inv[10005], g[105][105], h[105][105], c[105][105]; void Mult(int a[105][105], int b[105][105]) { int i, j, k; for (i = 0; i <= m; ++i) for (j = 0; j <= m; ++j) c[i][j] = 0; for (i = 0; i <= m; ++i) for (...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.PriorityQueue; import java.util.Random; im...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; inline int In() { char c = getchar(); int x = 0, ft = 1; for (; c < '0' || c > '9'; c = getchar()) if (c == '-') ft = -1; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; return x * ft; } inline int min(int a, int b) { return a < b ? a : b; } ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &item) { out << '(' << item.first << ", " << ite...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; long long mod(long long n) { if (n < 0) { return (n % MOD + MOD) % MOD; } else { return n % MOD; } } long long fp(long long a, long long p) { long long ans = 1, cur = a; for (long long i = 0; (1ll << i) <= p; +...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; struct Matrix { int h, w; vector<long long> mat; Matrix() { h = w = 0; } Matrix(int h, int w) { this->h = h, this->w = w; mat.resize(h * w); } long long& at(int i, int j) { return mat[w * (i - 1) + (j - 1)]; } static Matrix ident(int size) { Matrix...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10; int n, k; int s[maxn], cc, cnt; int c[maxn][maxn]; const long long mod = 1e9 + 7; long long ans[maxn][maxn], b[maxn][maxn], a[maxn][maxn], tmp[maxn][maxn]; void init() { c[1][0] = c[1][1] = 1; for (int i = 2; i <= 100; ++i) { c[i][0] = 1; ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 110; long long kOper, n, cnt; long long c[N]; struct Matrix { long long x[N][N]; Matrix() { for (int i = 0; i <= N - 1; ++i) for (int j = 0; j <= N - 1; ++j) x[i][j] = 0; } } a, b; long long px(long long a, long long q)...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 5; const int MOD = 1e9 + 7; long long C[N][N]; void multiply(long long A[N][N], long long B[N][N], int n) { for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= n; k++) { C[i][j] = (C[i][j] + A[i][k] * B[...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.14159265359; const long long MOD = (long long)1e9 + 7; const long long MAXN = (long long)100 + 10; const long long INF = (long long)2242545357980376863; const long double EPS = (long double)1e-8; long long pw(long long b, long long p) { if (p == 0...