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
#include <bits/stdc++.h> using namespace std; char s1[6] = "heavy"; char s2[6] = "metal"; char str[1000005]; char tem[6]; int c[1000005]; int main() { memset(c, 0, sizeof(c)); scanf("%s", str); int i = 0, j, k, n = 0, m = 0; int len = strlen(str); for (i = 0; i <= len - 5; i++) { if (i != 0) c[i] = c[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
s=raw_input() def solve(s): h=0 ans=0 for i in range(len(s)-4): if s[i:i+5]=="heavy": h+=1 if s[i:i+5]=="metal": ans+=h return ans print(solve(s))
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; int heavy(0); long long amount(0); for (size_t i = 4; i < s.length(); ++i) { if (s[i] == 'l') { if (s[i - 4] == 'm' && s[i - 3] == 'e' && s[i - 2] == 't' && s[i - 1] == 'a') { amount += heavy; } ...
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
p=raw_input() n=len(p) C=list(0 for i in xrange(n+1)) h=list() for i in xrange (n-4): if p[i]=='h' and p[i+1]=='e' and p[i+2]=='a' and p[i+3]=='v' and p[i+4]=='y': h.append(i) if p[i]=='m' and p[i+1]=='e' and p[i+2]=='t' and p[i+3]=='a' and p[i+4]=='l': C[i]=C[i]+1 for i in xrange(1,n+1): C[...
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.IOException; import java.io.InputStreamReader; public class PowerfulHeavyMetal { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s = reader.readLine(); ...
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 def read_int(): return int(stdin.readline().split()[0]) def read_ints(): return [int(x) for x in stdin.readline().split()] line = stdin.readline()[:-1] starts, ends = [], [] for i in range(len(line) - 4): if line[i:i+5] == 'heavy': starts.append(i) for i in range(len(line) - 4): if line[i:...
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
from bisect import * s = raw_input() last_idx = 0 idx = 0 h = [] m = [] while 1: idx = s.find("heavy", last_idx) if idx == -1: break last_idx = idx+1 h.append(idx) last_idx = 0 while 1: idx = s.find("metal", last_idx) if idx == -1: break last_idx = idx+1 m.append(idx) #print h, m ans = 0 for x in h: i =...
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.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { static BufferedReader in; static StringTokenizer st; static PrintWri...
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
# Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase # mod=10**9+7 # sys.setrecursionlimit(10**6) # mxm=sys.maxsize # from functools import lru_cache def main(): s=input() n=len(s) h=0 ans=0 for i in range...
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 power { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String text = br.readLine(); long total=0; long heavy=0; if(...
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() i, heavy, count = 0, 0, 0 while i < len(s): temp = s[i:i+5] if temp == "heavy": heavy += 1 i += 5 elif temp == "metal": count += heavy i += 5 else: i += 1 print(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
#include <bits/stdc++.h> using namespace std; const int N = 21; string s; long long heavy = 0, sol = 0; int main() { cin >> s; for (int i = 0; i < s.size(); i++) { string temp = s.substr(i, 5); if (temp == "heavy") { heavy++; i += 4; } else if (temp == "metal") { sol += heavy; 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
#include <bits/stdc++.h> using namespace std; int main() { char s[1 << 20]; int64_t r = 0; int i = -1, h = 0; cin >> s; while (s[++i]) if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') h++, i += 4; else if (s[i] == 'm' && s[i + 1] == 'e' && s[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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); string s; set<int> h, m; set<int>::iterator it, itlow, itt; cin >> s; int posh = s.find("heavy"), posm = s.find("metal"); while (posh != string::npos) { h.insert(posh); posh = s.find("heavy", posh + 1, 5);...
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 ch[1000005]; int main() { string s = "heavy", ss = "metal", a, b; long long i, j, k, l, m, n, ans = 0, h, count; gets(ch); l = strlen(ch); h = 0, m = 0, count = 0; for (i = 0; i < l; i++) { a = ""; b = ""; for (j = i; j < i + 5; j++) a += ch[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
a=list(input().split('metal')) l=len(a) sum=0 #print(a) for i in range(l): sum+=(l-i-1)*a[i].count('heavy') print(sum)
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; public class CF_318B { public static void main(String[] args){ Scanner input = new Scanner(System.in); String str = input.next(); int ind = str.indexOf("metal"),s=0; while (ind>-1){ s++; ind = str.indexOf("metal",ind+5); } ...
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() h = 0 ans = 0 for i in range(len(s)): if s[i:i+5] == 'heavy': h += 1 if s[i:i+5] == "metal": if h > 0: ans += h 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() { string s, h = "heavy", m = "metal"; getline(cin, s); long long cnt = 0, cnt_h = 0; for (int i = 0; i < s.size(); i++) { string temp = s.substr(i, 5); if (temp == h) cnt_h++; if (temp == m) cnt += cnt_h; } cout << cnt << endl; 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
import math import bisect s=input() heavy=[] metal=[] for i in range(len(s)-4): if s[i] in ['m','h']: temp=s[i:i+5] if temp =="heavy": heavy.append(i) elif temp=="metal": metal.append(i) ans=0 for i in heavy: ans +=len(metal)-bisect.bisect(metal,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; long long i, m, ans, k, l, j, q, x, n, ma, mi; vector<int> v, g; string s; int main() { cin >> s; n = s.size(); for (i = 0; i < n - 4; i++) { if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') { v.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
s = input() a = 0 b = 0 s2 = "" for i in range(len(s)-4): if s[i:i+5] == "heavy": a+=1 elif s[i:i+5] == "metal": b+=a print(b)
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
def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def MAP2():return map(float,input().split()) def LIST(): return list(map(int, input().split())) def STRING(): return input() import string import sys from heapq import heappop , heappush from bisect import * from...
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() n = len(s) h = 0 x = 0 i = 0 while i < n-4: temp = (s[i:i+5]) if temp=="heavy": h+=1 i+=5 elif temp=="metal": x+=h i+=5 else: i+=1 #print(x) #print(h) print(x)
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() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, t; cin >> s; vector<long long> h, m; for (int i = 0; i + 4 < s.size(); i++) { t = s.substr(i, 5); if (t == "heavy") h.push_back(i); else if (t == "metal") m.p...
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/env python import sys import re line = sys.stdin.readline().strip() l = [(x.start(), 'h') for x in re.finditer(r'heavy', line)] + [(x.start(), 'm') for x in re.finditer(r'metal', line)] l.sort() l = "".join([x[1] for x in l]) count = 0 m = l.count('m') for x in l: if x == 'm': m -= 1 e...
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
i, res = 0, 0 for w in input().split("heavy"): res += w.count("metal") * i i += 1 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
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long sum1 = 0, sum2 = 0; for (int i = 0; i < s.size(); ++i) { if (s.substr(i, 5) == "heavy") sum2++; else if (s.substr(i, 5) == "metal") sum1 = sum1 + sum2; } cout << sum1 << endl; }
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.*; public class codeforce{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String s = sc.next(); StringBuilder sb = new StringBuilder(s); int h=0; long c=0; for(int i=0;i<sb.length()-4;i++){ if(sb.substring(i,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
s = raw_input() total = 0 curr_heavy = 0 for i in range(len(s) - 4): if s[i:i + 5] == "heavy": curr_heavy += 1 elif s[i:i + 5] == "metal": total += curr_heavy 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
//"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() { long long int ans = 0, t = 0; string s, a; cin >> s; for (long long int i = 0; i + 4 < 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
import java.io.*; import java.util.*; public class Main { public Scanner sc; public void run() { StringBuilder sb = new StringBuilder(sc.next()); if (sb.length() < 10) { System.out.println(0); return; } long[] cs = new long[sb.length()-3]; c...
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; long long h, x, i, n, a; int main() { cin >> s; for (i = 0; i < s.size(); i++) { if (s.substr(i, 5) == "heavy") h++; if (s.substr(i, 5) == "metal") x = x + h; } cout << x; }
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 static java.lang.Math.*; import java.io.*; import java.util.*; import java.math.*; public class Main{ BufferedReader in; PrintWriter out; StringTokenizer st; String next() { while (st==null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (Exception e) {} ...
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
z=r=0 for w in input().split("heavy"):r+=w.count("metal")*z;z+=1 print(r) # Made By Mostafa_Khaled
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
def finder(S, t): n = len(S) answer = [] i1 = 0 for i in range(n): if S[i]==t[i1]: i1+=1 if i1==len(t): i1=0 answer.append(i-len(t)+1) else: i1=0 if S[i]==t[i1]: i1+=1 return answer def p...
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 m, n = map(int, input().split()) if m % 2 == 1: if n <= (m + 1) // 2: print(2 * n - 1) else: print(2 * n - (m + 1)) else: if n <= m // 2: print(2 * n - 1) else: pritn(2 * n - m) ''' #B s = input() l = s.split('heavy') res = 0 for i in range(1, len(l)): 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.*; public class Solution { // static boolean[][] isVisited; static Scanner sc = new Scanner(System.in); public static void main(String args[]) { // int t=sc.nextInt(); // while(t-->0){ String s=sc.next(); int ni=s.length(); // int i=0,j=0; List<Integer> he...
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.Scanner; /** * Created by amayorov on 10.09.2014. */ public class Codeforces318B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); int st_index = str.indexOf("heavy", 0); int end_index = st_index; ...
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() h, m = [], [] cur = s.find('heavy') while cur != -1: h.append(cur) cur = s.find('heavy', cur + 5) cur = s.find('metal') while cur != -1: m.append(cur) cur = s.find('metal', cur + 5) mi, val = 0, 0 for x in h: while mi < len(m) and m[mi] < x: mi += 1 val += len(m) - mi print(v...
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 Main{ public static void main(String[] args)throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine(); long counth=0; 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
s = input() m=0 h=0 for i in range(4,len(s)): if (s[i]=='l'): if(s[i-4]=='m' and s[i-3]=='e' and s[i-2]=='t' and s[i-1]=='a'): m=m+h elif(s[i-4]=='h' and s[i-3]=='e' and s[i-2]=='a' and s[i-1]=='v' and s[i]=='y'): h=h+1 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() s = s.replace("heavy", "1") s = s.replace("metal", "0") tmp = "" for i in s: if(i == "1"): tmp += "1" if(i == "0"): tmp += "0" if len(tmp) == 0: print(0) exit(0) d = [0 for i in range(10**6+1)] if tmp[len(tmp)-1] == "0": d[len(tmp)-1] = 1 for i in reversed(range(len(tmp) ...
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.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class B188 { public void solve() throws IOException { Scanner sc = new Scanner(System.in); BufferedReader br...
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; char s[1000100], h[] = "heavy", m[] = "metal"; int main() { scanf(" %s", s); int len = strlen(s); bool f; long long ans = 0; int c = 0; for (int i = 0; i < len - 4; i++) { f = true; for (int j = 0; j < 5; j++) if (s[i + j] != h[j]) f = false; 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
s = input() num2 = len(s) num_heavy = 0 num = 0 for i in range(num2-4): if s[i] == "h": if s[i+1:i+5] =="eavy": num_heavy += 1 if s[i] == "m": if s[i+1:i+5] == "etal": num += num_heavy print(num)
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 x = 0, y = 0, i = 0; string s; cin >> s; while (i < s.size()) { if (s.substr(i, 5) == "heavy") { x++; i += 4; } if (s.substr(i, 5) == "metal") { y += x; i += 4; } else { i++; } } cout << 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
/* * Code Author: Jayesh Udhani * Dhirubhai Ambani Institute of Information and Communication Technology (DA-IICT ,Gandhinagar) * 2nd Year ICT BTECH Student */ import java.io.*; import java.util.*; public class Main { public static void main(String args[]) { InputReader in = new InputReader(System.in); Outpu...
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 CODE { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { String s = sc.next(); ArrayList<Integer> h = new ArrayList<>(s.length() / 5); HashSet<Integer> m = new HashSet<>(); int last = -1; for (int 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
#include <bits/stdc++.h> int main(int argc, char *argv[]) { int state = 0; unsigned long long int heavy, count; count = heavy = 0; char ch; ch = getchar(); while (ch >= 'a' && ch <= 'z') { switch (ch) { case 'h': state = 1; break; case 'e': if (state == 1) 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
string = input('') heavy = list() metal = list() start = 0 while (string.find("heavy", start) != -1): heavy.append(string.find("heavy", start)) start = string.find("heavy", start) + 5 start = 0 while (string.find("metal", start) != -1): metal.append(string.find("metal", start)) start = string.find("meta...
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.lang.*; import java.math.BigInteger; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t,ca,i,j; String[] my; String line = br.readLine(); ...
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
a=input() ch=0 cm=0 for i in range(0,len(a)-4): if(a[i:i+5]=="heavy"): ch+=1 elif(a[i:i+5]=="metal"): cm+=ch print(cm)
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() { string kalimat; long long result = 0, temp2 = 0; getline(cin, kalimat); for (long long i = kalimat.length() - 1; i >= 0; i--) { if (kalimat[i] == 'y') { if (kalimat[i - 1] == 'v' && kalimat[i - 2] == 'a' && kalimat[i - 3] == 'e' && k...
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() alen = len(s) ans = 0 h = 0 for i in range(0,alen-4): if s[i:i+5] == "heavy": h += 1 elif s[i:i+5] == "metal": ans += h 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() { ios_base::sync_with_stdio(false); cin.tie(0); string s; long long k = 0, sum = 0; cin >> s; 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') { k++; ...
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() c = 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() a = [i for i in xrange(len(s)) if "heavy" == s[i:i+5]] b = [i for i in xrange(len(s)) if "metal" == s[i:i+5]] ans = 0; j = 0 for i in xrange(len(a)): while j < len(b) and b[j] < a[i]: j += 1 ans += len(b)-j 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.*; public class Tester{ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String linea = in.readLine(); String heavy = "heavy"; String metal = "metal"; int ultimo = linea.length()-1; // Cada vez que pi...
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.io.*; import java.util.*; public class j { public static void main(String aa[])throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); long n=0,t=0,p=0,k=0,m=0; String s; int i; s=b.readLine(); n=s.length(); Integer d[]; Integer e[]; Vector v1=new Vector(); Vector v2=new ...
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.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class CodeForce188B1 { public static void main(String[] args) throws IOException { InputStream inputSt...
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) i = length = sub = 0 while 1: if i<=l-5: if s[i:i+5]=='heavy': length += 1 i += 5 elif s[i:i+5]=='metal': sub += length i += 5 else: i += 1 else: break print(sub)
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
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Sachin Rana */ import java.io.*; public class MyClass { public static void main(String[] args)throws IOExceptio...
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 cntm = 0, cnt = 0; int x; string second; bool flag1 = false, flag2 = false; cin >> second; if (second.size() < 10) { cout << 0; return 0; } for (int i = 0; i < second.size() - 4; i++) { if (second[i] == 'h' && second[i + 1]...
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
#http://codeforces.com/problemset/problem/318/B #solved string = input() h = string.count("heavy") m = string.count("metal") out = h * m lmh = 0 lmm = 0 for i in range(len(string)): mb = lmm if string[i] == "h": if string[i: i + 5] == "heavy": lmh += 1 elif string[i] == "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
#include <bits/stdc++.h> using namespace std; struct edge { long long from, to, w; edge(long long from, long long to, long long w) : from(from), to(to), w(w) {} bool operator<(const edge& e) const { return (w > e.w); } }; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % 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; int n = s.length(); long long int heavy = 0, ans = 0; for (int i = 0; i <= n - 5; i++) { string t = s.substr(i, 5); if (t == "heavy") heavy++; if (t == "metal") ans += heavy; } 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
s = input() l = s.split('heavy') ans = 0 for i in range(1, 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
a=list(input().split('metal')) l=len(a) sum=0 for i in range(l): sum+=(l-i-1)*a[i].count('heavy') print(sum)
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 Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); String str = sc.next(); ArrayList<Integer> heavy = new ArrayList<Integer>(); ArrayList<Integer> metal = new ArrayList<Integer>(); int start =...
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 i, m, n; int main() { string s, e; cin >> s; n = s.length(); long long c = 0, co = 0; for (i = 0; i < n; i++) { e = s.substr(i, 5); if (e == "heavy") c++; else if (e == "metal") co += c; } cout << 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
#include <bits/stdc++.h> using namespace std; string s; long long ans, a[(int)(1e6 + 1010)], k; int main() { cin >> s; for (long i = 0; i <= (int)(s.length()) - 5; i++) { if (s.substr(i, 5) == "heavy") k++; if (s.substr(i, 5) == "metal") ans += k; } cout << 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
#include <bits/stdc++.h> using namespace std; long long int b[1000002] = {}; int main() { string m; cin >> m; long long int x = 0; for (int i = 0; i < m.length(); i++) { if (m.substr(i, 5) == "heavy") { b[x] = 1; x++; i += 4; } if (m.substr(i, 5) == "metal") { b[x] = 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; int main() { int index, i, k; int arr[1000010]; int metal[1000010]; string str; cin >> str; index = str.find("heavy"); i = 0; while (index != -1) { arr[i++] = index; index = str.find("heavy", index + 1); } k = 0; index = str.find("metal"); wh...
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> int main() { char hmetal[1000010]; int heavy[200001]; int metal[200001]; int lenh = 0; int lenm = 0; scanf("%s", hmetal); int lens = strlen(hmetal); long long substr = 0; for (int i = 0; i + 4 < lens; i++) { if (hmetal[i] == 'h' and hmetal[i + 1] == 'e' and hmetal[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
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect, ...
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 dx[]{1, -1, 0, 0}; int dy[]{0, 0, 1, -1}; int dx8[]{1, -1, 0, 0, 1, -1, 1, -1}; int dy8[]{0, 0, 1, -1, 1, -1, -1, 1}; const long long OO = 1e9 + 7; int main() { string s; cin >> s; string m = "metal"; string h = "heavy"; reverse(((s).begin()), ((s).end())); ...
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.*; public class CF_318B { public static void main(String args[]){ String str ; Scanner scan = new Scanner(System.in); str = scan.nextLine(); scan.close(); long total=0,heavycount=0; for(int i=0;i<Math.abs(str.length()-4);i++) { if(i+5 > str.length())break; //System.out.println(str.substr...
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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import java.util.StringTokenizer; public class code { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(ne...
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; long long heavy; long long ukupno; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> s; heavy = 0; ukupno = 0; for (int i = 4; i < s.size(); i++) { if (s[i] == 'l' && s[i - 1] == 'a' && s[i - 2] == 't' ...
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() st='' if len(a)<5: print(0) else: for i in range(4,len(a)): if a[i-4]=='h' and a[i-3]=='e' and a[i-2]=='a' and a[i-1]=='v' and a[i]=='y': st+='h' elif a[i-4]=='m' and a[i-3]=='e' and a[i-2]=='t' and a[i-1]=='a' and a[i]=='l': st+='m' totm=st.count('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
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.util.*; import java.lang.*; import java.io.*; public class Rextester { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(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; string t; long long cnt1[3000001]; int main() { ios_base::sync_with_stdio(0); cin >> t; cnt1[0] = 0; int n = (int)t.length(); for (int i = 0; i <= n - 4; ++i) { if (t.substr(i, 5) == "heavy") ++cnt1[i + 1]; cnt1[i + 1] += cnt1[i]; } long long ans = 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 BS(int ar[], int siz, int b) { int left = 0, right = siz - 1, mid; while (left != right) { mid = left + (right - left) / 2; if (ar[mid] <= b) left = mid + 1; else right = mid; } return right; } int main() { string s; cin >> s; int a...
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 n, m; char s[1001000]; int main() { scanf("%s", &s); n = strlen(s); long long ans = 0, tmp = 0; for (int i = (0); i < (n); i++) { if (!memcmp(s + i, "heavy", strlen("heavy"))) tmp++; else if (!memcmp(s + i, "metal", strlen("metal"))) ans += t...
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 static java.lang.System.in; import static java.lang.System.out; import java.io.*; import java.util.*; public class B318 { static final double EPS = 1e-10; static final double INF = 1 << 31; static final double PI = Math.PI; public static Scanner sc = new Scanner(in); StringBuilder sb = new StringBuilder(...
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.io.*; import java.util.*; public class Task318B { PrintWriter out; BufferedReader input; Task318B() { input = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); try { solver(); } catch(IOException ex) {} out.close(); } StringTokenizer st = new StringT...
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() { ios::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; long long int i, j; long long int count = 0; long long int ans = 0; for (i = 0; i < s.size(); i++) { if (s.substr(i, 5) == "heavy") count++; if (s.substr(i, 5) == "metal") a...
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.Scanner; public class StringOfPower { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); int heavy = 0; long res = 0; for (int i = 0; i <= s.length() - 5; i++) { String temp = s.substring(i, i + 5); if (temp.equals("heavy")) ...
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
;(function () { print(function (s) { var t = []; ['heavy', 'metal'].forEach(function (e, i) { var pos = -1; while (true) { pos = s.indexOf(e, pos + 1); if (pos !== -1) t.push([i, pos]); else break; } }); t = t.sort(function (a, b) { return a[1] - b[1]; }).map(function (e) { return e[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
s=input() a=0 b=0 for i in range(len(s)-4): if s[i:i+5]=="heavy": a+=1 elif s[i:i+5]=="metal": b+=a print(b)
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() { string str; long long c = 0, re = 0; cin >> str; vector<bool> beg(str.size(), 0); vector<bool> end(str.size(), 0); for (int i = 0; i < str.size(); i++) { if (i < str.size() - 4 && str[i] == 'h' && str[i + 1] == 'e' && str[i + 2] == 'a' &...
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.InputStream; import java.io.InputStreamReader; import java.util.InputMismatchException; import java.util.*; import java.io.*; public class Main{ public static class InputReader { private InputStream stream; private byte[] buf = new byte[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
s = raw_input() i = 0 heavy = [] metal = [] while i < len(s) - 4: if s[i:i+5] == "heavy": heavy.append(i) i += 5 elif s[i:i+5] == "metal": metal.append(i) i += 5 else: i += 1 total = 0 hindex = 0 mindex = 0 while hindex < len(heavy) and mindex < len(metal): whil...
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
#include <bits/stdc++.h> using namespace std; const int L = 1e6; char t[L + 1]; int flg[L]; int main() { scanf(" %s", t); int len = strlen(t); for (int i = 0; i < len; i++) { if (strncmp("heavy", t + i, 5) == 0) flg[i] = 1; } for (int i = 0; i < len; i++) { if (strncmp("metal", t + i, 5) == 0) flg[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
read_ints = lambda: map(int, raw_input().split()) str= raw_input() l= len(str) ch, ans= 0,0 for i in range(l-5+1): tmp= str[i:i+5] if tmp=="heavy": ch+=1 elif tmp=="metal": ans+= ch 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; char s[1000005]; int n, pref[1000005]; char h[7] = " heavy"; char m[7] = " metal"; void kmp1() { int i, q = 0; for (i = 1; i <= n; i++) { if (q && m[q + 1] != s[i]) { q = 0; } if (m[q + 1] == s[i]) { q++; } if (q == 5) { pref[i - 4]...
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.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.next(); long sum = 0, cnt = 0; for (int i=0;i<s.length()-4;i++){ if (s.substring(i,i+5).equals("heavy")){ cnt++; } if (s.substring(i,i+5).equals("metal")...
JAVA