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; const int NMax = 1001000; char A[NMax]; int N; long long sum[NMax]; vector<int> S; int main() { scanf("%s", A); N = strlen(A); for (int i = 4; i < N; i++) { if (A[i - 4] == 'h' && A[i - 3] == 'e' && A[i - 2] == 'a' && A[i - 1] == 'v' && A[i - 0] == '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
s = input()[::-1] h = "heavy"[::-1] m = "metal"[::-1] sum = 0 cnt_b = 0 if h and m in s: for i in range(len(s)): if s[i: i + len(m)] == m: cnt_b += 1 elif s[i: i + len(h)] == h: sum += cnt_b 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
s=str(input()) s=s[::-1] count=0 ans=0 for i in range(0,len(s)): if s[i:i+5]=="latem": count+=1 if s[i:i+5]=="yvaeh": ans+=count 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
n = cou = 0 t = input().split('heavy') for i in t: cou += i.count('metal')*n n+=1 print(cou)
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.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Locale; public class array2 { public static void main(String[] args) { InputStreamReader in=new InputStreamReader(System.in); BufferedReader con=new BufferedReader(in); try { ...
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 m=0 ans=0 for i in range(len(s)-1,3,-1): # print(s[i],end='') #print(s[i-4:i+1]) if s[i-4:i+1]=='heavy': h+=1 ans+=m if s[i-4:i+1]=='metal': m+=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
str = raw_input() ans = 0 heavy = 0 for i in xrange(len(str)): if str[i:i+5] == "heavy": heavy += 1 if str[i:i+5] == "metal": ans += heavy 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 str[2100000]; const char id1[] = "heavy"; const char id2[] = "metal"; int main() { scanf("%s", str); int len = strlen(str); long long cntofh = 0; long long cntofm = 0; long long ans = 0; int i, j; bool judge; for (i = 0; i < len; i++) { if (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
import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner s=new Scanner(System.in); String temp=s.nextLine(); int he[]=new int[1000000]; //int me[]=new int[100000]; int k=0; int l=0,m=0; int nt=temp.indexOf("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
#include <bits/stdc++.h> using namespace std; int H[1000002], M[1000002]; int l, ll; int main() { string str; cin >> str; long long int cnt = 0; for (int i = 0; i < str.size(); i++) if (str[i] == 'h' && str.substr(i, 5) == "heavy") H[l++] = i; else if (str[i] == 'm' && str.substr(i, 5) == "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; int main() { char a[1000100]; scanf("%s", a); int len = strlen(a) - 4; long long ans = 0, h = 0, i, j, k; for (i = 0; i < len; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') h++, i += 4; el...
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; long long h, m, ans; cin >> s; int n = s.length(); string s1, s2, r1, r2; s1 = "heavy"; s2 = "metal"; r1 = "heavy"; r2 = "metal"; h = 0; m = 0; ans = 0; for (int i = 0; i < n; i++) { if ((s[i] == 'h') && (i + 5 <= n)) { ...
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 io,os # speedforce 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= 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
import java.util.Scanner; public class StringsOfPower { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); in.close(); int currentIndex = 0; int nextHeavy = s.indexOf("heavy", currentIndex); int nextMetal = s.indexOf("metal", currentIndex); int nu...
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)): c = s[i : i + 5] if c == "metal": ans += h if c == "heavy": h += 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.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); char[] arr = str.toCharArray(); long h =0; long m =0; for(int i=0;i<str.length()-4;i++){ if(arr[i]=='h'&& a...
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 B { public static void solution(BufferedReader reader, PrintWriter writer) throws IOException { In in = new In(reader); Out out = new Out(writer); String s = in.next(); FenwickTree h = new FenwickTree(s.length() + 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=input() i=0 j=len(s)-1 c='metal' p='heavy' h=[] m=[] while i<len(s)-4 and j>=4: if s[i:i+5]==p: h.append(i) i+=1 if s[j-4:j+1]==c: m.append(j) j-=1 c=0 for i in range(len(m)): lower=0 upper=len(h)-1 while lower<=upper: mid=(lower+upper)//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
from bisect import bisect_left s=input() heavy=[] driver=[] for i in range(len(s)): if i+5<=len(s): if s[i:i+5]=="heavy": heavy.append(i) if i+5<=len(s): if s[i:i+5]=="metal": driver.append(i) ans=0 for j in heavy: x=bisect_left(driver,j) ans+=len(driver)-x 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
import math import time str = input() array = [] for i in range(4, len(str)): if str[i-4] == 'h' and str[i-3] == 'e' and str[i-2] == 'a' and str[i-1] == 'v' and str[i]=='y': array.append(1) if str[i-4] == 'm' and str[i-3] == 'e' and str[i-2] == 't' and str[i-1] == 'a' and str[i]=='l': array.ap...
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() heavy = 0 ans = 0 for i in range(0, len(str)): if str[i:i + 5] == "heavy": heavy += 1 elif str[i:i + 5] == "metal": ans += heavy 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=input() count,ans,i=0,0,0 while(i<len(s)-4): if(s[i:i+5]=="heavy"): count+=1 i+=5 elif(s[i:i+5]=="metal"): ans+=count i+=5 else: i+=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.util.*; public class CF188B { public static long heaveMetal(String s) { long ans = 0; long heavy = 0; for(int i = 0; i <= s.length()-5; i++) { String part = s.substring(i, i+5); if(part.equals("heavy")) heavy++; if(part.equals("metal")) ans += heavy; } return ans; } ...
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 main() { long long m = 0, res = 0; cin >> s; for (int i = s.length() - 5; i >= 0; i--) { if (s.substr(i, 5) == "metal") m++; else if (s.substr(i, 5) == "heavy") res += m; } cout << res << 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
arr=input() countex=0 countin=0 for i in range(len(arr)): if(arr[i:i+5]=="heavy"): countin+=1 if(arr[i:i+5]=="metal"): countex+=countin print(countex)
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=h=0 for k in raw_input().split("heavy"): r+=k.count("metal")*h h+=1 print r
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 Main{ int[] array; public Main(int size) { array = new int[size + 1]; } public int rsq(int ind) { assert ind > 0; int sum = 0; while (ind > 0) { sum += array[ind]; ind -= ind & (-ind); } return sum; ...
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.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Stack; public class Haha{ public static void main(String[] args) throws IOException{ BufferedRead...
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 inS = raw_input() size = len(inS) inS += '*'*10 h = 0 out = 0 for i in range(size): if inS[i] == 'h': if inS[i:i+5] == "heavy": h += 1 elif inS[i] == 'm': if inS[i:i+5] == "metal": out += h sys.stdout.write(str(out))
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.*; public class yvr{ public static void main(String args[]){ Scanner s=new Scanner(System.in); String a=s.nextLine(); String x="heavy"; String y="metal"; long c=0,p=0; for(int i=a.length()-5;i>=0;i--){ if(a.substring(i,i+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=raw_input() m=0 ans=0 for i in xrange(len(s)-4): temp=s[i:i+5] if temp=="heavy": m+=1 if temp=="metal": ans+=m 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
st=input() ch=0 c=0 cm=0 for i in range(0,len(st)-4): if(st[i:i+5]=="heavy"): ch+=1 elif(st[i:i+5]=="metal"): if cm==0 and ch>=1: cm=1 cm=cm*ch else: cm=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
import sys, re inp = sys.stdin.read().strip() m = re.compile('(heavy|metal)').findall(inp) res = 0 if m: n = [0 for i in m] s = 0 for i in xrange(len(m)-1, -1, -1): if m[i] == 'metal': s += 1 n[i] = s for i in xrange(len(m)): if m[i] == 'heavy': 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
import java.util.*; import java.io.*; public class a { public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(System.out); String s = input.next(); int n = s.length(); ArrayList<Integer> heavy = new ArrayList<Integer>(), metal = 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.*; import java.util.*; import java.math.*; import java.math.BigInteger; public final class codeforces { static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); static ArrayList<ArrayList<Integer>> g; static long mod=1000000007; static boolean set[]; ...
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; const int INF = (int)1e9; const long long INF64 = (long long)1e18; long double eps = 1e-6; const long double pi = 3.14159265358979323846; const int N = 1e6 + 100; long long fact[N], modulo = INF + 7; int h[N] = {0}; int m[N] = {0}; int main() { string a; cin >> a; int...
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; const int INF = (0u - 1) / 2; char S[1000002]; int main() { long long n = 0; gets(S); int i = 0, j = 0; vector<int> v1, v2; char A[10] = "heavy!"; char B[10] = "metal!"; while (S[i] != 0) { if (S[i] == A[j]) { ++j; if (A[j] == '!') { 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
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
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, z=0, 0 for i in input().split('heavy'): r+=z*i.count('metal') z+=1 print(r)
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
counter=0 ans=0 for i in raw_input().split('heavy'): ans+=i.count('metal')*counter counter+=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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastRe...
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 a[1000010]; int main() { scanf("%s", a); int len = strlen(a) - 4; long long int ans = 0, h = 0, i, j, k; for (i = 0; i < len; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') { i += 4; h...
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; const int MAXN = 1001000; char str[MAXN]; char h[] = "heavy"; char m[] = "metal"; int main() { scanf("%s", str); int left = 0; int a = 0; int b = 0; long long ans = 0; for (int i = 0; str[i]; ++i) { if (str[i] != h[a]) a = 0; if (str[i] == h[a]) ++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
res = 0 i = 0 for word in input().split('heavy'): res += i * word.count('metal') 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
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.List; 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 = raw_input() count = 0 ans = 0 for i in range(len(s)): if s[i:i + 5] == 'heavy': count += 1 i += 5 elif s[i:i + 5] == 'metal': ans += count i += 5 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.*; import java.lang.*; import java.io.*; public class Temp { static int imax = Integer.MAX_VALUE, imin = Integer.MIN_VALUE; static long lmax = Long.MAX_VALUE, lmin = Long.MIN_VALUE; static long mod = (long) 1e9 + 7; public static void main(String[] args) throws java.lang.Exception { InputReade...
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 str[1000005]; int sum[1000005]; int main(void) { long long ans; int n, i; scanf("%s", str + 1); n = strlen(str + 1); for (i = n - 4; i >= 1; i--) { sum[i] = sum[i + 1]; if (str[i] == 'm' && str[i + 1] == 'e' && str[i + 2] == 't' && str[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
import java.io.*; import java.util.*; public class Main{ static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter writer; static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } static long nextLong() throws IOException { return Long.parseLong(nextToken()...
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 cf_Strings_Of_Power { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { char[] arr = sc.next().toCharArray(); int heavy = 0; long ans = 0; int n = arr.length; for(int i = 0;i < n;i++) { if(arr[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> using namespace std; int main() { string inp, heavy{"heavy"}, metal{"metal"}; cin >> inp; long long check{}; for (size_t k{0}; k < inp.size(); k++) { if (inp.substr(k, 5) == metal) { check++; k = k + 4; } } long long count{}; for (size_t i{}; i < inp.size(); 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; bool chk(string &s, string &temp, int i) { string x = s.substr(i, 5); return (x == temp); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> ws >> s; int n = s.size(); vector<int> h, m(n); m[n - 1] = 0; string a = "heavy", b...
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')) ;z=0;l=len(a) for i in range(l): z+=(l-i-1)*a[i].count('heavy') print(z)
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.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Map; import java.util.PriorityQueue; impo...
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().strip() Len = len(s) cnt = ans = 0 for i in xrange(Len): if s[i] == 'h' and i+5<=Len and s[i:i+5]=='heavy': cnt += 1; if s[i] == 'm' and i+5<=Len and s[i:i+5]=='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
#include <bits/stdc++.h> using namespace std; int main() { long long int k = 0, n, h = 0; string input; cin >> input; n = input.length(); for (int i = 0; i < n; i++) { if (input.substr(i, 5) == "heavy") h++; if (input.substr(i, 5) == "metal") k += h; } cout << k << 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 java.util.*; import java.io.*; public class stringsOfPower { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String s = sc.next(); ArrayList<Character> al = new ArrayList<>(); for(int i = 0; i <= s.length() - 5; i++){ if(s.substring...
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; int i; cin >> s; vector<int> a1, a2; if (s.length() < 5) { cout << 0 << endl; return 0; } for (i = 0; i < s.length() - 4; i++) { if (s[i] == 'h' && s.substr(i, 5) == "heavy") { a1.push_back(i); } else if (s[i] == '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
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String word = scanner.next(); int heavy = 0; long number = 0; for (int i = 0; i <= word.length() - 5; i++) { String temp = word.subs...
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; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Sanchit M. Bhatnagar (sanchitbhatnagar@gmail.com) */ public class Main {...
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
str=raw_input() l=len(str) num=0 val=0 for i in range (l-4): if str[i]=='h' and str[i+1]=='e' and str[i+2]=='a' and str[i+3]=='v' and str[i+4]=='y': num+=1 if str[i]=='m' and str[i+1]=='e' and str[i+2]=='t' and str[i+3]=='a' and str[i+4]=='l': val+=num print val
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; vector<int> a; string temp1 = "heavy"; string temp2 = "metal"; int pos = 0; int i = 0; while (i < s.length()) { if (s[i] == 'h') { pos = 0; while (pos < 5 && i < s.length() && s[i] == temp1[pos]) { ++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() res = 0 h = 0 for i in range(len(s)): if s[i:i+5] == 'heavy': h += 1 elif s[i:i+5] == 'metal': res += h 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
s=input() def heavy(s,i): if i-4>=0 and s[i]=='y' and s[i-1]=='v' and s[i-2]=='a' and s[i-3]=='e' and s[i-4]=='h': return 1 return 0 def metal(s,i): if i-4>=0 and s[i]=='l' and s[i-1]=='a' and s[i-2]=='t' and s[i-3]=='e' and s[i-4]=='m': return 1 return 0 a=0 count=0 i=len(s)-1 while i>0: if metal(s,i...
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 Main{ public static void main(String[] args) { Scanner s=new Scanner(System.in); // String str=s.next(); Queue<Integer> heavy =new LinkedList<>(); Queue<Integer> metal =new LinkedList<>(); //heavy metals checking int i,j; i=0; while(str.indexOf("heavy",i)!=-1){ 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class StringsOfPower { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); S...
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.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer;...
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() c = 0 answer = 0 s = "".join(reversed(s)) for i in range(len(s) - 4): if s[i:i+5] == "latem": c+=1 elif s[i:i+5] == 'yvaeh': answer += c print(answer)
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 Div2_318B { public static void main(String[] args) { @SuppressWarnings("resource") Scanner in = new Scanner(System.in); String str = in.next(); List<Integer> h = new ArrayList<Integer>(), m = new ArrayList<Integer>(); long cnt = 0; 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
import sys import math # # Turn of Garbage collection. For speed up in program. # import gc; # gc.disable(); inp = raw_input() a = inp.split('heavy') ans = 0 for i, b in enumerate(a): 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
from sys import stdin def main(): cadena =stdin.readline().strip() i = 0 j = i+4 heavy = 0 ans = 0 while j< len(cadena): if cadena[i:j+1] == "heavy": heavy +=1 elif cadena[i:j+1] == "metal": ans += heavy i+=1 j+=1 print(ans) 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
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String word = sc.nextLine(); long heavy=0; long total=0; for (int i = 0; i < word.length() - 4; i++) { if (word.substring(i, i + 5).equals...
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 * from math import * from sys import * s = input() n = len(s) ct = 0 ans = 0 for i in range(n-4): if(s[i:i+5] == "heavy"): ct += 1 elif(s[i:i+5] == "metal"): ans += ct 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; string str; int main() { cin >> str; vector<int> heavy, metal; for (int i = 0; i < max((int)(str.size() - 4), 0); i++) { string str1 = str.substr(i, 5); if (str1 == "heavy") heavy.push_back(i); if (str1 == "metal") metal.push_back(i); } long long a = 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; const long long N = 1e6 + 1; string g; deque<long long> v, vc; long long cnt; void DNM() { cin >> g; if (g.size() < 5) { cout << 0; return; } for (long long i = 0; i < g.size() - 4; i++) { if (g[i] == 'h' and g[i + 1] == 'e' and g[i + 2] == 'a' and ...
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
song, heavy_count, result = input(), 0, 0 for i in range(len(song) - 4): if song[i:i+5] == 'heavy': heavy_count += 1 elif song[i:i+5] == 'metal': result += heavy_count print(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
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3; int cnt1 = 0, cnt2 = 0; long long res = 0; cin >> s1; s1 += " "; for (int i = 0; i < s1.size() - 8; i++) { if (s1.substr(i, 5) == "heavy") cnt1++; if (s1.substr(i, 5) == "metal") res += cnt1; } cout << res <...
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() heavycount = 0 ans = 0 for i in range(len(s)-4): if s[i:i+5]=='heavy': heavycount+=1 elif s[i:i+5]=='metal': ans+=heavycount 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; char s[1000005], *k; int p, q; long long cnt; vector<int> v; int main() { scanf("%s", s); while (NULL != (k = strstr(s + p, "heavy"))) { p = k - s; v.push_back(p); p += 1; } while (NULL != (k = strstr(s + q, "metal"))) { q = k - s; cnt += lower_b...
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 ans = 0; long long sum = 0; for (int i = 0; i < s.size(); i++) { string q = s.substr(i, 5); if (q == "heavy") { ans++; } if (q == "metal") { sum += ans; } } cout << sum; 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
/** * * @author sarthak */ import java.util.*; import java.math.*; import java.io.*; public class rnd188_B { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); ...
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 s = sys.stdin.readline()[:-1] heavy = [] metal = [] for i in range(len(s)-4): #print(s[i]) w = s[i:i+5] #print(w) if w == "heavy" : heavy.append(i) elif w == "metal": metal.append(i) #print(word) #print(index) c = 0 x = 0 for i in range(len(heavy)): for j in rang...
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; #pragma comment(linker, "/STACK:268435456") int main() { string st; cin >> st; if (st.size() <= 5) { cout << 0; return 0; } long h = 0; string s; long long r = 0; long long d = 0; for (long i = 0; i <= st.size() - 5; i++) { s = st.substr(i, 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; long long l, sol, z, c, HEAVY[1000099], METAL[1000099]; char S[1000099]; int main() { scanf("%s", S); l = strlen(S); for (int i = 0; i < l; i++) { if (S[i] == 'h' && S[i + 1] == 'e' && S[i + 2] == 'a' && S[i + 3] == 'v' && S[i + 4] == 'y') { z++; ...
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
x = input() a = "heavy" b = "metal" c = 0 s = 0 for i in range(len(x)-4): if x[i:i+5] == a: c += 1 if x[i:i+5] == b: s += c 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
s=input() l=[] l1=[] j=-3 i=-3 while(True): j=s.find("metal",j+3) if j==-1 : break l.append(j) while(True): i=s.find("heavy",i+3) if i==-1 : break l1.append(i) p=len(l1) k1=0 j1=0 ost=0 out=0 for i in range(len(l)) : if l[i]>ost : for j in range(j1,p) : i...
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 bisect s = input() answer = 0 hpos = [] metpos = [] for i in range(len(s)-4): if s[i:i+5] == "heavy": hpos.append(i+4) for i in range(len(s)-4): if s[i:i+5] == "metal": metpos.append(i) hpos.sort() metpos.sort() s = len(metpos) for pos in hpos: k = bisect.bisect_left(metpos, pos) ...
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 n = s.length(); long long ans = 0, heavy = 0; for (long long i = 0; i < n - 4; i++) { if (s.substr(i, 5) == "heavy") heavy++; if (s.substr(i, 5) == "metal") ans += heavy; } cout << ans << 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
#include <bits/stdc++.h> using namespace std; long long m, ans; string ss, s; long long i; int main() { cin >> s; for (i = 0; i + 4 < s.length(); i++) { ss = s.substr(i, 5); if (ss == "heavy") { m++; } if (ss == "metal") { ans += m; } } cout << ans << 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 java.io.*; import java.util.*; public class Main { StreamTokenizer in; BufferedReader inb; PrintWriter out; String problemname = "success"; public static void main(String[] args) throws Exception { new Main().run(); } public void run() throws Exception { inb = new BufferedReader( // new FileRead...
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() n = len(s) c = [0] * n i = s.find("heavy") while i != -1: c[i] += 1 i = s.find("heavy", i + 1) for i in xrange(n - 1): c[i + 1] += c[i] res = 0 i = s.find("metal") while i != -1: res += c[i] i = s.find("metal", i + 1) 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * */ /** * @author mohanad * */ public class Div2_318B { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(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
z = res = 0 t = input().split('heavy') for i in t: res += i.count('metal')*z; z+=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
line = raw_input() count = 0 for i, h in enumerate(line.split("heavy")): count += i * h.count("metal") print 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
#!/usr/bin/python import re #list2 = [[0 for x in xrange(25)] for x in xrange(25)] #list1 = [[0 for x in xrange(25)] for x in xrange(25)] aString = raw_input() #word="heavy" #if word in test: # print('success') #print test.find('heavy') #print test.rfind('heavy') #print test.find_all('heavy') #list1= [(a.start(), a.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
#include <bits/stdc++.h> using namespace std; int main() { string actual; cin >> actual; long long int l = actual.length(); string h = "heavy"; string m = "metal"; long long int add = 0; long long int ans = 0; for (long long int i = 0; i < l; i++) { if (actual.substr(i, 5) == h) { add++; }...
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
// ~/BAU/ACM-ICPC/Teams/A++/BlackBurn95 import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.Double.parseDouble; import static java.lang.String.*; 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 = raw_input() heavy = [] metal = [] tl = 0 res = 0 re = 0 pos = 0 l = len(s) for x in range(l-4): if s[x:x+5] == "heavy": tl +=1 heavy.append(x) elif s[x:x+5] == "metal": metal.append(x) res = res+tl #print(heavy) #print(metal) 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
def powerful(s): h = "heavy" m = "metal" i = 0 j = 0 dp = "" ans = 0 countH = 0 for it in range(len(s)): if s[it] == h[i]: i+=1 if i == 5: countH+=1 #dp+="h" i = 0 else: if s[it] == h[0]: ...
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> #pragma comment(linker, "/STACK:256000000") using namespace std; int a[1100000]; int b[1100000]; void init() {} int main() { init(); string s; cin >> s; for (int i = 0; i < 1100000; i++) a[i] = 0; for (int i = 0; i < s.size(); i++) { if (s.size() - 1 - i > 0) if (s[i] == 'm'...
CPP