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
str=input() countM=0 countResult=0 for i in range(0,len(str)-4): if(str[i:i+5]=="heavy"): countM=countM+1; elif(str[i:i+5]=="metal"): countResult=countResult+countM; print(countResult)
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 maxn = 1e6 + 10; char s[maxn]; void get_input() { cin >> s; } void solve() { long long ans = 0; long long kom = 0; long long i = 0; while (s[i] != 0) { if (s[i] == 'h') { i++; if (s[i] == 'e') { i++; if (s[i] == '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
s = input() dic = {} l = len(s) i = diclen = sub = 0 while 1: if i<=l-5: if s[i:i+5]=='heavy': dic[i] = 0 diclen += 1 i += 5 elif s[i:i+5]=='metal': sub += diclen 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
a=input() n=len(a) b=[] c=[] y=k=0 for i in range(n-4): if a[i]=='h' : if a[i:i+5]=="heavy": b.append(i) i+=4 k+=1 if a[i]=='m': if a[i:i+5]=="metal": c.append(i) i+=4 y+=k else: i+=1 print(y)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = raw_input() i, h, m = 0, 'heavy', 'metal' ha, ma = [], [] while(i + 5 <= len(s)): if s[i:i + 5] == h: i += 5 ha.append(i) elif s[i:i + 5] == m: i += 5 ma.append(i) else: i += 1 r, n = 0, len(ma) for j in ha: lo, hi = 0, n while(lo < hi): mid = (hi + lo) / 2 if ma[mid] < j: ...
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
ans = 0 s = input() heavy = 0 i = 0 if not len(s) < 5: while i < len(s) - 4: if s[i] == 'h' and s[i + 1] == 'e' and s[i + 2] == 'a' and s[i + 3] == 'v' and s[i + 4] == 'y': heavy += 1 i += 5 elif s[i] == 'm' and s[i + 1] == 'e' and s[i + 2] == 't' and s[i + 3] == 'a' and 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
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long c1 = 0, c2 = 0; for (long long 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') { c1 += 1; } if (s[i] == 'm' && s[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
#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; int main() { string s; cin >> s; vector<int> a, b; if (s.length() < 5) { cout << "0"; return 0; } for (int i = 0; i < s.length() - 4; i++) { if (s[i] == 'h') { if (s.substr(i, 5) == "heavy") a.push_back(i); } } for (int i = 0; i < s.len...
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
r=input() S=r.split('heavy') k=0 for i in range(len(S)) : p=S[i].count('metal') k=k+i*p print(k)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException,InterruptedException{ Scanner sc=new Scanner(System.in); char[] arr=sc.next().toCharArray(); long c=0,cm=0; ArrayList<Character> arrayList=new ArrayList<>(); for (int i = 0; i < arr.length-4...
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 Maxn = 1000 * 1000 + 100; int dp[Maxn]; int main() { string s; long long int k = 0; cin >> s; for (int i = s.size() - 5; i >= 0; i--) { if (s[i] == 'm' && s[i + 1] == 'e' && s[i + 2] == 't' && s[i + 3] == 'a' && s[i + 4] == 'l') { dp[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.util.*; import java.io.*; import java.math.*; /* javac Main.java java Main > a.txt */ public class Main { public static void process()throws IOException { String s=nn(); int len=s.length(); int l=0,h=len-5; long freq=0; long ans=0; if(!s.contains("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
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s=in.next(); int heavy=0; long metal=0; int i; for(i=4;i<s.length();++i) { if(s.charA...
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 gcd(int a, int b) { if (b > a) return gcd(b, a); return b == 0 ? a : gcd(b, a % b); } int main() { char s[1000001]; scanf("%s", s); long long int i, count = 0, ans = 0; for (i = 0; i < strlen(s); i++) { if (strncmp(s + i, "heavy", 5) == 0) { count+...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
a = raw_input() count, end = 0, 0 for i in range(0, len(a)): if a[i:(i+5)] == 'heavy': count += 1 elif a[i:(i+5)] == 'metal': end += count print end
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 10, MAX = 2e5 + 1e4, MOD = 1e9 + 7; void OUT(long double o, int x) { cout << fixed << setprecision(x) << o; return; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; long long x = 0, z = 0; for...
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 JavaApp { public static Scanner in = new Scanner(System.in); public static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { String s = in.next(); String d; long ans = 0, H = 0; for ...
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() metalPositions = [] i = 0 while True: i = s.find("metal", i) if i == -1: break; metalPositions.append(i) i += 5 count = 0 beg = 0 i = 0 while True: i = s.find("heavy", i) if i == -1: break i += 5 for j in range(beg, len(metalPositions)): if metalPosi...
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
h,v=0,0 a=b='z'*5 for c in raw_input(): a,b=a[1:]+c,b[1:]+c h+=a=='heavy' v+=(b=='metal')*h print v
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import re import sys import bisect def find_gt(a, x, l): i = bisect.bisect_right(a, x) if i != len(a): return i return l l = sys.stdin.readline() h = [m.start() for m in re.finditer("heavy", l)] m = [m.start() for m in re.finditer("metal", l)] count = 0 l = len(m) for x in h: count += l - find_gt(m, x,...
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/env python import re def main( ): l = input( ) heavyCnt = 0 res = 0 for i in range( 4, len( l ) ): if l[ i - 4 : i + 1 ] == "heavy": heavyCnt += 1 if l[ i - 4 : i + 1 ] == "metal": res += heavyCnt print( res ) if __name__ == '__main__': 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.*; import java.io.*; public class String_of_power { private static int next(ArrayList<Integer> arr, int target) { int start = 0, end = arr.size() - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; // Move to...
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() n = len(s) ans = 0 m = 0 for i in range(n - 5, -1, -1): if s[i:i + 5] == "metal": m += 1 elif s[i:i + 5] == "heavy": ans += m 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; const long long int mod = 1000000007; const long long int mymax = 1e18; const long long int mymin = -1e18; const double PIE = 3.1415926536; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s, a = "heavy", b = "metal"; cin >> s; long int slen = s.lengt...
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 oo = (int)(1e9); const long double PI = 3.141592653589793; int PP = 1000000007; const int MAXN = 111111 * 2, MAXE = 111111; template <typename TT> void read(TT &x) { char ch; for (ch = getchar(); ch > '9' || ch < '0'; ch = getchar()) ; for (x = 0; ch >= ...
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() p = 0 for i,c in enumerate(s.split('heavy')): p += c.count('metal') * i print p
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; string str; int main() { ios_base::sync_with_stdio(0); getline(cin, str); long long res = 0; long long hv = 0; for (int i = 0; i + 5 <= str.size(); i++) { if (str.substr(i, 5) == "heavy") hv++; if (str.substr(i, 5) == "metal") res += hv; } 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
import java.util.Scanner; public class HeavyMetal { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String test = scan.next(); int h = 0; long ans = 0; for (int i = 5; i <= test.length(); i++) { if ( test.substring(i-5, i).equals("heavy") ) ++h; else if ( test.su...
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.*; //Codeforces public class Codeforces1 { private static MyScanner in; private static PrintStream out; private static boolean LOCAL_TEST = false; private static void solve() throws IOException { String s = in.nextString(); long cnt = 0; ArrayList<Integer> heavyPos = new 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
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e6 + 10; const string t = "heavy", tt = "metal"; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; ll ans = 0; map<string, ll> mp; if (s.size() < 5) cout << 0 << endl, exit(0); else ...
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 s = sys.stdin.readline().split("heavy") metals = 0 total = 0 for i in xrange(len(s) - 1, 0, -1): metals = metals + s[i].count("metal") total = total + metals 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
s=input() n=len(s) ans,cnt=0,0 for i in range(n-4): if s[i:i+5]=="heavy":cnt+=1 elif s[i:i+5]=='metal':ans+=cnt 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
def cal(heavy, metal): Res = 0 for i in range(len(heavy)): left = 0 right = len(metal) - 1 while left <= right: mid = (left + right) // 2 if metal[mid] > heavy[i]: if (metal[mid - 1] < heavy[i]) | (mid == 0): Res = Res + len(met...
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 B { public static void main(String[] args) throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); char s[]=reader.readLine().toCharArray(); long heavyCount=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
import java.util.Scanner; public class StringsOfPower { static char[] arr; public static void main(String[] args) { Scanner sc = new Scanner(System.in); arr = sc.nextLine().toCharArray(); long add = 0; long result = 0; for (int i = 0; i < arr.length; i++) { if(heavy(i)) { add++; 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=input() c=0;t=0; for i in range(len(s)): if s[i:i+5]=="heavy": c+=1 elif s[i:i+5]=="metal": t+=c print(t)
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() lens = len(s) x,ans,i = [0]*3 while(i<len(s)): if(s[i:i+5]=="heavy"): x+=1 if(s[i:i+5]=="metal"): ans+=x i+=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 sys from collections import Counter input = sys.stdin.readline printt = sys.stdout.write ############ ---- Input Functions ---- ############ def aa(): #for int return(int(input())) def bb(): #for int arr return(list(map(int,input().split()))) def cc(): #for string s = input() return s #(list(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() n=len(s) i=0 heavycount=0 totalcount=0 while i<=n-5: if s[i:i+5]=="heavy": heavycount=heavycount+1 #print("heavy",heavycount) i=i+5 elif s[i:i+5]=="metal": totalcount=totalcount+heavycount #print("metal",totalcount) i=i+5 else: i=i+1 print(t...
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 om { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String x=sc.next().replace("heavy",".").replace("metal","?"); int dot=0; long ans=0; for(int i=0;i<x.length();i++){ if(x.charAt(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.InputStreamReader; import java.lang.reflect.Constructor; import java.util.Arrays; import java.util.StringTokenizer; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author utp */ public class CodeB { ...
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 fast_power_mod(long long b, long long p, long long m) { if (p == 0) return 1; long long res = fast_power_mod(b, p / 2, m) % m; if (p % 2 == 0) return ((res) * (res)) % m; else return ((res) * (res) * (b % m)) % m; } long long arthmetic_seq_sum(long...
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 c = 0, k = 0; cin >> s; if (s.length() < 5) { cout << 0 << endl; return 0; } for (int i = 0; i < s.length() - 4; i++) { if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[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.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class B { public static void main(String...
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.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Scann...
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
#itne me hi thak gaye? from bisect import bisect_left s = input() h = [i for i in range(len(s)) if s.startswith('heavy', i)] m = [i for i in range(len(s)) if s.startswith('metal', i)] # print(h, m) ans = 0 for i in h: ans += len(m) - bisect_left(m, 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
s = raw_input(); len_s = len(s) heavy_amount, all = 0, 0; for i in xrange(len_s-4): if s[i:i+5] == "heavy": heavy_amount += 1; elif s[i:i+5] == "metal": all += heavy_amount; print all;
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.ArrayList; import java.util.Arrays; public class Main { static int [] heavyar; static int [] metalar; static int found=-1; public static void main(String [] args) throws IOException { BufferedReader b...
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 n, i, j, cnth = 0, cntm = 0, flag1 = 0, flag2 = 0; long long ans = 0; 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') { ...
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,b=0,0 n=len(s) for i in range(n): if(s[i:i+5]=='heavy'): a=a+1 elif(s[i:i+5]=='metal'): b=b+a print(b)
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[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; string str; int n; bool arr[1100000], brr[1100000]; long long cum[1100000]; void check(int idx) { if (idx + 5 <= str.size()) { if (str.substr(idx, 5) == string("heavy")) arr[idx] = 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
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) { Scanner scan = new Scanner(System.in); char[] s = scan.nextLine().toCharArray(); ArrayList<Int...
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 maxINT = 998244353; vector<int> kmp(string p, string cur) { string s = p + "#" + cur; int n = s.length(); vector<int> v(n); vector<int> ans; for (int i = 1; i < n; ++i) { int j = v[i - 1]; while (j != 0 && s[i] != s[j]) { j = v[j - 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
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int r = 0; int z = a.size(); long long int x = 0; for (int i = 0; i <= z;) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') { r++; i += 4; } else if (a[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; const int maxn = 1e6; bool a[maxn]; long long j = 0; string s; long long ans = 0; int main() { cin >> s; if (s.length() < 5) { printf("0\n"); return 0; } for (long long i = 0; i <= s.length() - 5; ++i) { if (s.substr(i, 5) == "heavy") a[j++] = 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
import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main extends PrintWriter { BufferedReader in; StringTokenizer stok; final Random rand = new Random(31); final int inf = (int) 1e9; final long linf = (long) 1e18; boolean f(char[] s, int off, char[] t) { ...
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> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") const int INF = 1e9; const int N = 2e5 + 5; using namespace std; int Exp(int x, int y) { int ans = 1; for (int i = 1; i <= y; i++) ans *= 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
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<int> pre; vector<int> post; for (int i = 0; i < s.length(); i++) { string p = ""; if (s[i] == 'h') { int j = i; int hl = 5; while (j < s.length() && hl) { p += s[j]; j++; hl-...
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; import java.util.LinkedList; public class StringsofPower { public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.nextLine(); s = s.replaceAll("heavy", "#"); s = s.replaceAll("metal", "*"); long numOfMetal = 0; for (int i = 0; i < s.len...
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; vector<int> start; vector<int> e; void find(string s) { string a; for (int i = 0; i <= (int)s.size() - 5; i++) { a = ""; a += s[i]; a += s[i + 1]; a += s[i + 2]; a += s[i + 3]; a += s[i + 4]; if (a == "heavy") { start.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
#include <bits/stdc++.h> using namespace std; char h[6] = "heavy"; char m[6] = "metal"; char s[1000005]; int main() { scanf("%s", s); int len = strlen(s); int i, j; i = j = 0; long long ans = 0; for (int k = 0; k < len; k++) { if (s[k] == h[0] && s[k + 1] == h[1] && s[k + 2] == h[2] && s[k + 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
def sol(s): h = "heavy" m = "metal" i = 0 j = 0 occ = "" for c in s: if c == h[i]: if i == len(h)-1: occ+="h" i = 0 else: i+=1 else: if c == h[0]: i = 1 else: ...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
//package codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; /** * Created with IntelliJ IDEA. * User: ANURAG * Date: 6/22/13 * Time: 12:32 AM * To change this template use...
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() { char s[1000009]; vector<int> v; scanf("%s", s); int i, j; long long int S = 0; for (i = 0; s[i]; 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); 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
import re from collections import OrderedDict I=lambda:map(int, raw_input().split()) s=raw_input() x=[a.start() for a in list(re.finditer('heavy', s))] y=[a.start() for a in list(re.finditer('metal', s))] d=OrderedDict() prev=0 for a in x: d[a]=prev+1 prev=d[a] ans=0 items=d.items() n=len(items) i=0 for a in y:...
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 binary_search(int *arr, int n, int x) { int l = 0, r = n - 1, mid, ans = n; while (l <= r) { mid = (l + r) / 2; if (arr[mid] > x) { r = mid - 1; ans = mid; } else l = mid + 1; } return ans; } int main() { string s; cin >> 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
import java.io.*; import java.util.*; public class Main { FastReader scn; PrintWriter out; String INPUT = ""; void solve() { char[] arr = scn.next().toCharArray(); String h = "heavy", m = "metal"; int n = arr.length; StringBuilder sb = new StringBuilder(); int M = 0; for(int i = 0; i <= n - 5; i++) { ...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr(): s=input() n=len(s) cnt=ans=0 for i in range(n): if s[i-4:i+1]=='heavy':cnt+=1 if s[i-4:i+1]=='metal':ans+=cnt 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 { static String s; static long cnt = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); s = sc.next(); long sum = 0; for (int i = 0; i + 4 < s.length(); i++) { if ("heavy".equals(s.substring(i, i + 5))) { cnt++; } if ("m...
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,a ,ans = raw_input(),0 ,0 for i in xrange(len(s)-4): if s[i:i+5] == "heavy" : a+=1 elif s[i:i+5]=='metal': ans += a 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; public class B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char[] str = br.readLine().toCharArray(); 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
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import java.util.St...
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.awt.image.RescaleOp; import java.io.BufferedInputStream; import java.io.BufferedReader; 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.HashMap; import java.util...
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 = raw_input() s = sys.stdin.readline() #heavy = [] heavy_num = 0 total_sum = 0 n = len(s) i = 0 while i < n - 4: if s[i] == 'h': if s[i+1] == 'e': if s[i+2] == 'a': if s[i+3] == 'v': if s[i+4] == 'y': i += 5 ...
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; vector<string> pos; int main() { string str; while (cin >> str) { pos.clear(); for (int i = 0; i < str.size(); i++) { string flag = str.substr(i, 5); if (flag == "heavy") { pos.push_back("h"); i += 4; } else if (flag == "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() { string str; cin >> str; long long int h = 0, ans = 0, i; int len = (int)str.size(); for (int i = 0; i < len; i++) { if (str[i] == 'h' && str[i + 1] == 'e' && str[i + 2] == 'a' && str[i + 3] == 'v' && str[i + 4] == 'y') { h++; 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.util.*; import java.util.concurrent.ScheduledExecutorService; import java.io.*; import java.lang.*; import java.math.*; public class CodeChef { public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in); String str=scan.next(); int n= str.length(); 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
s=input() sum=0 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
import java.io.BufferedReader; import java.io.IOException; import java.util.Scanner; public class ProB { static BufferedReader br; static long count = 0; public static void main(String[] args) { Scanner cin = new Scanner(System.in); try { check(cin.next().toCharArray()); } catch (IOException e) { e.pri...
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.util.ArrayList; import java.util.Arrays; /** * * @author Donato */ public class StringsOfPower { public static long base = 128L; public static int tope = 1000000+10; static long[] powB = new long[top...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long ans = 0, h = 0; if (s.size() < 10) { cout << 0 << endl; return 0; } for (int i = 0; i < s.size() - 4; i++) { if (s.substr(i, 5) == "heavy") { h++; } if (s.substr(i, 5) == "metal") { 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
s = raw_input() str = "" for i in xrange(len(s)-4): t = s[i:i+5] if t == "heavy": str += "1" elif t == "metal": str += "2" count_1 = 0 res = 0 for num in str: if num == "1": count_1 += 1 elif num == "2": res += count_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 io,os,sys,atexit input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline @atexit.register def write(): sys.__stdout__.write(io.StringIO().getvalue()) from collections import deque as que, defaultdict as vector from bisect import bisect as bsearch from heapq import* inin = lambda: int(input()) inar = lambda...
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, math def rs(): return sys.stdin.readline().strip() def ri(): return int(sys.stdin.readline().strip()) def ras(): return list(sys.stdin.readline().strip()) def rai(): return map(int,sys.stdin.readline().strip().split()) def solve(): s = rs() s = s.replace("heavy", "$").replace("me...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long int N = s.length(); string a = "heavy"; string b = "metal"; vector<int> hea; vector<int> me; for (int i = 0; i < N; i++) { if (s[i] == 'h') { string init = ""; if (i + 4 < N) { for (int j = 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() { string s; cin >> s; long long h = 0, m = 0; for (long long i = 0; i < s.size(); i++) { if (s.substr(i, 5) == "heavy") h += 1; else if (s.substr(i, 5) == "metal") m += h; } cout << m << "\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
#include <bits/stdc++.h> using namespace std; int gcd(int m, int n) { if (m % n == 0) return n; else gcd(n % m, m); } int main() { string a; while (cin >> a) { long long i, j, k, s = 0, p = 0, l; l = a.size(); for (int i = 0; i < l; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[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 os from math import* s=input() ch=0 cm=0 ans=[] z=0 for i in range(len(s)-4): if s[i:i+5]=="heavy": z=1 ans.append(ch*cm) cm=0 ch+=1 elif s[i:i+5]=="metal": if z==1: cm+=1 ans.append(ch*cm) #print(ans) print(sum(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() mask1 = "heavy" mask2 = "metal" index1= [] index2 = [] def smallestbigger(arr, left, right, element): if left == right: return left if left < right: mid = (left+right)//2 if arr[mid] == element: return mid if arr[mid] > element: return small...
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 re data = raw_input() a = 'heavy' b = 'metal' apos = [m.start() for m in re.finditer(a, data)] bpos = [m.start() for m in re.finditer(b, data)] result = 0 if len(apos) and len(bpos): i = j = 0 while j<len(bpos): while i<len(apos) and apos[i] < bpos[j]: i += 1 result += 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 sys text = sys.stdin.readline().strip() i = 0 heavys = 0 result = 0 while (i + 5) <= len(text): if text[i:i+5] == "heavy": heavys +=1 i += 5 elif text[i:i+5] == "metal": result += heavys i += 5 else: i += 1 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
import java.util.Scanner; public class cf{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); String s=sc.next(),t=""; int heavy=0,metal=0,temp=0; long cnt=0L; for(int i=0;i<s.length()-4;i++){ t=s.substring(i,i+5); if(t.equals("heavy")){ temp++; i+=4; } else if(t...
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.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; import static java.lang.Math.*; public class Main { public static void solve(FastScanner fscan, BufferedWriter bw) throws IOException { String s = fscan.nextLine(); long ans = 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
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long ans = 0, cnt = 0; for (long long i = 0; i < s.size(); i++) { string check = s.substr(i, 5); if (check == "heavy") cnt++; if (check == "metal") ans += cnt; } cout << ans; return 0; }
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long int ans = 0, c = 0; for (int i = 4; i < s.length(); i++) { if (s[i] == 'l' && s[i - 4] == 'm' && s[i - 3] == 'e' && s[i - 2] == 't' && s[i - 1] == 'a') ans += c; else if (s[i] == 'y' && s[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
s = raw_input() n = len(s) ends = 0 for i in xrange(n): t = s[i:i+5] if t == 'metal': ends += 1 answer = 0 for i in xrange(n): t = s[i:i+5] if t == 'heavy': answer += ends if t == 'metal': ends -= 1 print answer
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string get() { char ch[1000010]; scanf("%s", ch); return ch; } const int MAX_LG = 21; const long long maxn = 1e3 + 10; const long long base = 29; const long long mod = 1e9 + 7; const long long INF ...
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 s = sys.stdin.readline() l = len(s) i = length = sub = 0 while 1: if i<=l-5: if s[i]=='h': i += 1 if s[i]=='e': i += 1 if s[i]=='a': i += 1 if s[i]=='v': i += 1 ...
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() heavy = 0 answer = 0 for i in range(len(str) - 4): if (str[i:i+5] == "heavy"): heavy+=1 elif (str[i:i+5] == "metal"): answer += heavy print answer
PYTHON