akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

char s[15];
char c[15];

int main()
{
    scanf("%s",c);
    int l=strlen(c);
    int n=0;
    for(int i=0,j=0;i<l;i++)
    {
        if(c[i]!='B')
        {
            s[j]=c[i];
            j++;
            n++;
        }
        else if(c[i]=='B'&&n>0)
        {
            j--;
            n--;
        }
    }
    for(int i=0;i<n;i++)
        printf("%c",s[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	set<int> all_numbers;
	for (int i = 3; i <= 9; ++i) {
		for (int j = 1; j <= i - 2; ++j) {
			for (int k = 1; k <= i - 2; ++k) {
				int l = i - j - k;
				if (l < 1) {
					break;
				}

				string num;
				num += string(j, '3');
				num += string(k, '5');
				num += string(l, '7');
				do { 
					int i_num = stoi(num);
					all_numbers.insert(i_num);
				} while (next_permutation(num.begin(), num.end()));
			}
		}
	}

	int ans = 0;
	for (auto it = all_numbers.begin(); it != all_numbers.end(); ++it) {
		if (*it <= n) {
			++ans;
		} else {
			break;
		}
	}

	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 4876
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    string s;
    cin>>s;
    vector<int>s1;
    for(auto itr : s)
    {
        if(itr=='R')
        s1.push_back(1);
        if(itr=='G')
        s1.push_back(2);
        if(itr=='B')
        s1.push_back(3);
    }
    long long ans=0;
    long long a[n+5],b[n+5],c[n+5];
    int count=0;
    int count1=0;
    int count2=0;
    for(int i=0;i<n;i++)
    {
        if(s1[i]==1)
        count++;
        if(s1[i]==2)
        count1++;
        if(s1[i]==3)
        count2++;
        a[i]=count;
        b[i]=count1;
        c[i]=count2;
    }
   /* for(int i=0;i<n;i++)
    cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<'\n';*/
    for(int i=1;i<n-1;i++)
    {
        int mid=s1[i];
        for(int j=0;j<i;j++)
        {
            if(s1[j]==mid)
            continue;
            int start=s1[j];
            int search=6-start-mid;
            if(search==1)
            ans+=a[n-1]-a[i];
            if(search==2)
            ans+=b[n-1]-b[i];
            if(search==3)
            ans+=c[n-1]-c[i];
            if(i+i-j>=n)
            continue;
            if(s1[i+(i-j)]==search)
            ans--;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sz[find(x)];
    }
};

int main(){
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    map<int, vector<int>> xs, ys;
    for(int i=0; i<N; i++){
        cin >> X[i] >> Y[i];
        xs[X[i]].push_back(i);
        ys[Y[i]].push_back(i);
    }
    UnionFind uf(N);
    for(auto& p : xs){
        auto& v = p.second;
        for(int a : v) uf.unite(a, v[0]);
    }
    for(auto& p : ys){
        auto& v = p.second;
        for(int a : v) uf.unite(a, v[0]);
    }
    vector<set<int>> xst(N), yst(N);
    for(int i=0; i<N; i++){
        xst[uf.find(i)].insert(X[i]);
        yst[uf.find(i)].insert(Y[i]);
    }

    int64_t ans = -N;
    for(int i=0; i<N; i++){
        int64_t xsz = xst[i].size(), ysz = yst[i].size();
        ans += xsz * ysz;
    }
    cout << ans << endl;
}


Measured memory_bytes: 26880
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
int n,m;
int dp[100005];// i as End
vi E[100005];// reversed edge
inline int DP(int cur){
	if (dp[cur]>=0) return dp[cur];
	int N=E[cur].size();
	if (N==0) return dp[cur]=0;
	int res=0;
	for (int i=0;i<N;++i) res=max(res,DP(E[cur][i]));
	return dp[cur]=res+1;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=m;++i){
		int x,y;cin>>x>>y;
		E[y].pb(x);
	}
	memset(dp,-1,sizeof(dp));
	int ans=0;
	for (int i=1;i<=n;++i) ans=max(ans,DP(i));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i, n) {
        if (i%2==0 && (a[i]&1)) ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstring>
using namespace std;
char s[202];
int main()
{
	int flag=0;
	cin>>s;
	int len=strlen(s);
	for(int i=0;i<len;i++)
	{
		if(s[i]=='C')
		for(int j=i;j<len;j++)
		{
			if(s[j]=='F')
			flag=1;
		}
	}
	if(flag==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
main(void){
    
    int a,b,c,ex;
    scanf("%d %d %d",&a,&b,&c);
    
    if(a>b){
        ex=b;
        b=a;
        a=ex;
    }
    if(a>c){
        ex=c;
        c=a;
        a=ex;
    }
    if(b>c){
        ex=b;
        b=c;
        c=ex;
    }
    printf("%d %d %d\n",a,b,c);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 998244353;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {

 ios::sync_with_stdio(false);

string s,t;
cin>>s>>t;
ll n=s.size();
ll ans=0;
for(int i=0;i<n;i++){
if(s[i]!=t[i])ans++;

}

cout<<ans<<endl;
return 0;
}






Measured memory_bytes: 3860
function Main(input){
    input = input.split("\n");
    var k = 0;
    while(1){
        input[k] = input[k].split(" ");
        var d = parseInt(input[k][0],10);
        var e = parseInt(input[k++][1],10);
        if(d == 0 && e == 0)
            break;

        var min = 100000000;
        for(var i = 0;i <= d;i++){
            if(Math.abs(e - Math.sqrt(i * i + (d - i) * (d - i))) < min)
                min = Math.abs(e - Math.sqrt(i * i + (d - i) * (d - i)));
        }
        console.log(min);
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 17104
'use strict'

const main = (input) => {
    input = input.split('\n')[0].split(' ').map(i => parseInt(i))
    const nums = input.sort((a, b) => b - a)
    console.log(nums[0] * 10 + nums[1] + nums[2])
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
# 01-Getting_Started-X_cubic.py

# x ??? 3 ???
# ???????????´??° x ?????????????????§???x ?????????????¨????????????????????????????????????°?????????????????????????????????

# Input
# ??\?????¨?????????????????´??° x ????????????????????????
# Output
# x ?????????????¨???????????????????????????????????????????????????????????????????????????????????????????????????????

# Sample Input 1
# 2
# Sample Output 1
# 8
x=int( input() )

print(x**3);

Measured memory_bytes: 7640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
int a,b;
cin >> a >>b;
int sum = a;
int cnt = 1;
if(b == 1){
  cout << 0 << endl;
  return 0;
}
while(sum < b){
  sum += a-1;
  cnt ++;
}
cout << cnt << endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }
  else if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  else{
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
while True:
    n, m = map(int, input().split())
    if not n and not m:
        break

    dataset = [0 for _ in range(m)]
    for i in range(n):
        d, v = map(int, input().split())
        dataset[d - 1] = max(v, dataset[d - 1])
    print(sum(dataset))


Measured memory_bytes: 5616
def gcd(a,b): return a if b == 0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)

for h in range(input()):
	tmp = raw_input()
	for a in range(26):
		if gcd(a,26)!=1:
			continue
		for b in range(26):
			s = ""
			for q in tmp:
				if q.isalpha():
					s += chr((((ord(q)-97)*a+b)%26)+97)
				else:
					s += q
			if ("that" in s)or("this" in s):
				print s

Measured memory_bytes: 6388
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <sstream>
#define ull unsigned long long
#define ll long long
#define INF 1000000007
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,l;
    ll ans=0;
    cin >> n;
    vector<int> a;
    for(int i=0;i<2*n;i++){
        cin >> l;
        a.push_back(l);
    }
    sort(a.begin(),a.end());
    int w = a.size();
    for(int i=0;i<w;i=i+2){
        if(a[i]>a[i+1]){
            ans+=a[i+1];
        }
        else if(a[i]<a[i+1]){
            ans+=a[i];
        }
        else if(a[i]==a[i+1]){
            ans+=a[i];
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] Hi = new int[N];
        int max = 0;
        int cnt = 0;
        for (int i=0; i<N; i++) {
            Hi[i] = sc.nextInt();
            if (Hi[i] >= max) {
                cnt++;
                max = Hi[i];
            }
        }


        System.out.println(cnt);
    }
}


Measured memory_bytes: 22740
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
int offset[12] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
string date[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

int main(int argc, char const* argv[])
{
  int m, d;
  while(cin >> m >> d){
    if(m == 0 && d == 0)break;
    int days = offset[m - 1] + d;
    days = (2 + days) % 7;
    cout << date[days] << endl;
  }
	return 0;
}



Measured memory_bytes: 3192
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    a, b = map(int, input().split())

    A = str(a) * b
    B = str(b) * a
    if A < B:
        print(A)
    else:
        print(B)


if __name__ == '__main__':
    main()

Measured memory_bytes: 5764
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e5 + 10, S2 = 1e7 * 2, MOD = 1e9 + 7;

ll cnt[52][27];



int main() {
    fastInp;

    ll n, m;
    cin >> n >> m;

    ll ml = 0;
    vector<ll> xs(n);
    for (int i = 0; i < n; i++) cin >> xs[i];

    sort(xs.begin(), xs.end());
    for (int i = 1; i < n; i++) {

        ml += (((xs[i] - xs[i - 1]) * (((i) * (n - i)) % MOD))) % MOD;
        ml %= MOD;
    }

    vector<ll> ys(m);
    ll ans = 0, pr;
    for (int i = 0; i < m; i++) cin >> ys[i];

    sort(ys.begin(), ys.end());
    for (int i = 1; i < m; i++) {
        ans += ((((ys[i] - ys[i - 1]) * (((i) * (m - i)) % MOD))) % MOD * ml) % MOD;
        ans %= MOD;
    }

    cout << ans;
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>

using namespace std;

int max_digit = 10;

void dfs(int d, long long cur, vector<long long> & A) {
	A.push_back(cur);

	if (d == max_digit) return;

	for (int i = -1; i <= 1; i++) {
		int add = (cur % 10) + i;
		if (0 <= add && add <= 9) {
			dfs(d + 1, cur * 10 + add, A);
		}
	}
}

int main(void) {
	int K; cin >> K;
	vector<long long> A;
	for (int i = 1; i <= 9; i++) {
		dfs(1, i, A);
	}
	sort(A.begin(), A.end());
	cout << A[K - 1] << endl;
}

Measured memory_bytes: 2420
n = gets.to_i
a = gets.split.map(&:to_i)

c = Hash.new(0)
a.each {|e| c[e] += 1}

arr = [0,0]
c.each do |key,value|
    next if value == 1
    value = 4 if value > 4
    arr += Array.new(value/2,key)
end

puts arr.sort[-2,2].inject(:*)

Measured memory_bytes: 106332
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    A = input()
    if A == 'AC':
        AC += 1
    elif A == 'WA':
        WA += 1
    elif A == 'TLE':
        TLE += 1
    else:
        RE += 1
        
print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;

int main(){

    int N, D, X;
    cin >> N;
    cin >> D >> X;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    long long ans = X;
    for(int i = 0; i < N; i++){
        for(int j = 0; j * A[i] + 1 <= D; j++){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    Q, *BC = map(int, read().split())

    total = sum(A)
    d = Counter(A)
    for b, c in zip(BC[::2], BC[1::2]):
        total -= b * d[b]
        total += c * d[b]
        d[c] += d[b]
        d[b] = 0
        print(total)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 113532
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		if(i%3==0||i%5==0){
			
		}
		else{
			ans+=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>

using namespace std;

int dist[2000][2000];
bool vis[2000][2000];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int H, W;
    cin >> H >> W;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            dist[i][j] = 10000, vis[i][j] = false;
    queue<pair<int,int> > Q;
    for(int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        for(int j = 0; j < W; j++)
        {
            if(s[j] == '#')
            {
                dist[i][j] = 0;
                vis[i][j] = true;
                Q.push({i, j});
            }
        }
    }
    auto inside = [&](int i, int j){
        if (i < 0 || i >= H || j < 0 || j >= W)
            return 0;
        return 1;
    };
    while(!Q.empty())
    {
        int i = Q.front().first;
        int j = Q.front().second;
        Q.pop();
        vector<pair<int,int> > ngbhs = {{i + 1, j}, {i - 1, j}, {i, j + 1}, {i, j - 1}};
        for(auto f : ngbhs)
        {
            if (inside(f.first, f.second))

                if(!vis[f.first][f.second])
                {
                    vis[f.first][f.second] = true;
                    dist[f.first][f.second] = min(dist[i][j] + 1, dist[f.first][f.second]);
                    Q.push(f);
                }
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            ans = max(ans, dist[i][j]);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 20624
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
int n;
LL a[20];
LL dfs(int l,int r,int x,int y)
{
	if(l+1==r)return 0;
	LL ans=1e18;
	for(int i=l+1;i<=r-1;++i)ans=min(ans,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)+a[i]*(x+y));
	return ans;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)scanf("%lld",&a[i]);
	cout<<a[1]+a[n]+dfs(1,n,1,1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.BF", "r", stdin );
	int n;
	scanf ("%d", &n );
	vector<int> A (n, 0 );
	rep (i, n ) scanf (" %d", &A[i] );

	int q;
	scanf ("%d", &q );
	vector<int> M (q, 0 );
	rep (i, q ) scanf (" %d", &M[i] ); 

	set<int> sum;
	for (int i = 0; i < 1<<n; i++ ){
		int curr = 0;
		for (int j = 0; j < n; j++ ){
			if (i & (1<<j ) ){
				curr += A[j];
			} // end if
		} // end for
		sum.insert (curr );
	} // end for
	rep (i, q ){
		if (sum.count (M[i] ) ){
			printf ("yes\n" );
		}else{
			printf ("no\n" );
		} // end if
	} // end rep
		
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
template <typename T>
struct UnionFind {
   vector<T> par; 
 
   UnionFind(T N) : par(N) { 
        for(T i = 0; i < N; i++) par[i] = i;
   }
 
   int root(T x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
   }
 
   void unite(T x, T y) { 
       T rx = root(x); 
       T ry = root(y); 
       if (rx == ry) return; 
       par[rx] = ry; 
   }
 
   bool same(T x, T y) { 
       T rx = root(x);
       T ry = root(y);
       return rx == ry;
   }
};

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}


int main() {
    
    ll a,b,c,d,cnt=0;
    cin >> a >> b >> c >> d;
    ll e=lcm(c,d);
    cout << fixed << setprecision(19);
    cout << b-a+1-(b/c+b/d-(a-1)/c-(a-1)/d-b/e+(a-1)/e)<< endl;
    
}

Measured memory_bytes: 256
let range a b = 
    let rec range' j xs =
        if a > j then xs
        else range' (j - 1) (j :: xs) in
    range' b [];;

let take_while f xs =
	let rec take_while' zs = function
		  [] -> List.rev zs
		| (y :: ys) -> if f y then 
						take_while' (y :: zs) ys
					 else
					 	List.rev zs
	in take_while' [] xs
;;


let drop_while f xs =
	let rec drop_while' = function
		  [] -> []
		| (y :: ys) -> if f y then 
						drop_while' ys
					 else
					 	(y :: ys)
	in drop_while' xs
;;

let () =
	let solve n x =
		if 3 * n - 3 < x then print_endline "0"
		else (
			let min_range = range 1 (min (x / 3) (n - 2)) in
			let solve' accum min = 
				let mid_range = range (min + 1) (n - 1) in
				take_while (fun mid -> min + mid * 2 + 1 <= x) mid_range
				|> drop_while (fun mid -> min + mid + n < x) 
				|> List.length 
				|> (+) accum in
			List.fold_left solve' 0 min_range |> Printf.printf "%d\n" ) in
	let rec f _ = 
		let line = Scanf.sscanf (read_line ()) "%d %d" (fun x y -> (x, y)) in
		match line with
			  (0, 0) -> ()
			| (n, x) -> solve n x; f ()
	in f ();;


Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int W,H,N; cin >> W >> H >> N;
    int a=0; int b=W; int c=0; int d=H;

    for(int i=0;i<N;i++){
        int x,y,flag; cin >> x >> y >> flag;
        if(flag == 1) a=max(a,x);
        if(flag == 2) b=min(b,x);
        if(flag == 3) c=max(c,y);
        if(flag == 4) d=min(d,y);
    }
    cout << max(b-a, 0)*max(d-c, 0) << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define sz(x)             (int)x.size()
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*(b/gcd(a,b)))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
#define watch(x)         cout << #x << " = " << x << endl
#define trace(x)         cerr << #x << " = " << x << endl
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){
    
	string s; cin>>s;
	int n = len(s);
	for(int i = n-2;i;i-=2){
		bool flag = true;
		for(int j = 0;j<i/2;j++){
			if(s[j] != s[j+i/2]) flag = false;
		}
		if(flag){
			cout<<i;
			return;
		}
	}
	
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W==0)break;
            for(int j=0;j<W;j++)System.out.print("#");
            System.out.print("\n");
            for(int i=0;i<H-2;i++){
                System.out.print("#");
                for(int j=0;j<W-2;j++){
                    System.out.print(".");
                }
                System.out.print("#");
                System.out.print("\n");
            }
            for(int j=0;j<W;j++)System.out.print("#");
            System.out.print("\n\n");
        }
    }
}


Measured memory_bytes: 35124
#include<bits/stdc++.h>
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
int n,dg[100005],used[100005],ans=0;
vector<int> g[100005];
map <pii,int> mp;
vector<pii> ed;
void DFS(int v,int cl){
    used[v]=1;
    int t=1;
    for(int k=0;k<g[v].size();k++){
        int a=min(v,g[v][k]),b=max(v,g[v][k]);
        if(used[g[v][k]]==0){
                if(cl==t)
                t++;
           mp[{a,b}]=t;
        DFS(g[v][k],t);
        t++;
        }
    }
}
int main(){
scanf("%d",&n);
for(int k=1;k<n;k++){
    int a,b;
   scanf("%d%d",&a,&b);
    g[a].push_back(b);
    g[b].push_back(a);
    dg[a]++;
    dg[b]++;
    ed.push_back({a,b});
    ans=max(ans,max(dg[a],dg[b]));
}
printf("%d\n",ans);
DFS(1,0);
for(int k=0;k<ed.size();k++){
        int a=min(ed[k].x,ed[k].y),b=max(ed[k].x,ed[k].y);
printf("%d\n",mp[{a,b}]);
}
 return 0;
}


Measured memory_bytes: 16376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n, w;
  cin >> n >> w;
  if (n == w)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

bool Prime[int(1e5 + 5)];
int Sum[int(1e5 + 5)];

int main(){
  Prime[2] = true;
  for (int i = 3; i < 1e5 + 5; i++){
    Sum[i] = Sum[i - 1];
    if (i % 2 == 0) continue;

    Prime[i] = true;
    for (int j = 2; j * j <= i; j++){
      if (i % j == 0) Prime[i] = false;
    }
    
    if (Prime[i] && Prime[(i + 1) / 2]) Sum[i]++;
  }

  int Q; cin >> Q;
  for (int i = 0; i < Q; i++){
    int L, R; cin >> L >> R;
    cout << Sum[R] - Sum[L - 1] << endl;
  }
  

  return 0;
}


Measured memory_bytes: 1152
import sys
n,k=map(int,input().split())
d=list(map(int,input().split()))

while True:
    flag=False
    for i in range(len(str(n))):
        if int(str(n)[i]) in d:
            flag=True
            break
    if flag==True:
        n+=1
    else:
        print(n)
        break

Measured memory_bytes: 3060
from sys import stdin
import bisect

n,q = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]
lin = []
point = 0
for i in range(n-1):
    if s[i] + s[i+1] == "AC":
        lin.append(i+1)
for j in range(q):
    hi = bisect.bisect(lin,li[j][1]-1)
    lo = bisect.bisect(lin,li[j][0]-1)
    print(hi-lo)

Measured memory_bytes: 30340
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n;
    scanf("%lld",&n);
    ll a[n],b[n];
    rep(i,0,n){
        scanf("%lld%lld",&a[i],&b[i]);
    }
    ll plus=0;
    rrep(i,n-1,0){
        if( (a[i]+plus) %b[i] ){
            plus+= b[i] - (a[i]+plus) %b[i];
        }
    }

    
    printf("%lld\n",plus);
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>

using namespace std;

const int maxK = 1e5 + 5;

vector<int> w(maxK, 0), l(maxK, 1), st(305);

int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> st[i];
    for(int i = 0; i < n; i++) {
        w[st[i]] = 1, l[st[i]] = 0;
    }
    for(int i = st[0] + 1; i <= k; i++) {
        for(int j = 0; j < n; j++) {
            if(i - st[j] >= st[0]) {
                w[i] |= l[i - st[j]];
                l[i] &= w[i - st[j]];
            }
            else if(i - st[j] >= 0) {
                w[i] |= w[st[j]];
                l[i] &= l[st[j]];
            }
        }
    }
    //for(int i = 0; i <= k; i++) cout << i << ' ' << w[i] << ' ' << l[i] << endl;
    cout << (w[k] ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 3904
from functools import lru_cache

def resolve():
    import sys
    input = sys.stdin.readline
    
    H = int(input())

    @lru_cache(maxsize=None)
    def dfs(h):
        if h <= 1:
            return 1
        else:
            return dfs(h//2) + dfs(h//2) + 1

    print(dfs(H))


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int mod=1e9+7;
int a[2100];
int f[2100];
int n,k;
int ans1;
int ans2=0;
long long ans=0,sum;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		for(int j=1;j<i;j++)
		if(a[j]>a[i]) ans1++;
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		if(a[j]<a[i]) f[i]++;
	}
	
	for(int i=1;i<=n;i++)
	ans2+=f[i];
	sum=(long long)k*k-k;
	sum/=2;
	sum%=mod;
	sum=(long long)sum*ans2%mod;
	ans+=(long long)ans1*k%mod;
	ans+=(long long)sum;
	cout<<ans%mod;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int k;
    string s;

    cin>> k>> s;

    if(s.size()> k)
    s= s.substr(0, k) +"...";

    cout<< s<< '\n';


    return 0;
}




Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
int H[200005];
int  comp(const void*a,const void*b)//用来做比较的函数。
{    return *(int*)a-*(int*)b;}//从小到大排序
int main()
{
    int N,K;
    scanf("%d%d",&N,&K);
    long long i;
    for(i=0;i<N;i++)
    {
        scanf("%d",&H[i]);
    }
    qsort(H,N,sizeof(int),comp);//排序
    long long sum;
    if(K>=N)
    {        printf("0");
    }
    else
    {
        sum=0;
        for(i=0;i<N-K;i++)
        {
            sum=sum+(long long)H[i];
        }
        printf("%lld",sum);
    }
    return 0;
}


Measured memory_bytes: 1788
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int A[n+1], B[n+1], C[10000+1];
    
    for (int i=0; i<10000+1; i++) {
        C[i] = 0;
    }
    
    for (int i=0; i<n; i++) {
        scanf("%d", &A[i+1]);
        C[A[i+1]]++;
    }
    
    for (int i=0; i<10000+1; i++) C[i+1] = C[i+1] + C[i];
    
    for (int j=0; j<n; j++) {
        B[C[A[j+1]]] = A[j+1];
        C[A[j+1]]--;
    }
    
    for (int i=0; i<n; i++) {
        if(i) printf(" ");
        printf("%d", B[i+1]);
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 18372
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<bool> V;
typedef map<int, int> M;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

string s;

ll solve(int n, V pos)
{
    ll res = 0;

    if (n == s.size() - 1)
    {
        ll cnt = 1;
        for (int i = s.size() - 1; i >= 0; i--)
        {
            if (pos[i])
                cnt = 1;
            res += (s[i] - '0') * cnt;

            cnt *= 10;
        }

        return res;
    }

    pos.push_back(true);

    res += solve(n + 1, pos);

    pos[pos.size() - 1] = false;

    res += solve(n + 1, pos);

    return res;
}

int main()
{

    cin >> s;

    V pos;

    cout << solve(0, pos) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int cnt(0);
  while(A>=B){
    B*=2;
    cnt++;
  }
  while(B>=C){
    C*=2;
    cnt++;
  }
  if(cnt <= K) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;

#define endl ("\n")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SQ (a)*(a)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define deb(x) cout<<#x<<" "<<x<<endl;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll mod = 1e9L+7;
int n;
vector<ll> inp;
vector<int> dp;

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    /*freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #ifndef ONLINE_JUDGE
    #endif*/
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;

        ll ans = 0;
        rep(i,0,s.length())
        {
            ans += s[i] - '0';
        }

        if(ans % 9 == 0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3740
n = int(input())
A = list(map(int, input().split()))

from itertools import accumulate
B = [0]+A
B = list(accumulate(B))
#print(B)

d = {}
d[0] = 1
ans = 0
for i in range(1, n+1):
    if B[i] in d:
        ans += d[B[i]]
        d[B[i]] += 1
    else:
        d[B[i]] = 1
print(ans)


Measured memory_bytes: 42124
/*
 * Code be weshen zyk :'(
 * I won't surrender quietly
 */
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define S second
#define F first
#define pb push_back

using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 3e3 + 5, K = 12, MOD = 998244353;
const ll MX = 1e15;
ll S[N][N], C[N][N];
ll p2[N], p2p[N];
ll n, m;
void init() {
	p2[0] = p2p[0] = 1;
	for (int i = 1; i < N; i++) {
		p2[i] = (p2[i-1] + p2[i-1]) % m;
		p2p[i] = (p2p[i-1] + p2p[i-1]) % (m - 1);
	}
	for (int i = 0; i < N; i++)
		for (int j = 0; j <= i; j++)
			if (i == j || j == 0)
				C[i][j] = 1;
			else
				C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % m;
	S[0][0] = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			if (j == 0)
				S[i][j] = 1;
			else
				S[i][j] = (S[i - 1][j] * (j + 1) + S[i - 1][j - 1]) % m;
		}
	}

}
ll fast(ll b, ll e, ll m) {
	if (!e)
		return 1;
	if (e & 1)
		return b * fast(b, e - 1, m) % m;
	return fast(b * b % m, e >> 1, m);
}
ll solve(int once) {
	ll ret = 0;
	///number of ways to partition once numbers on j sets
	for (int i = 0; i <= once; i++) {
		ret += S[once][i] * fast(2, p2p[n - once], m) % m
				* fast(p2[n - once], i, m) % m; ///number of partitions * number of remaining sets of what is left
		///number of remaining toppings = (n - once)
		///2 ^ (2 ^ toppings)
		if (ret >= m)
			ret -= m;
	}
//	cout << ret << '\n';
	return ret * C[n][once] % m;
}
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	cin >> n >> m;
	init();
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i & 1) {
			ans -= solve(i);
		} else
			ans += solve(i);
		if (ans >= m)
			ans -= m;
		if (ans < 0)
			ans += m;
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 139776
#include<bits/stdc++.h>
using namespace std;


#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;

ULL dp[400][400] = {};
ULL s[401];

ULL qdp(int l, int r) {
	if (l == r) return 0;
	if (dp[l][r] != 0xfffffffffffffff) return dp[l][r];
	ULL ans = 0xffffffffffffffe;
	for (int i = l; i < r; i++) {
		ans = min(ans, qdp(l, i) + qdp(i+1, r));
	}
	return dp[l][r] = ans + s[r + 1] - s[l];
}

void solve() {
	int n; cin >> n;
	s[0] = 0;
	rep(i, n) rep(j, n) dp[i][j] = 0xfffffffffffffff;
	rep(i, n) { ULL a; cin >> a; s[i + 1] = s[i] + a; }
	cout << qdp(0, n - 1) << endl;
}

int main() {

	solve();

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ld long double
#define tc() ll t;cin>>t;while(t--)
#define inp(n) ll n;cin>>(n)
#define inp2(n,m) ll n,m;cin>>(n);cin>>(m)
#define inp3(n,m,g) ll n,m,g;cin>>(n);cin>>(m);cin>>(g)
#define inps(s) string s;cin>>(s)
#define fr(i,n) for(ll i=0;i<n;i++)
#define rf(n,i) for(ll i=n-1;i>=0;i--)
#define vi vector<int >
#define vl vector<ll>
#define vd vector<ld>
#define vs vector<string >
#define pii pair<int,int>
#define pci pair<char ,int>
#define pic pair<int ,char>
#define psi pair<string ,int>
#define mii map<int ,int >
#define mci map<char ,int>
#define msi map<string ,int>
#define si set<int >
#define ss set<string>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007

int main() {
    fast
    ll a;
    double b,v;
    cin>>a>>b;
    ll y = round(b*100);
    cout<<a*y/100<<endl;
	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    int n,m;
    string s;
    cin >> n >> m;
    cin >> s;
    vector<int>v;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '0')
            v.push_back(i);
    }
    int at = n;
    vector<int>ans;

    while(true)
    {
        if(at <= 0)
            break;
        int last = at;
        at = *lower_bound(v.begin(), v.end(), at - m);
        if(last == at)
        {
            puts("-1");
            return 0;
        }
        ans.push_back(last - at);
    }
    reverse(ans.begin(), ans.end());
    for(auto &jump : ans)
        cout << jump << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 1592
#include<stdio.h>
#include<string.h>

int main(){
	//
	int a, b, n, x, y, i, j;
	//
	int dp[17][17];
	//while
	while( scanf("%d %d", &a, &b) != EOF && a && b ){
		
		//
		memset( dp, -1, sizeof(dp) );
		
		//
		scanf( "%d", &n );
		
		//0
		for( i = 0; i <= a; i++ ){
			dp[i][0] = 0;
		}
		for( i = 0; i <= b; i++ ){
			dp[0][i] = 0;
		}
		
		dp[1][1] = 1; //1
		
		for( i = 0; i < n; i++ ){
			//
			scanf( "%d %d", &x, &y );
			
			//0
			dp[x][y] = 0;
		}
		for( i = 1; i <= a; i++ ){ 
			for( j = 1; j <= b; j++ ){
				//
				if( dp[i][j] != -1 ){
					continue;
				}
				
				//
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			}
		}
		
		//
		printf( "%d\n", dp[a][b] );
	}
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);
	int M = 0, cnt;
	rep(i, n){
		cin >> a.at(i);
		if(M < a.at(i)){
			M = a.at(i);
			cnt = i;
		}
	}
	rep(i, n){
		if(i != cnt) cout << M << endl;
		else{
			int ans = 0;
			rep(j, n){
				if(j != cnt) ans = max(ans, a.at(j));
			}
			cout << ans << endl;
		}
	}
} 

Measured memory_bytes: 2432
import math
x = int(input())
for k in range(x, 2 * x):
    factor = 0
    if k % 2 == 0 and k != 2:
        continue
    for divisor in range(2, math.floor(math.sqrt(k)) + 1):
        if k % divisor == 0:
            factor += 1
    if factor == 0:
        print(k)
        break

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

N = int(input())
aN = list(map(int, input().split()))

ans = float('inf')
for i in range(min(aN), max(aN)+1):
    sum1 = 0
    for j in range(N):
        sum1 += (aN[j] - i) ** 2
    ans = min(sum1, ans)
print(ans)

Measured memory_bytes: 3060
N,M = gets.split.map(&:to_i)
path = Hash.new{|h,k| h[k] = Array.new}
M.times do
  a,b = gets.split.map(&:to_i)
  path[a] << b
  path[b] << a
end

queue = [1]
mark = {1 => 0}
loop do
  break if queue == []
  i = queue.shift

  (path[i]).each do |j|
    next unless mark[j].nil?
    mark[j] = i
    queue << j
  end
end

puts "Yes"
puts mark.sort.map(&:last)[1..-1]

Measured memory_bytes: 43256
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
using namespace std;


int main(int argc, char const *argv[])
{
	//ifstream cin("input.txt");
	
	int n,k;
	cin>>n>>k;
	vector<int> prices(n);
	rep(i, 0, n-1)
		cin>>prices[i];

	sort(prices.begin(), prices.end());

	int sum = 0;
	rep(i, 0, k-1)
		sum += prices[i];

	cout<<sum;


}

Measured memory_bytes: 3632