Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
ans = 0 s = raw_input() heavy = 0 i = 0 if not len(s) < 5: while i < len(s) - 4: if s[i] == 'h' and s[i + 1] == 'e' and s[i + 2] == 'a' and s[i + 3] == 'v' and s[i + 4] == 'y': heavy += 1 i += 5 elif s[i] == 'm' and s[i + 1] == 'e' and s[i + 2] == 't' and s[i + 3] == 'a' and ...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
//"We have two lives, and the second begins when we realize we only have one." β€” Confucius import java.util.*; import java.io.*; public class A { public static void main(String[] args) { FastScanner fs = new FastScanner(); String str= fs.next(); String prefix="heavy",suffix="metal"; long ans=0;long ...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long t = s.size(), c = 0, cnt = 0; for (int i = 0; i < t - 4; ++i) { if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') c++; if (s[i] == 'm' && s[i + 1] == 'e' && s...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#!/usr/bin print sum(-~c * g.count('metal') for c, g in enumerate(raw_input().split('heavy')[1:]))
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; long long int modular_pow(long long int base, long long int exponent) { long long int result = 1; while (exponent > 0) { if (exponent % 2 == 1) result = (result * base) % 1000003; exponent = exponent >> 1; base = (base * base) % 1000003; } return result;...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
L = input().split('heavy') ans = 0 for i in range(len(L)): ans += i*L[i].count('metal') print(ans)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
from bisect import bisect_left s, starts, start, k = input(), [], 0, 0 while True: pos = s.find('heavy', start) start = pos + 1 if pos < 0: break starts.append(pos) while True: pos = s.find('metal', start) if pos < 0: print(k) break start, k = pos + 1, k + bisect_l...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
# -*- coding:utf-8 -*- import sys def some_func(): """ """ num = 0 count = 0 s_flag = 0 e_flag = 0 while True: data = sys.stdin.read(1) if data == "\n": break if data == "h": s_flag = 1 e_flag = 0 elif data == "e" and s_f...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = input() a = [] for i in range(len(s)): c = s[i:i+5] if c == 'heavy': a.append(0) elif c == 'metal': a.append(1) k = 0 ans = 0 for i in a: if i == 0: k += 1 else: ans += k print(ans)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Iterator; import java.util.TreeMap; public class StringPower { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStrea...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
c = 0 for x,z in enumerate(input().split("heavy")): c += x*z.count("metal") print(c)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
R=raw_input() m=t=0 for i in range(5,len(R)+1): t+=R[i-5:i]=="heavy" m+=t*(R[i-5:i]=="metal") print m
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; long long c = 0; long long q = 0; char a[str.size()]; long long b[str.size()]; for (int k = 0; k < str.size(); k++) { a[k] = str.at(k); } if (str.size() < 5) { cout << "0" << endl; return 0; } b[str.size...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import sys from collections import defaultdict, Counter from itertools import permutations, combinations from math import sin, cos, asin, acos, tan, atan, pi sys.setrecursionlimit(10 ** 6) def pyes_no(condition, yes = "YES", no = "NO", none = "-1") : if condition == None: print (none) elif condition : pri...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int inf = 2000000000; int arrh[1000005]; int arrm[1000005]; char strh[] = "heavy"; char strm[] = "metal"; int main() { char str[1000005]; scanf("%s", str); int l = strlen(str); int h = 0, m = 0; int pos = 0; long long ans ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws IOException { S = rd.readLine(); int[] app = new int[1000001]; for(int i=0; i<S.length()-4; i++){ if(S.substring(i, i+5).equals("heavy")) app[i] = 1; } for(int i=0; i<S.length(); i++) app[i] += (i==0? 0: ...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
input_str = input() if input_str.find('heavy') == -1: print(0) else: a = input_str.index('heavy')+5 b = 1 result = 0 while a < len(input_str): if input_str[a:(a+5)] == 'heavy': b+=1 a+=4 elif input_str[a:(a+5)] == 'metal': result+=b a+=...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
str = input() h=0 m=0 for i in range(len(str)-4): if str[i:i+5] =="heavy": h+=1 if str[i:i+5] == "metal": m+=h print(m)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = input().strip() H = s.split("heavy") co,k = 0,0 for i in H: co += i.count("metal")*k k += 1 print(co)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
hc = 0 total = 0 while 1: try: line = raw_input() length = len(line) pos = 0 while pos <= length - 5: stri = line[pos:pos+5] pos += 1 if stri == "heavy": hc += 1 pos += 4 elif stri == "metal": ...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; bool is_heavy(string& s, int ind) { return s[ind + 3] == 'v' && s[ind] == 'h' && s[ind + 1] == 'e' && s[ind + 2] == 'a' && s[ind + 4] == 'y'; } bool is_metal(string& s, int ind) { return s[ind + 2] == 't' && s[ind] == 'm' && s[ind + 1] == 'e' && s[ind ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import re s = raw_input() heavy = [] metal = [] for m in re.finditer('heavy', s): heavy.append(m.start()) for m in re.finditer('metal', s): metal.append(m.start()) nh = len(heavy) nm = len(metal) ih = im = 0 total = 0 while ih < nh and im < nm: if metal[im] > heavy[ih]: total += nm - im ih +...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Main { public static void main(String[]args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int l=s.length()...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; string s; int r[1000013] = {0}; int main() { cin >> s; int l = s.size(); int count = 0; for (int i = l - 1; i >= 0; i--) { if (s[i] == 'm' && i >= 4) { string temp(s.begin() + i, s.begin() + i + 5); if (temp == "metal") { count++; } ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s=raw_input() h,v,a,b=0,0,'zzzzz','zzzzz' for c in s: a,b=a[1:]+c,b[1:]+c if a=='heavy':h+=1 elif b=='metal':v+=h print v
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
__author__ = 'Azad' import re import bisect s = raw_input() # q = [m.start() for m in re.finditer('heavy', s)] #print [m.start() for m in re.finditer('metal', s)] e = [m.start() for m in re.finditer('metal', s)] i = bisect.bisect_left(e, 0) y = len(e) print sum([ y-bisect.bisect_left(e, x) for x in q]) #prin...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import deque as que, defaultdict as vector from bisect import bisect as bsearch from heapq import* inin = lambda: int(input()) inar = lambda: list(map(int,input().split())) inst= lambda: input().decode().rstrip('\n\r') INF=float('in...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); Queue<Integer> h = new LinkedList<Integer>(); Queue<Integer> m = new LinkedList<Intege...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.*; public class B { static final String HEAVY = "heavy"; static final String METAL = "metal"; static long [] find(String text, String pattern){ final long [] res = new long[text.length()]; for (int i = text.indexOf(pattern); i >= 0; i = text.indexOf(pattern, i + pattern.length())){ res[i] = ...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
from bisect import bisect as bs s = input() posHeavy = [] posMetal = [] for i in range(len(s)-4): if s[i:i+5]=='heavy': posHeavy.append(i+4) for i in range(len(s)-4): if s[i:i+5]=='metal': posMetal.append(i) res = 0 for i in posHeavy: res+=len(posMetal)-bs(posMetal,i) print(res)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Metal { public static void main(String[] args) throws IOException{ BufferedReader br; br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int i; int l = s.le...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; long long a[1234567]; int main() { long long k = 0, l = 0; string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == 'm' && s[i + 1] == 'e' && s[i + 2] == 't' && s[i + 3] == 'a' && s[i + 4] == 'l') l++; a[i] = l; } for (int i =...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
line = raw_input() total_count = 0 try: lines = line.split('heavy') for i, line in enumerate(lines): total_count += line.count('metal') * i except Exception: pass print total_count
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import static java.lang.System.*; import static java.lang.Math.*; import java.util.*; public class B318{ public static Scanner sc = new Scanner(in); //public static Random sc=new Random(); public static int upper_bound(Integer[] a,int val) { int f=0,l=a.length; int len=l-f; while(l...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
def solve(s): c, r = 0, 0 for i in range(5, len(s) + 1): if s[i - 5:i] == 'heavy': c += 1 elif s[i - 5:i] == 'metal': r += c return r print(solve(input()))
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static void main(String [] args ) { try{ String str; BufferedReader br = new BufferedReader(new InputStreamReader(System....
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
ans = count = 0 for s in raw_input().split("heavy"): ans += s.count("metal") * count count += 1 print ans
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int main() { char in[1000009]; cin >> in; int len = strlen(in); int pre = 0; long long int ans = 0; for (int i...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
w=map(str,raw_input().split('heavy')) ans=chk=be=0 ic=[] for i in range(1,len(w)): if 'metal' in w[i]: ic.append(w[i].count('metal')) else: ic.append(0) ans=chk=sum(ic) for i in range(1,len(ic)+1): chk-=ic[i-1] ans+=chk print ans
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out); int test_cases = 1; Solver s = new Solver(); for (int i = 1; i <= test_cas...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, len, r, res, flag; char s[1000005], h[10] = "heavy", m[10] = "metal"; cin >> s; len = strlen(s); r = 0; res = 0; for (i = 0; i < len; i++) { flag = 0; if (s[i] == 'h') { for (j = 0; j < 5; j++) { if (s[i + j] ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s=input().split('heavy') start=0 rs=0 for i in range(1,len(s)): rs=rs+s[i].count('metal')*i print(rs)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.Scanner; /** * * @author claudio */ public class Main{ public static void main(String [] args) { Scanner sc=new Scanner(System.in); String palabra=sc.nextLine(); long heavy =0; long total=0; for (int i = 0; i < palab...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.util.*; /** * * @author N-AssassiN */ public class B { private static BufferedReader reader; private static PrintWriter out; private static StringTokenizer tokenizer; ...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */public final class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long int c = 0; long long int ans = 0; for (long int i = 0; i < s.size(); i++) { if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') { i += 4; c++; } else if...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; import static java.lang.Math.*; public class Main extends Thread{ public static void main(String... args)throws IOException { n...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long i, h = 0, m = 0; for (i = 0; i < s.size(); i++) { if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') { h++; } if (s[i] == 'm' && s[i + 1] == 'e' && s[i + 2...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; char str[1000010]; int h_sum; char str_h[] = "heavy", str_m[] = "metal"; int judge_h(int x) { int k = 0; for (int i = x; i < x + 5; i++) { if (str[i] == str_h[i - x]) k++; else break; } if (k == 5) return 1; else return 0; } int judge_m...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
L=list(input().split("heavy")) ans=0 for i in range(len(L)): ans += i*(len(list(L[i].split("metal")))-1) print(ans)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.HashSet; import java.util.StringTokenizer; import javax.print.attribute.standard.MediaSize.Other; public class Main { pu...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = input() l = len(s) k = [ 0 for i in range(l) ] start = 0 while True: temp = s.find("heavy",start,l) if temp==-1: break else: k[temp] = 1 start = temp+1 start = 0 while True: temp = s.find("metal",start,l) if temp==-1: break else: k[temp] = 2 ...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.*; import java.io.*; public class d2_188_B { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); long ans=0 , count=0; ArrayList<Integer> list=new ArrayList<Integer>(); ...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import sys right_metal = {'m': 0, 'e': 1, 't': 2, 'a': 3, 'l': 4} right_heavy = {'h': 0, 'e': 1, 'a': 2, 'v': 3, 'y': 4} metal_it = 4 metal_sub_it = 4 count_metal = 0 heavy_it = 4 heavy_sub_it = 4 total_count = 0 def find_substr(inp_str, start, end, rights, inner=True): global total_count match_count = 0 right...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; long long int c = 0; vector<int> v; int n = s.length(); for (int i = 0; i < n; i++) { if (s.substr(i, 5) == "metal") { v.push_back(i); } } int j = 0; ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = raw_input() total = 0 m = 0 c = len(s)-5 while(c >= 0): if(s[c:c+5] == 'metal'): m+=1 if(s[c:c+5] == 'heavy'): total+=m c -= 1 print total
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; inline void inpint(int &n) { n = 0; register int ch = getchar_unlocked(); bool sign = 0; while (ch < 48 || ch > 57) { if (ch == '-') sign = 1; ch = getchar_unlocked(); } while (ch >= 48 && ch <= 57) { n = (n << 3) + (n << 1) + ch - 48, ch = getchar_u...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; long long int cnt = 0, ans = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') { ++cnt; } if (s[i] == 'm' && s[i + 1] == 'e' &...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
temp = raw_input() '''x = temp.count('heavy') y = temp.count('metal') if(x==0 or y==0): print(0) exit(0)''' ls = ['h','e','a','v','y'] js = ['m','e','t','a','l'] m1 = [] m2 = [] ans = 0 sum = 0 i = 0 while i<(len(temp)-4): buf = '' check1 = False if(temp[i]=='h' or temp[i]=='m'): k...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
string = raw_input() ans = 0 numb = string.split('heavy') for i, b in enumerate(numb): ans+=b.count('metal')*i print ans
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #deactivate when input contains string from collections import deque as que, defaultdict as vector from bisect import bisect as bsearch from heapq import* inin = lambda: int(input()) inar = lambda: list(map(int,input().split())) inst= lambda: input(...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import sys s=raw_input().split('heavy') #splitsen bij woord 'heavy' res=0 for i in range(len(s)): res+=s[i].count('metal')*i print res
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; char s[maxn + 100], *s1 = "heavy", *s2 = "metal"; int main() { long long h1 = 0, sum = 0; scanf("%s", s); int len = strlen(s); for (int i = 0; i < len - 4; i++) { int t1 = 0, t2 = 0; for (int j = 0; j < 5; j++) { if (s[i + j] == s...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; template <class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; } const int oo = int(1e9) + 7; const int dx[] = {1, 0, 0, -1}; const int dy[] = {0, -1, 1, 0}; const int N = in...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; queue<long long> heavy; queue<long long> metal; long long con; void heavys(string cad) { long long pos = cad.find("heavy"); while (pos != con) { heavy.push(pos); pos = cad.find("heavy", pos + 1); } } void metals(string cad) { long long pos = cad.find("metal"...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; long long int uz, q, D[1000005], B[1000005], y, at = 1, sayac; string a; map<long long int, long long int> mp; int main() { cin >> a; uz = a.size(); for (long long int i = 0; i <= uz - 1; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; string s; int main() { long long i, j, ans = 0; map<string, int> m; string s1 = "heavy", s2 = "metal"; cin >> s; long long n = s.size(); for (i = 0; i < n; i++) { string a = s.substr(i, 5); if (a == s1) m[s1]++; if (a == s2) { ans += m[s1]; ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long int cnt = 0; long long int ans = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'h') { if (s[i + 1] == 'e') { if (s[i + 2] == 'a') { if (s[i + 3] == 'v') { if (s[i + 4] == 'y')...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long cnt = 0, ans = 0; for (int i = 0; i < s.size(); i++) { if (s.substr(i, 5) == "heavy") cnt++; if (s.substr(i, 5) == "metal") ans += cnt; } cout << ans; return 0; }
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int len, i; int pos = 0, pos1; long long sum = 0; int s = 0; int heavy[200000] = {0}; int metal[1000000] = {0}; char str[1000001]; scanf("%s", str); len = strlen(str); for (i = 0; i < len; i++) { if (str[i] == 'h' && str[i + 1] == 'e' &&...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
a = input() if 'heavy'not in a: print(0) elif 'metal' not in a: print(0) elif len(a)<10: print(0) else: p=0 d=0 for k in range(len(a)-9): if d==0: if a[k:k+5]=='heavy': p+=a[k+5:].count('metal') s=a[k+5:].count('metal') d...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = raw_input() i = 0 le = len(s) heavys = 0 metals = [] c = 0 while i < le - 4: if s[i] == 'h' and s[i+1] == 'e' and s[i+2] == 'a' and s[i+3] == 'v' and s[i+4] == 'y': heavys += 1 i += 4 elif s[i] == 'm' and s[i+1] == 'e' and s[i+2] == 't' and s[i+3] == 'a' and s[i+4] == 'l': c += h...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
t = input() t = t.replace('heavy', '0') t = t.replace('metal', '1') a, b, s = 0, t.count('1'), 0 for i in t: if i == '0': a += 1 s += b elif i == '1': b -= 1 print(s)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
a=input() b='' sh=0 sm=0 for i in range(0,len(a)-4): if a[i:i+5]=='heavy': sh+=1 if a[i:i+5]=='metal': sm+=sh print(sm)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s=input() a,b=0,0 n=len(s) for i in range(n): if(s[i:i+5]=='heavy'): a=a+1 elif(s[i:i+5]=='metal'): b=b+a print(b) #print the result
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
inp = input() if(len(inp)<10): print(0) exit(0) string=inp.split("heavy")[1:] count=0 counter=[None for i in range(len(string))] for i in range(len(string)): counter[i]=string[i].count("metal") count=counter[int(len(string)-1)] for i in range(len(string)-2,-1,-1): counter[i]+=counter[i+1] count+...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
//package com.deepak.PolyTest; import java.util.ArrayList; import java.util.Scanner; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) { String st = new String(); String temp; st = sc.nextLine(); long len = st.length...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
word = input() n = len(word) a = 'heavy' b = 'metal' arr = [0 for i in range(n)] brr = [0 for i in range(n)] for i in range(n): if word[i:i+5]==a: arr[i]+=1 if word[i:i+5]==b: brr[i]+=1 for i in range(n-2,-1,-1): brr[i]+=brr[i+1] ans = 0 for i in range(n): ans+=arr[i]*brr[i] print(ans)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { long long int ans = 0, t = 0; string s, a; cin >> s; for (long long int i = 0; i < s.length(); i++) { a = s.substr(i, 5); if (a == "heavy") t++; if (a == "metal") ans += t; } cout << ans; return 0; }
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; long long count = 0; stack<char> st; if (str.size() < 10) { cout << 0; return 0; } for (long long i = 0; i <= str.size() - 5; i++) { if (str[i] == 'h' && str[i + 1] == 'e' && str[i + 2] == 'a' && str[i +...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
//package com.turtle.bone; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class AK375 { public static Scanner cin = new Scanner(System.in); public static void main(String[] args) { // TODO Auto-generated method stub while (cin.hasNext()) { String str=cin.next(); lon...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
def main(): s=str(input()) s=s.replace("heavy","-") s=s.replace("metal","+") p,n=0,0 for k in s: if (k=="-"): n+=1 elif k=="+": p+=(n) print(p) main()
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> kmp(string s) { int n = s.length(); vector<int> pi(n, 0); vector<int> ans; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) pi[i] = j + 1; if (pi[i] == 5) ans.push_back(i); ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
a = map(str, raw_input().split('heavy')) c = 0 b = 0 ans = 0 for i in a: ans += b * i.count('metal') b += 1 print ans
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; bool test(string f1, string f2) { if (f1.compare(f2) == 0) return true; return false; } int main() { string a, m = "metal", h = "heavy"; cin >> a; long long int sum = 0, temp = 0; for (int i = a.length() - 1; i >= 0; i--) { if (a[i] != 'y' && a[i] != 'l') co...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
from sys import stdin s = stdin.readline().strip('\r\n') s = s.replace('heavy','1'); s = s.replace('metal','2'); one = 0 two = 0 ans = 0 for i in range(len(s)): if(s[i] == '1'): one+=1 if(s[i] == '2'): ans+=one print ans
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long x = 0; long long ans = 0; for (long long i = 0; i < (int)s.length() - 4; i++) { if (s.substr(i, 5) == "heavy") x++; if (s.substr(i, 5) == "metal") ans += x; } cout << ans << "\n"; return 0; }
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#!/usr/bin/python def main(): result, lst = 0, raw_input().split('heavy') for i in range(len(lst)): result+=lst[i].count('metal')*i print result if __name__=='__main__': main()
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
z=r=0 for w in input().split("heavy"):r+=w.count("metal")*z;z+=1 print(r) #JSR
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.*; import java.util.*; public class test { public static void main(String[] argv){ Scanner in=new Scanner(System.in); String s=in.next(); int [] a=new int[200000]; int x=0; int count=0; while(x>=0&&x<s.length()){ x=s.indexOf("metal",x); if(x>=0) a[count++]=x; else break; x++;...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import sys def fastio(): from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() def debug(*va...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.*; import java.util.*; import java.math.BigInteger; /* * This file was created by ayush in attempt to solve the problem problems */ public class main { public void solve(char[] inp, PrintWriter out) { long heavyCount =0; long ans =0; for(int i=0;i<inp.length-4;i++){ if(inp[i]=='h' && inp[i+1]=...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
from collections import defaultdict, deque, Counter, OrderedDict from bisect import insort, bisect_right, bisect_left import threading, sys def main(): s = input() ans, c = 0, 0 for i in range(0,len(s)-4): ss = s[i:i+5] if ss == "heavy": c += 1 elif ss == "metal": ans += c print...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = input() metals = [] heavys = [] ind = cur = -1 while True: cur = s.find('heavy', ind + 1) if cur != -1: heavys.append(cur) ind = cur else: break ind = cur = -1 while True: cur = s.find('metal', ind + 1) if cur != -1: metals.append(cur) ind = cur else: ...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
subst = input().split('heavy') res = 0 for i in range(len(subst)): res += i * subst[i].count('metal') print(res)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.*; import java.util.regex.*; public class powerstring { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); int x=0; long ans=0; for(int i=0;i<=s.length()-5;i++) { String temp = s.substring(i,i+5); if(temp.equals("heavy")) x++;...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
from sys import stdin from collections import defaultdict as dd s=stdin.readline().rstrip() c=0 ans=0 for i in range(len(s)-4): if s[i:i+5]=="heavy": c+=1 elif s[i:i+5]=="metal": ans+=c print(ans)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = raw_input() cnt = 0 ans = 0 for i in xrange(len(s)): cur = s[i - 4: i + 1] if cur == "heavy": cnt += 1 elif cur == "metal": ans += cnt print ans
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.Scanner; public class code { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String line = scan.nextLine(); long heavy = 0, ans = 0; for(int i = 0; i < line.length()-4; i++) if(line.substring(i, i+5).equals("heavy")) heavy++; else if(line.substring(i...
JAVA