import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

		public class temp
		{
			public static void main(String[] args)
			{
				InputReader in = new InputReader(System.in);
				PrintWriter pw = new PrintWriter(System.out);

				String s = in.nextLine();
				int n = s.length();
				int[] a = new int[n];
				int[] ans = new int[6];
				int count = 0;

				for(int i=0;i<n;i++)
					a[i] = s.charAt(i) - '0';

				int i = 0, j = 0;

				while(i + 2 < n)
				{
					for(j=i;j<i+3;j++)
						ans[j-i] = a[j]%3;

					ans[3] = ans[2];
					ans[2] = (ans[0] + ans[1])%3;
					ans[4] = (ans[1] + ans[2])%3;
					ans[5] = (ans[0] + ans[1] + ans[2])%3;

					for(int k=0;k<6;k++)
					{
						if(ans[k]%3 == 0)
						{
							count++;

							if(k < 2)
								i += k + 1;
							else if(k < 4)
								i += k;
							else if(k == 4)
								i += k - 1;
							else
								i += k - 2;

							break;
						}
					}
				}

				if(i < n)
				{
					if(a[i]%3 == 0)
						count++;

					i++;

					if(i < n)
					{
						if(a[i]%3 == 0)
							count++;
						else if((a[i-1] + a[i])%3 == 0)
							count++;
					}
				}

				pw.println(count);

				pw.flush();
				pw.close();
			}

			static class pair implements Comparable<pair>
			{
				Integer x, y;
				pair(int x,int y)
				{
					this.x=x;
					this.y=y;
				}

				public int compareTo(pair o) {
					int result = x.compareTo(o.x);
					if(result==0)
						result = y.compareTo(o.y);

					return result;
				}

				public String toString()
				{
					return x+" "+y;
				}

				public boolean equals(Object o)
				{
					if (o instanceof pair)
				    {
						pair p = (pair)o;
						return p.x - x == 0 && p.y - y == 0 ;
					}
					return false;
				}

				public int hashCode()
				{
					return new Long(x).hashCode()*31 + new Long(y).hashCode();
				}
			}

			static class InputReader
			{

				private final InputStream stream;
				private final byte[] buf = new byte[8192];
				private int curChar, snumChars;
				private SpaceCharFilter filter;

				public InputReader(InputStream stream)
				{
					this.stream = stream;
				}

				public int snext()
				{
					if (snumChars == -1)
						throw new InputMismatchException();
					if (curChar >= snumChars)
					{
						curChar = 0;
						try
						{
							snumChars = stream.read(buf);
						}
						catch (IOException e)
						{
							throw new InputMismatchException();
						}
						if (snumChars <= 0)
							return -1;
					}
					return buf[curChar++];
				}

				public int nextInt()
			    {
					int c = snext();
					while (isSpaceChar(c))
					{
						c = snext();
					}
					int sgn = 1;
					if (c == '-')
				    {
						sgn = -1;
						c = snext();
					}
					int res = 0;
					do
					{
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = snext();
					} while (!isSpaceChar(c));
					return res * sgn;
				}

				public long nextLong()
			    {
					int c = snext();
					while (isSpaceChar(c))
					{
						c = snext();
					}
					int sgn = 1;
					if (c == '-')
					{
						sgn = -1;
						c = snext();
					}
					long res = 0;
					do
					{
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						res *= 10;
						res += c - '0';
						c = snext();
					} while (!isSpaceChar(c));
					return res * sgn;
				}

				public int[] nextIntArray(int n)
				{
					int a[] = new int[n];
					for (int i = 0; i < n; i++)
					{
						a[i] = nextInt();
					}
					return a;
				}

				public String readString()
			    {
					int c = snext();
					while (isSpaceChar(c))
					{
						c = snext();
					}
					StringBuilder res = new StringBuilder();
					do
					{
						res.appendCodePoint(c);
						c = snext();
					} while (!isSpaceChar(c));
					return res.toString();
				}

				public String nextLine()
				{
					int c = snext();
					while (isSpaceChar(c))
						c = snext();
					StringBuilder res = new StringBuilder();
					do
					{
						res.appendCodePoint(c);
						c = snext();
					} while (!isEndOfLine(c));
					return res.toString();
				}

				public boolean isSpaceChar(int c)
				{
					if (filter != null)
						return filter.isSpaceChar(c);
					return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
				}

				private boolean isEndOfLine(int c)
				{
					return c == '\n' || c == '\r' || c == -1;
				}

				public interface SpaceCharFilter
			    {
					public boolean isSpaceChar(int ch);
				}
			}

			static class CodeX {
	        public static void sort(long arr[]) {
	            merge_sort(arr, 0, arr.length - 1);
	        }

	        private static void merge_sort(long A[], long start, long end) {
	            if (start < end) {
	                long mid = (start + end) / 2;
	                merge_sort(A, start, mid);
	                merge_sort(A, mid + 1, end);
	                merge(A, start, mid, end);
	            }

	        }

	        private static void merge(long A[], long start,long mid, long end) {
	            long p = start, q = mid + 1;
	            long Arr[] = new long[(int)(end - start + 1)];
	            long k = 0;

	            for (int i = (int)start; i <= end; i++) {
	                if (p > mid)
	                    Arr[(int)k++] = A[(int)q++];

	                else if (q > end)
	                    Arr[(int)k++] = A[(int)p++];

	                else if (A[(int)p] < A[(int)q])
	                    Arr[(int)k++] = A[(int)p++];

	                else
	                    Arr[(int)k++] = A[(int)q++];
	            }
	            for (int i = 0; i < k; i++) {
	                A[(int)start++] = Arr[i];
	            }

	        }

	    }
		}


import java.util.*;
import java.io.*;

public class cf496d{
	public static void main(String [] args) throws IOException{
		InputReader in = new InputReader("cf496d.in");

		String s = in.next();
		int [][] arr = new int[s.length() + 1][3];

		for(int i = 0; i < s.length(); i++){
			int num = s.charAt(i) - 48;

			int modded = (arr[i][1] + 2 * arr[i][2]) % 3;

			arr[i + 1][0] +=  arr[i][0];
			if(num % 3 == 0){
				arr[i + 1][0]++;
				continue;
			}
			else{
				if((modded + num) % 3 == 0)
					arr[i + 1][0]++;
				else if(arr[i][3 - num] > 0)
					arr[i + 1][0]++;
				else{
					if(modded != 0)
						arr[i + 1][modded]++;
					arr[i + 1][num]++;
				}
			}
		}
		System.out.println(arr[s.length()][0]);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(String s) {
			try{
				reader = new BufferedReader(new FileReader(s), 32768);
			}
			catch (Exception e){
				reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			}
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
				    tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
				    throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.util.*;
import java.io.*;

public class cf496d{
	public static void main(String [] args) throws IOException{
		InputReader in = new InputReader("cf496d.in");

		String s = in.next();
		int [][] arr = new int[s.length() + 1][3];

		for(int i = 0; i < s.length(); i++){
			int num = s.charAt(i) - 48;

			int modded = arr[i][1] + 2 * arr[i][2];

			arr[i + 1][0] +=  arr[i][0];
			if(num % 3 == 0){
				arr[i + 1][0]++;
				continue;
			}
			else{
				if((modded + num) % 3 == 0)
					arr[i + 1][0]++;
				else
					arr[i + 1][(modded + num) % 3]++;
			}
		}
		System.out.println(arr[s.length()][0]);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(String s) {
			try{
				reader = new BufferedReader(new FileReader(s), 32768);
			}
			catch (Exception e){
				reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			}
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
				    tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
				    throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.util.*;
import java.io.*;

public class cf496d{
	public static void main(String [] args) throws IOException{
		InputReader in = new InputReader("cf496d.in");

		String s = in.next();
		int [][] arr = new int[s.length() + 1][3];

		for(int i = 0; i < s.length(); i++){
			int num = s.charAt(i) - 48;

			int modded = (arr[i][1] + 2 * arr[i][2]) % 3;

			arr[i + 1][0] +=  arr[i][0];
			if(num % 3 == 0){
				arr[i + 1][0]++;
				continue;
			}
			else{
				if((modded + num) % 3 == 0)
					arr[i + 1][0]++;
				else if(arr[i][3 - num % 3] > 0)
					arr[i + 1][0]++;
				else{
					if(modded != 0)
						arr[i + 1][modded]++;
					arr[i + 1][num % 3]++;
				}
			}
		}
		System.out.println(arr[s.length()][0]);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(String s) {
			try{
				reader = new BufferedReader(new FileReader(s), 32768);
			}
			catch (Exception e){
				reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			}
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
				    tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
				    throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        int[] arr = new int[input.length()+1];
        for(int i=1;i<=input.length();i++){
            arr[i] = input.charAt(i-1) - '0';
        }
        int n = input.length();
        int[] need = new int[10];
        int cnt = 0 ;
        for(int i=1;i<=n;i++){
            if(arr[i]%3==0){
                cnt++;
                need = new int[10];
            }
            else{
                if(need[arr[i]]!=0 && (need[arr[i]] + arr[i]) % 3 ==0){
                    cnt++;
                    need = new int[10];
                    continue;
                }
                int [] temp = new int[10];

                for(int j=0;j<=9;j++){
                    temp[j] = need[j];
                    for(int k=0;k<=9;k++){
                        if((need[j] + arr[i] + k) % 3 == 0 )
                        {
                            temp[k] = need[j] + arr[i];
                        }
                    }
                }
                for(int j=0;j<=9;j++){
                    need[j]  = temp[j];
                }
            }
        }
        System.out.println(cnt);
    }
}


import java.io.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        int[] arr = new int[input.length()+1];
        for(int i=1;i<=input.length();i++){
            arr[i] = input.charAt(i-1) - '0';
        }
        int n = input.length();
        int[] need = new int[10];
        int cnt = 0 ;
        for(int i=1;i<=n;i++){
            if(arr[i]%3==0){
                cnt++;
                need = new int[10];
            }
            else{
                if(need[arr[i]]!=0 && (need[arr[i]] + arr[i]) % 3 ==0){
                    cnt++;
                    need = new int[10];
                    continue;
                }
                int [] temp = new int[10];
                for(int j=0;j<=9;j++){
                    temp[j] = need[j];
                }
                for(int j=0;j<=9;j++){
                    for(int k=0;k<=9;k++){
                        if((need[j] + arr[i] + k) % 3 == 0 )
                        {
                            temp[k] = need[j] + arr[i];
                        }
                    }
                }
                for(int j=0;j<=9;j++){
                    need[j]  = temp[j];
                }
            }
        }
        System.out.println(cnt);
    }
}


import java.io.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        int[] arr = new int[input.length()+1];
        for(int i=1;i<=input.length();i++){
            arr[i] = input.charAt(i-1) - '0';
        }
        int n = input.length();
        int[] need = new int[10];
        int cnt = 0 ;
        for(int i=1;i<=n;i++){
            if(arr[i]%3==0){
                cnt++;
                need = new int[10];
            }
            else{
                if(need[arr[i]]!=0 && (need[arr[i]] + arr[i]) % 3 ==0){
                    cnt++;
                    need = new int[10];
                    continue;
                }
                for(int j=0;j<=9;j++){
                    if((arr[i]+j)%3==0){
                        need[j] = arr[i];
                    }
                    else{
                        int temp = need[j];
                        need[j] = 0 ;
                        for(int k=0;k<=9;k++){
                            if((temp + arr[i] + k) % 3 == 0 ){
                                need[k] = temp + arr[i];
                                break;
                            }
                        }
                    }
                }

            }
        }
        System.out.println(cnt);
    }
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String st[] = br.readLine().split(" ");
		String str=st[0];
		int n=str.length();
		int fin[]=new int[n];
		Arrays.fill(fin,-1);

		int r=(str.charAt(0)-'0')%3;
		fin[r]=0;
		int dp[]=new int[n];
		dp[0]=(r%3==0)?1:0;
		for(int i=1;i<str.length();i++){
			r=(r+str.charAt(i)-'0')%3;
			dp[i]=dp[i-1];
			if(fin[r]!=-1){
				dp[i]=Math.max(dp[i],dp[fin[r]]+1);
			}
			fin[r]=i;
		}
		//debug(dp);
	System.out.println(dp[n-1]);
    }

/****************************Solutions Ends****************************/

/****************************Template Begins***************************/
	static class Pair implements Comparable<Pair> {
		int u;
		int v;
		int index=-1;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}

		public int compareTo(Pair other) {
			if(index!=other.index)
				return Long.compare(index, other.index);
			return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	static long modulo(long a,long b,long c) {
		long x=1;
		long y=a;
		while(b > 0){
			if(b%2 == 1){
				x=(x*y)%c;
			}
			y = (y*y)%c; // squaring the base
			b /= 2;
		}
		return  x%c;
	}
	static long gcd(long x, long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		long r=0, a, b;
		a = (x > y) ? x : y; // a is greater number
		b = (x < y) ? x : y; // b is smaller number
		r = b;
		while(a % b != 0)
		{
			r = a % b;
			a = b;
			b = r;
		}
		return r;
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String st[] = br.readLine().split(" ");
		String str=st[0];
		int n=str.length();
		int fin[]=new int[n];
		Arrays.fill(fin,-1);
		fin[0]=0;
		int r=str.charAt(0)-'0';
		int dp[]=new int[n];
		dp[0]=(r%3==0)?1:0;
		for(int i=1;i<str.length();i++){
			r=(r+str.charAt(i)-'0')%3;
			dp[i]=dp[i-1];
			if(fin[r]!=-1){
				dp[i]=Math.max(dp[i],dp[fin[r]]+1);
			}
			fin[r]=i;
		}
	System.out.println(dp[n-1]);
    }

/****************************Solutions Ends****************************/

/****************************Template Begins***************************/
	static class Pair implements Comparable<Pair> {
		int u;
		int v;
		int index=-1;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}

		public int compareTo(Pair other) {
			if(index!=other.index)
				return Long.compare(index, other.index);
			return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	static long modulo(long a,long b,long c) {
		long x=1;
		long y=a;
		while(b > 0){
			if(b%2 == 1){
				x=(x*y)%c;
			}
			y = (y*y)%c; // squaring the base
			b /= 2;
		}
		return  x%c;
	}
	static long gcd(long x, long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		long r=0, a, b;
		a = (x > y) ? x : y; // a is greater number
		b = (x < y) ? x : y; // b is smaller number
		r = b;
		while(a % b != 0)
		{
			r = a % b;
			a = b;
			b = r;
		}
		return r;
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String st[] = br.readLine().split(" ");
		String str=st[0];
		int n=str.length();
		int fin[]=new int[3];
		Arrays.fill(fin,-1);

		int r=(str.charAt(0)-'0')%3;
		fin[r]=0;
		fin[0]=0;
		int dp[]=new int[n];
		dp[0]=(r%3==0)?1:0;
		for(int i=1;i<str.length();i++){
			r=(r+str.charAt(i)-'0')%3;
			dp[i]=dp[i-1];
			if(fin[r]!=-1){
				dp[i]=Math.max(dp[i],dp[fin[r]]+1);
			}
			fin[r]=i;
		}
		//debug(dp);
	System.out.println(dp[n-1]);
    }

/****************************Solutions Ends****************************/

/****************************Template Begins***************************/
	static class Pair implements Comparable<Pair> {
		int u;
		int v;
		int index=-1;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}

		public int compareTo(Pair other) {
			if(index!=other.index)
				return Long.compare(index, other.index);
			return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	static long modulo(long a,long b,long c) {
		long x=1;
		long y=a;
		while(b > 0){
			if(b%2 == 1){
				x=(x*y)%c;
			}
			y = (y*y)%c; // squaring the base
			b /= 2;
		}
		return  x%c;
	}
	static long gcd(long x, long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		long r=0, a, b;
		a = (x > y) ? x : y; // a is greater number
		b = (x < y) ? x : y; // b is smaller number
		r = b;
		while(a % b != 0)
		{
			r = a % b;
			a = b;
			b = r;
		}
		return r;
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String st[] = br.readLine().split(" ");
		String str=st[0];
		int n=str.length();
		int fin[]=new int[n];
		Arrays.fill(fin,-1);

		int r=str.charAt(0)-'0';
		fin[r]=0;
		int dp[]=new int[n];
		dp[0]=(r%3==0)?1:0;
		for(int i=1;i<str.length();i++){
			r=(r+str.charAt(i)-'0')%3;
			dp[i]=dp[i-1];
			if(fin[r]!=-1){
				dp[i]=Math.max(dp[i],dp[fin[r]]+1);
			}
			fin[r]=i;
		}
		//debug(dp);
	System.out.println(dp[n-1]);
    }

/****************************Solutions Ends****************************/

/****************************Template Begins***************************/
	static class Pair implements Comparable<Pair> {
		int u;
		int v;
		int index=-1;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}

		public int compareTo(Pair other) {
			if(index!=other.index)
				return Long.compare(index, other.index);
			return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	static long modulo(long a,long b,long c) {
		long x=1;
		long y=a;
		while(b > 0){
			if(b%2 == 1){
				x=(x*y)%c;
			}
			y = (y*y)%c; // squaring the base
			b /= 2;
		}
		return  x%c;
	}
	static long gcd(long x, long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		long r=0, a, b;
		a = (x > y) ? x : y; // a is greater number
		b = (x < y) ? x : y; // b is smaller number
		r = b;
		while(a % b != 0)
		{
			r = a % b;
			a = b;
			b = r;
		}
		return r;
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String st[] = br.readLine().split(" ");
		String str=st[0];
		int n=str.length();
		int fin[]=new int[3];
		Arrays.fill(fin,-1);

		int r=(str.charAt(0)-'0')%3;
		fin[r]=0;
		int dp[]=new int[n];
		dp[0]=(r%3==0)?1:0;
		for(int i=1;i<str.length();i++){
			r=(r+str.charAt(i)-'0')%3;
			dp[i]=dp[i-1];
			if(fin[r]!=-1){
				dp[i]=Math.max(dp[i],dp[fin[r]]+1);
			}
			fin[r]=i;
		}
		//debug(dp);
	System.out.println(dp[n-1]);
    }

/****************************Solutions Ends****************************/

/****************************Template Begins***************************/
	static class Pair implements Comparable<Pair> {
		int u;
		int v;
		int index=-1;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}

		public int compareTo(Pair other) {
			if(index!=other.index)
				return Long.compare(index, other.index);
			return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	static long modulo(long a,long b,long c) {
		long x=1;
		long y=a;
		while(b > 0){
			if(b%2 == 1){
				x=(x*y)%c;
			}
			y = (y*y)%c; // squaring the base
			b /= 2;
		}
		return  x%c;
	}
	static long gcd(long x, long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		long r=0, a, b;
		a = (x > y) ? x : y; // a is greater number
		b = (x < y) ? x : y; // b is smaller number
		r = b;
		while(a % b != 0)
		{
			r = a % b;
			a = b;
			b = r;
		}
		return r;
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }
    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        char[] s = sc.next().toCharArray();

        int n = s.length;
        int prefixSum[] = new int[n];
        prefixSum[0] = s[0] - '0';

        for(int i = 1; i < n; ++i) {
            prefixSum[i] = prefixSum[i - 1] + s[i] - '0';
        }
        for(int i = 0; i < n; ++i)
            prefixSum[i] = prefixSum[i] % 3;

        int lastInd[] = new int[3];

        for(int i = 0; i < 3; ++i)
            lastInd[i] = -2;
        lastInd[0] = -1;

        int dp[] = new int[n];

        for(int i = 0; i < n; ++i) {
            int prevInd = lastInd[prefixSum[i]];
            if((int)(s[i] - '0') % 3 == 0) {
                if(i == 0)
                    dp[i] = 1;
                else
                    dp[i] = dp[i - 1] + 1;
            }
            else if(prevInd != -2) {
                if(prevInd == -1)
                    dp[i] = max(dp[i - 1], 1);
                else
                    dp[i] = max(dp[i - 1], dp[prevInd] + 1);
            }
            if(i + 1 != n && s[i + 1] != '0')
                lastInd[prefixSum[i]] = i;
        }

        w.print(dp[n - 1]);

        w.close();
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }
    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        char[] s = sc.next().toCharArray();

        int n = s.length;
        int prefixSum[] = new int[n];
        prefixSum[0] = s[0] - '0';

        for(int i = 1; i < n; ++i) {
            prefixSum[i] = prefixSum[i - 1] + s[i] - '0';
        }
        for(int i = 0; i < n; ++i)
            prefixSum[i] = prefixSum[i] % 3;

        int lastInd[] = new int[3];

        for(int i = 0; i < 3; ++i)
            lastInd[i] = -1;

        int dp[] = new int[n];

        for(int i = 0; i < n; ++i) {
            int prevInd = lastInd[prefixSum[i]];
            if(i - prevInd != 1) {
                if(s[prevInd + 1] == '0')
                    dp[i] = dp[i - 1];
                else {
                    if(prevInd == -1)
                        dp[i] = max(dp[i - 1], 1);
                    else
                        dp[i] = max(dp[i - 1], dp[prevInd] + 1);
                }
            }
            else {
                if((int)(s[i] - '0') % 3 == 0) {
                    if(i == 0)
                        dp[i] = 1;
                    else
                        dp[i] = dp[i - 1] + 1;
                }
            }
            lastInd[prefixSum[i]] = i;
        }

        w.print(dp[n - 1]);

        w.close();
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }
    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        char[] s = sc.next().toCharArray();

        int n = s.length;
        int prefixSum[] = new int[n];
        prefixSum[0] = s[0] - '0';

        for(int i = 1; i < n; ++i) {
            prefixSum[i] = prefixSum[i - 1] + s[i] - '0';
        }
        for(int i = 0; i < n; ++i)
            prefixSum[i] = prefixSum[i] % 3;

        int lastInd[] = new int[3];

        for(int i = 0; i < 3; ++i)
            lastInd[i] = -2;
        lastInd[0] = -1;

        int dp[] = new int[n];

        for(int i = 0; i < n; ++i) {
            int prevInd = lastInd[prefixSum[i]];
            if(i != 0)
                dp[i] = dp[i - 1];
            if((int)(s[i] - '0') % 3 == 0) {
                if(i == 0)
                    dp[i] = 1;
                else
                    dp[i] = dp[i - 1] + 1;
            }
            else if(prevInd != -2) {
                if(prevInd == -1)
                    dp[i] = max(dp[i - 1], 1);
                else
                    dp[i] = max(dp[i - 1], dp[prevInd] + 1);
            }
            if(i + 1 != n && s[i + 1] != '0')
                lastInd[prefixSum[i]] = i;
        }

        w.print(dp[n - 1]);

        w.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String s = in.next();
			char[] chars = s.toCharArray();
			int[] topline = new int[s.length()];
			int[] combine = new int[s.length()];
			int count = 0;
			for (int i = 0; i < chars.length; i++) {
				if ((chars[i] - '0') % 3 == 0) {
					count++;
					// chars[i] = '-';
					topline[i] = -1;
					combine[i] = -1;
				} else {
					topline[i] = chars[i] - '0';
					combine[i] = topline[i];
				}
			}

			for (int len = 2; len <= s.length(); len++) {
				int[] com = new int[s.length() - (len - 1)];
				for (int i = 0; i < com.length; i++) {
					int a = combine[i];
					int b = topline[i + (len - 1)];
					if (a > 0 && b > 0) {
						com[i] = a + b;
						if (com[i] % 3 == 0) {
							com[i] = -1;
							count++;
							i += (len - 1);
						}
					} else {
						com[i] = -1;
					}
				}
				combine = com;
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public Long nextLong() {
			return Long.parseLong(next());
		}

		public Double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String s = in.next();
			int count = 0;
			int tmp = 0;
			for (int i = 0; i < s.length(); i++) {
				if (s.charAt(i) == '0') {
					count++;
					tmp = 0;
				} else {
					tmp += (s.charAt(i) - '0');
					if (tmp % 3 == 0) {
						count++;
						tmp = 0;
					}
				}
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public Long nextLong() {
			return Long.parseLong(next());
		}

		public Double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			StringBuilder sb = new StringBuilder(in.next());
			int count = 0;
			for (int i = 0; i < sb.length(); i++) {
				if (sb.charAt(i) == '0' || (sb.charAt(i) - '0') % 3 == 0) {
					count++;
					sb.setCharAt(i, '-');
				}
			}
			for (int len = 2; len <= sb.length(); len++) {
				for (int i = 0; i < sb.length() - (len - 1); i++) {
					int counter = 0;
					int num = 0;
					for (int j = i; j < len + i; j++) {
						if (sb.charAt(j) == '-') {
							i += (j - i);
							break;
						}
						counter += (sb.charAt(j) - '0');
						num++;
					}
					if (num == len) {
						if (counter % 3 == 0) {
							count++;
							for (int j = i; j < len + i; j++) {
								sb.setCharAt(j, '-');
							}
							i += (len - 1);
						}
					}
				}
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public Long nextLong() {
			return Long.parseLong(next());
		}

		public Double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String s = in.next();
			int count = 0;
			boolean one = false;
			boolean two = false;
			for (int i = 0; i < s.length(); i++) {
				if ((s.charAt(i) - '0') % 3 == 0) {
					count++;
					one = false;
					two = false;
				} else {
					int re = (s.charAt(i) - '0') % 3;
					if ((one && two) || (one && re == 2) || (two && re == 1)) {
						count++;
						one = false;
						two = false;
					} else {
						if (re == 1 && one || re == 2 && two) {
							two = true;
							one = true;
						} else if (re == 1) {
							one = true;
						} else if (re == 2) {
							two = true;
						}
					}
				}
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public Long nextLong() {
			return Long.parseLong(next());
		}

		public Double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String s = in.next();
			int count = 0;
			boolean one = false;
			boolean two = false;
			for (int i = 0; i < s.length(); i++) {
				int re = (s.charAt(i) - '0') % 3;
				if (re == 0) {
					count++;
					one = false;
					two = false;
				} else {
					if ((one && two) || (one && re == 2) || (two && re == 1)) {
						count++;
						one = false;
						two = false;
					} else {
						if ((re == 1 && one) || (re == 2 && two)) {
							two = true;
							one = true;
						} else if (re == 1) {
							one = true;
						} else if (re == 2) {
							two = true;
						}
					}
				}
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public Long nextLong() {
			return Long.parseLong(next());
		}

		public Double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String s = in.next();
			char[] chars = s.toCharArray();
			int[] topline = new int[s.length()];
			int[] combine = new int[s.length()];
			int count = 0;
			for (int i = 0; i < chars.length; i++) {
				if ((chars[i] - '0') % 3 == 0) {
					count++;
					// chars[i] = '-';
					topline[i] = -1;
					combine[i] = -1;
				} else {
					topline[i] = chars[i] - '0';
					combine[i] = topline[i];
				}
			}

			for (int len = 2; len <= s.length(); len++) {
				int[] com = new int[s.length() - (len - 1)];
				boolean canCom = false;
				for (int i = 0; i < com.length; i++) {
					int a = combine[i];
					int b = topline[i + (len - 1)];
					if (a > 0 && b > 0) {
						canCom = true;
						com[i] = a + b;
						if (com[i] % 3 == 0) {
							com[i] = -1;
							count++;
							i += (len - 1);
						}
					} else {
						com[i] = -1;
					}
				}
				if(!canCom) {
					break;
				}
				combine = com;
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public Long nextLong() {
			return Long.parseLong(next());
		}

		public Double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String s = in.next();
			int count = 0;
			int tmp = 0;
			for (int i = 0; i < s.length(); i++) {
				if ((s.charAt(i) - '0') % 3 == 0) {
					count++;
					tmp = 0;
				} else {
					tmp += (s.charAt(i) - '0');
					if (tmp % 3 == 0) {
						count++;
						tmp = 0;
					}
				}
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public Long nextLong() {
			return Long.parseLong(next());
		}

		public Double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;

public class ma
{
	//Credits to geeksforgeeks for fast scanning
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    //Credits to geeksforgeeks for fast scanning

    public static void main(String[] args) throws IOException
    {
    	//System.out.println(((2-6)%3)==-1);
    	FastReader s=new FastReader();
        String str=s.nextLine();
        long len=str.length();
        long arr[]=new long[(int)len];
        arr[0]=Integer.parseInt(Character.toString( str.charAt(0)));
        for(long i=1;i<len;i++){
        	arr[(int)i]=arr[(int)i-1]+Integer.parseInt(Character.toString( str.charAt((int)i)));
        }
        long one=-1;long two=-1;long zero=-1;
        long ans[]=new long[(int)len];
        if(arr[0]%3==0){ans[0]=1;zero=0;}
        else if(arr[0]%3==1)one=0;
        else two=0;
        for(int i=1;i<len;i++){
        	long temp=arr[i]-arr[i-1];
        	//System.out.println(temp+" "+arr[i]+" "+ans[i-1]);
        	if(temp==0){
        		//System.out.println("d");
        		ans[i]=ans[i-1]+1;
        	}
        	else if((arr[i]%3)==1){
        		if(one==-1){one=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)one]>=ans[i-1])ans[i]=ans[(int)one]+1;
        			else ans[i]=ans[i-1];
        			one=i;
        		}
        	}
        	else if((arr[i]%3)==2){
        		if(two==-1){two=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)two]>=ans[i-1])ans[i]=ans[(int)two]+1;
        			else ans[i]=ans[i-1];
        			two=i;
        		}
        	}
        	else if((arr[i]%3)==0){
        		if(zero==-1){zero=i;ans[i]=Math.max(1, ans[i-1]);}
        		else{
        			if(ans[(int)zero]>=ans[i-1])ans[i]=ans[(int)zero]+1;
        			else ans[i]=ans[i-1];
        			zero=i;
        		}
        	}
        }
        for(int i=0;i<len;i++)System.out.print(ans[i]+" ");
        System.out.println();
        System.out.println(ans[(int)len-1]);

    }

}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;

public class ma
{
	//Credits to geeksforgeeks for fast scanning
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    //Credits to geeksforgeeks for fast scanning

    public static void main(String[] args) throws IOException
    {
    	//System.out.println(((2-6)%3)==-1);
    	FastReader s=new FastReader();
        String str=s.nextLine();
        int len=str.length();
        int arr[]=new int[len];
        arr[0]=Integer.parseInt(Character.toString( str.charAt(0)));
        for(int i=1;i<len;i++){
        	arr[i]=arr[i-1]+Integer.parseInt(Character.toString( str.charAt(i)));
        }
        int one=-1;int two=-1;int zero=-1;
        int ans[]=new int[len];
        if(arr[0]%3==0){ans[0]=1;zero=0;}
        else if(arr[0]%3==1)one=0;
        else two=0;
        for(int i=1;i<len;i++){
        	int temp=(arr[i]-arr[i-1])%3;
        	//System.out.println(temp+" "+arr[i]+" "+ans[i-1]);
        	if(temp==0){
        		//System.out.println("d");
        		ans[i]=ans[i-1]+1;
        	}
        	else if((arr[i]%3)==1){
        		if(one==-1){one=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[one]>=ans[i-1])ans[i]=ans[one]+1;
        			else ans[i]=ans[i-1];
        			one=i;
        		}
        	}
        	else if((arr[i]%3)==2){
        		if(two==-1){two=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[two]>=ans[i-1])ans[i]=ans[two]+1;
        			else ans[i]=ans[i-1];
        			two=i;
        		}
        	}
        	else if((arr[i]%3)==0){
        		if(zero==-1){zero=i;ans[i]=Math.max(1, ans[i-1]);}
        		else{
        			if(ans[zero]>=ans[i-1])ans[i]=ans[zero]+1;
        			else ans[i]=ans[i-1];
        			zero=i;
        		}
        	}
        }
        System.out.println(ans[len-1]);

    }

}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;

public class ma
{
	//Credits to geeksforgeeks for fast scanning
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    //Credits to geeksforgeeks for fast scanning

    public static void main(String[] args) throws IOException
    {
    	//System.out.println(((2-6)%3)==-1);
    	FastReader s=new FastReader();
        String str=s.nextLine();
        long len=str.length();
        long arr[]=new long[(int)len];
        arr[0]=Integer.parseInt(Character.toString( str.charAt(0)));
        for(long i=1;i<len;i++){
        	arr[(int)i]=arr[(int)i-1]+Integer.parseInt(Character.toString( str.charAt((int)i)));
        }
        long one=-1;long two=-1;long zero=-1;
        long ans[]=new long[(int)len];
        if(arr[0]%3==0){ans[0]=1;zero=0;}
        else if(arr[0]%3==1)one=0;
        else two=0;
        for(int i=1;i<len;i++){
        	long temp=arr[i]-arr[i-1];
        	//System.out.println(temp+" "+arr[i]+" "+ans[i-1]);
        	if(temp==0){
        		//System.out.println("d");
        		ans[i]=ans[i-1]+1;
        		if(arr[i]%0==0)zero=i;else if(arr[i]%0==1)one=i;else if(arr[i]%0==2)two=i;
        	}
        	else if((arr[i]%3)==1){
        		if(one==-1){one=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)one]>=ans[i-1])ans[i]=ans[(int)one]+1;
        			else ans[i]=ans[i-1];
        			one=i;
        		}
        	}
        	else if((arr[i]%3)==2){
        		if(two==-1){two=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)two]>=ans[i-1])ans[i]=ans[(int)two]+1;
        			else ans[i]=ans[i-1];
        			two=i;
        		}
        	}
        	else if((arr[i]%3)==0){
        		if(zero==-1){zero=i;ans[i]=Math.max(1, ans[i-1]);}
        		else{
        			if(ans[(int)zero]>=ans[i-1])ans[i]=ans[(int)zero]+1;
        			else ans[i]=ans[i-1];
        			zero=i;
        		}
        	}
        }
        //for(int i=0;i<len;i++)System.out.print(ans[i]+" ");
        //System.out.println();
        System.out.println(ans[(int)len-1]);

    }

}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;

public class ma
{
	//Credits to geeksforgeeks for fast scanning
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    //Credits to geeksforgeeks for fast scanning

    public static void main(String[] args) throws IOException
    {
    	//System.out.println(((2-6)%3)==-1);
    	FastReader s=new FastReader();
        String str=s.nextLine();
        long len=str.length();
        long arr[]=new long[(int)len];
        arr[0]=Integer.parseInt(Character.toString( str.charAt(0)));
        for(long i=1;i<len;i++){
        	arr[(int)i]=arr[(int)i-1]+Integer.parseInt(Character.toString( str.charAt((int)i)));
        }
        long one=-1;long two=-1;long zero=-1;
        long ans[]=new long[(int)len];
        if(arr[0]%3==0){ans[0]=1;zero=0;}
        else if(arr[0]%3==1)one=0;
        else two=0;
        for(int i=1;i<len;i++){
        	long temp=(arr[i]-arr[i-1])%3;
        	//System.out.println(temp+" "+arr[i]+" "+ans[i-1]);
        	if(temp==0){
        		//System.out.println("d");
        		ans[i]=ans[i-1]+1;
        	}
        	else if((arr[i]%3)==1){
        		if(one==-1){one=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)one]>=ans[i-1])ans[i]=ans[(int)one]+1;
        			else ans[i]=ans[i-1];
        			one=i;
        		}
        	}
        	else if((arr[i]%3)==2){
        		if(two==-1){two=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)two]>=ans[i-1])ans[i]=ans[(int)two]+1;
        			else ans[i]=ans[i-1];
        			two=i;
        		}
        	}
        	else if((arr[i]%3)==0){
        		if(zero==-1){zero=i;ans[i]=Math.max(1, ans[i-1]);}
        		else{
        			if(ans[(int)zero]>=ans[i-1])ans[i]=ans[(int)zero]+1;
        			else ans[i]=ans[i-1];
        			zero=i;
        		}
        	}
        }
        System.out.println(ans[(int)len-1]);

    }

}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;

public class ma
{
	//Credits to geeksforgeeks for fast scanning
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    //Credits to geeksforgeeks for fast scanning

    public static void main(String[] args) throws IOException
    {
    	//System.out.println(((2-6)%3)==-1);
    	FastReader s=new FastReader();
        String str=s.nextLine();
        long len=str.length();
        long arr[]=new long[(int)len];
        arr[0]=Integer.parseInt(Character.toString( str.charAt(0)));
        for(long i=1;i<len;i++){
        	arr[(int)i]=arr[(int)i-1]+Integer.parseInt(Character.toString( str.charAt((int)i)));
        }
        long one=-1;long two=-1;long zero=-1;
        long ans[]=new long[(int)len];
        if(arr[0]%3==0){ans[0]=1;zero=0;}
        else if(arr[0]%3==1)one=0;
        else two=0;
        for(int i=1;i<len;i++){
        	long temp=arr[i]-arr[i-1];
        	//System.out.println(temp+" "+arr[i]+" "+ans[i-1]);
        	if(temp==0){
        		//System.out.println("d");
        		ans[i]=ans[i-1]+1;
        		if(arr[i]%3==0)zero=i;else if(arr[i]%3==1)one=i;else if(arr[i]%3==2)two=i;
        	}
        	else if((arr[i]%3)==1){
        		if(one==-1){one=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)one]>=ans[i-1])ans[i]=ans[(int)one]+1;
        			else ans[i]=ans[i-1];
        			one=i;
        		}
        	}
        	else if((arr[i]%3)==2){
        		if(two==-1){two=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)two]>=ans[i-1])ans[i]=ans[(int)two]+1;
        			else ans[i]=ans[i-1];
        			two=i;
        		}
        	}
        	else if((arr[i]%3)==0){
        		if(zero==-1){zero=i;ans[i]=Math.max(1, ans[i-1]);}
        		else{
        			if(ans[(int)zero]>=ans[i-1])ans[i]=ans[(int)zero]+1;
        			else ans[i]=ans[i-1];
        			zero=i;
        		}
        	}
        }
        //for(int i=0;i<len;i++)System.out.print(ans[i]+" ");
        //System.out.println();
        System.out.println(ans[(int)len-1]);

    }

}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;

public class ma
{
	//Credits to geeksforgeeks for fast scanning
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    //Credits to geeksforgeeks for fast scanning

    public static void main(String[] args) throws IOException
    {
    	//System.out.println(((2-6)%3)==-1);
    	FastReader s=new FastReader();
        String str=s.nextLine();
        long len=str.length();
        long arr[]=new long[(int)len];
        arr[0]=Integer.parseInt(Character.toString( str.charAt(0)));
        for(long i=1;i<len;i++){
        	arr[(int)i]=arr[(int)i-1]+Integer.parseInt(Character.toString( str.charAt((int)i)));
        }
        long one=-1;long two=-1;long zero=-1;
        long ans[]=new long[(int)len];
        if(arr[0]%3==0){ans[0]=1;zero=0;}
        else if(arr[0]%3==1)one=0;
        else two=0;
        for(int i=1;i<len;i++){
        	long temp=arr[i]-arr[i-1];
        	//System.out.println(temp+" "+arr[i]+" "+ans[i-1]);
        	if(temp==0){
        		//System.out.println("d");
        		ans[i]=ans[i-1]+1;
        	}
        	else if((arr[i]%3)==1){
        		if(one==-1){one=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)one]>=ans[i-1])ans[i]=ans[(int)one]+1;
        			else ans[i]=ans[i-1];
        			one=i;
        		}
        	}
        	else if((arr[i]%3)==2){
        		if(two==-1){two=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[(int)two]>=ans[i-1])ans[i]=ans[(int)two]+1;
        			else ans[i]=ans[i-1];
        			two=i;
        		}
        	}
        	else if((arr[i]%3)==0){
        		if(zero==-1){zero=i;ans[i]=Math.max(1, ans[i-1]);}
        		else{
        			if(ans[(int)zero]>=ans[i-1])ans[i]=ans[(int)zero]+1;
        			else ans[i]=ans[i-1];
        			zero=i;
        		}
        	}
        }
        //for(int i=0;i<len;i++)System.out.print(ans[i]+" ");
        //System.out.println();
        System.out.println(ans[(int)len-1]);

    }

}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;

public class ma
{
	//Credits to geeksforgeeks for fast scanning
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    //Credits to geeksforgeeks for fast scanning

    public static void main(String[] args) throws IOException
    {
    	//System.out.println(((2-6)%3)==-1);
    	FastReader s=new FastReader();
        String str=s.nextLine();
        int len=str.length();
        int arr[]=new int[len];
        arr[0]=Integer.parseInt(Character.toString( str.charAt(0)));
        for(int i=1;i<len;i++){
        	arr[i]=arr[i-1]+Integer.parseInt(Character.toString( str.charAt(i)));
        }
        int one=-1;int two=-1;
        int ans[]=new int[len];
        if(arr[0]%3==0)ans[0]=1;
        else if(arr[0]%3==1)one=0;
        else two=0;
        for(int i=1;i<len;i++){
        	int temp=(arr[i]-arr[i-1])%3;
        	//System.out.println(temp+" "+arr[i]+" "+ans[i-1]);
        	if(arr[i]%3==0 && ans[i-1]==0){
        		//System.out.println("d");
        		ans[i]=1;
        	}
        	else if(temp==0){
        		//System.out.println("d");
        		ans[i]=ans[i-1]+1;
        	}
        	else if(temp==1){
        		if(one==-1){one=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[one]>=ans[i-1])ans[i]=ans[one]+1;
        			else ans[i]=ans[i-1];
        			one=i;
        		}
        	}
        	else if(temp==2){
        		if(two==-1){two=i;ans[i]=ans[i-1];}
        		else{
        			if(ans[two]>=ans[i-1])ans[i]=ans[two]+1;
        			else ans[i]=ans[i-1];
        			two=i;
        		}
        	}
        }
        System.out.println(ans[len-1]);

    }

}


/*
 * 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.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Arpit
 */
public class codeF {

    /**
     * @param args the command line arguments
     */
    public static int rec(String s,String temp,int i){
        if(i>=s.length()){
        return 0;
        }

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Long.valueOf(temp)%3==0)return 1+rec(s,"",i+1);
        else{
        return Math.max(rec(s,temp,i+1),rec(s,"",i+1));
        }

    }
    public static int rec2(String s,String temp,int i,HashMap<String,Integer> hs){
        if(i>=s.length()){
        return 0;
        }

        String yo = String.valueOf(i)+"|"+temp;

        if(!hs.containsKey(yo)){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            hs.put(yo, 1+rec2(s,"",i+1,hs));
        else{
            hs.put(yo,Math.max(rec2(s,temp,i+1,hs),rec2(s,"",i+1,hs)));
        }}else{
        //System.out.println("aayaartyu");
        }
        return hs.get(yo);
    }
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s = new Scanner(System.in);
       //long t = s.nextLong();
       HashMap<String,Integer> hs = new HashMap<>();
        String as = s.next();
        //System.out.println(rec(as,"",0));
        System.out.println(rec2(as,"",0,hs));

    }}


/*
 * 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.
 */
//package javaapplication156;
import java.util.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
/**
 *
 * @author Arpit
 */
public class codeF {

	static char[] s;
	static int n, memo[][][];

        public static int rec2(String s,String temp,int i,HashMap<String,Integer> hs){
        if(i>=s.length()){
        return 0;
        }
        if(temp.length()>5)return 0;
        String yo = String.valueOf(i)+"|"+temp.length();

        if(!hs.containsKey(yo)){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            hs.put(yo, 1+rec2(s,"",i+1,hs));
        else{
            hs.put(yo,Math.max(rec2(s,temp,i+1,hs),rec2(s,"",i+1,hs)));
        }}else{
        //System.out.println("aayaartyu");
        }
        return hs.get(yo);
    }
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		String ass = sc.next();
                s = ass.toCharArray();
		n = s.length;
		memo = new int[n+1][4][2];
		for(int [][]i:memo)
			for(int []j:i)
				Arrays.fill(j ,-1);
		//out.println(dp(0, 0, 0));
                HashMap<String,Integer> hs = new HashMap<>();
                out.println(rec2(ass,"",0,hs));
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


/*
 * 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.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Arpit
 */
public class codef {

    /**
     * @param args the command line arguments
     */
    public static int rec(String s,String temp,int i){
        if(i>=s.length()){
        return 0;
        }
        temp=temp+s.charAt(i);
        if(Integer.valueOf(temp)%3==0)return 1+rec(s,"",i+1);
        else{
        return Math.max(rec(s,temp,i+1),rec(s,"",i+1));
        }

    }
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s = new Scanner(System.in);
        //long t = s.nextLong();
        String as = s.next();
        System.out.print(rec(as,"",0));

    }}


/*
 * 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.
 */
//package javaapplication156;
import java.util.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
/**
 *
 * @author Arpit
 */
public class codeF {

	static char[] s;
	static int n, memo[][][];
	static int dp(int idx, int mod, int z){
		if(idx == n)
			return mod == 0 && z == 1?1:0;
		if(memo[idx][mod][z] != -1)
			return memo[idx][mod][z];
		int ans = 0;
		if(s[idx] == '0' && z == 0){
			ans = Math.max(ans, 1 + dp(idx+1, 0, 0)); //beg and end 3ndi
		}
		else{
			ans = Math.max(ans, (mod == 0 && z == 1?1:0) + dp(idx+1, (s[idx]-'0')%3, 1)); //beg from 3ndi
			ans = Math.max(ans, ((mod + s[idx]-'0')%3 == 0?1:0) + dp(idx+1, 0, 0)); //end 3ndi
			ans = Math.max(ans, dp(idx+1, (mod + s[idx]-'0')%3, 1)); //hkammel
		}
		return memo[idx][mod][z] = ans;
	}

        public static int rec2(String s,String temp,int i,HashMap<String,Integer> hs){
        if(i>=s.length()){
        return 0;
        }
        if(temp.length()>5)return 0;
        String yo = String.valueOf(i)+"|"+temp.length();

        if(!hs.containsKey(yo)){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            hs.put(yo, 1+rec2(s,"",i+1,hs));
        else{
            hs.put(yo,Math.max(rec2(s,temp,i+1,hs),rec2(s,"",i+1,hs)));
        }}else{
        //System.out.println("aayaartyu");
        }
        return hs.get(yo);
    }
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		String ass = sc.next();
                s = ass.toCharArray();
		n = s.length;
		memo = new int[n+1][4][2];
		for(int [][]i:memo)
			for(int []j:i)
				Arrays.fill(j ,-1);
		//out.println(dp(0, 0, 0));
                HashMap<String,Integer> hs = new HashMap<>();
                out.println(rec2(ass,"",0,hs));
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


/*
 * 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.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Arpit
 */
public class codef {

    /**
     * @param args the command line arguments
     */
    public static int rec(String s,String temp,int i){
        if(i>=s.length()){
        return 0;
        }
        temp=temp+s.charAt(i);
        if(Integer.valueOf(temp)%3==0)return 1+rec(s,"",i+1);
        else{
        return Math.max(rec(s,temp,i+1),rec(s,"",i+1));
        }

    }
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s = new Scanner(System.in);
        long t = s.nextLong();
        String as = String.valueOf(t);
        System.out.print(rec(as,"",0));

    }}


/*
 * 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.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Arpit
 */
public class codeF {

    /**
     * @param args the command line arguments
     */
    public static int rec(String s,String temp,int i){
        if(i>=s.length()){
        return 0;
        }

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Long.valueOf(temp)%3==0)return 1+rec(s,"",i+1);
        else{
        return Math.max(rec(s,temp,i+1),rec(s,"",i+1));
        }

    }
    public static int rec2(String s,String temp,int i,HashMap<String,Integer> hs){
        if(i>=s.length()){
        return 0;
        }
        if(temp.length()>5)return 0;
        String yo = String.valueOf(i)+"|"+temp.length();

        if(!hs.containsKey(yo)){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            hs.put(yo, 1+rec2(s,"",i+1,hs));
        else{
            hs.put(yo,Math.max(rec2(s,temp,i+1,hs),rec2(s,"",i+1,hs)));
        }}else{
        //System.out.println("aayaartyu");
        }
        return hs.get(yo);
    }
    public static int rec3(String s,String temp,int i,int[][] dp){
        if(i>=s.length()){
        return 0;
        }

        if(dp[i][temp.length()]==-1){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            dp[i][temp.length()]=1+rec3(s,"",i+1,dp);
        else{
            dp[i][temp.length()]=Math.max(rec3(s,temp,i+1,dp),rec3(s,"",i+1,dp));
        }}

        return dp[i][temp.length()];
    }
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s = new Scanner(System.in);
       //long t = s.nextLong();
       HashMap<String,Integer> hs = new HashMap<>();
        String as = s.next();
        //int[][] dp = new int[as.length()*10][as.length()*10];

        //System.out.println(rec(as,"",0));
        System.out.println(rec2(as,"",0,hs));
       // System.out.println(rec3(as,"",0,dp));

    }}


/*
 * 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.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Arpit
 */
public class codeF {

    /**
     * @param args the command line arguments
     */
    public static int rec(String s,String temp,int i){
        if(i>=s.length()){
        return 0;
        }

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Long.valueOf(temp)%3==0)return 1+rec(s,"",i+1);
        else{
        return Math.max(rec(s,temp,i+1),rec(s,"",i+1));
        }

    }
    public static int rec2(String s,String temp,int i,HashMap<String,Integer> hs){
        if(i>=s.length()){
        return 0;
        }
        if(temp.length()>10)return 0;
        String yo = String.valueOf(i)+"|"+temp;

        if(!hs.containsKey(yo)){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            hs.put(yo, 1+rec2(s,"",i+1,hs));
        else{
            hs.put(yo,Math.max(rec2(s,temp,i+1,hs),rec2(s,"",i+1,hs)));
        }}else{
        //System.out.println("aayaartyu");
        }
        return hs.get(yo);
    }
    public static int rec3(String s,String temp,int i,int[][] dp){
        if(i>=s.length()){
        return 0;
        }

        if(dp[i][temp.length()]==-1){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            dp[i][temp.length()]=1+rec3(s,"",i+1,dp);
        else{
            dp[i][temp.length()]=Math.max(rec3(s,temp,i+1,dp),rec3(s,"",i+1,dp));
        }}

        return dp[i][temp.length()];
    }
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s = new Scanner(System.in);
       //long t = s.nextLong();
       HashMap<String,Integer> hs = new HashMap<>();
        String as = s.next();
        int[][] dp = new int[as.length()*10][as.length()*10];
        for(int i=0;i<as.length();i++){
        for(int j=0;j<as.length();j++){
        dp[i][j]=-1;
        }
        }
        //System.out.println(rec(as,"",0));
        System.out.println(rec2(as,"",0,hs));
       // System.out.println(rec3(as,"",0,dp));

    }}


/*
 * 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.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Arpit
 */
public class codeF {

    /**
     * @param args the command line arguments
     */
    public static int rec(String s,String temp,int i){
        if(i>=s.length()){
        return 0;
        }

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Long.valueOf(temp)%3==0)return 1+rec(s,"",i+1);
        else{
        return Math.max(rec(s,temp,i+1),rec(s,"",i+1));
        }

    }
    public static int rec2(String s,String temp,int i,HashMap<String,Integer> hs){
        if(i>=s.length()){
        return 0;
        }

        String yo = String.valueOf(i)+"|"+temp;
        if(yo.length()>20)return 0;
        if(!hs.containsKey(yo)){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            hs.put(yo, 1+rec2(s,"",i+1,hs));
        else{
            hs.put(yo,Math.max(rec2(s,temp,i+1,hs),rec2(s,"",i+1,hs)));
        }}else{
        //System.out.println("aayaartyu");
        }
        return hs.get(yo);
    }
    public static int rec3(String s,String temp,int i,int[][] dp){
        if(i>=s.length()){
        return 0;
        }

        if(dp[i][temp.length()]==-1){

        //if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<5&&Integer.valueOf(temp)%3==0)
            dp[i][temp.length()]=1+rec3(s,"",i+1,dp);
        else{
            dp[i][temp.length()]=Math.max(rec3(s,temp,i+1,dp),rec3(s,"",i+1,dp));
        }}

        return dp[i][temp.length()];
    }
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s = new Scanner(System.in);
       //long t = s.nextLong();
       HashMap<String,Integer> hs = new HashMap<>();
        String as = s.next();
        int[][] dp = new int[as.length()*10][as.length()*10];
        for(int i=0;i<as.length();i++){
        for(int j=0;j<as.length();j++){
        dp[i][j]=-1;
        }
        }
        //System.out.println(rec(as,"",0));
        System.out.println(rec2(as,"",0,hs));
       // System.out.println(rec3(as,"",0,dp));

    }}


/*
 * 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.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Arpit
 */
public class codef {

    /**
     * @param args the command line arguments
     */
    public static int rec(String s,String temp,int i){
        if(i>=s.length()){
        return 0;
        }
        if(s.charAt(i)=='0')return 1+rec(s,"",i+1);
        temp=temp+s.charAt(i);

        if(temp.length()<2&&Long.valueOf(temp)%3==0)return 1+rec(s,"",i+1);
        else{
        return Math.max(rec(s,temp,i+1),rec(s,"",i+1));
        }

    }
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner s = new Scanner(System.in);
       //long t = s.nextLong();

        String as = s.next();
        int count=0;
        for(int i=0;i<as.length();i++){
        if(Integer.valueOf(as.charAt(i))%3==0)
            count++;
        else{
        if(i+1<as.length()){
        int ck=Integer.valueOf(as.substring(i,i+2));
        if(ck%3==0){
        count++;
        i++;
        }

        }
        }
        }

        System.out.print(count);

    }}


#include<bits/stdc++.h>
using namespace std;
long long a[100005];
int vis[100005];
vector<pair<int,long long>> v[100005];
long long dis[100005];
void dfs(int i)
{vis[i]=1;
for(auto j:v[i])
{if(!vis[j.first])
   {dis[j.first]+=dis[i]+(j.second);
   dfs(j.first);
   }
}
}
int main()
{
int n,b;
long long f;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n-1;i++)
{cin>>b>>f;
v[i+1].push_back({b,f});
v[b].push_back({i+1,f});
}
dis[1]=0;
dfs(1);
int ct=0;
for(int i=2;i<=n;i++)
if(dis[i]>a[i])
ct++;
//cout<<dis[i]<<" ";

cout<<ct;
}


#include<iostream>
#include<vector>
#include<cstring>
#define N 100005
using namespace std;

long long int a[N];
vector<long long int> v[N];
vector<long long int> w[N];
int sub[N];
bool vis[N];
int ans = 0;

int dfs(int s){
    vis[s] = true;
    if(v[s].size()==1 && s!=1){
        sub[v[s][0]] = 0;
        return 0;
    }
    for(long long int i=0;i<v[s].size();i++){
        if(!vis[v[s][i]]){
         sub[s] += dfs(v[s][i])+1;
        }
    }
    return sub[s];
}

void dfs1(int s,long long int maxd,long long int wt){
    vis[s] = 1;
    maxd = max(maxd+wt,wt);
    if(maxd>a[s]){
        // cout<<s<<" ";
        ans += (sub[s]+1);
        return;
    }
    for(int i=0;i<v[s].size();i++){
        int c = v[s][i];
        wt = w[s][i];
        if(!vis[c]){
            dfs1(c,maxd,wt);
        }
    }
}

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    long long int p,c;
    for(int i=1;i<n;i++){
        cin>>p>>c;
        v[i+1].push_back(p);
        v[p].push_back(i+1);
        w[i+1].push_back(c);
        w[p].push_back(c);
    }
    memset(sub,0,sizeof(sub));
    memset(vis,0,sizeof(vis));
    dfs(1);
    for(int i=1;i<=n;i++)
    cout<<sub[i]<<" ";
    memset(vis,0,sizeof(vis));
    dfs1(1,0,0);
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
#define N 100005
using namespace std;

long long int a[N];
vector<long long int> v[N];
vector<long long int> w[N];
int sub[N];
bool vis[N];
int ans = 0;

int dfs(int s){
    vis[s] = true;
    if(v[s].size()==1){
        sub[v[s][0]] = 0;
        return 0;
    }
    for(long long int i=0;i<v[s].size();i++){
        if(!vis[v[s][i]]){
         sub[s] += dfs(v[s][i])+1;
        }
    }
    return sub[s];
}

void dfs1(int s,long long int maxd,long long int wt){
    vis[s] = 1;
    maxd = max(maxd+wt,wt);
    if(maxd>a[s]){
        ans += (sub[s]+1);
        return;
    }
    for(int i=0;i<v[s].size();i++){
        int c = v[s][i];
        wt = w[s][i];
        if(!vis[c]){
            dfs1(c,maxd,wt);
        }
    }
}

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    long long int p,c;
    for(int i=1;i<n;i++){
        cin>>p>>c;
        v[i+1].push_back(p);
        v[p].push_back(i+1);
        w[i+1].push_back(c);
        w[p].push_back(c);
    }
    memset(sub,0,sizeof(sub));
    memset(vis,0,sizeof(vis));
    dfs(1);
    memset(vis,0,sizeof(vis));
    dfs1(1,0,0);
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
#define N 100005
using namespace std;

long long int a[N];
vector<long long int> v[N];
vector<long long int> w[N];
int sub[N];
bool vis[N];
int ans = 0;

int dfs(int s){
    vis[s] = true;
    if(v[s].size()==1 && s!=1){
        sub[v[s][0]] = 0;
        return 0;
    }
    for(long long int i=0;i<v[s].size();i++){
        if(!vis[v[s][i]]){
         sub[s] += dfs(v[s][i])+1;
        }
    }
    return sub[s];
}

void dfs1(int s,long long int maxd,long long int wt){
    vis[s] = 1;
    maxd = max(maxd+wt,wt);
    if(maxd>a[s]){
        ans += (sub[s]+1);
        return;
    }
    for(int i=0;i<v[s].size();i++){
        int c = v[s][i];
        wt = w[s][i];
        if(!vis[c]){
            dfs1(c,maxd,wt);
        }
    }
}

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    long long int p,c;
    for(int i=1;i<n;i++){
        cin>>p>>c;
        v[i+1].push_back(p);
        v[p].push_back(i+1);
        w[i+1].push_back(c);
        w[p].push_back(c);
    }
    memset(sub,0,sizeof(sub));
    memset(vis,0,sizeof(vis));
    dfs(1);
    memset(vis,0,sizeof(vis));
    dfs1(1,0,0);
    cout<<ans<<endl;
    return 0;
}