description
stringlengths
35
9.39k
solution
stringlengths
7
465k
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
n,q = map(int,raw_input().split()) s = raw_input() x = [int(s[i]) for i in range(n)] p = [1] c = 1 MOD = 10**9+7 for i in range(1,10**5+1): c = (c*2)%MOD p.append(c) cum_sum = [0]*(n+1) c = 0 for i in range(n): c += x[i] cum_sum[i+1] = c for i in range(q): l,r = map(int,raw_input().split()) n1 = cum_sum[r] - cum_...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; inline long long int __gcd(long long int a, long long int b); void pdash(int n = 1); int bitcount(long long int u); long long int power(long long int x, long long int y); long long int power(long long int x, long long int y, long long int z); long long int modInverse(long l...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; long long fac[1] = {1}, inv[1] = {1}; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long mp(long long a, long long b) { long long r...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import stdin, stdout import cProfile, math from collections import Counter from bisect import bisect_left,bisect,bisect_right import itertools from copy import deepcopy from fractions import Fraction printHeap = str() memory_constrained = False P = 10**9+7 import sys sys.setrecursionlimit(10000000) class Ope...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long poww(int n) { long long ans = 1; long long a = 2; while (n) { if (n & 1) ans *= a, ans %= 1000000000 + 7; a *= a, a %= 1000000000 + 7; n >>= 1; } return ans; } int main(void) { int n, m; string s; int p[100005]; cin >> n >> m; cin >...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long zeros[100000 + 342], ones[100000 + 342]; long long add(long long a, long long b) { return (a + b) % mod; } long long sub(long long a, long long b) { return ((a % mod) - (b % mod) + mod) % mod; } long long mul(long long a, long long b)...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = map(int, r[0].strip().split()) s = list(map(int, r[1].strip())) p = [0] for i in range(n): p.append(p[i] + int(s[i])) for k in range(q): a, b = map(int, r[k + 2].strip().split()) l = b - a + 1 one = p[b] - p[a - 1] zero = l - one sys.st...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import stdin, stdout n,q = tuple(map(int,stdin.readline().split())) arr = list(str(stdin.readline()))[:-1] arr[0] = int(arr[0]) for i in range(1,n): arr[i] = int(arr[i]) + arr[i-1] arr.insert(0,0) mod = int(1e9+7) inputs = [ tuple(map(int,line.split())) for line in stdin ] ans = [] for l,r in inputs: ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import os import sys def init_input(): it = iter(os.read(sys.stdin.fileno(), 10 ** 7).split()) return lambda: next(it).decode(), lambda: int(next(it)), lambda: float(next(it)) ns, ni, nf = init_input() MOD = 10 ** 9 + 7 n, q = ni(), ni() s = 'x' + ns() c = [0] * (n + 1) for i in range(1, n + 1): c[i] = c[i ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#!/usr/bin/env python """ This file is part of https://github.com/Cheran-Senthil/PyRival. Copyright 2018 Cheran Senthilkumar all rights reserved, Cheran Senthilkumar <hello@cheran.io> Permission to use, modify, and distribute this software is given under the terms of the MIT License. """ from __future__ import divisi...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class Main { private static class Solution { int[] arr; int[] pre; int n; int[] p2; int mod = 1_000_000_000 + 7; public ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static Scanner in; // static StreamTokenizer in; // static int nextInt() throws IOException { // in.nextToken(); // return (int)in.nval; //...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long cnt[100002]; string s; long long pre[100002]; long long fi(long long a, long long n) { long long b = n - a; long long i, cn = 0, ans = 0; if (a == 0) return 0; ans = pre[b]; ans *= (pre[a] - 1); ans %= 1000000007; if (ans < 0) ans += 1000000007; re...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
/* Rajkin Hossain */ import java.io.*; import java.util.*; public class C { static FastInput k = new FastInput(System.in); static FastOutput z = new FastOutput(); static int n, q; static char [] y; static Pair [] data; static long mod = (long) 1e9 + 7l; static long pow...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; public class ProblemC { public static final long M = 1_000_000_000 + 7; /* Iterative Function to calculate (x^y)%p in O(log y) */ static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if ((y & 1l) > 0) res = (res * x)...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; const long long mo = 1e9 + 7; int n, m, k; long long a[maxn], sum[maxn]; long long c[maxn]; long long ans, ct, cnt, tmp, flag; char s[maxn]; long long power(long long a, long long n) { long long ans = 1; a = a % mo; while (n) { if (n & 1) ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].strip().split() n = int(n) q = int(q) s = r[1] p = [0] k = 0 for v in range(n): d = int(s[v]) k += d p.append(k) ans = [] for k in range(q): a, b = r[k + 2].strip().split() a = int(a) b = int(b) l = b - a + 1 one = p[b] - p...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int s[100001]; long long p[100001]; long long mod = 1e9 + 7; int cnt(int left, int right) { return s[right] - s[left - 1]; } int main() { int n, q; cin >> n >> q; string a; cin >> a; s[1] = (int)(a[0] - '0'); for (int i = 1; i < a.length(); i++) { s[i + 1] =...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import stdin, stdout from itertools import repeat def main(): n, q = map(int, stdin.readline().split()) s = stdin.readline().strip() dat = map(int, stdin.read().split(), repeat(10, 2 * q)) a = [0] * (n + 1) for i, x in enumerate(s): a[i+1] = a[i] + (x == '1') ans = [0] * q m...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; using namespace std; string s; long long tree_bit[200100]; int lim; void update_bit(int idx, int val) { while (idx <= lim) { tree_bit[idx] += val; if (tree_bit[idx] >= 1000000007) tree_bit[idx] %= 1000000007; idx += (idx & -idx); } } long long query_bit(int ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int delta[4][2] = {{-1, -0}, {0, 1}, {1, 0}, {0, -1}}; long long calc_pow(long long a, long long p, long long m = 1000000007) { long long res = 1; while (p > 0) { if (p & 1) res = (res * a) % m; a = (a * a) % m; p >>= 1; } return res; } long long calc_po...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int main() { long long n, q; cin >> n >> q; vector<long long> powe(n + 1, 0); powe[0] = 1; for (long long i = 1; i <= n; i++) powe[i] = (powe[i - 1] * 2) % 1000000007; vector<long long> A(n, 0), pre(n, 0); string s; cin >> s; for (long long i = 0; i < n; i...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; const int INF = 0x3f3f3f3f; const int mod = 1000000007; string str; long long n, q; long long l, r; long long cum[100005]; long long p[100005]; void make() { for (int i = 1; i <= n; i++) { if (str[i - 1] == '1') cum[i] = cum[i - 1] + 1; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
n,q=map(int,input().split()) a=list(map(int,list(input()))) p=[0]+a[:] M=10**9+7 for i in range(1,n+1):p[i]+=p[i-1] o=[] for _ in range(q): l,r=map(int,input().split()) w=p[r]-p[l-1] z=(r-l+1)-w o.append(str((pow(2,w+z,M)-pow(2,z,M))%M)) print('\n'.join(map(str,o)))
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const int N = 1e6 + 10, M = 2e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f; long long a[N], sum[N]; long long q_pow(long long a, long long k) { long long s = 1; while (k) { if (k & 1) s = s * a %...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; namespace fast_IO { inline int read_int() { register int ret = 0, f = 1; register char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { ret = (ret << 1) + (ret << 3) + int(c - 48); c ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.*; public class Main { public static long MOD = 1000_000_007; public static void solve(FastIO io) { int n = io.nextInt(); int q = io.nextInt(); String parts = io.nextLine(); int[] ones = new int[n+1]; for(int i = 1; i <= n; ++i){ ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import stdin out = [] n,q = map(int, raw_input().split()) s = raw_input() pref = [0] for i in s: if i == '0': pref.append(pref[-1]) else: pref.append(pref[-1]+1) MOD = pow(10,9)+7 for line in stdin.readlines(): l,r = map(int, line.split()) num1 = pref[r] - pref[l-1] num...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import math if __name__ == '__main__': n,q = [int(x) for x in input().split()] qq = str(input()) s = [ int(x) for x in qq] prefix = [0]*n prefix[0]= s[0] temp = [0]*(n+1) temp[0]=1 mod = (pow(10,9)//1)+7 for i in range(1,n): prefix[i] += prefix[i-1] + s[i] temp[i] =( 2*(temp[i-1]%mod) )%mod temp[n] ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; const int MOD = 1e9 + 7; string a; long long sum[MAX_N]; long long fpow(long long a, long long b) { long long aa = 1; while (b > 0) { if (b & 1) aa = aa * a % MOD; a = a * a % MOD; b /= 2; } return aa; } int main() { long lon...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.io.*; import java.math.*; // Solution to PCS Problem 89: Banh Mi // https://pcs.cs.cloud.vt.edu/contests/89/problems/C // Solution by: jLink23 public class BanhMi { private static PrintWriter out; public static final int MOD = 1000000007; public static void main(String[] args) {...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 15; const int MOD = int(1e9) + 7; int n, q; vector<long long> ans; int one_cnt[MAXN]; long long bin_pow[MAXN]; long long bin_pref[MAXN]; void in() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> q; ans.resize(q + 5); string ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
###### ### ####### ####### ## # ##### ### ##### # # # # # # # # # # # # # ### # # # # # # # # # # # # # ### ###### ######### # # # # # # ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.io.*; public class Main { static int n, q; static boolean[] arr; static query[] qs; static long[] out, pows; static long mod = (long)(1e9 + 7), modi = 500000004L, ans; public static void main (String[] args) throws IOException { //pre comp pows of two mod p...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.InputMismatchException; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.io.*; public class Main { public static int gcd(int a , int b) { int divs=0; int divd=0; if(a>=b) { divd=a; divs=b; } else { divd=b; divs=a; } int rem=divd%divs; while(rem!=0) { int temp=divs; divs=rem; divd=temp; rem=divd%divs; } ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long double PI = 4 * atan(1); long long n, q, dp[100001], po[100001], x, cur, ans, l, r; string second; void init() { po[0] = 1; for (int i = 1; i < 100001; i++) { po[i] = (po[i - 1] * 2LL) % MOD; } } int main() { ios::sync_with_stdio...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class codeforces { static class Student{ int x,y; Student(int x,int y){...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; import org.omg.CORBA.INTERNAL; import javax.swing.plaf.basic.BasicTreeUI; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; public class Main { private static Scanner sc; private static Printer ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys i = int r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].strip().split() n = i(n) q = i(q) s = r[1] p = [0] k = 0 for v in range(n): d = i(s[v]) k += (1 - d) p.append(k) ans = [] for k in range(q): a, b = r[k + 2].strip().split() a = i(a) b = i(b) l = b - a + 1 zero = p[b...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.net.Inet4Address; import java.util.*; import java.io.*; public class Did_I_Deserve_It{ public static long power(long x, long y, long p) { // Initialize result long res = 1; // Update x if it is more // than or equal to p x = x % p; while (y > 0) ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(0); if ("" == "input") { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } else if ("" != "") { freopen( "" ".in", "r", stdin); freopen...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long power(long long n) { if (n == 0) return 1; long long a = power(n / 2); a *= a; a %= 1000000007; if (n % 2) a *= 2; a %= 1000000007; return a; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q;...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, vector<T>& v) { if (v.size() == 0) { os << "empty vector\n"; return os; } for (auto element : v) os << element << " "; return os; } template <typename T, typename second> ostream& operator<<(ostream& os,...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long n, i, j, ans = 0; long long M = (long long)1E9 + 7; long long a[1000000], zero[1000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long sum = 0; a[1] = 1, a[2] = 2; sum = 3; for (i = 3; i <= 100000 + 5; i++) { a[i] = (1 + s...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 5; int pre[N], pw[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n, q, l, r, a, b; char ch; cin >> n >> q; int sum = 0, temp, ans; pw[0] = 1, pre[0] = 0; for (int i = 1; i <= n; i++) { cin >> ch; pre[i] += (pre...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.io.*; import java.math.*; public class Main { static void precompute_pow(long arr[],int n){ arr[0]=1l; for(int i=1;i<=n;i++) arr[i]=(arr[i-1]*2l)%mod; } public static void process()throws IOException { int n=ni(),q=ni(); long pow[]=new ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 1; long long l, r, n, q, p[MAXN], a[MAXN], k, m, mod = 1e9 + 7; string s; int main() { cin >> n >> q >> s; for (int i = 0; i < n; i++) { a[i + 1] += a[i]; if (s[i] == '1') a[i + 1]++; } p[0] = 1; for (int i = 1; i <= 1e5; i++) p[i] =...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int maxN = 1e6 + 5, MOD = 1e9 + 7, eps = 1e-7, INF = 1e9; const double PI = acos(-1); int n, q, a, b; string str; int acum[maxN]; long long mulmod(long long a, long long b) { long long ret = 0; while (b) { if (b & 1) ret = (ret + a) % MOD; b >>= 1, a = (a ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.Scanner; public class Main { private static long MOD = 1000000007; public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(), q = s.nextInt(), curSum = 0; s.nextLine(); String str = s.nextLine(); long[] pows = new...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Main { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int mod= 1000000007; int n = ni(), Q...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.InputMismatchException; public class Q3 { public static int mod = (int) 1e9 + 7; public static long[] pow = new long[100003]; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int MAXN = 1e5, MOD = 1e9 + 7; int n, q; string s; vector<int> pow2(MAXN + 1); int main() { ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); pow2[0] = 1; for (int i = 1; i <= MAXN; ++i) { pow...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; const int mod = 1e9 + 7; inline pair<long long, long long> mp(long long a, long long b) { pair<long long, long long> temp; temp.first = a; temp.second = b; return temp; } long long read_int() { char r; bool start = false, neg = false; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys input_file = sys.stdin C = (10**9+7) [n, q] = list(int(i) for i in input_file.readline().split()) temp = input_file.readline() lst = [] for char in temp[:-1]: lst.append(int(char)) new_lst = [(0, 0)] for i in lst: if i == 0: new_lst.append((new_lst[-1][0]+1, new_lst[-1][1])) else: ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.Arrays; import java.util.ArrayList;...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> char s[100005]; int cnt[100005]; const long long mod = 1000000007; long long powm(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } int main() { int n, q, l, r, m, len; scanf("%d%d", &n, &...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const int inf = 1e8; const int mod = 1e9 + 7; int n, t; int pre[maxn]; char s[maxn]; long long ksm(long long a, long long b) { long long res = 1; while (b) { if (b & 1) { res = (res * a) % mod; } a = (a * a) % mod; b >>=...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; int64_t const base = 1e9 + 7; int n, q, l, r, cnt, res; string s; int64_t f[100005], i_th[100005]; int main() { ios::sync_with_stdio(0); cin >> n >> q >> s; i_th[1] = 1; for (int i = 2; i <= 100003; ++i) i_th[i] = (i_th[i - 1] << 1) % base; for (int i = 0; i < s.s...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int N = 300000 + 10; const int mod = 1e9 + 7; int n, q; char s[N]; long long sum[N]; long long pw[N], fibo[N], pw2[N], pw3[N]; int main() { scanf("%d%d", &n, &q); scanf("%s", s + 1); for (int i = 1; i <= n; ++i) { sum[i] = sum[i - 1] + (s[i] == '1'); } f...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.*; public class Main { private static final int MOD = 1000000007; private static int add(long a, long b) { return (int) ((a%MOD+b%MOD)%MOD); } private static int subtract(long a, long b) { return add(a, -b); } private static int multiply(long a...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; template <typename T> using V = vector<T>; template <typename T, typename U> using P = pair<T, U>; template <typename T> void cout_join(vector<T> &v, string d = " ") { for (int i = (0); i < (v.size()); ++i) { if (i > 0) cout << d; cout << v[i]; } cout << endl;...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
MOD = 10 ** 9 + 7 MAXN = 10 ** 5 + 1 N, Q = map(int, raw_input().strip().split()) arr = map(int, [ i for i in raw_input().strip()]) # calculate prefix sum pre = [0 for _ in range(N+1)] for ind, val in enumerate(arr): pre[ind + 1] = pre[ind] + val # calculate powers of two pows = [1 for _ in range(MAXN)] for i in...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].split(' ') n = int(n) q = int(q) s = r[1] p = [0] for v in range(n): p.append(p[v] + int(s[v])) ans = [] for k in range(q): a, b = r[k + 2].split(' ') a = int(a) b = int(b) l = b - a + 1 one = p[b] - p[a - 1] ans.append(str((p...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.*; public class Main { static class Reader { BufferedReader in; Reader() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); // initial size buffer C = 32768 ??? /// default C = 8192 } Reader(String name) t...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def add(a,b): return (a+b)%1000000007 def mul(a,b): return (a*b)%1000000007 def sub(a,b): return (a-b+1000000007)%1000000007 def qpow(a, b): r = 1 k = ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.io.*; public class Banhmi { // https://codeforces.com/contest/1062/problem/C public static void main(String[] args) throws IOException, FileNotFoundException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader in = new BufferedReader(ne...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].strip().split() n = int(n) q = int(q) s = r[1] p = [0] k = 0 for i in range(n): d = int(s[i]) k += d p.append(k) ans = [] for k in range(q): a, b = r[k + 2].strip().split() a = int(a) b = int(b) l = b - a + 1 one = p[b] - p...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.*; import java.math.*; public class A implements Runnable { public void run() { long startTime = System.nanoTime(); int M = (int) (1e9 + 7); int n = nextInt(); int m = nextInt(); char[] c = nextToken().toCharArray(); int[] s = ne...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
def solve(): mod=10**9+7 def _mp(): return map(int,raw_input().split()) n,q=_mp() #n=10**5 count=[0 for _ in range(n+2)] p2=[1 for _ in range(n+2)] r=1 for i in range(1,n+1): # r*=2 p2[i]=(p2[i-1]*2)%mod s=raw_input() for i in range(1,n+1): count[i]=count[i-1]+int(s[i-1]) for i in range(q): l,r=_mp...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; char str[1008611]; long long s1[1008611], s2[1008611]; long long pow_(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % 1000000007; b >>= 1; a = (a * a) % 1000000007; } return ans; } long long inv(long long x) { retu...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
# Causes TLE # C++17 implemention -> 1062c.cpp MOD = 1000000007 def main(): buf = input() buflist = buf.split() n = int(buflist[0]) q = int(buflist[1]) buf = input() x = buf sum_list = [0] # sentinel / one indexing for i, deliciousness in enumerate(x): sum_list.append(int(delic...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100002; const int MOD = 1000000007; int n, nQueries, ps[MAX_N]; int64_t pw2[MAX_N]; void solve() { cin >> n >> nQueries; pw2[0] = 1; for (int i = 1; i <= n; ++i) { char x; cin >> x; ps[i] = ps[i - 1] + x - '0'; pw2[i] = pw2[i - 1] * 2...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int LIMIT = 1e5 + 7; const int MOD = 1e9 + 7; const int MAX = 1 << 30; int n, q, l, r, dp[LIMIT], f[LIMIT]; char c; int main() { scanf("%d %d\n", &n, &q); f[0] = 1; for (int i = 0; i < n; i++) { scanf("%c", &c); dp[i + 1] = dp[i] + (c - '0'); f[i + 1...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! from sys import stdin, stdout import collections #N = int(input()) #s = input() N,Q = [int(x) for x in stdin.readline().split()] s = input() ones = [0]*N t = 0 for i in range(N): if s[i]=='1': ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() n, q = r[0].split(' ') n = int(n) q = int(q) M = 10 ** 9 + 7 twopow = [1] * (2 * n + 1) for j in range(1, (2 * n + 1)): twopow[j] = twopow[j - 1] * 2 % M s = r[1] p = [0] * (n + 1) for v in range(n): p[v + 1] = p[v] + (s[v] == '1') ans = [0] * q for k in range(q): a, b =...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.DataInputStream; import java.io.IOException; import java.util.InputMismatchException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @au...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Main { static class Task { int NN =...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import sys r = sys.stdin.readlines() M = 10 ** 9 + 7 n, q = r[0].split(' ') n = int(n) q = int(q) s = r[1] p = [0] for v in range(n): p.append(p[v] + int(s[v])) ans = [] for k in range(q): a, b = r[k + 2].split(' ') a = int(a) b = int(b) l = b - a + 1 one = p[b] - p[a - 1] v = (pow(2, l, M) ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
def init_input(): import os from sys import stdin it = iter(os.read(stdin.fileno(), 10 ** 7).split()) return lambda: next(it).decode(), lambda: int(next(it)), lambda: float(next(it)) ns, ni, nf = init_input() MOD = 10 ** 9 + 7 n, q = ni(), ni() s = 'x' + ns() c = [0] * (n + 1) for i in range(1, n + 1)...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
def beki(a,b): waru=10**9+7 ans=1 while(b>0): if(1 & b): ans= ans * a %waru b >>= 1 a=a * a % waru return ans n,m=map(int,input().split()) s=input() ans=[] waru=10**9+7 ruiseki=[0]*(n+1) bekij=[1]*(n+1) for i in range(n): ruiseki[i+1]=ruiseki[i]+int(s[i]) b...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from sys import stdin out = [] n,q = map(int, raw_input().split()) s = raw_input() pref = [0] for i in s: if i == '0': pref.append(pref[-1]) else: pref.append(pref[-1]+1) MOD = pow(10,9)+7 pow2 = [1]*(1+n) for i in range(n): pow2[i+1] = (pow2[i] *2)%MOD for line in stdin.readl...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int mul(int a, int b) { return (long long)a * b % mod; } int power(int a, long long b) { int res = 1; while (b > 0) { if (b & 1) { res = mul(res, a); } a = mul(a, a); b >>= 1; } return res; } void solve() { int n, q; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; int n, q, f[N]; char c; int binPow(int x, int y) { int ans = 1; while (y > 0) { if (y & 1) ans = (1LL * ans * x) % mod; x = (1LL * x * x) % mod; y >>= 1; } return ans; } int main() { ios::sync_with_stdio(...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int n, q, x, y, z, h; string s; long long a[100005], b[100005]; void init() { b[0] = 1; for (int i = 1; i <= n; i++) { b[i] = b[i - 1] * 2 % mod; } } int main() { cin >> n >> q; cin >> s; init(); for (int i = 0; i < n; i++) a[i] = ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> #pragma GCC optimize("03") using namespace std; long long int const mod = 1e9 + 7; long long int pre[100010][2]; void mul(long long int &x, long long int val) { x = (x * val) % mod; if (x < 0) x += mod; } void add(long long int &x, long long int val) { x = (x + val) % mod; if (x < 0) x ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long a[1000000]; long long bp(long long a, int n) { long long res = 1; while (n) { if (n % 2) res *= a; a *= a; a %= mod; n /= 2; res %= mod; } return res; } int main() { int n, q; cin >> n >> q; for (...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { FastReader reader = new FastReader(); PrintWriter writer = new PrintWriter(System.out); int n = reader.nextInt(); int q = reader.nextInt(); String input = reader.nextLine(); int[] zeros = new int[n+1]; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
import java.io.*; import java.util.stream.Stream; /** * @author madi.sagimbekov */ public class C1062C { private static BufferedReader in; private static BufferedWriter out; public static void main(String[] args) throws IOException { open(); int[] nq = readInts(); int n = nq[0]...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int INFMEM = 63; const int INF = 1061109567; const long long LINF = 4557430888798830399LL; const double DINF = numeric_limits<double>::infinity(); const long long MOD = 1000000007; const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dy[8]...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const long long sz = 2e5 + 5; const long long MD = 1e9 + 7; pair<long long, long long> st[2 * sz]; long long arr[sz]; long long n, q; string s; pair<long long, long long> ADD(pair<long long, long long> &A, pair<long long, long long> &B) { re...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long int bs(long long int a, long long int b) { long long int res = 1; while (b) { if (b & 1) res *= a; res %= ((long long int)1e9 + 7); b >>= 1; a *= a; a %= ((long long int)1e9 + 7); } return res; } signed main() { long long int n, m; ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
from __future__ import division from sys import stdin, stdout # from fractions import gcd # from math import * # from operator import mul # from functools import reduce # from copy import copy from collections import deque, defaultdict, Counter rstr = lambda: stdin.readline().strip() rstrs = lambda: [str(x) for x in s...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long gcd(long long n1, long long n2) { if (!n1) return n2; if (!n2) return n1; if (n1 % n2 == 0) return n2; return gcd(n2, n1 % n2); } long long powmod(long long base, long long exponent) { base %= 1000000007; long long ans = 1; while (exponent) { if ...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; const int nn = 1e5 + 5; const long long MOD = 1e9 + 7; long long pangkat[nn], arr[nn], pre0[nn], pre1[nn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, q; pangkat[0] = 1; for (int i = 1; i <= 1e5; i++) { pangkat[i] = (...
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he de...
#include <bits/stdc++.h> using namespace std; long long n, q, l, r, sum[100010], tmp1, tmp2, ans; string s; long long Pow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1 == 1) ans = (ans * a) % 1000000007LL; a = (a * a) % 1000000007LL, b >>= 1; } return ans % 1000000007LL; } int mai...