#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    string s;
    long long t;
    cin >> t;
    for (long long q = 0; q < t; q++) {
        cin >> s;
        long long res = 0, cur = 0;
            for (long long i = 0; i < s.size(); i++) {
                res++;
                if (s[i] == '+') {
                    cur++;
                }
                else {
                    cur--;
                }
                if (cur < 0) {
                    cur = 0;
                    res += i + 1;
                }
            }
        cout << res << endl;
    }
    return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    string s;
    long long t;
    cin >> t;
    for (long long q = 0; q < t; q++) {
        cin >> s;
        long long res = 0, init = 0, cur, si, plus = 0, minus = 0;
        bool ok = true;
        si = s.size();
        for (long long i = 0; i < si; i++) {
            if (s[i] == '+') {
                plus++;
            }
            else {
                minus++;
            }
        }
        while (true) {
            //if (init >= minus) {
                //res += si;
                //break;
            //}
            //else {
                cur = init;
                ok = true;
                long long  minus2 = minus; // plus2 = plus,
                for (long long i = 0; i < s.size();) {
                    //if (cur >= minus2) {
                        //res += si;
                       // break;
                    //}
                    while (s[i] == '+' && i < si) {
                        cur++;
                        i++;
                        //res++;
                    }
                    if (cur >= minus2) {
                        res += si;
                        break;
                    }
                    while (s[i] == '-' && i < si && cur >= 0) {
                        cur--;
                        i++;
                        minus2--;
                        //res++;
                    }
                    if (cur < 0) {
                        res += i;
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    break;
                }
                init++;
            //}
        }
        cout << res << endl;
    }
    return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    string s;
    long long t;
    cin >> t;
    for (long long q = 0; q < t; q++) {
        cin >> s;
        long long res = 0, init = 0, cur, si;
        bool ok = true;
        si = s.size();
        while (true) {
            cur = init;
            ok = true;
            for (long long i = 0; i < si; i) {
                while (s[i] == '+' && i < si) {
                    cur++;
                    i++;
                    res++;
                }
                while (s[i] == '-' && i < si && cur >= 0) {
                    cur--;
                    i++;
                    res++;
                }
                if (cur < 0) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                break;
            }
            init++;
        }
        cout << res << endl;
    }
    return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    string s;
    long long t;
    cin >> t;
    for (long long q = 0; q < t; q++) {
        cin >> s;
        long long res = 0, init = 0, cur, si, plus = 0, minus = 0;
        bool ok = true;
        si = s.size();
        for (long long i = 0; i < si; i++) {
            if (s[i] == '+') {
                plus++;
            }
            else {
                minus++;
            }
        }
        while (true) {
            if (init >= minus) {
                res += si;
                break;
            }
            else {
                cur = init;
                ok = true;
                for (long long i = 0; i < s.size(); i++) {
                    res++;
                    if (s[i] == '+') {
                        cur++;
                    }
                    else {
                        cur--;
                    }
                    if (cur < 0) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    break;
                }
                init++;
            }
        }
        cout << res << endl;
    }
    return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    string s;
    long long t;
    cin >> t;
    for (long long q = 0; q < t; q++) {
        cin >> s;
        long long res = 0, init = 0, cur, si, plus = 0, minus = 0;
        bool ok = true;
        si = s.size();
        for (long long i = 0; i < si; i++) {
            if (s[i] == '+') {
                plus++;
            }
            else {
                minus++;
            }
        }
        while (true) {
            if (init >= minus) {
                res += si;
                break;
            }
            else {
                cur = init;
                ok = true;
                long long plus2 = plus, minus2 = minus;
                for (long long i = 0; i < s.size(); i++) {
                    if (cur + plus2 >= minus2) {
                        res += si - i;
                        break;
                    }
                    res++;
                    if (s[i] == '+') {
                        cur++;
                        plus2--;
                    }
                    else {
                        cur--;
                        minus2--;
                    }
                    if (cur < 0) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    break;
                }
                init++;
            }
        }
        cout << res << endl;
    }
    return 0;
}


// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi

bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

ll fact[1000101];

bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

void fac() {
        fact[0] = 1;
        for(int i = 1; i < 1000101; i++) {
                fact[i] = (fact[i-1] * i);
                fact[i] %= MOD;
        }
}

ll binpow(ll val, ll deg, ll mod) {
        if (!deg) return 1 % mod;
        if (deg & 1) return binpow(val, deg - 1, mod) * val % mod;
        ll res = binpow(val ,deg >> 1, mod);
        return (res*res) % mod;
}

ll nCr(ll n, ll i) {
        ll res = fact[n];
        ll div = fact[n-i] * fact[i];
        div %= MOD;  div = binpow(div, MOD - 2, MOD);
        return (res * div) % MOD;
}

// map<ll, list<ll>> m;
map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    fac();
    cin >> t;
    while(t--) {
        string s;
        cin >> s;
        ll ans=0, x=0, w=0;
        for(ll i=0; i<s.length(); i++) {
            if(s[i]=='-') {
                x--;
            }
            else {
                x++;
            }
            if(x+w<0) {
                ans+=i+1;
                w++;
            }
        }
        ans+=s.length();
        cout << ans << endl;

    }
}


// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi

bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

ll fact[1000101];

bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

void fac() {
        fact[0] = 1;
        for(int i = 1; i < 1000101; i++) {
                fact[i] = (fact[i-1] * i);
                fact[i] %= MOD;
        }
}

ll binpow(ll val, ll deg, ll mod) {
        if (!deg) return 1 % mod;
        if (deg & 1) return binpow(val, deg - 1, mod) * val % mod;
        ll res = binpow(val ,deg >> 1, mod);
        return (res*res) % mod;
}

ll nCr(ll n, ll i) {
        ll res = fact[n];
        ll div = fact[n-i] * fact[i];
        div %= MOD;  div = binpow(div, MOD - 2, MOD);
        return (res * div) % MOD;
}

// map<ll, list<ll>> m;
map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    fac();
    cin >> t;
    while(t--) {
        string s;
        cin >> s;
        ll ans=0, x=0, w=0;
        for(ll i=0; i<s.length(); i++) {
            if(s[i]=='-') {
                x--;
            }
            else {
                x++;
            }
            if(x+w<0) {
                ans+=i+1;
                w++;
            }
        }
        ans+=s.length();
        cout << ans << endl;
    }
}


// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi

bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

ll fact[1000101];

bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

void fac() {
        fact[0] = 1;
        for(int i = 1; i < 1000101; i++) {
                fact[i] = (fact[i-1] * i);
                fact[i] %= MOD;
        }
}

ll binpow(ll val, ll deg, ll mod) {
        if (!deg) return 1 % mod;
        if (deg & 1) return binpow(val, deg - 1, mod) * val % mod;
        ll res = binpow(val ,deg >> 1, mod);
        return (res*res) % mod;
}

ll nCr(ll n, ll i) {
        ll res = fact[n];
        ll div = fact[n-i] * fact[i];
        div %= MOD;  div = binpow(div, MOD - 2, MOD);
        return (res * div) % MOD;
}

// map<ll, list<ll>> m;
map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    fac();
    cin >> t;
    while(t--) {
        string s;
        cin >> s;
        ll ans=0, x=0, w=0;
        for(ll i=0; i<s.length(); i++) {
            if(s[i]=='-') {
                x--;
            }
            else {
                x++;
            }
            if(x+w<0) {
                ans+=i+1;
                w++;
            }
        }
        ans+=s.length();
        cout << ans << endl;

    }

}


// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi

bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

ll fact[1000101];

bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

void fac() {
        fact[0] = 1;
        for(int i = 1; i < 1000101; i++) {
                fact[i] = (fact[i-1] * i);
                fact[i] %= MOD;
        }
}

ll binpow(ll val, ll deg, ll mod) {
        if (!deg) return 1 % mod;
        if (deg & 1) return binpow(val, deg - 1, mod) * val % mod;
        ll res = binpow(val ,deg >> 1, mod);
        return (res*res) % mod;
}

ll nCr(ll n, ll i) {
        ll res = fact[n];
        ll div = fact[n-i] * fact[i];
        div %= MOD;  div = binpow(div, MOD - 2, MOD);
        return (res * div) % MOD;
}

// map<ll, list<ll>> m;
map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    fac();
    cin >> t;
    while(t--) {
        string s;
        cin >> s;
        ll ans=0, x=0;
        for(ll i=0; i<s.length(); i++) {
            if(s[i]=='-') {
                x--;
            }
            else {
                x++;
            }
            if(x+i<0) {
                ans+=i+1;
            }
        }
        ans+=s.length();
        cout << ans << endl;
    }
}


// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi

bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

ll fact[1000101];

bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

void fac() {
        fact[0] = 1;
        for(int i = 1; i < 1000101; i++) {
                fact[i] = (fact[i-1] * i);
                fact[i] %= MOD;
        }
}

ll binpow(ll val, ll deg, ll mod) {
        if (!deg) return 1 % mod;
        if (deg & 1) return binpow(val, deg - 1, mod) * val % mod;
        ll res = binpow(val ,deg >> 1, mod);
        return (res*res) % mod;
}

ll nCr(ll n, ll i) {
        ll res = fact[n];
        ll div = fact[n-i] * fact[i];
        div %= MOD;  div = binpow(div, MOD - 2, MOD);
        return (res * div) % MOD;
}

// map<ll, list<ll>> m;
map<ll, ll> m;

int main() {
    C

//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    fac();
    cin >> t;
    while(t--) {
        string s;
        cin >> s;
        ll ans=0, x=0, w=0;
        for(ll i=0; i<s.length(); i++) {
            if(s[i]=='-') {
                x--;
            }
            else {
                x++;
            }
            if(x+w<0) {
                ans+=i+1;
                w++;
            }
        }
        ans+=s.length();
        cout << ans << endl;

    }
}


#include<bits/stdc++.h>
#define ll int long long
#define str string
using namespace std;
int T;
int main()
{
   cin>>T;
   while(T--){
      int res=0,x=0; str s;cin>>s;
      int n=s.size();
      for(int i=1;i<=n;i++){
         if(s[i-1]=='-')x--;
         else x++;
         if(i-1+x<0)res+=i;
      }res+=n;cout<<res<<endl;
   }
}


#include<bits/stdc++.h>
#define ll int long long
#define str string
using namespace std;
int T;
int main()
{
   cin>>T;
   while(T--){
      int res=0,x=0; str s;cin>>s;
      int n=s.size();
      for(int i=0;i<n;i++){
         if(s[i]=='-')
            x--;
         else x++;
         if(i+x<0||i==n-1)res+=(i+1);
      }if(n-1+x<0)res+=n;cout<<res<<endl;
   }
}


#include<bits/stdc++.h>
#define ll int long long
#define str string
using namespace std;
int T;
int main()
{
   cin>>T;
   while(T--){
      int res=0,minus=0; str s;cin>>s;
      for(int i=0;i<s.size();i++){
         if(s[i]=='-'){
            minus++;
            if(i-minus<0)res+=i+1;
         }
         else minus--;
      }cout<<res+s.size()<<endl;
   }
}


#include<bits/stdc++.h>
#define ll int long long
#define str string
using namespace std;
int T;
int main()
{
   cin>>T;
   while(T--){
      int res=0; str s;cin>>s;
      for(int i=0;i>=0;i++){
         int cur=i;bool ok=true;
         for(int i=0;i<s.size();i++){
            res++;
            if(s[i]=='+')cur++;
            else cur--;
            if(cur<0){ok=false;break;}
         }if(ok)break;
      }cout<<res<<endl;
   }
}


#include<bits/stdc++.h>
#define ll int long long
#define str string
using namespace std;
int T;
int main()
{
   cin>>T;
   while(T--){
      int res=0,x=0; str s;cin>>s;
      int n=s.size();
      for(int i=0;i<n;i++){
         if(s[i]=='-')
            x--;
         else x++;
         if(i+x<0)res+=(i+1);
      }if(n-1+x<0)res+=n;cout<<res<<endl;
   }
}


#include<bits/stdc++.h>
#define ll int long long
#define str string
using namespace std;
int T;
int main()
{
   cin>>T;
   while(T--){
      int res=0,x=0; str s;cin>>s;
      int n=s.size();
      for(int i=0;i<n;i++){
         if(s[i]=='-')
            x--;
         else x++;
         if(i+x<0||i==n-1)res+=(i+1);
      }if(n-1+x>=0)res+=n;cout<<res<<endl;
   }
}


#include<bits/stdc++.h>
#define ll int long long
using namespace std;
int T;
int main()
{
   cin>>T;
   while(T--){
      int res=0,x=0; string s;cin>>s;
      int n=s.size();
      for(int i=0;i<n;i++){
            if(s[i]=='+')x++;
            else x--;
            if(x<0){res+=i;x=0;res++;}
      }res+=n;cout<<res<<endl;
   }
}


#include<bits/stdc++.h>
#define ll int long long
using namespace std;
int T;
int main()
{
   cin>>T;
   while(T--){
      ll res=0,x=0; string s;cin>>s;
      int n=s.size();
      for(int i=0;i<n;i++){
            if(s[i]=='+')x++;
            else x--;
            if(x<0){res+=i;x=0;res++;}
      }res+=n;cout<<res<<endl;
   }
}


#include<bits/stdc++.h>
# define ll long long
# define fo(i,n)for(int i=0;i<n;i++)
# define fo1(i,n)for(int i=1;i<=n;i++)
# define pb push_back
# define endl "\n"
# define mod 1000000007ll
# define pi  3.1415926535897932384626
using namespace std;
void solve(string s)
{
   ll res=0,curr=0,k=1,f=0;
   for(int i=0;i<s.size();i++)
   {
       if(s[i]=='+')
       {
        curr++;
         f++;
       }
       else
       curr--;
       if(curr<0)
       {
           res+=(i+1);
           curr=k;
           k++;
           curr-=(i+1);
           curr+=f;
       }
   }
   cout<<res+s.size();
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)
    {
      string s;
      cin>>s;
      solve(s);
      cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
# define ll long long
# define fo(i,n)for(int i=0;i<n;i++)
# define fo1(i,n)for(int i=1;i<=n;i++)
# define pb push_back
# define endl "\n"
# define mod 1000000007ll
# define pi  3.1415926535897932384626
using namespace std;
void solve(string s)
{
    ll res=0;
    for(ll i=0;i<=INFINITY;i++)
    {
       ll curr=i;
       bool ok=true;
       for(ll j=0;j<s.size();j++)
       {
           res++;
          if(s[j]=='+')
           curr++;
           else
           curr--;
           if(curr<0)
           {
               ok=false;
               break;
           }
       }
       if(ok)
       break;
    }
    cout<<res;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)
    {
      string s;
      cin>>s;
      solve(s);
      cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int nmax=100000;
int fin[3],dp[nmax];
int main(){
	int c,cur=0,i=0;
	fin[0]=0;
	fin[1]=-1;
	fin[2]=-1;
	while((c=getchar())!=EOF){
		if(c=='\n')break;
		i++;
		cur+=c-'0';
		cur%=3;
		dp[i]=dp[i-1];
		if(fin[cur]!=-1) dp[i]=max(dp[i],dp[fin[cur]]+1);
		fin[cur]=i;
	}
	printf("%d\n",dp[i]);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int nmax=200005;
int fin[3],dp[nmax];
int main(){
	int c,cur=0,i=0;
	fin[0]=0;
	fin[1]=-1;
	fin[2]=-1;
	while((c=getchar())!=EOF){
		if(c=='\n')break;
		i++;
		cur+=c-'0';
		cur%=3;
		dp[i]=dp[i-1];
		if(fin[cur]!=-1) dp[i]=max(dp[i],dp[fin[cur]]+1);
		fin[cur]=i;
	}
	printf("%d\n",dp[i]);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int nmax=10000;
int fin[3],dp[nmax];
int main(){
	int c,cur=0,i=0;
	fin[0]=0;
	fin[1]=-1;
	fin[2]=-1;
	while((c=getchar())!=EOF){
		if(c=='\n')break;
		i++;
		cur+=c-'0';
		cur%=3;
		dp[i]=dp[i-1];
		if(fin[cur]!=-1) dp[i]=max(01,dp[fin[cur]]+1);
		fin[cur]=i;
	}
	printf("%d\n",dp[i]);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int nmax=10000;
int fin[3],dp[nmax];
int main(){
	int c,cur=0,i=0;
	fin[0]=0;
	fin[1]=-1;
	fin[2]=-1;
	while((c=getchar())!=EOF){
		if(c=='\n')break;
		i++;
		cur+=c-'0';
		cur%=3;
		//dp[i]=dp[i-1];
		if(fin[cur]!=-1) dp[i]=max(dp[i-1],dp[fin[cur]]+1);
		fin[cur]=i;
	}
	printf("%d\n",dp[i]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<time.h>
#include<sys/time.h>
using namespace std;
char c[300000];
int f[3][300000];
double gettime()
{
    struct timeval time ;
    if (gettimeofday(&time,NULL)){
        return 0;
    }
    return (double)time.tv_sec + (double)time.tv_usec * .000001;
}
int main()
{
	double stime=gettime();
	gets(c);
	int now,ans=0;
	for (register int i=0;i<210000;i++)
	f[1][i]=f[2][i]=-99999;
	for (register int i=1;i<=strlen(c);i++){
	for (register int j=0;j<3;j++){
			if (gettime()-stime>2500) {
				printf("%d",ans);
				return 0;
			}
			if (f[j][i-1]<0) continue;
			f[(c[i-1]-'0')%3][i]=max(f[(c[i-1]-'0')%3][i],f[j][i-1]);
			f[j][i]=max(f[j][i],f[j][i-1]);
			if ((j+c[i-1]-'0')%3==0) f[0][i]=max(f[0][i],f[j][i-1]+1);
			else f[(j+c[i-1]-'0')%3][i]=max(f[(j+c[i-1]-'0')%3][i],f[j][i-1]);
			//printf("f[%d][%d]=%d<%d %d>\n",j,i,f[j][i],f[(6-c[i-1]+'0')%3][i-1],i);
		}
	}
	for (int i=0;i<3;i++) ans=max(ans,f[i][strlen(c)]);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<time.h>
#include<sys/time.h>
using namespace std;
char c[300000];
int f[3][300000];
double gettime()
{
    struct timeval time ;
    if (gettimeofday(&time,NULL)){
        return 0;
    }
    return (double)time.tv_sec + (double)time.tv_usec * .000001;
}
int main()
{
	double stime=gettime();
	gets(c);
	int now,ans=0;
	for (register int i=0;i<210000;i++)
	f[1][i]=f[2][i]=-99999;
	for (register int i=1;i<=strlen(c);i++){
	for (register int j=0;j<3;j++){
			if (gettime()-stime>800) {
				printf("%d",ans);
				return 0;
			}
			if (f[j][i-1]<0) continue;
			f[(c[i-1]-'0')%3][i]=max(f[(c[i-1]-'0')%3][i],f[j][i-1]);
			f[j][i]=max(f[j][i],f[j][i-1]);
			if ((j+c[i-1]-'0')%3==0) f[0][i]=max(f[0][i],f[j][i-1]+1);
			else f[(j+c[i-1]-'0')%3][i]=max(f[(j+c[i-1]-'0')%3][i],f[j][i-1]);
			//printf("f[%d][%d]=%d<%d %d>\n",j,i,f[j][i],f[(6-c[i-1]+'0')%3][i-1],i);
		}
	}
	for (int i=0;i<3;i++) ans=max(ans,f[i][strlen(c)]);
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int b[10];
    cin>>a;
    int n=a.size(),ans=0,cnt=0,sum=0;
    for(int i=0;i<n;i++)
    {
        b[cnt++]=a[i]-'0';
        sum+=b[cnt-1];
        if(sum%3==0||cnt>=3||b[cnt-1]%3==0)
        {
            ans++;
            cnt=0;
            sum=0;
        }
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;

    cin >> s;

    int n = s.length();

    int ans = 0;

    int i = 0;
    while (i < n)
    {
        char c = s[i];
        int k = c - '0';

        // cout << k << " ";

        if (k % 3 == 0)
        {
            ans++;
            i++;
            // cout << endl;
            continue;
        }

        if (i < n-1)
        {
            c = s[i+1];
            int l = c - '0';

            l = 10 * k + l;

            // cout << l << " ";

            if (l % 3 == 0)
            {
                ans++;
                i += 2;
                // cout << endl;
                continue;
            }

            if (i < n-2)
            {
                c = s[i+2];
                int m = c - '0';

                m = 10 * l + m;

                // cout << m << " ";

                if (m % 3 == 0)
                {
                    ans++;
                    i += 3;
                    // cout << endl;
                    continue;
                }
            }
        }

        // cout << endl;

        i++;

    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;

    cin >> s;

    int n = s.length();

    int ans = 0;

    for (int i = 0; i < n;)
    {
        char c = s[i];
        int k = c - '0';

        if (k % 3 == 0)
        {
            ans++;
            i++;
            continue;
        }

        if (i < n-1)
        {
            c = s[i+1];
            int l = c - '0';

            l = 10 * l + k;

            if (l % 3 == 0)
            {
                ans++;
                i += 2;
                continue;
            }

            if (i < n-2)
            {
                c = s[i+2];
                int m = c - '0';

                m = 100 * m + l;

                if (m % 3 == 0)
                {
                    ans++;
                    i += 3;
                    continue;
                }
            }
        }

        i++;

    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;

    cin >> s;

    int n = s.length();

    int ans = 0;

    for (int i = 0; i < n;)
    {
        char c = s[i];
        int k = c - '0';

        if (k % 3 == 0)
        {
            ans++;
            i++;
            continue;
        }

        if (i < n-1)
        {
            c = s[i+1];
            int l = c - '0';

            l = 10 * k + l;

            if (l % 3 == 0)
            {
                ans++;
                i += 2;
                continue;
            }

            if (i < n-2)
            {
                c = s[i+2];
                int m = c - '0';

                m = 10 * l + m;

                if (m % 3 == 0)
                {
                    ans++;
                    i += 3;
                    continue;
                }
            }
        }

        i++;

    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;

    cin >> s;

    int n = s.length();

    int ans = 0;

    int i = 0;
    while (i < n)
    {
        char c = s[i];
        int k = c - '0';

        // cout << k << " ";

        if (k % 3 == 0)
        {
            ans++;
            i++;
            // cout << endl;
            continue;
        }

        if (i < n-1)
        {
            c = s[i+1];
            int l = c - '0';

            l = 10 * k + l;

            // cout << l << " ";

            if (l % 3 == 0)
            {
                ans++;
                i += 2;
                // cout << endl;
                continue;
            }

            if (i < n-2)
            {
                c = s[i+2];
                int m = c - '0';

                m = 10 * l + m;

                // cout << m << " ";

                if (m % 3 == 0)
                {
                    ans++;
                    i += 3;
                    // cout << endl;
                    continue;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;

    cin >> s;

    int n = s.length();

    int ans = 0;

    for (int i = 0; i < n;)
    {
        char c = s[i];
        int k = c - '0';

        // cout << k << " ";

        if (k % 3 == 0)
        {
            ans++;
            i++;
            continue;
        }

        if (i < n-1)
        {
            c = s[i+1];
            int l = c - '0';

            l = 10 * k + l;

            // cout << l << " ";

            if (l % 3 == 0)
            {
                ans++;
                i += 2;
                continue;
            }

            if (i < n-2)
            {
                c = s[i+2];
                int m = c - '0';

                m = 10 * l + m;

                // cout << m << " ";

                if (m % 3 == 0)
                {
                    ans++;
                    i += 3;
                    continue;
                }
            }
        }

        // cout << endl;

        i++;

    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;

    cin >> s;

    int n = s.length();

    int ans = 0;

    for (int i = 0; i < n;)
    {
        char c = s[i];
        int k = c - '0';

        if (k % 3 == 0)
        {
            ans++;
            i++;
            continue;
        }

        if (i < n-1)
        {
            c = s[i+1];
            int l = c - '0';

            l = 10 * l + k;

            if (l % 3 == 0)
            {
                ans++;
                i += 2;
                continue;
            }

            if (i < n-2)
            {
                c = s[i+1];
                int m = c - '0';

                m = 100 * m + l;

                if (m % 3 == 0)
                {
                    ans++;
                    i += 3;
                    continue;
                }
            }
        }

        i++;

    }

    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int ans[200010];
char s[200010];
int r=0;
int judge[2];
int main(){
	memset(judge,-1,sizeof(judge));
	cin>>s;
	int n=strlen(s);
	judge[0]=0;
	for(int i=1;i<=n;i++)
	{
		r=(r+s[i-1]-'0')%3;
		ans[i]=ans[i-1];
		if(judge[r]!=-1)
		   ans[i]=max(ans[i-1],ans[judge[r]]+1);
		judge[r]=i;
	}
	cout<<ans[n]<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int ans[200010];
char s[200010];
int r=0;
int judge[2];
int main(){
	memset(judge,-1,sizeof(judge));
	cin>>s;
	int n=strlen(s);
	judge[0]=0;
	for(int i=1;i<=n;i++)
	{
		r=(r+s[i-1]-'0')%3;
		//ans[i]=ans[i-1];
		if(judge[r]!=-1)
		   ans[i]=max(ans[i-1],ans[judge[r]]+1);
		judge[r]=i;
	}
	cout<<ans[n]<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int ans[200010];
char s[200010];
int r=0;
int judge[3];
int main(){
	memset(judge,-1,sizeof(judge));
	cin>>s;
	int n=strlen(s);
	judge[0]=0;
	for(int i=1;i<=n;i++)
	{
		r=(r+s[i-1]-'0')%3;
		ans[i]=ans[i-1];
		if(judge[r]!=-1)
		   ans[i]=max(ans[i-1],ans[judge[r]]+1);
		judge[r]=i;
	}
	cout<<ans[n]<<endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
   string s;
   cin >> s;
   int cnt = 0;
   int sum = 0;
   int row = 0;
   for(int i = 0; i < s.size(); ++i){
        sum = min( 0+ (s.at(i) - '0'), sum + (s.at(i) - '0') % 3);
        row++;
        if(sum == 0 || row >= 3){
            cnt++;
            row = 0;
        }

   }

   cout << cnt;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
   string s;
   cin >> s;
   int n = s.size();
  // cout << s[0] << endl;
   int sum = 0;
   vector<int> d(n+1);
   vector<int> fin(3,-1);
   fin[0] = 0;
   for(int i = 1; i <= n; i++){
        d[i] = d[i-1];
        sum = (sum + s[i-1] - '0') % 3;
        if(fin[sum] != -1){
            d[i] = max(d[i], d[fin[sum]] + 1);
            //cout << d[i];
        }
        //cout << sum << endl;
        fin[sum] = i;
   }

   cout << d[n];

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
   string s;
   cin >> s;
   int cnt = 0;
   int sum = 0;
   int row = 0;
   for(int i = 0; i < s.size(); ++i){
        sum = min( 0+ (s.at(i) - '0') % 3, sum + (s.at(i) - '0') % 3);
        row++;
        if(sum == 0 || row >= 3){
            cnt++;
            row = 0;
        }

   }

   cout << cnt;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
   string s;
   cin >> s;
   int cnt = 0;
   int sum = 0;
   int row = 0;
   for(int i = 0; i < s.size(); ++i){
        sum = min( (s.at(i) - '0') % 3, (sum + (s.at(i) - '0') % 3));
        row++;
        if(sum == 0 || row >= 3){
            cnt++;
            row = 0;
        }

   }

   cout << cnt;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int Max[5], fg[5];
int main()
{
	scanf("%s", s);
	int sum = 0;
	for(int i = 0; i < strlen(s); ++i)
	{
		sum += s[i] - '0';
		sum %= 3;
		//cout << sum << endl;
		if(!sum) Max[sum]++;
		else
		{
			if(fg[sum]) Max[sum]++;
			Max[sum] = max(max(Max[sum], Max[(sum + 1) % 3]), Max[(sum + 2) % 3]);
		}
		fg[sum] = 1;
	}
	cout<< Max[sum % 3] << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int Max[5], fg[5];
int main()
{
	scanf("%s", s);
	int sum = 0;
	int n = strlen(s);
	fg[0] = 1;
	for(int i = 0; i < n; ++i)
	{
		sum += s[i] - '0';
		sum %= 3;
		if(fg[sum]) Max[sum]++;
		Max[sum] = max(max(Max[sum], Max[(sum + 1) % 3]), Max[(sum + 2) % 3]);
		fg[sum] = 1;
	}
	cout<< Max[sum % 3] << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int Max[5], fg[5];
int main()
{
	scanf("%s", s);
	int sum = 0;
	int n = strlen(s);
	for(int i = 0; i < n; ++i)
	{
		sum += s[i] - '0';
		sum %= 3;
		if(!sum) Max[sum]++;
		else
		{
			if(fg[sum]) Max[sum]++;
			Max[sum] = max(max(Max[sum], Max[(sum + 1) % 3]), Max[(sum + 2) % 3]);
		}
		fg[sum] = 1;
	}
	cout<< Max[sum % 3] << endl;
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

typedef long double ld;
int f(char c)
{
    int a=c-'0';
    return a;
}
int main()
{
    ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

string s;
cin>>s;string a;int k=0;int c=0;int z=0;
for(int i=0;i<s.length();i++)
{
    if(f(s[i])%3==0)
    { k=0;
        c++;z=0;

    }
    else { z++;

        k+=f(s[i]);
        if(k%3==0||z==3)
        {c++;k=0;z=0;}

    }

    }

cout<<c;
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

typedef long double ld;
ll f(char c)
{
    int a=c-'0';
    return a;
}
int main()
{
    ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

string s;
cin>>s;string a;ll k=0;ll c=0;
for(ll i=0;i<s.length();i++)
{
    if(f(s[i])%3==0)
    { k=0;
        c++;
    }
    else {
        k+=f(s[i]);
        if(k%3==0)
        {c++;k=0;}

    }

}
cout<<c;
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

typedef long double ld;
int f(char c)
{
    int a=c-'0';
    return a;
}
int main()
{
    ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

string s;
cin>>s;string a;int k=0;int c=0;
for(int i=0;i<s.length();i++)
{
    if(f(s[i])%3==0)
    { k=0;
        c++;
    }
    else {
        k+=f(s[i]);
        if(k%3==0)
        {c++;k=0;}

    }

}
cout<<c;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

string s;
int a[200005];
int main()
{
    //freopen("in.txt", "r", stdin);
    while(cin>>s)
    {
        int ans=0;
        memset(a, 0, sizeof(a));
        int st=0;
        int sum=0;
        int cnt=0;
        for(int i = 0; i < s.size(); i++)
        {
            a[cnt++]=s[i]-'0';
            sum+=a[cnt-1];
            if(sum%3==0 || cnt>=3 || a[cnt-1]%3==0)
            {
                ans++;
                sum=0;
                cnt=0;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAX_N 200005
char s[MAX_N];

int main()
{
    //freopen("in.txt", "r", stdin);
    int i,sum, x, res, cnt;
    while(~scanf("%s", s)){
        res = 0; cnt = 0;
        for(i = 0; s[i]; ++i){
            x = s[i] - '0';
            ++cnt;
            sum += x;
            if(x%3 == 0 || cnt == 3 || sum%3 == 0) {
                ++res;
                sum = 0;
                cnt = 0;
            }
        }
        printf("%d\n", res);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAX_N 200005
char s[MAX_N];

int main()
{
    //freopen("in.txt", "r", stdin);
    int i,sum, x, res;
    while(~scanf("%s", s)){
        res = 0;
        for(i = 0; s[i]; ++i){
            x = s[i] - '0';
            sum += x;
            if(x%3 == 0 || sum%3 == 0) {
                ++res;
                sum = 0;
            }
        }
        printf("%d\n", res);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int n = s.length();

	int r = 0;
	vector<int> fin(3, -1);
	fin[0] = 0;

	vector<int> z(n + 1);
	for (int i = 1; i <= n; i++) {
	    r = (r + s[i - 1] - '0') % 3;
	    z[i] = z[i - 1];
	    if (fin[r] != -1)
	        z[i] = max(z[i], z[fin[r]] + 1);
	    fin[r] = i;
	}

	cout << z[n] << endl;
}


#include<bits/stdc++.h>
using namespace std;

vector<int> cnt(31);
int cz(int x)
{
	int ans=0;
	for (int i=30; i>=0 && x>0; --i)
	{
		int need=min(x>>i, cnt[i]);
		ans+=need;
		x-=(1<<i)*need;
	}
	if (x>0)
	{
		ans=-1;
	}
	return ans;
}
int main()
{
	int n, q, i;
	cin >> n >> q;

	for (i=0; i<n; ++i)
	{
		int x;
		cin >> x;
		++cnt[__builtin_ctz(x)];
	}

	while (q--)
	{
		int x, ans;
		cin >> x;
		ans=cz(x);
		cout << ans << endl;
	}
	return 0;
}


//CazadorDivino
//No esta listo
#include "bits/stdc++.h"
#include <math.h>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

char c[N];
int dp[N], sum[N];
bool check(int i, int j){
	if( (sum[j] - sum[i-1]) % 3 == 0) return true;
	else return false;
}
int main(){
	clr(dp,0);clr(sum,0);
	string s; cin>>s;
	int ns = (int)s.size();
	rep(i,0,(int)s.size()-1){
		 c[i+1] = s[i];
		 sum[i+1] = sum[i]+(s[i]-'0');
	}
	//~ rep(i,1,ns)
		//~ cout<<sum[i]<<" "; cout<<endl;
	int j = ns;
	per(i,j,1){
		if(i == j){
			dp[i] = (c[i]-'0')%3 == 0? 1: 0;
		}
		else{
			rep(k,i,j){
					int x = 0;
					//~ cout<<i<<" "<<k<<"check:"<<check(i,k)<<endl;
					if(check(i,k)) x =1;
					dp[i] = max(dp[i], x + dp[k+1]);
			}
		}
	}

	//~ rep(i,1,j)
		//~ cout<<dp[i]<<" ";
	//~ cout<<endl;
	cout<<dp[1];
	return 0;
}


//CazadorDivino
//No esta listo
#include "bits/stdc++.h"
#include <math.h>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

char c[N];
int dp[N];
int convert(int i, int j){
	int x = 0;
	int pw = 0;
	per(k,j,i){
		x += (c[k]-'0')*pow(10,pw);
		pw++;
	}
	return x;
}
int main(){
	clr(dp,0);
	string s; cin>>s;
	int ns = (int)s.size();
	rep(i,0,(int)s.size()-1) c[i+1] = s[i];
	int j = ns;
	per(i,j,1){
		if(i == j){
			dp[i] = convert(i,i)%3 == 0? 1: 0;
		}
		else{
			rep(k,i,j){
					int x = 0;
					if(convert(i,k)%3 == 0) x =1;
					dp[i] = max(dp[i], x + dp[k+1]);
			}
		}
	}

	//~ rep(i,1,j)
		//~ cout<<dp[i]<<" ";
	//~ cout<<endl;
	cout<<dp[1];
	return 0;
}


//CazadorDivino
//No estas listo
#include "bits/stdc++.h"
#include <math.h>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int sum[N], mo[3],a[N];
int dp[N];
int T(int n){
	int &r = dp[n];
	if(r!=-1)
		return r;
	if(n == 0) {r = 0; return 0;}
	if (n == 1){
		if((sum[n]-sum[n+1])%3 == 0) {r =1; return 1;}
		else {r = 0;return 0;}
	}
	int k = n;
	while(k > 0){
		//~ cout<<sum[k]<<"-"<<sum[n+1]<<endl;
		if((sum[k] - sum[n+1]) % 3 == 0)
			break;
		k--;
	}
	//~ cout<<k<<endl;
	if(k == 0){
		//~ cout<< "T("<<n -1<<")="<<T(n-1)<<endl;
		//~ return T(n-1);
		r = T(n-1);
		return r;
	}
	else{
		//~ cout<< "T("<<n -1<<") 1+T("<<k-1<<")"<<endl;
		//~ return max(T(n-1), 1 + T(k-1));
		r = max(T(n-1), 1 + T(k-1));
		return r;
		//return T(n-1);
	}
}

int main(){
	int n;
	string s; cin>>s;
	n = s.size();
	rep(i,0,(int)s.size()-1){
		a[i+1] = s[i]-'0';
	}

	clr(mo,-1);
	clr(dp,-1);
	clr(sum,0);

	per(i,n,1){
		if(i ==  n)
			sum[i] = a[i];
		else
			sum[i]=sum[i+1]+a[i];
	}
	//~ rep(i,1,n){
		//~ cout<<sum[i]<<" ";
	//~ }cout<<endl;

	cout<<T(n);
	//cout<<dp[n];
	return 0;
}


//CazadorDivino
//No estas listo
#include "bits/stdc++.h"
#include <math.h>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int sum[N], a[N], dp[N];

int T(int n){
	int &r = dp[n];
	if(r!=-1)
		return r;
	if(n == 0) {r = 0; return 0;}
	if (n == 1){
		if((sum[n]-sum[n+1])%3 == 0) {r =1; return 1;}
		else {r = 0;return 0;}
	}
	int k = n;
	while(k > 0){
		if((sum[k] - sum[n+1]) % 3 == 0)
			break;
		k--;
	}
	if(k == 0){
		r = T(n-1);
		return r;
	}
	else{
		r = max(T(n-1), 1 + T(k-1));
		return r;
	}
}

int main(){
	int n;
	string s; cin>>s;
	n = s.size();
	rep(i,0,(int)s.size()-1){
		a[i+1] = s[i]-'0';
	}

	clr(dp,-1);
	clr(sum,0);

	per(i,n,1){
		if(i ==  n)
			sum[i] = a[i];
		else
			sum[i]=sum[i+1]+a[i];
	}

	cout<<T(n);
	//cout<<dp[n];
	return 0;
}


//CazadorDivino
//No estas listo
#include "bits/stdc++.h"
#include <math.h>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int sum[N], mo[3],a[N];
int dp[N];
int T(int n){
	int &r = dp[n];
	if(r!=-1)
		return r;
	if(n == 0) {r = 0; return 0;}
	if (n == 1){
		if((sum[n]-sum[n+1])%3 == 0) {r =1; return 1;}
		else {r = 0;return 0;}
	}
	int k = n;
	while(k > 0){
		if((sum[k] - sum[n+1]) % 3 == 0)
			break;
		k--;
	}
	if(k == 0){
		r = T(n-1);
		return r;
	}
	else{
		r = max(T(n-1), 1 + T(k-1));
		return r;
	}
}

int main(){
	int n;
	string s; cin>>s;
	n = s.size();
	rep(i,0,(int)s.size()-1){
		a[i+1] = s[i]-'0';
	}

	clr(dp,-1);
	clr(sum,0);

	per(i,n,1){
		if(i ==  n)
			sum[i] = a[i];
		else
			sum[i]=sum[i+1]+a[i];
	}

	cout<<T(n);
	//cout<<dp[n];
	return 0;
}


//CazadorDivino
//No esta listo
#include "bits/stdc++.h"
#include <math.h>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

char c[N];
int dp[N], sum[N];
bool check(int i, int j){
	if( (sum[j] - sum[i-1]) % 3 == 0) return true;
	else return false;
}
int main(){
	clr(dp,0);clr(sum,0);
	string s; cin>>s;
	int ns = (int)s.size();
	rep(i,0,(int)s.size()-1){
		 c[i+1] = s[i];
		 sum[i+1] += s[i]-'0';
	}
	int j = ns;
	per(i,j,1){
		if(i == j){
			dp[i] = (c[i]-'0')%3 == 0? 1: 0;
		}
		else{
			rep(k,i,j){
					int x = 0;
					if(check(i,k)) x =1;
					dp[i] = max(dp[i], x + dp[k+1]);
			}
		}
	}

	//~ rep(i,1,j)
		//~ cout<<dp[i]<<" ";
	//~ cout<<endl;
	cout<<dp[1];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    int n=s.length();
    int c=0,sum=0;
    int v[]={1,0,0};
    for(int i=0;i<n;i++)
    {
        sum+=(int)s[i];
        if(v[sum%3]==1)
        {
            c++;
            v[0]=1;
            v[1]=0;
            v[2]=0;
            sum=0;
        }
        else
        {
            v[sum%3]=1;
        }
    }
    cout<<c;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    int n=s.length();
    int c=0,sum=0;
    int v[]={1,0,0};
    for(int i=0;i<n;i++)
    {
        sum+=(int)s[i];
        if(v[sum%3]==1)
        {
            c++;
            v[0]=1;
            v[1]=0;
            v[2]=0;
        }
        else
        {
            v[sum%3]=1;
        }
    }
    cout<<c;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    int n=s.length();
    int c=0,rem=0;
    for(int i=0;i<n;i++)
    {
        int temp=0;
        temp=(int)s[i];
        if(temp%3==0)
        {
            c++;
            rem=0;
        }
        else
        {
            rem+=temp;
            if(rem%3==0)
            {
                c++;
                rem=0;
            }
        }
    }
    cout<<c;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 200000+10;
char str[MAXN];
int sum, mark[3] = {1,0,0};

void solve()
{
	int ans = 0;
	int len = strlen( str );
	for(int i = 0; i < len; i++ ){
		int temp = str[i] - '0';
		sum += temp;
		sum %= 3;
		if( mark[sum] ){
			ans++;
			mark[1] = mark[2] = 0;
			mark[0] = 1;
			sum = 0;
		}else{
			mark[sum] = 1;
		}
	}
	printf("%d\n", ans);
}

int main()
{
	scanf("%s", &str);
	solve();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 200000+10;
char str[MAXN];
int sum, cnt;

void solve()
{
	int ans = 0;
	int len = strlen(str);
	for(int i = 0; i < len; i++ ){
		int temp = str[i] - '0';
		sum += temp;
		cnt ++;
		if( sum%3 == 0 || temp%3 == 0 || cnt == 3 ){
			sum = 0;
			cnt = 0;
			ans ++;
		}
	}
	printf("%d\n", ans);
}

int main()
{
	scanf("%s", &str);
	solve();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 200000+10;
char str[MAXN];
int sum, cnt;

void solve()
{
	int ans = 0;
	for(int i = 0; i < strlen(str); i++ ){
		int temp = str[i] - '0';
		sum += temp;
		cnt ++;
		if( sum%3 == 0 || temp%3 == 0 || cnt == 3 ){
			sum = 0;
			cnt = 0;
			ans ++;
		}
	}
	printf("%d\n", ans);
}

int main()
{
	scanf("%s", &str);
	solve();
	return 0;
}


#include<iostream>

#include<string>

#include<map>

#define ll long long int

using namespace std;

int main()

{

  string s;

  cin>>s;

  int ans=0;

  int cnt=0;

  int mark[3]={1,0,0};

  for(int i=0;i<s.length();i++)

  {

    cnt+=s[i]-'0';

    cnt%=3;

    if(mark[cnt])

    {

      ans++;

      mark[1]=mark[2]=0;

      cnt=0;

    }

    else

    {

      mark[cnt]=1;//如果再次访问到了cnt说明中间加了一个3的倍数，如13 10

    }

  }

  cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 200000+10;
char str[MAXN];
int sum, cnt;

void solve()
{
	int ans = 0;
	for(int i = 0; i < strlen(str); i++ ){
		int temp = str[i] - '0';
		sum += temp;
		cnt ++;
		if( sum%3 == 0 || temp%3 == 0 || cnt == 3 ){
			sum = 0;
			cnt = 0;
			ans ++;
		}
	}
	printf("%d\n", ans);
}

int main()
{
	scanf("%s", str);
	solve();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 200000+10;
char str[MAXN];
int sum, mark[3] = {1,0,0};

void solve()
{
	int ans = 0;
	for(int i = 0; i < strlen(str); i++ ){
		int temp = str[i] - '0';
		sum += temp;
		sum %= 3;
		if( mark[sum] ){
			ans++;
			mark[1] = mark[2] = 0;
			mark[0] = 1;
			sum = 0;
		}else{
			mark[sum] = 1;
		}
	}
	printf("%d\n", ans);
}

int main()
{
	scanf("%s", &str);
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

const int maxn=200006;
char num[maxn];

int main()
{
    scanf("%s",num);
    int ans=0;
    int len=strlen(num);
    int t=0;
    for(int i=0;i!=len;i++)
    {
        t+=(num[i]-'0');
        if((num[i]-'0')%3==0 ||t%3==0)
        {
            t=0;
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

const int maxn=200005;
char num[23];

int main()
{
    scanf("%s",num);
    int ans=0;
    int len=strlen(num);
    int t=0;
    for(int i=0;i!=len;i++)
    {
        t+=(num[i]-'0');
        if((num[i]-'0')%3==0 ||t%3==0)
        {
            t=0;
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

const int maxn=200006;
char num[maxn];

int main()
{
    scanf("%s",num);
    int ans=0;
    int len=strlen(num);
    int t=0;
    for(int i=0;i!=len;i++)
    {
        t+=(num[i]-'0');
        if((num[i]-'0')%3==0 ||t%3==0 || (num[i]+num[i-1])%3==0)
        {
            t=0;
            ans++;
            num[i]=0;
        }
    }
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>

const int MaxN = 2e5 + 5;

int N;
int Dp[MaxN], G[3];
char S[MaxN];

int main()
{
    scanf("%s", S);
    N = strlen(S);
    G[1] = G[2] = -1;
    for(int i = 0, s = 0; i < N; ++i)
    {
        s = (s + S[i] - '0') % 3;
        if(S[i] == '0') Dp[i] = Dp[i - 1] + 1;
        else Dp[i] = std::max(Dp[i - 1], G[s] + 1);
        G[s] = std::max(G[s], Dp[i]);
    }
    printf("%d\n", Dp[N - 1]);
    return 0;
}


#include <bits/stdc++.h>

const int MaxN = 2e5 + 5;

int Len;
int Dp[MaxN], G[MaxN];
char A[MaxN];

inline int read()
{
    register int x = 0, v = 1;
    register char ch = getchar();
    while(!isdigit(ch))
    {
        if(ch == '-') v = -1;
        ch = getchar();
    }
    while(isdigit(ch))
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * v;
}

int main()
{
    scanf("%s", A + 1);
    Len = strlen(A + 1);
    for(int i = 1, s = 0; i <= Len; ++i)
    {
        s = (s + A[i] - '0') % 3;
        if(A[i] == '0') Dp[i] = Dp[i - 1] + 1;
        else Dp[i] = G[s] + 1;
        G[s] = std::max(G[s], Dp[i]);
    }
    printf("%d\n", Dp[Len]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>

const int MaxN = 2e5 + 5;

int N;
int Dp[MaxN], G[3];
char S[MaxN];

int main()
{
    scanf("%s", S);
    N = strlen(S);
    G[0] = G[1] = G[2] = -1;
    for(int i = 0, s = 0; i < N; ++i)
    {
        s = (s + S[i] - '0') % 3;
        if(S[i] == '0') Dp[i] = Dp[i - 1] + 1;
        else Dp[i] = std::max(Dp[i - 1], G[s] + 1);
        G[s] = std::max(G[s], Dp[i]);
    }
    printf("%d\n", Dp[N - 1]);
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	long long T = 0;
	long long Ten = 1;
	for (int i=r;i>=l;i--) {
		T += Ten*(s[i]-'0');
		Ten *= 10;
	}
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	int num = 0;
	for (int i=0;i<s.size();i++) {
		int t = s[i]-'0';
		num++;
		if (t%3 == 0 || num==3) { ans++; num=0; continue;}
		if (i == 0) continue;
		int q = s[i-1]-'0';
		if (num == 1) continue;
		if ((q*10+t)%3 == 0) { ans++; num=0;}
	}
	cout<<ans<<endl;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	long long T = 0;
	for (int i=l;i<r+1;i++) T += pow(10,r-i)*(s[i]-'0');
	//cout<<T<<endl;
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	long long T = 0;
	long long Ten = 1;
	for (int i=r;i>=l;i--) {
		int X = s[i]-'0';
		T += Ten*X;
		Ten *= 10;
	}
	//cout<<T<<endl;
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.size();i++) {
		for (int j=i;j<s.size();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool f(string s, int l, int r)
{
	int T = 0;
	for (int i=l;i<r+1;i++) T += pow(10,r-i)*(s[i]-'0');
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (f(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	if (r-l > 5) return false;
	long long T = 0;
	long long Ten = 1;
	for (int i=r;i>=l;i--) {
		int X = s[i]-'0';
		T += Ten*X;
		Ten *= 10;
	}
	//cout<<T<<endl;
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string str;
	cin>>str;
	char s[2000010];
	strcpy(s,str.c_str());
	int ans = 0;
	for (int i=0;s[i]!='\0';i++) {
		for (int j=i;s[j]!='\0';j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool f(const string s, const int l, const int r)
{
	int T = 0;
	for (int i=l;i<r+1;i++) T += pow(10,r-i)*(s[i]-'0');
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (f(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	if (r-l > 5) return false;
	long long T = 0;
	long long Ten = 1;
	for (int i=r;i>=l;i--) {
		int X = s[i]-'0';
		T += Ten*X;
		Ten *= 10;
	}
	//cout<<T<<endl;
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string str;
	cin>>str;
	char s[2000010];
	strcpy(s,str.c_str());
	int ans = 0;
	for (int i=0;s[i]!='\0';i++) {
		for (int j=i;s[j]!='\0';j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	if (r-l > 3) return false;
	long long T = 0;
	for (int i=l;i<r+1;i++) T += pow(10,r-i)*(s[i]-'0');
	//cout<<T<<endl;
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	long long T = 0;
	long long Ten = 1;
	for (int i=r;i>=l;i--) {
		int X = s[i]-'0';
		T += Ten*X;
		Ten *= 10;
	}
	cout<<T<<endl;
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.size();i++) {
		for (int j=i;j<s.size();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	long long T = 0;
	for (int i=l;i<r+1 && i<s.length();i++) T += pow(10,r-i)*(s[i]-'0');
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	int T = 0;
	for (int i=l;i<r+1;i++) T += pow(10,r-i)*(s[i]-'0');
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	long long T = 0;
	long long Ten = 1;
	for (int i=r;i>l;i--) {
		T += Ten*(s[i]-'0');
		Ten *= 10;
	}
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	if (r-l > 3) return false;
	int T = 0;
	int Ten = 1;
	for (int i=r;i>=l;i--) {
		int X = s[i]-'0';
		T += Ten*X;
		Ten *= 10;
	}
	//cout<<T<<endl;
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.length();i++) {
		for (int j=i;j<s.length();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool f(const string s, const int l, const int r)
{
	int T = 0;
	for (int i=l;i<r+1;i++) {
		int X = pow(10,r-i);
		int Y = s[i]-'0';
		T += X*Y;
	}
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.size();i++) {
		for (int j=i;j<s.size();j++) {
			if (f(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool judge(string s, int l, int r)
{
	long long T = 0;
	long long Ten = 1;
	for (int i=r;i>=l;i--) {
		T += Ten*(s[i]-'0');
		Ten *= 10;
	}
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.size();i++) {
		for (int j=i;j<s.size();j++) {
			if (judge(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool f(const string s, const int l, const int r)
{
	int T = 0;
	for (int i=l;i<r+1;i++) T += pow(10,r-i)*(s[i]-'0');
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i=0;i<s.size();i++) {
		for (int j=i;j<s.size();j++) {
			if (f(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

bool f(const string s, const int l, const int r)
{
	long long T = 0;
	for (int i=l;i<r+1;i++) T += pow(10,r-i)*(s[i]-'0');
	if (T%3 == 0) 	return true;
	else			return false;
}

int main()
{
	string s;
	cin>>s;
	int Len = s.size();
	int ans = 0;
	for (int i=0;i<Len;i++) {
		for (int j=i;j<Len;j++) {
			if (f(s,i,j)) {
				i = j;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
string x;
int ans;
int main(){
	cin>>x;
	for(int i=0,cnt=0;i<x.length();i++){
		if(x[i]=='0'||x[i]=='3'||x[i]=='6'||x[i]=='9'){
			ans++;
			x[i]='a';
			cnt=0;
		}else if(i>0&&(x[i]+x[i-1])%3==0&&x[i-1]!='a'&&cnt%3==2){
			ans++;
			x[i]=x[i-1]='a';
			cnt=0;
		}else{
			cnt++;
		}
	}
	for(int i=0,cnt=0;i<x.length();i++){
		if(x[i]=='a'){
			ans+=(cnt)/3;
			cnt=0;
		}else{
			cnt++;
		}
	}
	cout<<ans<<endl;
}


#include<iostream>
#include<cstring>
using namespace std;
string x;
int ans;
int main(){
	cin>>x;
	for(int i=0;i<x.length();i++){
		if(x[i]=='0'||x[i]=='3'||x[i]=='6'||x[i]=='9'){
			ans++;
			x[i]='a';
		}else if(i>0&&(x[i]+x[i-1])%3==0&&x[i-1]!='a'){
			ans++;
			x[i]=x[i-1]='a';
		}
	}
	for(int i=0,cnt=0;i<x.length();i++){
		if(x[i]=='a'){
			ans+=cnt/3;
			cnt=0;
		}else{
			cnt++;
		}
	}
	cout<<ans<<endl;
}


x,y,z=(int(i) for i in input().split())
if (x+y)/z==(x/z + y/z):
    print((x+y)/z, 0)
else:
    print((x+y)/z, min(z-x%z, z-y%z))


x,y,z = map(int,input().split())
ans1 = (x+y)//z
p = x%z
q = y%z
if (p+q) >= z:
	ans2 = min(p,q)
else:
	ans2 = 0
print(ans1,ans2)


x,y,z = map(int,input().split())
ans1 = (x+y)//z
p = x%z
q = y%z
if (p+q) >= z:
	ans2 = min(p,q)
else:
	ans2 = min(p,q)
print(ans1,ans2)


x,y,z = map(int,input().split())
ans1 = (x+y)//z
p = x%z
q = y%z
if (p+q) >= z:
	ans2 = min(z-p,z-q)
else:
	ans2 = 0
print(ans1,ans2)


a,b,c=map(int,input().split());s=(a//c);s1=(b//c);a=(a%c);b=(b%c);print(s+s1+(a+b)//c,0 if (a+b)<c else min(min(c-a,b),min(c-b,a)))


x,y,z=list(map(int,input().split()))
if(x%z==0 or y%z==0):
    c=0
    s=x//z
    m=y//z
else:
    rem1=x%z
    rem2=y%z
    if(rem1>=rem2):
        x=x+rem2
        c=rem2
    else:
        y=y+rem1
        c=rem1
    if(x%z==0 or y%z==0):
        s=x//z
        m=y//z
print((s+m),c)


x,y,z=list(map(int,input().split()))
rs=(x+y)//z
if(x%z!=0 and y%z!=0 and ((x%z)+(y%z)>=z)):
    if((x%z)+(y%z)==z):
        c=min(x%z,y%z)
    else:
        c=z-max(x%z,y%z)

else:
    c=0
print(rs,c)


x,y,z=list(map(int,input().split()))
if(z>0):
    if(x%z==0 or y%z==0):
        c=0
        s=x//z
        m=y//z
    else:
        rem1=x%z
        rem2=y%z
        if(rem1>=rem2):
            x=x+rem2
            c=rem2
        else:
            y=y+rem1
            c=rem1
        if(x%z==0 or y%z==0):
            s=x//z
            m=y//z
    print((s+m),c)


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("OUTPUX.out","w")
N,S,K=map(int,input().split())
ans=(N+S)//K
idk=min((N%K),(S%K))
print(ans,idk)


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("OUTPUX.out","w")
N,S,K=map(int,input().split())
ans=(N+S)//K
O=N%K
R=S%K
count=0
if O+R>=K:
	count=K-max(O,R)
print(ans,idk)


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("OUTPUX.out","w")
N,S,K=map(int,input().split())
ans=(N+S)//K
O=N%K
R=S%K
count=0
if O+R>=K:
	count=K-max(O,R)
print(ans,count)


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("OUTPUX.out","w")
N,S,K=map(int,input().split())
ans=(N+S)//K
idk=K-max(S%K,N%K)
print(ans,idk)


x, y ,z =map(int, input().split())
cnt = 0

a = (x+y)//z

if x%z+y%z < z:
    b=0
else:
	b = min(z-x%z,z-y%z)

print(a, b)


x, y ,z =map(int, input().split())
cnt = 0

a = (x+y)//z

if x+y < z:
    b=0
b = min(z-x%z,z-y%z)

print(a, b)


x, y ,z =map(int, input().split())
cnt = 0

max = (x+y)//z
min = max(x%z,y%z)

print(max, min)


x, y ,z =map(int, input().split())
cnt = 0

if x+y < z:
    print(0, 0)

a = (x+y)//z
b = min(z-x%z,z-y%z)

print(a, b)


x, y, z = map(int, input().split())

r1 = int((x+y) / z)
r2 = min(x%z, y%z)

print(r1, r2)


x, y, z = map(int, input().split())

r1 = int((x+y) / z)
if x+y >= z: r2 = min(x%z, y%z)
else: r2 = 0

print(r1, r2)


x, y, z = map(int, input().split())

o = x//z + y//z
x = x%z
y = y%z
o2 = 0

if (x+y)%z != (x+y):
  o += 1
  if x > y:
    o2 = z - x
  else:
    o2 = z - y

print(o, o2)


x, y, z = map(int, input().split())

o = x//z + y//z
x = x%z
y = y%z

try:
  if (x+y)%z != (x+y):
    o += 1
    if x > y:
      o2 = z - x
    else:
      o2 = z - y
  print(o, o2)

except NameError:
  print(0, 0)


x, y, z = map(int, input().split())

a1 = (x+y)//z

if x+y < z:
  a2 = 0

else:
  if x%z==0 or y%z==0:
    a2 = 0

  else:
    a2 = min(x%z, y%z, x%y, y%z, a1*z-max(x,y))
    if a2 == 0: a2 = 1

print(a1, a2)


x, y, z = map(int, input().split())

r1 = int((x+y) / z)
if (x+y) % z != 0: r2 = (x+y) % z
elif x+y >= z: r2 = min(x%z, y%z)
else: r2 = 0

print(r1, r2)


x, y, z = map(int, input().split())

a1 = (x+y)//z

if x+y < z:
  a2 = 0

o = x//z + y//z
x = x%z
y = y%z

if (x+y)%z != (x+y):
  o += 1
  if x > y:
    o2 = z - x
  else:
    o2 = z - y

print(o, o2)


x,y,z=(input()).split(" ")
x=(int)(x)
y=(int)(y)
z=(int)(z)
sum1=0
left=0
if(x<z and y<z):
    if(x+y<z):
        print('0', min(x,y))
    else:
        sumd=((x+y)//z)
        left=(x+y)-z*((x+y)//z)
        x-=left
        y-=left
        if(x<0):
            print(sumd, y)
        elif(y<0):
            print(sumd, x)
        else:
            print(sumd, min(x,y))
elif(x<z):
    y+=x

    print(y//z, y-(z*(y//z)))

elif(y<z):
    x+=y
    print(x//z, x-(z*(x//z)))

else:
    sum1+=x//z
    sum1+=y//z
    x=x-(z*(x//z))
    y=y-(z*(y//z))
    #print(x, y)
    sum1+=(y+x)//z
    left=(y+x)-(z*((y+x)//z))
    x=x-left
    y=y-left
    if(y<0 and x<0):
        print(sum1, 0)
    elif(y<0):
        print(sum1,x)
    elif(x<0):
        print(sum1,y)
    else:
        print(sum1, min(x,y))


x,y,z=(input()).split(" ")
x=(int)(x)
y=(int)(y)
z=(int)(z)
sum1=0
left=0
if(x<z and y<z):
    if(x+y<z):
        print('0', '0')
    else:
        sumd=((x+y)//z)
        left=(x+y)-z*((x+y)//z)
        x-=left
        y-=left
        if(x<0):
            print(sumd, y)
        elif(y<0):
            print(sumd, x)
        else:
            print(sumd, min(x,y))
elif(x<z):
    y+=x

    print(y//z, y-(z*(y//z)))

elif(y<z):
    x+=y
    print(x//z, x-(z*(x//z)))

else:
    sum1+=x//z
    sum1+=y//z
    x=x-(z*(x//z))
    y=y-(z*(y//z))
    #print(x, y)
    sum1+=(y+x)//z
    left=(y+x)-(z*((y+x)//z))
    x=x-left
    y=y-left
    if(y<0 and x<0):
        print(sum1, 0)
    elif(y<0):
        print(sum1,x)
    elif(x<0):
        print(sum1,y)
    else:
        print(sum1, min(x,y))


x,y,z=(input()).split(" ")
x=(int)(x)
y=(int)(y)
z=(int)(z)
sum1=0
left=0
if(x<z):
    y+=x
    print(y//z+" "+x)

elif(y<z):
    x+=y
    print(x//z+" "+y)

else:
    sum1+=x//z
    sum1+=y//z
    x=x-(z*(x//z))
    y=y-(z*(y//z))
    #print(x, y)
    sum1+=(y+x)//z
    left=(y+x)-(z*((y+x)//z))
    x=x-left
    y=y-left
    if(y<0):
        print(sum1,x)
    if(x<0):
        print(sum1,y)
    else:
        print(sum1, min(x,y))


x,y,z=(input()).split(" ")
x=(int)(x)
y=(int)(y)
z=(int)(z)
sum1=0
left=0
if(x<z):
    y+=x
    print(y//z+" "+x)

elif(y<z):
    x+=y
    print(x//z+" "+y)

else:
    sum1+=x//z
    sum1+=y//z
    x=x-(z*(x//z))
    y=y-(z*(y//z))
    sum1+=(y+x)//z
    print(sum1,min(x,y))


x,y,z=(input()).split(" ")
x=(int)(x)
y=(int)(y)
z=(int)(z)
sum1=0
left=0
if(x<z and y<z):
    if(x+y<z):
        print('0', min(x,y))
    else:
        left=(x+y)-z*((x+y)//z)
        x-=left
        y-=left
        if(x<0):
            print((x+y)//z, y)
        elif(y<0):
            print((x+y)//z, x)
        else:
            print((x+y)//z, min(x,y))
elif(x<z):
    y+=x

    print(y//z, y-(z*(y//z)))

elif(y<z):
    x+=y
    print(x//z, x-(z*(x//z)))

else:
    sum1+=x//z
    sum1+=y//z
    x=x-(z*(x//z))
    y=y-(z*(y//z))
    #print(x, y)
    sum1+=(y+x)//z
    left=(y+x)-(z*((y+x)//z))
    x=x-left
    y=y-left
    if(y<0):
        print(sum1,x)
    if(x<0):
        print(sum1,y)
    else:
        print(sum1, min(x,y))


x,y,z=(input()).split(" ")
x=(int)(x)
y=(int)(y)
z=(int)(z)
sum1=0
left=0
if(x<z and y<z):
    if(x+y<z):
        print('0', min(x,y))
    else:
        left=(x+y)-z*((x+y)//z)
        x-=left
        y-=left
        if(x<0):
            print((x+y)//z, y)
        elif(y<0):
            print((x+y)//z, x)
        else:
            print((x+y)//z, min(x,y))
elif(x<z):
    y+=x

    print(y//z, y-(z*(y//z)))

elif(y<z):
    x+=y
    print(x//z, x-(z*(x//z)))

else:
    sum1+=x//z
    sum1+=y//z
    x=x-(z*(x//z))
    y=y-(z*(y//z))
    #print(x, y)
    sum1+=(y+x)//z
    left=(y+x)-(z*((y+x)//z))
    x=x-left
    y=y-left
    if(y<0 and x<0):
        print(sum1, 0)
    elif(y<0):
        print(sum1,x)
    elif(x<0):
        print(sum1,y)
    else:
        print(sum1, min(x,y))


R = lambda: map(int, input().split())
a,b,c = R()
print((a+b)//c,min(a%c,b%c))


R = lambda: map(int, input().split())
a,b,c = R()
k = (a+b)//c
if c > a and c > b:print(0,0)
elif c > a:
    if k == b // c:print(k,0)
    else:print(k,min(a%c,b%c))
elif c > b:
    if k == a // c:print(k,0)
    else:print(k,min(a%c,b%c))
else:print((a+b)//c,min(a%c,b%c))


R = lambda: map(int, input().split())
a,b,c = R()
k = (a+b)//c
if a % c == 0 and b % c == 0:print(k,0);quit();
if c > a and c > b:
    if k == 0:print(0,0)
    else:print(k,c-max(a,b))
elif c > a:
    if k == (b // c):print(k,0)
    else:print(k,c-max(a%c,b%c))
elif c > b:
    if k == (a // c):print(k,0)
    else:print(k,c-max(a%c,b%c))
else:
    if k == ((a//c)+(b//c)):print(k,0)
    else:print((a+b)//c,c-max(a%c,b%c))


R = lambda: map(int, input().split())
a,b,c = R()
if c > a and c > b:print(0,0)
else:print((a+b)//c,min(a%c,b%c))


R = lambda: map(int, input().split())
a,b,c = R()
k = (a+b)//c
if c > a and c > b:print(0,0)
elif c > a:
    if k == (b // c):print(k,0)
    else:print(k,min(a%c,b%c))
elif c > b:
    if k == (a // c):print(k,0)
    else:print(k,min(a%c,b%c))
else:print((a+b)//c,min(a%c,b%c))


x, y, z = [int(i) for i in input().split()]
m = (x + y) // z
cnt1 = 0
cnt2 = 0
while x % z != 0:
	x += 1
	cnt1 += 1
while y % z != 0:
	y += 1
	cnt2 += 1
print(m, min(cnt1, cnt2))


x, y, z = [int(i) for i in input().split()]
m = (x + y) // z
t1  = (x + z - 1) // z
t2 = (y + z - 1) // z
if x % z == 0 and y % z == 0:
	print(m, 0)
else:
	print(m, min(z * t1 - x, z * t2 - y))


x, y, z = [int(i) for i in input().split()]
m = (x + y) // z
if x // z + y // z == m:
	print(m, 0)
else:
	print(m, min(z - x % z, z - y % z))


x, y, z = [int(i) for i in input().split()]
m = (x + y) // z
print(m, min(z - x % z, z - y % z))


x, y, z = [int(i) for i in input().split()]
m = (x + y) // z
t1  = (x + z - 1) // z
t2 = (y + z - 1) // z
print(m, min(z * t1 - x, z * t2 - y))


a,b,c=map(int,input().split())
fi=min(a%c,b%c)
res=(a+b)//c
print(res,fi)


a,b,c=map(int,input().split())
fi=min(a%c,b%c)
res=(a+b)//c
if res==0:
    print(res,0)
else:
    print(res,fi)


a,b,c=map(int,input().split())
fi=min(a%c,b%c)
res=(a+b)//c
if res==0:
    print(res,0)
else:
    re1=a%c
    re2=b%c
    re=re1+re2
    if re%c==0:
        print(res,fi)
    else:
        print(res,0)


a,b,c=map(int,input().split())
re1=a//c
re2=b//c
res=re1*c+re2*c
#print(res)
rt=a+b-res
if rt%c==0:
    fi=re1+re2+(rt//c)
print(fi,min(a,b)%c)


a,b,c=map(int,input().split())
res=(a+b)//c
if res==0:
    print(res,0)
else:
    re1=a%c
    re2=b%c
    re=re1+re2
    if re>=c:
        fi1=c-re1
        fi2=c-re2
        print(res,min(fi1,fi2))
    else:
        print(res,0)


a,b,c=map(int,input().split())
fi=min(a%c,b%c)
res=(a+b)//c
if res==0:
    print(res,0)
else:
    re1=a%c
    re2=b%c
    re=re1+re2
    if re>=c:
        print(res,fi)
    else:
        print(res,0)


x, y, z = map(int, input().split())
num = 0
debt = 0
if ((x % z) + (y % z)) >= z:
    num += x // z
    num += y // z
    num += 1
    if (x % z) < (y % z):
        debt += (z - (y % z))
    else:
       debt += (z - (x % z))
else:
    num += x // z
    num += y // z
print(str(num) + ' ' + str(debt))


x, y, z = map(int, input().split())
num = 0
debt = 0
if ((x % z) + (y % z)) > z:
    num += x // z
    num += y // z
    num += 1
    debt += (y % z) + (x % z) - z
else:
    num += x // z
    num += y // z
print(str(num) + ' ' + str(debt))


x, y, z = map(int, input().split())
num = 0
debt = 0
if ((x % z) + (y % z)) >= z:
    num += x // z
    num += y // z
    num += 1
    debt += (y % z) + (x % z) - z
else:
    num += x // z
    num += y // z
print(str(num) + ' ' + str(debt))


x, y, z = map(int, input().split())
num = 0
debt = 0
if ((x % z) + (y % z)) > z:
    num += x // z
    num += y // z
    num += 1
    debt += (z - (y % z))
else:
    num += x // z
    num += y // z
print(str(num) + ' ' + str(debt))


x, y, z = map(int, input().split())
num = 0
debt = 0
if ((x % z) + (y % z)) >= z:
    num += x // z
    num += y // z
    num += 1
    debt += (z - (y % z))
else:
    num += x // z
    num += y // z
print(str(num) + ' ' + str(debt))


x, y, z = map(int, input().split())

min_give = (min(min(x % z, z - x % z), min(y % z, z - y % z)))
r1 = (x + y) // z
r2 = x // z + y // z
if r1 == r2:
    min_give = 0

print (f'{r1} {min_give}')


x, y, z = map(int, input().split())

min_give = (min(min(x % z, z - x % z), min(y % z, z - y % z)))
r1 = int((x + y) / z)
r2 = int (x / z) + int (y / z)
if r1 == r2:
    min_give = 0

print (f'{r1} {min_give}')


x, y, z = map(int, input().split())

def min_give ():
    return (min(min(x % z, z - x % z), min(y % z, z - y % z)))
print (f'{int((x + y) / z)} {min_give()}')


x = input()
y = input()
z = input()
x = int (x)
y = int (y)
z = int (z)
def min_give ():
    return (min(min(x % z, z - x % z), min(y % z, z - y % z)))
print (f'{int((x + y) / z)} {min_give()}')


def chizk(x,y,z):

	res1=x%z
	res2=y%z

	if res1 + res2 < z:
		return(((x+y)//z),0)
	else:
		return((x+y)//z,z-max(res1,res2))

x,y,z = list(map(int,input().split()))
print(chizk(x,y,z))


def chizk(x,y,z):

	res1=x%z
	res2=y%z

	if res1 + res2 < z:
		return((x+y//z),0)
	else:
		return((x+y//z),z-max(res1,res2))

x,y,z = list(map(int,input().split()))
print(chizk(x,y,z))


x,y,z = map(int,input().split())

res1=x%z
res2=y%z

if res1 + res2 < z:
	return (x+y)//z ,0
else:
	return (x+y)//z, z-max(res1,res2)


x,y,z = list(map(int,input().split()))
res1=x%z
res2=y%z

if res1 + res2 < z:
	print((x+y//z),0)
else:
	print((x+y//z),c-max(res1,res2))


x,y,z = map(int,input().split())

res1=x%z
res2=y%z

if res1 + res2 < z:
	print( (x+y)//z ,0)
else:
	print( (x+y)//z, z-max(res1,res2))


def chizk(x,y,z):

	res1=x%z
	res2=y%z

	if res1 + res2 < z:
		return (x+y)//z ,0
	else:
		return (x+y)//z, z-max(res1,res2)

x,y,z = list(map(int,input().split()))
print(chizk(x,y,z))


'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

l=input()
list=l.split()
x=int(list[0])
y=int(list[1])
cost=int(list[2])
if(x%cost+y%cost>=cost):
    print(int((x+y)//cost),cost-max(x%cost,y%cost))
else:
    print(int((x+y)//cost),0)


l=input()
list=l.split()
x=int(list[0])
y=int(list[1])
cost=int(list[2])
rem1=x%cost
rem2=y%cost
if(x%cost==0 and y%cost==0):
    print(int(x//cost+y//cost),x%cost)
elif(rem1>rem2):
    print(int((x+rem2)//cost+(y-rem2)//cost),cost-rem1)
else:
    print(int((x-rem1)//cost)+((y+rem1)//cost),cost-rem2)


'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

l=input()
list=l.split()
x=int(list[0])
y=int(list[1])
cost=int(list[2])
if(x%cost+y%cost>=cost):
    print(int((x+y)/cost),cost-max(x%cost,y%cost))
else:
    print(int((x+y)/cost),0)


l=input()
list=l.split()
x=int(list[0])
y=int(list[1])
cost=int(list[2])
rem1=x%cost
rem2=y%cost
if(x%cost==0 and y%cost==0):
    print(int(x//cost+y//cost),x%cost)
elif(rem1>=rem2):
    print(int((x+rem2)//cost+(y-rem2)//cost),rem2)
else:
    print(int((x+rem1)//cost+(y-rem1)//cost),rem1)


l=input()
list=l.split()
x=int(list[0])
y=int(list[1])
cost=int(list[2])
rem1=x%cost
rem2=y%cost
if(x%cost==0 and y%cost==0):
    print(int(x/cost+y/cost),x%cost)
elif(rem1>=rem2):
    print(int((x+rem2)/cost+(y-rem2)/cost),rem2)
else:
    print(int((x+rem1)/cost+(y-rem1)/cost),rem1)


'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

l=input()
list=l.split()
x=int(list[0])
y=int(list[1])
cost=int(list[2])
rem1=x%cost
rem2=y%cost
if(x%cost==0 and y%cost==0):
    print(int(x//cost+y//cost),x%cost)
elif(rem1>rem2 and cost-rem1>cost):
    print(int((x+rem2)//cost+(y-rem2)//cost),cost-rem1)
else:
    if(cost-rem1<=rem2):
        print(int((x-rem1)//cost)+((y+rem1)//cost),cost-rem1)
    elif(cost-rem2<rem1):
         print(int((x-rem1)//cost)+((y+rem1)//cost),cost-rem2)
    else:
        print(int((x-rem1)//cost)+((y+rem1)//cost),0)


l=input()
list=l.split()
x=int(list[0])
y=int(list[1])
cost=int(list[2])
rem1=x%cost
rem2=y%cost
if(x%cost==0 and y%cost==0):
    print(int(x//cost+y//cost),x%cost)
elif(rem1>rem2 and cost-rem1>cost):
    print(int((x+rem2)//cost+(y-rem2)//cost),cost-rem1)
else:
    if(cost-rem1<rem2):
        print(int((x-rem1)//cost)+((y+rem1)//cost),cost-rem1)
    elif(cost-rem2<rem1):
         print(int((x-rem1)//cost)+((y+rem1)//cost),cost-rem2)
    else:
        print(int((x-rem1)//cost)+((y+rem1)//cost),0)


'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

l=input()
list=l.split()
x=int(list[0])
y=int(list[1])
cost=int(list[2])
if(x%cost+y%cost>=cost):
    print((x+y)/cost,cost-max(x%cost,y%cost))
else:
    print((x+y)/cost,0)


x, y, z = map(int, input().split())
print((x + y) // z, end=' ')
if x % z == 0 or y % z == 0:
    print(0)
else:
    print(min(abs(z - x % z), abs(z - y % z)))


x, y, z = map(int, input().split())
print((x + y) // z, end=' ')
if x//z + y//z == (x + y) // z:
    print(0)
else:
    print(min(abs(z - x % z), abs(z - y % z)))


x, y, z = map(int, input().split())
print((x + y) // z, end=' ')
if x % z == 0 or y % z == 0:
    print(0)
else:
    print(min(z - abs(x - z), z - abs(y - z)))


x,  , z = map(int, input().split()
print('{} {}'.format((x+y)//z, min(x%z, y%z)))


x, y, z = map(int, input().split())
a=x%z
b=y%z
c = min(a,b) if a+b>=z else 0
print('{} {}'.format((x+y)//z,c))


x,y,z=map(int, input().split())
print('{} {}'.format((x+y)//z, min(x%z,y%z)))


x, y, z = map(int, input().split())
a = x % z
b = y % z
c = (z-max(a,b)) if a+b >=z else 0
print('{} {}'.format((x+y)//z,c))


x,y,z = map(int, input().split())
a=x%z
b=y%
c=min(a,b) if a+b>=z else 0
print('{} {}'.format((x+y)//z,c))


x, y, z = map(int, input().split()
print('{} {}'.format((x+y)//z, min(x%z, y%z))


x, y, z = map(int, input().split()
print('{} {}'.format((x+y)//z, min(x%z, y%z)))


x,y,z = map(int,input().split())

if x < y: [x, y] = [y, x]

x1 = x
y1 = y

cnt = 0
if x % z != 0:
    diff = (((x // z) + 1) * z) - x
    y -= diff
    x += diff
    cnt = diff

if (x1 // z + y1 // z) >= (x // z + y // z):
    print(x1 // z + y1 // z, 0)
else:
    print(x // z + y // z, cnt)


x,y,z = map(int,input().split())
cnt1 = 0
x1 = x
y1 = y
if x1 % z != 0:
    diff = (((x1 // z) + 1) * z) - x1
    x1 += diff
    y1 -= diff
    cnt1 = diff

cnt = 0
if y % z != 0:
    diff = (((y // z) + 1) * z) - y
    x -= diff
    y += diff
    cnt = diff

print(max(x1 // z + y1 // z, x // z + y // z), min(cnt, cnt1))


x,y,z = map(int,input().split())
cnt1 = 0
x1 = x
y1 = y
if x1 % z != 0:
    diff = (((x1 // z) + 1) * z) - x1
    cnt1 = diff

cnt = 0
if y % z != 0:
    diff = (((y // z) + 1) * z) - y
    cnt = diff

if (x + y) // z == 0:
    cnt = 0

print((x + y) // z, min(cnt, cnt1))


x,y,z = map(int,input().split())
cnt = 0
while x % z != 0:
    if y > 0:
        x+=1
        y-=1
        cnt+=1

print(x // z + y // z, cnt)


x,y,z = map(int,input().split())

if x < y: [x, y] = [y, x]

if (x + y) // z == x // z + y // z:
    print((x + y) // z, 0)
    exit()

x1 = x
y1 = y

cnt = 0
if x % z != 0:
    diff = (((x // z) + 1) * z) - x
    y -= diff
    x += diff
    cnt = diff

cnt1 = 0
if y1 % z != 0:
    diff = (((y1 // z) + 1) * z) - y1
    y1 += diff
    x1 -= diff
    cnt1 = diff

if x1 < 0 or y1 < 0:
    cnt1 = 10**20

if x < 0 or y < 0:
    cnt = 10**20

if (cnt1 == 10**20 and cnt == 10**20):
    print((x + y) // z, 0)
else:
    print((x + y) // z, min(cnt, cnt1))


x,y,z = map(int,input().split())
cnt1 = 0
x1 = x
y1 = y
if x1 % z != 0:
    diff = (((x1 // z) + 1) * z) - x1
    cnt1 = diff

cnt = 0
if y % z != 0:
    diff = (((y // z) + 1) * z) - y
    cnt = diff

print((x + y) // z, min(cnt, cnt1))


x,y,z = map(int,input().split())
cnt1 = 0
x1 = x
y1 = y
if x1 % z != 0:
    diff = (((x1 // z) + 1) * z) - x1
    x1 += diff
    y1 -= diff
    if (y1 < 0):y1 = 0
    cnt1 = diff

cnt = 0
if y % z != 0:
    diff = (((y // z) + 1) * z) - y
    x -= diff
    if (x < 0):x = 0
    y += diff
    cnt = diff

print(max(x1 // z + y1 // z, x // z + y // z), min(cnt, cnt1))


x,y,z = map(int,input().split())
cnt1 = 0
x1 = x
y1 = y
while x1 % z != 0:
    if y1 > 0:
        x1+=1
        y1-=1
        cnt1+=1

cnt = 0
while y % z != 0:
    if x > 0:
        x-=1
        y+=1
        cnt+=1

print(max(x1 // z + y1 // z, x // z + y // z), min(cnt, cnt1))


x,y,z= map(int,input().split())
if x%z==0 or y%z==0:
    print(int((x+y)/z), "0")
else:
    a= x%z
    b= y%z
    c= min(z-a, z-b)
    if c== z-a:
        if b>= c:
            print(int((x+y)/z), c)
        else:
            print(int((x+y)/2),"0")
    else:
        if a>= c:
            print(int((x+y)/z), c)
        else:
            print(int((x+y)/2),"0")


x,y,z= map(int,input().split())
c1= x%z
c2= y%z
c3= (x+y)//z
print(c3,end=" ")
if x//z+ y//z==c3:
    print(0)
else:
    print(min(z-c1,z-c2))


x,y,z= map(int,input().split())
if x%z==0 or y%z==0:
    print(int((x+y)/z), "0")
else:
    a= x%z
    b= y%z
    c= z-a
    d= z-b
    print(int((x+y)/z), min(c,d))


s,m,c=map(int,input().split())
total=(s+m)//c
# print(total)
sasha=s%c
#print(sasha)
sasha_buy=s//c
#print(sasha_buy)
masha_buy=m//c
#print(masha_buy)
masha=m%c
#print(masha)
exchange=min(sasha,masha)
#print(exchange)
if (total==sasha_buy+masha_buy):
	print(total,0)
else:
	print (total, exchange)


s,m,c=map(int,input().split())
total=(s+m)//c
# print(total)
sasha=s%c
#print(sasha)
sasha_buy=s//c
#print(sasha_buy)
masha_buy=m//c
#print(masha_buy)
masha=m%c
#print(masha)
ex=max(sasha,masha)
change=c-ex
#print(exchange)
if (total==sasha_buy+masha_buy):
	print(total,0)
else:
	print (total, change)


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
vector<int> index[100100];
set<int> ne[100100];
int n,m;
int a[100100];
ll sum[100100];
ll ans=0ll;
ll mi=0ll;
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		cin >> a[i];
		a[i]--;
		if(i>0)
		{
			ans+=abs(a[i]-a[i-1]);
			sum[a[i]]+=abs(a[i]-a[i-1]);
			sum[a[i-1]]+=abs(a[i]-a[i-1]);
		}
		index[a[i]].pb(i);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<index[i].size();i++)
		{
			int d=index[i][j];
			if(d>0)ne[i].insert(a[d-1]);
			if(d<m-1)ne[i].insert(a[d+1]);
			if(d>0&&d<m-1)
			{
				for(int k=min(a[d-1],a[d+1])+1;k<max(a[d-1],a[d+1])-1;k++)
				{
					ne[i].insert(k);
				}
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		set<int>::iterator it=ne[i].begin();
		for(;it!=ne[i].end();it++)
		{
			int p=*it;
			ll ret=0ll;
			for(int j=0;j<index[i].size();j++)
			{
				int d=index[i][j];
				if(d>0)ret+=abs(a[d-1]-p);
				if(d<m-1)ret+=abs(a[d+1]-p);
			}
			ret-=sum[i];
			mi=min(mi,ret);
		}
	}
	cout << ans+mi << endl;
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m;
int a[100100];
vector<int> vec[100100];
vector<int> index[100100];
int dist[100100];
ll ret=0;
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d",&a[i]);
		if(i>0)ret+=abs(a[i]-a[i-1]);
		index[a[i]].pb(i);
	}
	if(n==1||m==1)
	{
		cout << 0 << endl;
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		if(i==0)
		{
			if(a[i]!=a[i+1])vec[a[i]].pb(a[i+1]);
			dist[i]=abs(a[i+1]-a[i]);
		}
		else if(i==m-1)
		{
			if(a[i]!=a[i-1])vec[a[i]].pb(a[i-1]);
			dist[i]=abs(a[i]-a[i-1]);
		}
		else
		{
			if(a[i]!=a[i+1])vec[a[i]].pb(a[i+1]);
			if(a[i]!=a[i-1])vec[a[i]].pb(a[i-1]);
			dist[i]=abs(a[i+1]-a[i])+abs(a[i]-a[i-1]);
		}
	}
	ll res=0;
	for(int i=1;i<=n;i++)
	{
		if(vec[i].empty())continue;
		sort(vec[i].begin(),vec[i].end());
		int sz=vec[i].size();
		for(int j=max(sz/2-1,0);j<=min(sz/2+1,sz-1);j++)
		{
			ll sum=0;
			for(int k=0;k<index[i].size();k++)
			{
				int p=index[i][k];
				sum-=dist[p];
				if(index[i][k]==0)sum+=abs(a[1]-vec[i][j]);
				else if(index[i][k]==m-1)sum+=abs(vec[i][j]-a[m-2]);
				else
				{
					sum+=abs(vec[i][j]-a[p-1])+abs(vec[i][j]-a[p+1]);
				}
			}
			res=min(res,sum);
		}
	}
	cout << ret+res << endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <ctime>

using namespace std;

long long i, j, n, m, k, a[200000], ans, m1, m2, l, r, c[200000], t, d[200000];
vector <vector <long long> > b(200000);

long long f(long long x, long long y)
{
    long long i, j, k;
    k = 0;
    for (i = 0; i < b[y].size(); i ++)
    {
        k += c[b[y][i]];
        d[b[y][i]] = x;
    }
    //for (i = 0; i < m; i ++)
        //cout << d[i] << " ";
        //cout << endl;
    j = 0;
    for (i = 0; i < b[y].size(); i ++)
    {
        if (b[y][i] == 0 && b[y][i] != m - 1)
            j += abs(x - d[b[y][i] + 1]);
        else if (b[y][i] != m - 1)
            j += (abs(x - d[b[y][i] + 1]) + abs(x - d[b[y][i] - 1]));
        else if (i != 0)
            j += abs(x - d[b[y][i] - 1]);
    }
    //cout << x << " " << y << " " << k << " " << j << endl;
    ans = min(ans, t - (k - j));
    for (i = 0; i < b[y].size(); i ++)
        d[b[y][i]] = a[b[y][i]];
    return (t - (k - j));
}

int main()
{
    cin >> n >> m;
    for (i = 0; i < m; i ++)
    {
        scanf("%I64d", &a[i]);
        b[a[i]].push_back(i);
        d[i] = a[i];
    }
    ans = 0;
    for (i = 0; i < m; i ++)
    {
        if (i != m - 1)
            ans = ans + abs(a[i + 1] - a[i]);
        if (i == 0 && i != m - 1)
            c[i] += (abs(a[i + 1] - a[i]));
        else if (i != m - 1)
            c[i] += (abs(a[i + 1] - a[i]) + abs(a[i - 1] - a[i]));
        else if (i != 0)
            c[i] += (abs(a[i - 1] - a[i]));
    }
    //for (i = 0; i < n - 1; i ++)
        //cout << c[i] << " ";
    t = ans;
    //cout << ans << endl;
    for (i = 1; i <= n; i ++)
    {
        l = 0;
        r = n + 5;
        while (r - l > 2)
        {
            m1 = l + (r - l) / 3;
            m2 = r - (r - l) / 3;
            if (f(m1, i) < f(m2, i))
                r = m1;
            else
                l = m2;
        }
    }
    for (i = l; i <= r; i ++)
    {
        for (j = 1; j <= n; j ++)
            f(j, i);
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <ctime>

using namespace std;

long long i, j, n, m, k, a[200000], ans, m1, m2, l, r, c[200000], t, d[200000];
vector <vector <long long> > b(200000);

long long f(long long x, long long y)
{
    long long i, j, k;
    k = 0;
    for (i = 0; i < b[y].size(); i ++)
    {
        k += c[b[y][i]];
        d[b[y][i]] = x;
    }
    //for (i = 0; i < m; i ++)
        //cout << d[i] << " ";
        //cout << endl;
    j = 0;
    for (i = 0; i < b[y].size(); i ++)
    {
        if (b[y][i] == 0 && b[y][i] != m - 1)
            j += abs(x - d[b[y][i] + 1]);
        else if (b[y][i] != m - 1)
            j += (abs(x - d[b[y][i] + 1]) + abs(x - d[b[y][i] - 1]));
        else if (b[y][i] != 0)
            j += abs(x - d[b[y][i] - 1]);
    }
    //cout << x << " " << y << " " << k << " " << j << endl;
    ans = min(ans, t - (k - j));
    for (i = 0; i < b[y].size(); i ++)
        d[b[y][i]] = a[b[y][i]];
    return (t - (k - j));
}

int main()
{
    cin >> n >> m;
    for (i = 0; i < m; i ++)
    {
        scanf("%I64d", &a[i]);
        b[a[i]].push_back(i);
        d[i] = a[i];
    }
    ans = 0;
    for (i = 0; i < m; i ++)
    {
        if (i != m - 1)
            ans = ans + abs(a[i + 1] - a[i]);
        if (i == 0 && i != m - 1)
            c[i] += (abs(a[i + 1] - a[i]));
        else if (i != m - 1)
            c[i] += (abs(a[i + 1] - a[i]) + abs(a[i - 1] - a[i]));
        else if (i != 0)
            c[i] += (abs(a[i - 1] - a[i]));
    }
    //for (i = 0; i < n - 1; i ++)
        //cout << c[i] << " ";
    t = ans;
    //cout << ans << endl;
    for (i = 1; i <= n; i ++)
        if (b[i].size() > 0)
    {
        l = 0;
        r = n + 5;
        while (r - l > 2)
        {
            m1 = l + (r - l) / 3;
            m2 = r - (r - l) / 3;
            if (f(m1, i) < f(m2, i))
                r = m2;
            else
                l = m1;
        }
    }
    for (i = l; i <= r; i ++)
    {
        for (j = 1; j <= n; j ++)
            f(j, i);
    }
    cout << ans;
    return 0;
}