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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class HeavyMetal { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); ...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 1; const long long mod = 1e9 + 7; const long long INF = 1e10; const long long M = (1 << 17) + 1; const long long LL = 1; string second; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> second; long long int c...
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 N = 1000010; const char sx[] = "heavy", sy[] = "metal"; char a[N]; int l, x, y; long long cnt, ans; inline bool check1(int pos) { for (int i = pos, j = 0; j < 5; i++, j++) if (a[i] != sx[j]) return false; return true; } inline bool check2(int pos) { 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
sentence = raw_input() sentence = sentence.replace('heavy','+') sentence = sentence.replace('metal','-') num = 0 result = 0 for char in sentence: if char=='+': num = num + 1 if char=='-': result+=num print result
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() c=ans=0 for i in range(len(s)-4): if s[i:i+5] == 'heavy': c+=1 elif s[i:i+5] == 'metal': ans+=c print(ans)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string a; vector<long long int> x, y; cin >> a; long long int n = a.size(); for (long long int i = 0; i < n - 4; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') x.push_back(i); ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = input() i, heavy, count = 0, 0, 0 while i < len(s): if s[i:i+5] == "heavy": heavy += 1 i += 5 elif s[i:i+5] == "metal": count += heavy i += 5 else: i += 1 print(count)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; string s; bool is_heavy(int i) { if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') return 1; return 0; } bool is_metal(int i) { if (s[i] == 'm' && s[i + 1] == 'e' && s[i + 2] == 't' && s[i + 3] == 'a' && 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
s=input() h=[] m=[] for i in range(len(s)-4): if(s[i:i+5]=='heavy'): h.append(i) for i in range(len(s)-4): if(s[i:i+5]=='metal'): m.append(i) l=0 r=0 total=0 while(l<len(h) and r<len(m)): if(m[r]>h[l]): total+=len(m)-r l+=1 else: r+=1 print(total)
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 s = raw_input() n = len(s) c = [0] * n for m in re.finditer("heavy", s): c[m.start()] += 1 for i in xrange(n - 1): c[i + 1] += c[i] res = 0 for m in re.finditer("metal", s): res += c[m.start()] 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
/** * Created with IntelliJ IDEA. * User: akashm * Date: 6/15/13 * Time: 12:08 AM * To change this template use File | Settings | File Templates. */ import java.util.*; public class B318 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine();...
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.Arrays; import java.util.Scanner; import java.lang.String; import java.lang.reflect.Array; import java.util.ArrayList; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); char[] p = s.toCharArray(); ...
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() ans=0 s=s.replace("heavy","1") s=s.replace("metal","2") heavy=[] metal=[] n=len(s) for i in range(n): if(s[i]=="1"): heavy.append(i) elif(s[i]=="2"): metal.append(i) n=len(heavy) nn=len(metal) x=0 l=nn for item in heavy: for i in range(x,nn): if(metal[i]>item): ...
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
str1 = input() heavycount = 0 sol = 0 i = 0 while i < len(str1)-4: if str1[i] == 'h': if str1[i:i+5] == 'heavy': heavycount += 1 if str1[i] == 'm': if str1[i:i+5] == 'metal': sol += heavycount i+=1 print(sol)
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.ArrayList; import java.util.Arrays; import java.util.Scanner; public class B138 { public static void main(String[] args){ Scanner in = new Scanner(System.in); String s = in.nextLine(); ArrayList<Integer> a = new ArrayList<>(); ArrayList<Integer> b = new ArrayList<>()...
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
/*** * ██████╗=====███████╗====███████╗====██████╗= * ██╔══██╗====██╔════╝====██╔════╝====██╔══██╗ * ██║==██║====█████╗======█████╗======██████╔╝ * ██║==██║====██╔══╝======██╔══╝======██╔═══╝= * ██████╔╝====███████╗====███████╗====██║===== * ╚═════╝=====╚══════╝====╚══════╝====╚═╝===== * ===...
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.InputStreamReader; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner r=new Scanner(new InputStreamReader(System.in)); String a=r.nextLine(); long l=a.length()-4,h=0,o=0; for(int j=0;j<l;j++){ String t=a.substri...
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
#kisi "metal" substring ke pehle jitne bhi "heavy" substring aayenge #wo utna count badhayega... nd so on... # s=raw_input() sub="aaaaa" count=a=0 for x in s: sub=sub[1:]+x if sub=="heavy": a+=1 if sub=="metal": count+=a 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; // String of Power : Codeforces // status : WA public class StringPower { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String 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
print(sum(i * s.count('metal') for i, s in enumerate(input().split('heavy'))))
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> heavies; vector<int> metals; int Greaters(int left, int right, int input) { int ans = 0; if (left == right - 1) { if (input <= metals[left]) { ans++; } return ans; } int mid = (left + right) / 2; if (metals[mid] >= input) { ans +=...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import sys def solve(string): str1 = 'heavy' str2 = 'metal' start = string.find(str1) end = string.rfind(str2) if start == -1 or end == -1: return 0 string = string[start+len(str1):end] data = {-1:True, len(string): False} pos = -1 cnt1 = 1 while True: pos = s...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
st=input() l=len(st) h=0 c=0 for i in range(0,l): if((i+5)<=l): if(st[i:i+5]=="heavy"): h=h+1 elif(st[i:i+5]=="metal"): c=c+h print(c)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package pkg188; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; /** * * @author Alik */ public class B { static String line; static int cur = 0; public static...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
L = "heavy" R = "metal" D = 0 AL = 0 # drop until first L # if no L then return D = 0 # split rest by L # set some AL to 0 # in [1, ..] pieces each # x = count R # add x to D # multiply x and AL and add to D # increment AL # return D s = raw_input() drop_index = s.find(L) if drop_index != -1: rest = s[drop_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
z=r=0 for w in input().split("heavy"): r+=w.count("metal")*z 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
st = input() p = 0 ans = 0 for i in range(len(st) - 4): if st[i:i+5] == 'heavy': p += 1 if st[i:i+5] == 'metal': ans += p 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().strip() ans = 0 head = 0 for i in range(4, len(s)): if s[i - 4: i + 1] == "heavy": head += 1 if s[i - 4: i + 1] == 'metal': ans += head print(ans)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s1; cin >> s1; long long heavy_count = 0, ans = 0; if (s1.size() > 5) { for (int i = 0; i < s1.size() - 5 + 1; i++) { if (s1[i] == 'h' && s1[i + 1] == 'e' && s1[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 java.util.Scanner; public class B { /** * @param args */ public static void main(String[] args) { Scanner sc=new Scanner(System.in); char[]s = sc.next().toCharArray(); long ans=0; long heavy=0; for(int i=0;i<s.length;i++){ if(isHeavy(s,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 str; while (cin >> str) { long long int sum, i, temp; sum = temp = 0; for (i = 0; i < str.size(); i++) { if (str[i] == 'h' && str[i + 1] == 'e' && str[i + 2] == 'a' && str[i + 3] == 'v' && str[i + 4] == 'y') { 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.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Trung Pham */ public class B { public 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.util.*; public class cf318B{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); String inp = sc.next(); int startIndx = 0; long count=0,heavy_cnt =0; int heavy_index = 0; int metal_index = 0; int heavy_index_o...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
a=input() b=0 c=0 for i in range(len(a)-4): if a[i:i+5]=='heavy':b+=1 if a[i:i+5]=='metal':c+=b print(c)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.*; import java.io.*; public class metalheavy{ public static void main(String args[]) throws IOException{ BufferedReader lector = new BufferedReader(new InputStreamReader(System.in)); String tmp = lector.readLine(); long a = 0; long b = 0; for(int n =0;n<=tmp.length()-5;n+=5){ if(tmp.substring(n,n+5).eq...
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 a[1000000]; cin >> a; if (strlen(a) < 5) { cout << 0 << endl; return (0); } long long i, j = 0, l, ans = 0; for (i = 0; i < strlen(a) - 4; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int N = s.size(); long long heavy = 0, sum = 0; for (int 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') heavy++; else if (heavy > 0 && s[i...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; long long int i, length, cnt = 0, res = 0; length = a.size(); for (i = 0; i < length; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') cnt++; 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; int main() { string str; while (cin >> str) { long long sum = 0, heavy = 0; string temp; for (int i = 0; i < str.size(); i++) { temp = str.substr(i, 5); if (temp == "heavy") heavy++, i += 4; else if (temp == "metal") sum += ...
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 StringsOfPower { static char[] arr; public static void main(String[] args) { Scanner sc = new Scanner(System.in); // arr = sc.nextLine().toCharArray(); String s = sc.nextLine(); s = s.replaceAll("metal", ","); s = s.replaceAll("heavy", "."); long add = 0; long res...
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(int argc, char** argv) { string s; unsigned long long n = 0; cin >> s; unsigned long long cnt = 0; size_t pos = 0; while (pos < s.size()) { if (s.compare(pos, 5, "heavy") == 0) { cnt++; pos += 5; } else if (s.compare(pos, 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
s=raw_input() n=len(s) looper=0 ans=0 for i in range(n-4): if s[i:i+5]=="heavy": looper+=1 elif s[i:i+5]=="metal": ans+=looper 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
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.*; import java.math.*; import java.io.*; /** * * @author magzhan */ public class Cf { public final stati...
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.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class test { static int MAX = 1000001; public static void main(String[] argvs) throws Exception{ FastScanner scan = new FastScanner(System.in); String in = scan....
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 Str[1000005] = {}; cin >> Str; long long len = strlen(Str); long long Total = 0; long long Count = 0; for (long long i = 0; i < len;) { if ((Str[i] == 'h') && (Str[i + 1] == 'e') && (Str[i + 2] == 'a') && (Str[i + 3] == 'v') && (Str...
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
# coding=utf-8 print(sum(i * s.count('metal') for i, s in enumerate(input().split('heavy'))))
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 s; long long ans, numo; int main() { cin >> s; if (s.length() < 10) { cout << 0; 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] == '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
def main(): l = [] for s in input().split('heavy')[1:]: l.append(0) for ss in s.split('metal'): l.append(1) del l[-1] res = a = 0 for t in l: if t: res += a else: a += 1 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
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) string s, s1; int p[1100000]; int e1[200010], e2[200010], l1, l2; long long r; int n; void sub() { int k = 0; p[0] = 0; for (int i = 1; i < n; i++) { while (k > 0 && s[i] != s[k]) k = p[k - 1]; if (s[i] == s[k]) k++; p[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 sys import fractions import string a = raw_input() a = a.replace('heavy', '0') a = a.replace('metal', '1') current = a.count('1') ret = 0 for c in a: if c == '0': ret += current elif c == '1': current -= 1 print ret
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; char s[1000010]; int ss[1000010]; int main() { int u = 0, v = 4, k = 0, l = 0, r = 0; int c = 0, d = 0; long long sum = 0; char s1[] = {"heavy"}; char s2[] = {"metal"}; scanf("%s", s); int p = strlen(s); while (v <= p - 1) { for (int i = u, j = 0; i <= v...
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
st=raw_input() heavy=0 count=0 for i in range(len(st)-4): if st[i:i+5] == 'heavy': heavy+=1 if st[i:i+5] == 'metal': count+=heavy 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
import java.util.Scanner; public class Codeforce { public static void main(String [] args){ Scanner in = new Scanner(System.in); String s = in.nextLine(); String temp; long ans=0, k=0; for(int i=0; i<s.length()-4; i++){ temp = s.substring(i,i+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
import java.util.*; import java.io.*; public class b188 { public static void main(String args[]) { String text; Scanner sc = new Scanner(System.in); text= sc.next(); int number=0; int heavyindex=0; int metalindex=0; int totalheavy=0; long totalmetal=0; int lastheavy = text.indexOf("heavy"); 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
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int a[N], b[N]; char s[N]; int main() { scanf("%s", s + 1); int n = strlen(s + 1); memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { if (s[i] == 'm' && s[i + 1] == 'e' && s[i + 2] == 't' && s[i + 3] == 'a' && s[i + 4] == 'l')...
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() t,r=0,0 for i in range(5,len(s)+1): t+=(s[i-5:i]=='heavy') r+=t*(s[i-5:i]=='metal') 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
#include <bits/stdc++.h> using namespace std; long long cnt, ans, i, j, temp, flag; string s, heavy = "heavy", metal = "metal"; int main() { cin >> s; for (i = 0; i < s.length(); i++) { temp = i; flag = 0; for (j = 0; j < 5; j++) { if (s[temp] == heavy[j]) ++temp; else break;...
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 h[1001000]; int m[1001000]; string s; int main() { cin >> s; int t1 = 0; int t2 = 0; for (int i = 0; i < (signed)s.length() - 4; i++) { if (s.substr(i, 5) == "heavy") h[t1++] = i; if (s.substr(i, 5) == "metal") m[t2++] = i; } long long resp = 0; in...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.*; import java.util.*; public class Woodcutters { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new Data...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
ans = 0 s = raw_input() heavy = 0 i = 0 if len(s) >= 5: while i < len(s) - 4: if s[i:i+5] == 'heavy': heavy += 1 i += 5 elif s[i:i+5] == 'metal': ans += heavy i += 5 else: 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
z=r=0 for w in input().split("heavy"):r+=w.count("metal")*z;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
string = input() n = len(string) havyMetals = [] for i in range(n): if i < n - 4: if string[i:i+5] in ["heavy", "metal"]: havyMetals.append(string[i:i+5]) counts = [[0, 0]] for i in range(len(havyMetals)): if havyMetals[i] == "heavy": counts.append([counts[-1][0] + 1, counts[-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
import re line = raw_input().strip() heavy = [(m.start(), 'h') for m in re.finditer('heavy', line)] metal = [(m.start(), 'm') for m in re.finditer('metal', line)] ls = heavy + metal ls.sort(key=lambda x: x[0]) metal_count = len(metal) cur_metal_count = metal_count ans = 0 for x in ls: if x[1] == 'h': 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.IOException; import java.io.InputStream; import java.io.PrintStream; import java.util.Scanner; public class ProblemB { public static void main(String[] args) { ProblemB problem = new ProblemB(); try { problem.solve(System.in, System.out); } catch (IOException e) { // TODO Auto-generated ca...
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 x = -5; long long sum = 0; long long a = 0; long long INF = s.length() + 5; long long z = -1, y = -1; while (x + 5 < s.length()) { long long z1 = z, y1 = y; if (z1 <= y1) z = s.find("heavy", x + 5); if...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.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; public class StringPower { public static void main(String[] args) { ...
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 a; cin >> a; long long f = 0, p = 0; for (int i = 0; i < a.length(); i++) { string s = ""; if (i + 5 <= a.length()) s += a[i], s += a[i + 1], s += a[i + 2], s += a[i + 3], s += a[i + 4]; if (s == "heavy") p++; else if ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = str(input()) n = len(s) hcount = 0 count=0 for i in range(n-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': hcount+=1 if s[i] == 'm' and s[i+1] == 'e' and s[i+2] == 't' and s[i+3] == 'a' and s[i+4] == 'l': count = count + hcount print(count)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s=raw_input() ans=0 a=s.split('heavy') 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
s=raw_input() t=s.split("metal") S=0 for i,j in enumerate(t): a=j.count("heavy") S+=a*(len(t)-1-i) print S
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = raw_input() count = 0 ans = 0 for i in range(len(s)): if s[i:i + 5] == 'heavy': count += 1 elif s[i:i + 5] == 'metal': ans += count 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
//package codeforces; import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import...
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, total, heavy = input(), 0, [] for i in range(len(s)-4): if s[i : i + 5] == 'heavy' : heavy.append(i) if s[i : i + 5] == 'metal' : total += len(heavy) print(total)
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 javafx.beans.NamedArg; import java.io.*; import java.net.Inet4Address; import java.util.Comparator; import java.util.*; /** * @author Yuxuan Wu */ public class Main { public static final int RANGE = 1000000; static int MAX = Integer.MAX_VALUE; static int MIN = Integer.MIN_VALUE; static int MODU...
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.*; import java.io.*; public class prob{ public static void main(String args[]) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); char[] a=st.nextToken().toCharArray(); int currentHeavy=0; int l=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; int main() { char arr[1000001]; cin >> arr; long long int len = strlen(arr); long long int cnt = 0; long long int inc = 0; long long int m = 4; for (long long int i = m; i < len; i++) { if (arr[i - 4] == 'h' && arr[i - 3] == 'e' && arr[i - 2] == 'a' && ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = list(input()) ans, cnt = 0, 0 for i in range(1, len(s) - 3): if s[-i] == 'l' and s[-i - 1] == 'a' and s[-i - 2] == 't' and s[-i - 3] == 'e' and s[-i - 4] == 'm': cnt += 1 elif s[-i] == 'y' and s[-i - 1] == 'v' and s[-i - 2] == 'a' and s[-i - 3] == 'e' and s[-i - 4] == 'h': ans += cnt print(a...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long N = 1e6 + 1; const long long mod = 1e9 + 7; const long double eps = 1E-7; long long n; string s; long long x, a[N]; int main() { ios_base::sync_with_stdio(0); cin >> s; n = s.size(); for (int i = n - 5; i >= 0; i--) { l...
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 static java.lang.Math.*; import java.io.*; public class SolutionB { public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); TreeMap<Integer, Long...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; long long int modular_pow(long long int base, long long int exponent) { long long int result = 1; while (exponent > 0) { if (exponent % 2 == 1) result = (result * base) % 1000003; exponent = exponent >> 1; base = (base * base) % 1000003; } return result;...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = input() heavy = 0 total = 0 i = 0 while i < len(s) - 4: if s[i:i + 5] == 'heavy': i += 5 heavy += 1 elif s[i:i + 5] == 'metal': i += 5 total += heavy else: i += 1 print("%d" % total)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = input().strip().split("metal") l = len(s)-1 found = 0 head = 'heavy' for i in range(l): mt = s[i].count(head) found += mt*(l-i) print(found)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line = reader.readLine(); int len = line.length(); line = line.replace("heavy", "*"); int lenH = line.l...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
line = raw_input() tmp = line result = 0 n = line.count("heavy") m = line.count("metal") arr = [] for i in range(len(line)): if line[i:i+5] == "heavy": result += m elif line[i:i+5] == "metal": m = m-1 print result
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 ans = 0, m = 0, h = 0; vector<char> v; string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (i < s.size() - 4 && s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') { 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
#include <bits/stdc++.h> using namespace std; template <typename T> string toString(T x) { if (x == 0) return "0"; bool negative = x < 0; string res; while (x) { res.push_back('0' + x % 10); x /= 10; } if (negative) res.push_back('-'); reverse(res.begin(), res.end()); return res; } template <typ...
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 f(a): return a*(a+1)//2 x=input() if "heavy" in x: x=x.replace("heavy","@") if "metal" in x: x=x.replace("metal","#") c=0 n=len(x) res=0 for i in range(n): if x[i]=="@": c+=1 if x[i]=="#": res+=c print(res)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long i = 0, a = 0, b = 0; while (i < s.length()) { if (s.substr(i, 5) == "heavy") { a++; i += 5; } else if (s.substr(i, 5) == "metal") { b += a; i += 5; } else ++i; } cout << b; re...
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() total = 0 heavy = [] for i in range(len(s)-4): if s[i:i+5] == 'heavy': heavy.append(i) if s[i:i+5] == 'metal': total += len(heavy) print(total)
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 aprail15 { static class InputReader { private InputStream stream; private byte[] inbuf = new byte[1024]; private int start= 0; private int end = 0; public InputReader(InputStream stream) { this.stream = stream; ...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; string s; long long cnt[1000007], n, res = 0; int main() { cin >> s; n = (long long)s.size(); cnt[0] = 0; for (long long i = 0; i <= (n - 5); ++i) { if (i > 0) cnt[i] = cnt[i - 1]; string t = s.substr(i, 5); if (t == "heavy") ++cnt[i]; } for (long lo...
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() h = 0 ans = 0 i = 0 for i in range(len(s)): if s[i] == "h" and s[i:i+5] == "heavy": h += 1 if s[i] == "m" and s[i:i+5] == "metal": if h >= 1: ans += h print(ans)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { char c[1000000]; long long int heavy_count = 0, result = 0; gets(c); int i = 0; while (i < strlen(c)) { if (c[i] == 'h') { i++; if (c[i] == 'e') { i++; if (c[i] == 'a') { i++; if (c[i] == 'v') { ...
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.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; import java.util.regex.Matche...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.TreeSet; import java.util.*; public class StringsOfPower { BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; ...
JAVA
342_B. Xenia and Spies
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, s, f; cin >> n >> m >> s >> f; map<long long int, pair<long long int, long long int> > hash; int i; long long int mx = INT_MIN; for (i = 0; i < m; i++) { long long int x, y, z; c...
CPP
342_B. Xenia and Spies
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
2
8
import java.io.*; import java.util.*; import java.*; import java.math.BigInteger; public class zad { private static BufferedReader in; private static StringTokenizer tok; private static PrintWriter out; private static String readToken() throws IOException { while (tok == null || !tok.hasMoreTo...
JAVA
342_B. Xenia and Spies
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
2
8
R=lambda:map(int,raw_input().split()) n,m,s,f=R() t=[R() for _ in range(m)]+[[10**9+9,0,0]] a,d=('R',1) if s<f else ('L',-1) i,j,v=1,0,'' while s!=f: b=s+d while t[j][0]<i:j+=1 if t[j][0]==i and ((s>=t[j][1] and s<=t[j][2]) or (b>=t[j][1] and b<=t[j][2])): v+='X' else: v+=a s=b #print i,s,b,f,t[j]...
PYTHON
342_B. Xenia and Spies
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
2
8
#include <bits/stdc++.h> using namespace std; int dir; int n, m, s, f; int tcurr = 1; string ret; int getNext() { if (dir == 0) return s + 1; else return s - 1; } char getNextMove() { if (dir == 0) return 'R'; else return 'L'; } int main() { cin >> n >> m >> s >> f; ret = ""; if (s <= f) ...
CPP
342_B. Xenia and Spies
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
2
8
def kansi(t,tim,x): if tim in t: z = t[tim] if z[0] <= x <= z[1]: return True else: return False else: return False def solver(): n,m,s,f = map(int, raw_input().split()) t = {} for _ in xrange(m): line = map(int,raw_input().split(...
PYTHON