akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	int a=7200;
	int x,y,z;
	int t1,t3;
	int p,q,r;
	string A,B,C;
	while(true){
		cin>>x>>y>>z;
		if(x+y+z==-3) break;
		t1=a-x*3600-y*60-z;
		t3=3*t1;
		p=t1/3600;
		t1%=3600;
		q=t1/60;
		r=t1%60;
		A="0"+to_string(p);
		if(q>=10){
			B=to_string(q);
		}
		else{
			B="0"+to_string(q);
		}
		if(r>=10){
			C=to_string(r);
		}
		else{
			C="0"+to_string(r);
		}
		cout<<A<<":"<<B<<":"<<C<<endl;
		p=t3/3600;
		t3%=3600;
		q=t3/60;
		r=t3%60;
		A="0"+to_string(p);
		if(q>=10){
			B=to_string(q);
		}
		else{
			B="0"+to_string(q);
		}
		if(r>=10){
			C=to_string(r);
		}
		else{
			C="0"+to_string(r);
		}
		cout<<A<<":"<<B<<":"<<C<<endl;
	}
}

Measured memory_bytes: 3200
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 10000000
using namespace std;

struct state {
  int n, cost;
  bool operator<(const state s) const {
    if(n < s.n) return true;
    if(n > s.n) return false;
    return cost > s.cost;
  }
};

int N, P[100];
state dp[2][50000];

state max_state(state a, state b) {
  return a < b ? b : a;
}

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) cin >> P[i];

    int current = 0, next = 1;
    state m = (state) { 0, INF };
    REP(i, 0, 2) REP(j, 0, 50000) dp[i][j] = m;
    dp[current][0].cost = 0;

    REP(i, 0, N) {
      REP(j, 0, 50000) dp[next][j] = dp[current][j];
      REP(j, 0, 50000) {
        int change = (1000 - P[i] % 1000) % 1000;
        int n = dp[current][j].n;
        int cost = dp[current][j].cost;
        int nn, ncost, nj;
        if(cost >= INF) continue;
        if(change >= 500) {
          nn = n + 1;
          nj = j + change - 500;
        } else if(change < 500) {
          if(j >= (500 - change)) {
            nn = n + 1;
            nj = j - (500 - change);
          } else {
            nn = n;
            nj = j + change;
          }
        }
        ncost = cost + P[i];
        dp[next][nj] = max_state(dp[next][nj], (state) { nn, ncost });
      }
      swap(current, next);
    }

    state ans = m;
    REP(i, 0, 50000) ans = max_state(ans, dp[current][i]);
    cout << ans.n << " " << ans.cost << endl;
  }
  return 0;
}

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

int main() {
  int n,x; 
  cin >> n>>x;
  vector<int>a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  int ans=0;
  rep(i,n){
    if(a.at(i)<x){
      if(i!=n-1){
        ans++;
        x-=a.at(i);
      }        
    }
    else if(a.at(i)==x){
      ans++;
      break;
    }
  } 
  cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())

g = [[] for _ in range(N)]
hen = []
dic = {}
for i in range(N-1):
  #iが辺のID
  a,b = map(int,input().split())
  a -= 1; b -= 1
  g[a].append((b,i))
  g[b].append((a,i))

#これが答え。辺の本数だけ空を用意する。
ans = [0 for _ in range(N-1)]

Q = deque([])
Q.append(0)
used = [0 for _ in range(N)] #訪れた頂点をここに記録
used[0] = 1
#pre = [-1 for _ in range(N)]

while Q:
  v = Q.popleft()
  #p = pre[v] #vの親
  c = -1
  for i in range(len(g[v])): #vとvの親が繋がっている色を探す。
    TO = g[v][i][0]
    ID = g[v][i][1]
    if used[TO] == 1:
      c = ans[ID]
  k = 1
  for i in range(len(g[v])): #vとつながっている親以外の色を塗っていく。
    TO = g[v][i][0]
    ID = g[v][i][1]
    if used[TO] == 1:
      continue
    if k == c:
      k += 1
    ans[ID] = k
    k += 1
    Q.append(TO)
    used[TO] = 1
    


#bfs(0,0,-1) #根を0として、仮想親の-1から仮想色0で繋がっている。
print(max(ans))
for i in ans:
  print(i)

Measured memory_bytes: 40072
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

vector<int> to[200005];
vector<int> ans;

void dfs(int v,int p=-1){//どこから来たか?
    for(int u : to[v]){ //頂点vから行けるところを全部なめる
        if(u==p) continue;
        ans[u] += ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        --a;--b;
        to[a].push_back(b);
        to[b].push_back(a);  
    }
    ans.resize(n);//0埋め
    rep(i,q){
        int p,x;
        cin>>p>>x;
        --p;
        ans[p]+=x;
    }
    dfs(0);
    rep(i,n) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 23424
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <string>

using namespace std;

int main() {

	string a;

	while (true) {

	cin >> a;

	if (a == "0") { break; }

	int b,s,i;

	s = 0;

	b = a.size();

	for (i = 0; i <= b - 1; ++i) {
		s += a[i] - '0';
	}

	cout << s << endl;

}

}


Measured memory_bytes: 3192
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

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

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class A01Matrix {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll h, w, a, b;
	    in >> h >> w >> a >> b;

	    for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(j<a && i<b) out << 1;
                else if(j>=a && i>=b) out << 1;
                else out << 0;
            }
            out << endl;
	    }
	}
};


int main() {
	A01Matrix solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>

using namespace std;

struct E {
    int froms, tos;
    E() {
        froms = tos = 0;
    }
};

vector<E> G;

int m, n;
int main() {
    cin >> m >> n;
    G.clear(); G.resize(m+1);
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        G[b].froms |= (1<<a);
        G[a].tos |= (1<<b);
    }
    vector<int> sG; // sorted Graph
    vector<int> S;
    for (int i = 1; i <= m; i++) {
        if (G[i].froms == 0) {
            S.push_back(i);
        }
    }
    while (!S.empty()) {
        int s = S.back(); S.pop_back();
        sG.push_back(s);
        for (int i = 1; i <= m; i++) {
            if (G[s].tos & (1<<i)) {
                G[s].tos &= (((1<<(m+1)) - 1) - (1<<i));
                G[i].froms &= ((1<<(m+1)) - 1 - (1<<s));
                if (G[i].froms == 0) {
                    S.push_back(i);
                }
            }
        }
    }
    for (int i = 0; i < sG.size(); i++) {
        cout << sG[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class FenwickTree {
    public:
        FenwickTree(int n) : N(n), data(n, 0) {
        }

        void init(int n) {
            N = n;
            data.resize(N);
            fill(data.begin(), data.end(), 0);
        }
        void put(int x, int v) {
            for (; x < N; x |= x + 1) {
                data[x] += v;
            }
        }

        int get(int x) {
            int res = 0;
            for (; x >= 0; x = (x & (x + 1)) - 1) {
                res += data[x];
            }
            return res;
        }

        int get(int l, int r) {
            if (l > r) {
                return 0;
            }

            return get(r) - get(l - 1);
        }

    private:
        vector<int> data;
        int N;
};

class Solution {
public:
    void init(string& s) {
        S = s;
        N = S.length();
        fts.clear();
        fts.resize(A, N);

        for (int i = 0; i < N; ++i) {
            fts[S[i] - 'a'].put(i, 1);
        }
    }

    void update(int x, char ch) {
        if (S[x] == ch) {
            return;
        }
        fts[S[x] - 'a'].put(x, -1);
        S[x] = ch;
        fts[S[x] - 'a'].put(x, 1);
    }


    int query(int l, int r) {
        if (l > r) {
            return 0;
        }
        int res = 0;
        for (int i = 0; i < A; ++i) {
            res += fts[i].get(l, r) > 0;
        }
        return res;
    }
private:
    string S;
    int N;
    const static int A = 26;
    vector<FenwickTree> fts;
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    string s;
    cin >> n;
    cin >> s;
    Solution sol;
    sol.init(s);

    int q;
    cin >> q;
    while (q-- > 0) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            char ch;
            cin >> x >> ch;
            --x;
            sol.update(x, ch);
        } else {
            int l, r;
            cin >> l >> r;
            --l, --r;
            cout << sol.query(l, r) << "\n";
        }
    }


    return 0;
}

Measured memory_bytes: 53660
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

#define MAX_N 100000
#define MAX_Q 100000
int n, q, k;


#define MAX_E 1000000
#define MAX_V 1000000

struct edge{int to; ll cost;};
edge es[MAX_E];
int V, E;
vector<edge> G[MAX_V];
ll dist[MAX_V];
int used[MAX_V];

void dijkstra(ll s){
  REP(i,V){
    dist[i] = INFll;
  }
  dist[s] = 0;
  priority_queue<pll, vector<pll>, greater<pll>> pque;
  pque.push(pll(0,s));
  while(!pque.empty()){
    ll v, d;
    d = pque.top().first;
    v = pque.top().second;
    pque.pop();
    if(dist[v] < d)continue;
    REP(i,G[v].size()){
      edge e = G[v][i];
      if(dist[e.to] > d + e.cost){
        dist[e.to] = d + e.cost;
        pque.push(pll(d+e.cost,e.to));
      }
    }
  }
}

int main(){
  cin >> n;
  int a[n-1], b[n-1];
  ll c[n-1];
  REP(i,n-1)cin >> a[i] >> b[i] >> c[i];
  cin >> q >> k;
  int x[q], y[q];
  REP(i,q)cin >> x[i] >> y[i];

  REP(i,n-1){
    edge e1, e2;
    e1.to = b[i]-1;
    e1.cost = c[i];
    G[a[i]-1].push_back(e1);
    e2.to = a[i]-1;
    e2.cost = c[i];
    G[b[i]-1].push_back(e2);
  }
  V = n;
  E = n-1;

  dijkstra(k-1);

  REP(i,q){
    cout << dist[x[i]-1] + dist[y[i]-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 41072
cnt = 0

a, b, c = map(int, input().split())

if (a >= 1 and a <= 10000) and (b >= 1 and b <= 10000) and (c >= 1 and c <= 10000):
    if a <= b:  
        for i in range(a, b+1):
            if c % i == 0:
                cnt += 1
        print("{0}".format(str(cnt)))
    else:
        pass
else:
    pass

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int p[10];
int N, M;
bool edge[10][10];
int match = 0; // 何通りあるか

// 順列を探す。
// pos : 位置, mask : 集合
void dfs(int pos, int mask) {
	if (pos == N) {
		// 順列が見つかった
		if (p[0] != 0) return; // 最初が0(1)で無かったら終了

		for (int i = 0; i < N - 1; i++) {
			if (!edge[p[i]][p[i + 1]]) {
				// つながってないンゴ]
				return;
			}
		}
		match++;

		return;
	}

	for (int i = 0; i < N; i++) {
		if (mask & (1 << i)) {
			p[pos] = i; // i確定
			dfs(pos+1, (mask^(1<<i))); // iを取り除いてdfs
		}

	}

}


int main() {
	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		edge[a - 1][b - 1] = true;
		edge[b - 1][a - 1] = true;
	}

	dfs(0, (1<<N) - 1);

	cout << match << endl;

	return 0;
}



Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/05/25
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef struct {
	char city[11];
	int point;
	int no;
} REST_t;

REST_t r[101] = {0};

int compare_u(const void *a, const void *b)
{
    // for qsort. a is 1st value, b is 2nd value.
	// for bsearch. a is key, b is compare value.
	REST_t *pa = (REST_t*)a;
	REST_t *pb = (REST_t*)b;
	int val = strcmp(pa->city, pb->city);
	if(val == 0) {
		int da = pa->point;
		int db = pb->point;
		if(da < db) {
	        val = 1;
	    } else if (da == db) {
	        val = 0;
	    } else {
	        val = -1;
	    }
	}
    return val;
}


int main()
{
    int N = 0, i = 0;
    scanf("%d", &N);
    for(i = 0; i < N; i++) {
    	scanf("%s %d", &(r[i].city[0]), &(r[i].point));
    	r[i].no = i;
    }
    qsort(r, N, sizeof(REST_t), compare_u);
    for(i = 0; i < N; i++) {
    	//printf("%s %d", r[i].city, r[i].point);
    	printf("%d\n", r[i].no + 1);
    }
    return 0;
}


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

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

using namespace std;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    int ai = 0;
    int bi = 0;
    int ci = 0;
    char x = 'a';
    char ans = '\0';
    while (1) {
        switch (x) {
            case 'a':
                if (ai == a.size()) {
                    cout << 'A';
                    return 0;
                }
                x = a[ai];
                ai++;
                break;
            case 'b':
                if (bi == b.size()) {
                    cout << 'B';
                    return 0;
                }
                x = b[bi];
                bi++;
                break;
            case 'c':
                if (ci == c.size()) {
                    cout << 'C';
                    return 0;
                }
                x = c[ci];
                ci++;
                break;
        }
    }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
  int n;
  cin >> n;
  deque<int> a;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t; 
    if (i % 2 ^ (n % 2 == 0)) {
      a.push_back(t);
    } else {
      a.push_front(t);
    }
  }
 
  for (size_t i = 0; i < a.size(); ++i) {
    if (0 < i) cout << " ";
    cout << a[i];
  }
  cout << "\n";
}

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

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll N;
  std::cin >> N;

  ll sum = 0LL;
  for (ll i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) sum += i;
  }

  print(sum);
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

void dfs(vector<vector<int>>& g, unordered_set<int>& visited, int v)
{
    visited.insert(v);
    for(auto& next_v:g[v])
    {
        if(visited.count(next_v) > 0) continue;
        dfs(g, visited, next_v);
    }
}

int main()
{    
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ret = 0;
    if(a>=b && a>=c)
        ret = a*pow(2,k)+b+c;
    else if(b>=a && b>=c)
        ret = a+b*pow(2,k)+c;
    else
        ret = a+b+c*pow(2,k);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int C[1100];
int B[1100];
int ad=0;
vector<string> str;
void f(string aa,string bb,string cc,int a,int b,int c){
	//printf("%s %s %s %d %d %d\n",aa.c_str(),bb.c_str(),cc.c_str(),a,b,c);
	if(a==0){
		f(bb,cc,"",b,c,0);
		return;
	}
	if(b+c==0){
		for(int i=0;i<a;i++)printf("%s",aa.c_str());printf("\n");return;
	}
	ad=0;
	for(int i=0;i<1100;i++)B[i]=C[i]=0;
	while(a==0){
		a=b;b=c;c=0;ad++;
	}
	for(int i=0;i<c;i++){
		C[i%a]++;
	}
	if(C[0]!=C[a-1]){
		int f=0;
		for(int i=0;i<a;i++)if(C[a-1]==C[i])f++;
		for(int i=0;i<b;i++){
			B[a-f+i%f]++;
		}
	}else{
		for(int i=0;i<b;i++){
			B[i%a]++;
		}
	}
	str.clear();
	for(int i=a-1;i>=0;i--){
		string tmp="";
		tmp+=aa;
		for(int j=0;j<C[i];j++)tmp+=cc;//printf("%c",'c'+ad);
		for(int j=0;j<B[i];j++)tmp+=bb;//printf("%c",'b'+ad);
		str.push_back(tmp);
	}
	std::sort(str.begin(),str.end());
//	for(int i=0;i<str.size();i++)printf("%s\n",str[i].c_str());
	string ta="",tb="",tc="";
	int va=0;
	int vb=0;
	int vc=0;
	int fi=0;
	int ph=0;
	for(int i=0;i<a;i++){
		if(str[i]==str[fi]){
			if(ph==0){va++;ta=str[i];}
			if(ph==1){vb++;tb=str[i];}
			if(ph==2){vc++;tc=str[i];}
		}else{
		//	printf("%s %s\n",str[i].c_str(),str[fi].c_str());
			if(ph==0){ph++;vb++;tb=str[i];fi=i;}
			else if(ph==1){ph++;vc++;tc=str[i];fi=i;}
			
		}
	}
	f(ta,tb,tc,va,vb,vc);
}
int main(){
	
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	f("a","b","c",a,b,c);
	
	
	/*for(int i=0;i<100;i++){
		int a=rand()%10;
		int b=rand()%10;
		int c=rand()%10;
		if(a+b+c==0)continue;
		printf("%d %d %d: ",a,b,c);
		f("a","b","c",a,b,c);
	}*/
}

Measured memory_bytes: 256
N=int(input())
if N==0: print(2)
elif N==1: print(1)
else:
    Ln_2=0
    Ln_1=2
    Ln=1
    for i in range(N-1):
        Ln_2=Ln_1
        Ln_1=Ln
        Ln=Ln_1+Ln_2
    print(Ln)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){

    int n;
    cin >>n;

    vector<int> a(n);

    for(int i = 0; i < n; i++){

        cin >> a[i];
    }

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

    cout << abs(a[0] - a[a.size()-1])<< endl;

    return 0;

}

Measured memory_bytes: 256
import numpy as np

H, W, K = map(int, input().split())
c = []
for i in range(H):
    c.append(list(input()))

cnt = 0
for i in range(2**H):
    si = list(str(bin(i))[2:].zfill(6))
    for j in range(2**W):
        sj = list(str(bin(j))[2:].zfill(6))
        a = np.array(c[:])
        for k in range(len(a)):
            if si[5-k] == '1':
                a[k] = '.'
        for k in range(len(a[0])):
            if sj[5-k] == '1':
                a[:, k] = '.'
        if np.count_nonzero(a == '#') == K: cnt+=1
print(cnt)

Measured memory_bytes: 27100
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstring>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
#define maxn 5000010

void read(ll &x){
	int f=1;x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	x*=f;
} 

ll n,a[maxn],x;
ll dp[3000][3000];
int main(){
	read(n),read(x);
	for(int i=1;i<=n;i++){
		read(a[i]);
		dp[i][0]=a[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<n;j++){
			int t=i-j;
			if(t<=0){
				t+=n;
			}
			dp[i][j]=min(dp[i][j-1],a[t]);
		}
	}
	ll ans=1e18;
	for(int i=0;i<n;i++){
		ll sum=0;
		for(int j=1;j<=n;j++){
			sum+=dp[j][i];
		}
		ans=min(ans,sum+i*x);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 49024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
    int a, b;
    cin >> a >> b;
    int n = a;
    if(0 < b && b < 10){
        n *= 10;
    }else if(10 <= b && b < 100){
        n *= 100;
    }else if(b == 100){
        n *= 1000;
    }
    n += b;

    rep(i,1000){
        if(i*i == n){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 256
S = input()
S = list(S)
flag = True
if ('N' in S and 'S' not in S):
    flag = False;
if ('S' in S and 'N' not in S):
    flag = False
if ('E' in S and 'W' not in S):
    flag = False
if ('W' in S and 'E' not in S):
    flag = False
if flag:
    print('Yes')
else:
    print('No')





Measured memory_bytes: 3060
S=input()
T=input()
l_s=len(S)
l_t=len(T)
ans=[]
i=0
while i+l_t<=l_s:
  j=0
  while j<l_t:
    if S[i+j]=="?" or S[i+j]==T[j]:
      j+=1
    else:
      break
  if j==l_t:
    A=S[:i]+T+S[i+l_t:]
    A=A.replace("?","a")
    ans.append(A)
  i+=1
print(sorted(ans)[0] if ans else "UNRESTORABLE")


Measured memory_bytes: 9084
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main{
	
	static char [][]grid;
	static int [][]graph;
	static int h;
	static int w;
	static Deque <Point> dq ;
	static int ans;
	static Point start,goal;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		 h = Integer.parseInt(sc.next());
		 w = Integer.parseInt(sc.next());
		
		grid = new char [h][w];
		graph = new int [h][w];
		int cnt = 0;
		
		for(int i = 0 ;i < h ;i++) {
			String s = sc.next();
			for(int j = 0 ; j < w ; j++) {
				grid[i][j] = s.charAt(j); 
				if(grid[i][j] == '.') {
					cnt++;
				}
			}
		}
		 start = new Point(0,0);
		 goal = new Point(h-1,w-1);
		graph[0][0] = 0; graph[h-1][w-1] = -1;
		dq = new ArrayDeque<Point> ();
		BFS(start);
		
		ans = graph[h-1][w-1];
		
		int ans1 = cnt - ans - 1 ;
		if(ans == -1) {
			System.out.println(ans);
			return;
		}
		
		System.out.println(ans1);
	}

	
	static void BFS(Point s) {
		
		
		int []dy = {0,1,0,-1};
		int []dx = {1,0,-1,0};
		

		
		for(int i = 0 ; i < 4 ; i++) {
			Point p = new Point(s.xGet()+dx[i],s.yGet()+dy[i]);
			if(Search(p)) {
				grid[p.yGet()][p.xGet()] = '#';
				dq.addLast(p);;
				graph[p.yGet()][p.xGet()] = graph[s.yGet()][s.xGet()] + 1; 
			
			}
		}
		
		if(dq.size() == 0) {
			return ;
		}
		BFS(dq.pop());
	}
	
	static boolean  Search(Point s) {

		if(s.xGet()< 0 || s.xGet() >= w || s.yGet() < 0 || s.yGet() >= h) {
			return false;
		}
		else if(grid[s.yGet()][s.xGet()] == '#') {
			return false;
		}
		else {
			return true;
		}
		
	}
}
class Point{
	private int x;
	private int y;
	
	public Point (int x, int y) {
		this.x = x;
		this.y = y;
	}
	public int xGet() {
		return x;
	}
	public int yGet() {
		return y;
	}
	public boolean equal(Point p) {
		if(x == p.xGet() && y == p.yGet()) {
			return true;
		}
		else {
			return false;
		}
	}
}





Measured memory_bytes: 23636
function Main(input) {
  input = input.split("\n")
  var a = input[0]
switch(a){
  case "Sunny":
  console.log("Cloudy");
  break;
  case "Cloudy":
  console.log("Rainy");
  break;
  case "Rainy":
  console.log("Sunny");
  break;
}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9L+7;
int n;
vector<int> inp;
vector<int> dp;


int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        cin>>n;
        
        int arr[n];
        for(int i=0;i<n;i++) cin>>arr[i];

        ll cnt=0;
        for(int i=0;i<n-2;i++)
        {
            
            for(int j=i+1;j<n-1;j++)
            {
                
                for(int k = j+1 ; k<n ; k++)
                {
                    int a = arr[i];
                    int b = arr[j];
                    int c = arr[k];

                    if(a==b or b==c or c==a) continue;

                    if(a<b)
                    {
                        int temp = a;
                        a=b;
                        b=temp;
                    }
                    if(a<c)
                    {
                        int temp = a;
                        a=c;
                        c=temp;
                    }
                    if(b+c>a) cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
    
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
	int a[3];
	cin>>a[0];
	cin>>a[1];
	cin>>a[2];
	int space;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			if(a[j]>a[j+1]){
				space=a[j];
				a[j]=a[j+1];
				a[j+1]=space;
				j=0;
			}
		}
	}
	cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
}

Measured memory_bytes: 1164
from fractions import gcd
from functools import reduce

N, X = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

A.append(X)
sortedA = sorted(A)
B = [sortedA[i+1] - sortedA[i] for i in range(len(sortedA)-1)]

ans = reduce(gcd, B)
print(ans)

Measured memory_bytes: 16280
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    
    
    int main(){
        int n,m;cin>>n>>m;
        cout<<(n==m ? "Yes":"No");
    }
    


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

typedef long long ll;
ll mod = 1000000007;
const double PI = 3.141592653589793238460;
const int INF = 1e9+5;

long long int x;
int n;

int main(){

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

    cin >> n >> x;
    vector<int> a(n+1);
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }

    if(a[1]==1){
        cout<<1;
        return 0;
    }

    vector<bool> vis(n+1);

    int start = 1;
    int count = 0;
    while(true){
        if(vis[start]==true) break;
        vis[start]=true;
        start = a[start];
        count++;
    }

    int temp=start;
    int cycle=0;
    while(temp!=start || cycle==0){
        temp = a[temp];
        cycle++;
    }

    if(x<=(count-cycle)){
        temp = 1;
        while(x>0){
            temp=a[temp];
            x--;
        }
        cout<<temp;
        return 0;
    }

    x -= (count-cycle);
    x = x%cycle;

    while(x>0 && cycle!=1){
        start=a[start];
        x--;
    }

    cout<<start;
    return 0;
}


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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPR(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;

// UnionFindTree
struct DisjointSet {

private:
    struct Vertex {
        int parent;
        int rank;
    };
    int _size;
    vector<Vertex> _vertices;

public:
    void init(int size) {
        _size = size;
        _vertices.resize(_size);
        for(int i=0; i<_size; i++) {
            _vertices[i].parent = i;
            _vertices[i].rank = 0;
        }
    }

    void unite(int x, int y) {
        link(find(x), find(y));
    }

    void link(int x, int y) {
        if (x==y) return;
        if (_vertices[x].rank > _vertices[y].rank) {
            _vertices[y].parent = x;
        } else {
            _vertices[x].parent = y;
            if (_vertices[x].rank == _vertices[y].rank) {
                _vertices[y].rank++;
            }
        }
    }

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

    int find(int index) {
        if (_vertices[index].parent == index) {
            return index;
        } else {
            return _vertices[index].parent = find(_vertices[index].parent);
        }
    }
};

struct Edge {
    int start;
    int end;
    ll cost;
    int time;
    bool used;
};

int N, M;
int h[1000];
vector<Edge> edges;
DisjointSet ufSet;

bool span(int time) {
    for(auto& edge: edges) {
        if (edge.time>=time && !ufSet.same(edge.start, edge.end)) {
            ufSet.unite(edge.start, edge.end);
            assert(ufSet.same(edge.start, edge.end));
            edge.used = true;
        }
    }

    int t = -1;
    REP(i, N) {
        if (h[i]>=time && t==-1) t = i;
        if (h[i]>=time && !ufSet.same(i, t)) return false;
    }
    return true;
}

void refresh() {
    ufSet.init(N);
    for(auto& edge: edges) edge.used = false;
}

ll solve() {
    scanf("%d%d", &N, &M);
    if (N==0 && M==0) return -1;
    REP(i, N) scanf("%d", &h[i]);

    edges = vector<Edge>();
    REP(i, M) {
        int a, b; ll c;
        scanf("%d%d%lld", &a, &b, &c);
        a--; b--;
        edges.push_back((Edge){a, b, c, min(h[a], h[b])});
    }
    sort(ALL(edges), [](Edge& e1, Edge& e2) {return e1.cost<e2.cost;});

    int temp[1000];
    memcpy(temp, h, sizeof(h));
    sort(temp, temp+N);
    int _i=0;
    REP(i, N) {
        refresh();
        if (!span(temp[i])) break;
        _i++;
    }
    refresh();
    REPR(j, _i) span(temp[j]);

    return [](){
        ll ans = 0;
        for(auto& edge: edges) {
            if (edge.used) ans += edge.cost;
        }
        return ans;
    }();
}

int main() {
    ll ans;
    while((ans=solve())>=0) {
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5;
int n;
ll x;
ll a[maxn+10];
int main()
{
    while(cin>>n>>x)
    {
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            a[i]+=a[i-1];
        }
        ll ans=1e18;
        for(int k=1;k<=n;k++)
        {
            ll sum=0;
            ll res=3ll;
            for(int i=n;i>=1;i-=k)
            {
                sum=sum+(a[i]-a[max(i-k,0)])*max(res,5ll);
                res+=2;
                if(sum>=ans)
                    break;
            }
            ans=min(ans,sum+x*(n+k));
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

long long K;

double cal(long long num){
	long long tmp = num;
	double dig = 0;
	while(tmp){
		dig += tmp%10;
		tmp /= 10;
	}
	return num/dig;
}

int main(){
	cin >> K;

	set<long long>cand;
	for(long long i = 1; i < 10; i++)
		cand.insert(i);
	for(long long i = 0; i < 13; i++){
		for(long long x = 0; x < 10; x++){
			for(long long y = 0; y < 10; y++){
				for(long long z = 0; z < 10; z++){
					long long tmp = 100 * x + 10 * y + z;
					for(long long k = 0; k < i; k++){
						tmp *= 10;
						tmp += 9;
					}
					cand.insert(tmp);
				}
			}
		}
	}
	cand.erase(0);

	vector<long long> vec;
	for(auto t: cand)
		vec.push_back(t);

	
	for(long long i = 0; i < vec.size() && K > 0; i++){
		bool ok = true;
		for(long long j = i + 1; j < vec.size() && j < i + 1000; j++){
			if(cal(vec[i]) > cal(vec[j]))
				ok = false;
		}
		if(ok){
			cout << vec[i] << endl;
			K--;
		}
	}

	/*
	if(K <= 9){
		for(long long i = 1; i <= K; i++){
			cout << i << endl;
		}
		return 0;
	}
	for(long long i = 1; i <= 9; i++){
		cout << i << endl;
	}
	K-=9;
	for(long long i = 1; i <= K; i++){
		cout << i << 9 << endl;
	}
	*/
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;

ll cnt[60] = {1};
ll p[60] = {1};
ll N, X;
ll ans = 0;

void solve(ll L, ll num){
    if(num == 0) return;
    if(num == 1) {
        ans += L == 0;
        return;
    }
    if(num == cnt[L]){
        ans += p[L];
        return;
    }
    num--;
    if(num > cnt[L - 1]){
        ans += p[L - 1];
        ans++;
        solve(L - 1, num - cnt[L - 1] - 1);
    }else if(num == cnt[L - 1]){
        ans += p[L - 1];
    }else{
        solve(L - 1, num);
    }
}

void init(){
    cin >> N >> X;
    for(ll i = 1; i <= 50; i++){
        cnt[i] = 2 * cnt[i - 1] + 3;
        p[i] = 1 + 2 * p[i - 1];
    }
}

int main(){
    init();
    solve(N, X);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){
  int N;
  string s;
  vector<char> a(26,0);
  vector<char> b(26,0);
  int mmax,temp_max;
  mmax=0;
  cin>>N;
  cin>>s;

  for(int i=0;i<N;i++){

    for(int j=0;j<i;j++){
      a[s[j]-'a']=1;
    }
    for(int j=i;j<N;j++){
      b[s[j]-'a']=1;
    }
    temp_max=0;
    for(int j=0;j<26;j++){
      if(a[j]==b[j] and a[j]!= 0) temp_max++;
    }

    if(temp_max > mmax) mmax=temp_max;

    for(int j=0;j<26;j++){
      a[j]=0;
      b[j]=0;
    }

  }

  cout << mmax << endl;

  return 0;
}


Measured memory_bytes: 256
/*	
TELL YOUR CODE TO START BELIEVING IN GOD!!
THEY HATE US BECAUSE THEY AIN'T US
	ARIJIT SUR 
	@duke_knight
	@surcode
	IIT ISM 
 WORK SO HARD THAT YOUR IDOL BECOMES YOUR COMPETITOR 
 */
#include<bits/stdc++.h>
#define SIZE 100008
#define mod (ll)(1e9+7)
#define INF 0x3f3f3f3f
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(a) (a>0?a:-a)
#define all(a) a.begin(),a.end()
#define pb push_back
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define input(a) {for(int i=0;i<a.size();i++) cin>>a[i];}
#define display(a) {for(int i=0;i<a.size();i++) cout<<a[i]<<""; cout<<endl;}
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long ll;
string add(string s, int x){
    reverse(s);
    int carry = x,y;
    for(int i=0;i<s.size();i++){
        y = s[i] - '0' + carry;
        carry = y/10;
        y = y%10;
        s[i] = (char)(y+'0');
        if(!carry) break;
    }
    if(carry) s.pb((char)(carry+'0'));
    reverse(s);
    return s;
}
bool multiple(string s){
    ll n = 0;
    reverse(s);
    for(int i=0;i<s.size();i++){
        n = n*10+ (s[i]-'0');
    }
    return (n%9==0);
}
bool work(string s){
    string str = "";
    for(int i=0;i<s.size();i++) str = add(str,s[i]-'0');
    if(str.size()<=5) return multiple(str);
    return work(str);

}
void solve(){
	string n;
    cin>>n;
    if(!work(n)) printf("No\n");
    else printf("Yes\n");

}
int main()
{
    IOS
    int t=1;
    //cin>>t;
    
    while(t--){
    	solve();
    }
    return 0;
}

Measured memory_bytes: 3728
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = left + 1;
    if (left < n && arr[left] > arr[i]) largest = left;
    else largest = i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;

    vector<char> ans(s.size());
    int pnt = 0;
    for (auto &c : s) {
        switch (c) {
            case '0':
                ans.at(pnt) = '0';
                pnt++;
                break;
            case '1':
                ans.at(pnt) = '1';
                pnt++;
                break;
            case 'B':
                pnt = max(0, pnt - 1);
                break;
            default:
                break;
        }
    }

    for (int i = 0; i < pnt; ++i) {
        cout << ans.at(i);
    }
    cout << endl;

    return 0;
}

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

int main (){
	int n;
	scanf("%d",&n);
    char c,d;
    cin>>c;
    int cnt=1;
    for(int i=2;i<=n;i++){
        cin>>d;
        if(d!=c)cnt++;
        c=d;
    }
    printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

mint dp[100005][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i,n) {
        {
            if (s[i] == '0') {
                dp[i+1][0] = dp[i][0];
                dp[i+1][1] = dp[i][1];
            } else {
                dp[i+1][1] = dp[i][0] + dp[i][1];
            } 
        }
        {
            if (s[i] == '0') {
                dp[i+1][1] += dp[i][1]*2;
            } else {
                dp[i+1][0] += dp[i][0]*2;
                dp[i+1][1] += dp[i][1]*2; 
            }
        }
    }
    mint ans;
    ans = dp[n][0] + dp[n][1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5260
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

int main() {
    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll cnt_r = 0, cnt_g = 0, cnt_b = 0;
    rep(i,n){
        if (s[i] == 'R') cnt_r++;
        if (s[i] == 'G') cnt_g++;
        if (s[i] == 'B') cnt_b++;
    }
    ll ans = cnt_b*cnt_g*cnt_r;
    for(ll i = 1; i < (n+1)/2; i++){
        rep(j,n-(2*i)){
            if ( (s[j] != s[j+i]) && (s[j] != s[j+(2*i)]) && (s[j+i] != s[j+(2*i)]) ) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	string s;
	cin >> s;
	map<char,int> ma;
	FOR(i,0,s.size()){
		ma[s[i]]++;
	}
	for(auto x:ma){
		if(x.second&1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}


 
int main(void){
    int N;
    int cnt=0;
    int max=0;
    scanf("%d",&N);
    int hgt[N];
    for(int j=0;j<N;j++){
        scanf("%d",&hgt[j]);
    }
    for(int i=0;i<N-1;i++){
        if((hgt[i]-hgt[i+1])>=0){
            cnt++;
           
        }else if(cnt>max){
            max=cnt;
            cnt=0;
        }else{
            cnt=0;
        }
    }
    if(max<cnt)
        max=cnt;
    printf("%d",max);
}


Measured memory_bytes: 512