akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define N 2000010
using namespace std;
struct node{
    int l,r,w,f;
}tree[N*2+1];
int x,y,z,i,a[N],n,m;
void build(int k,int t,int w)
{ int mid;
    if (t>w) return;
    if (t==w)
      {
        tree[k].l=t;tree[k].r=w;
        tree[k].w=a[t];
        return;
      }
    mid=(t+w)/2;
    build(k*2,t,mid);
    build(k*2+1,mid+1,w);
    tree[k].l=t;tree[k].r=w;
    tree[k].w=max(tree[k*2].w,tree[k*2+1].w);
}
int ask(int k,int t,int w,int x,int y)
{ 
int mid;
if(x>y) return 0;
if (t>w) return 0;
    if (x<=t&&w<=y)
      {
        return tree[k].w;
      }
    mid=(t+w)/2;
    int sum=-INT_MAX;
    if (x<=mid)sum=max(sum,ask(k*2,t,mid,x,y));
    if (y>mid)sum=max(sum,ask(k*2+1,mid+1,w,x,y));
    return sum;
}
int read(int &x)
{
    char c=getchar();int f=1;
    x=0;
    while (c<'0'||c>'9')
      {
      if (c=='-') f=-1;
      c=getchar();
      }
    while (c>='0'&&c<='9')
      {
        x=x*10+(int)c-48;
        c=getchar();
      }
    return x*f;
}
signed main()
{
    n=read(n);
    memset(a,INT_MAX,sizeof(a));
    for (int i=1;i<=n;i++) a[i]=read(a[i]);
    build(1,1,n);
    for (int i=1;i<=n;i++)
      { 
        printf("%d\n",max(ask(1,1,n,1,i-1),ask(1,1,n,i+1,n)));
      }
}

Measured memory_bytes: 17920
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=100+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    int h,w,n;
    while(cin>>h>>w>>n)
    {
        int a=max(h,w);
        cout<<(ceil(n*1.0/a))<<endl;
    }
    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n, m; // n:頂点数 m:辺数
  cin >> n >> m;
  
  vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    // G[v].emplace_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  vector<double> origin(n);
  
  for (int i = n - 2; i >= 0; i--) {
    double sum = 0;
    for (int j = 0; j < G[i].size(); j++) sum += origin[G[i][j]];
    origin[i] = sum / G[i].size() + 1;
  }
  
  double ans = origin[0];
  for (int i = n - 2; i >= 0; i--) {
    if (G[i].size() == 1) continue;
    vector<double> update = origin;
    for (int j = i; j >= 0; j--) {
      double sum = 0;
      if (j == i) {
        double maximum = 0;
        for (int k = 0; k < G[j].size(); k++) {
          sum += update[G[j][k]];
          maximum = max(maximum, update[G[j][k]]);
        }
        update[j] = (sum - maximum) / (G[j].size() - 1) + 1;
      }
      else {
        for (int k = 0; k < G[j].size(); k++) sum += update[G[j][k]];
        update[j] = sum / G[j].size() + 1;
      }
      ans = min(ans, update[0]);
    }
  }
  
  cout << fixed << setprecision(10) << ans << '\n';
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    string S;
    cin >> N >> S;
    vector<ll> vec(2 * N);
    vec[0] = 0;
    rep(i,2 * N - 1){
        if (S[i + 1] == S[i]){
            if (vec[i] == 0) vec[i + 1] = 1;
            if (vec[i] == 1) vec[i + 1] = 0;
        }
        else{
            vec[i + 1] = vec[i];
        }
    }
    vector<ll> left(2 * N, 0);
    vector<ll> right(2 * N, 0);
    ll ans = 1;
    left[0] = 1;
    rep(i,2 * N - 1){
        if (vec[i + 1] == 0) left[i + 1]++;
        if (vec[i + 1] == 1) right[i + 1]++;
        left[i + 1] += left[i];
        right[i + 1] += right[i];
    }
    vector<ll> fact(100005);
    fact[0] = 1;
    for (ll i = 1; i < 100005; i++){
        fact[i] = (fact[i - 1] * i) % 1000000007;
    }
    rep(i,2 * N - 1){
        if (vec[i + 1] == 1){
            ans = (ans * (left[i] - right[i])) % 1000000007;
        }
    }
    bool possible = true;
    if (S[0] == 'W') possible = false;
    if (left[2 * N - 1] !=  right[2 * N - 1]) possible = false;
    
    if (!possible) cout << 0 << endl;
    else{
        cout << (ans * fact[N]) % 1000000007 << endl;
    }
    
}


Measured memory_bytes: 9068
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
char a[5];
int main(){
    scanf("%s",a);
    if(a[0]==a[1]&&a[1]==a[2]){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 128
class Dice:
    def __init__(self):
        self.front = '1'
        self.back = '6'
        self.top = '5'
        self.bottom = '2'
        self. right = '3'
        self.left = '4'
    def turnRight(self):
        temp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = temp
        return self.top
    def turnLeft(self):
        temp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = temp
        return self.top
    def turnFront(self):
        temp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = temp
        return self.top
    def turnBack(self):
        temp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = temp
        return self.top

mydice = Dice()
mydice.top, mydice.front, mydice.right, mydice.left, mydice.back, mydice.bottom = input().split()

n = int(input())
for q in range(n):
    top, front = input().split()

    for rotate in range(3):
        mydice.turnFront()
        if mydice.top == front:
            break
        mydice.turnRight()
        if mydice.top == front:
            break
    mydice.turnFront()
    while top != mydice.top:
        mydice.turnRight()
    print(mydice.right)

Measured memory_bytes: 7812
#include <stdio.h>

#define lli long long int

int main() {
	lli n, t, mini;
	scanf("%lld %lld", &n, &mini);
	for (int i = 0; i < 4; i++) {
		scanf("%lld", &t);
		if (t < mini)
			mini = t;
	}
	printf("%lld\n", ((n + mini - 1) / mini) + 4);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include<windows.h>
//#include<conio.h>
using namespace std;
int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	cout<<max(a,max(b,c))*pow(2,k)+a+b+c-max(a,max(b,c));
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//(N-1)!をかけると、総和を求めればよいだけになる?
//移動の順序によって、距離の総和が異なる
// x[N-1]は必ず、1の移動になる
// x[N-2]は、1 or 2 (確率は1/2)
// x[N-3]は、1 or 2 or 3 

long long v[100009];
long long fact[100009], factinv[100009];

long long modPow(long long x, long long n, long long m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return modPow(x * x % m, n / 2, m);
  else
    return x * modPow(x, n - 1, m) % m;
}


long long Div(long long a, long long b, long long m) {
	return (a * modPow(b, m - 2, m)) % m;
}
//二項係数　nCr
//fact: N!
//factinv: fact[]のmodの逆元　a * a^(p-2) ≡ 1 (mod p)
//v:最大値の総移動回数
//(全通りの組合せを考えると、N==4のとき、3から4への移動を11回行う。N==5のとき、4から5への移動を50回)
void init() {
	fact[0] = 1;
	for (int i = 1; i <= 100000; i++) fact[i] = (1LL * fact[i - 1] * i) % MOD;
	for (int i = 0; i <= 100000; i++) factinv[i] = Div(1, fact[i], MOD);
	v[0] = 0;
	for (int i = 1; i <= 100000; i++) v[i] = (1LL * i * v[i - 1] + fact[i - 1]) % MOD;
}

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector <ll> x(N+1);
    REP(i,N)
    {
        cin >> x[i+1];
    }
    init();

    ll res = 0;
    for(int i = 1; i <= N-1; ++i)
    {
        ll val = v[i];
        val *= fact[N-1];
        val %= MOD;
        val *= factinv[i];
        val %= MOD;
        res += val * (x[i+1] - x[i]);
        res %= MOD;
    }



    cout << res << endl;


    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
unsigned long long N,tmp,BIG=1000000000000000000;
bool lebih=false;
int main(){
	cin>>N;
	unsigned long long total=1;
	for(unsigned long long i=0; i<N; i++){
		cin>>tmp;
		if(total!=0&&tmp<=(BIG/total)){
			total=total*tmp;
		}else if(total!=0){
			lebih=true;
		}
		if(tmp==0){
			total=0;
			lebih=false;
		}
	}
	if(lebih){
		cout<<-1<<'\n';
	}else{
		cout<<total<<'\n';
	}
}

Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    int l, r, d; cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i%d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import numpy as np

N = int(input())
ls = [int(s) for s in input().split()]

count = 0

for i in range(0, N-2):
  for j in range(i+1, N-1):
    l1 = ls[i]
    l2 = ls[j]
    if l2 == l1:
      continue
    for k in range(j+1, N):
      l3 = ls[k]
      if l3 in {l1, l2}:
        continue
      max_num = max((l1, l2, l3))
      if 2 * max_num < l1 + l2 + l3:
        count += 1

print(count)

Measured memory_bytes: 26972
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	int n = s.size();
	int k;
	cin >> k;
	set<string> pos;
	rep(i, n) repn(j, 1, min(100, n - i + 1)){
		string cur = s.substr(i, j);
		pos.insert(cur);
	}
	int cnt = 0;
	for(string x : pos){
		cnt++;
		if(cnt == k){
			cout << x << endl;
			return 0;
		}
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 65664
n, k = map(int, input().split())
p = list(map(int, input().split()))

a = [1+(i-1)/2 for i in p]
l = sum(a[:k])
ans = l
for i in range(1, n-k+1):
    l = l-a[i-1]+a[k+i-1]
    ans = max(ans, l)
print(ans)

Measured memory_bytes: 32000
n,t=map(int,input().split())
a=list(map(int,input().split()))
max=0
min=1000000000000000000000000000000000000
ans=1
for i in range(len(a)-1):
  if a[i]<min:
    min=a[i]
  elif min==a[i] or max==a[i]-min:
    ans+=1
  elif max<a[i]-min:
    ans=1
    max=a[i]-min
if a[len(a)-1]-min==max:
  ans+=1
print(ans)

Measured memory_bytes: 14680
N,M = map(int,input().split())

X = [0] * N
R = [0] *  N

ans = True
for i in range(M):
    s,c = map(int,input().split())
    
        
    if R[s-1] == 0:
        X[s-1] = c
        R[s-1] = "T"
        
    elif R[s-1] == "T" and X[s-1] != c :
        ans = False
        break
        
if ans:
    if X[0] == 0 and R[0] == 0 and N != 1:
        cnt = "1"
    else:
        cnt = str(X[0])
    for i in range(1,N):
        cnt = cnt + str(X[i])
    
    if len(cnt) == len(str(int(cnt))):
        
        print(cnt)
    else:
        print(-1)
else:
    print(-1)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    for(int i=1; i<N-1; i++){
        string l,r;
        l = S.substr(0,i);
        r = S.substr(i);
        vector<bool> sl(26,false),sr(26,false);
        for(int j=0; j<l.size(); j++){
            sl[l[j]-'a'] = true;
        }
        for(int j=0; j<r.size(); j++){
            sr[r[j]-'a'] = true;
        }
        int cnt = 0;
        for(int j=0; j<26; j++){
            if(sl[j] and sr[j]) cnt++;
        }
        chmax(ans,cnt);
    }
    cout << ans << enld;
    return 0;
}

Measured memory_bytes: 256
import collections
s = input()
anss = collections.defaultdict(int)
ans = 100
for i in s:
    if i not in anss:
        cnt = 0
        for j in s:
            if i == j:
                anss[i] = max(cnt, anss[i])
                cnt = 0
            else:
                cnt += 1
        anss[i] = max(cnt, anss[i])
        
for c in anss.values():
    if ans > c:
        ans = c
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind
{
    vector<int> par, rank;
    UnionFind(int n) : par(n), rank(n)
    {
        for (int i = 0; i < n; ++i)
            par[i] = i;
    }
    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y)
    {
        int rx = root(x), ry = root(y);
        if (rx == ry)
            return;
        if (rank[ry] > rank[rx])
            par[rx] = ry;
        else
            par[ry] = rx;
        if (rank[rx] == rank[ry])
            rank[rx]++;
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
};

vector<ll> fac, inv, finv;

void initcom()
{
    fac = inv = finv = vector<ll>(1e6);
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    for (ll i = 2; i < 1e6; ++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(int n, int k)
{
    if (n < 0 || k < 0)
        return 0;
    if (n < k)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll gcd(ll x, ll y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}
ll mopow(ll a, ll x, ll mod)
{
    ll res = 1;
    while (x > 0)
    {
        if (x & 1)
            res = res * a % mod;
        a = a * a % mod;
        x >>= 1;
    }
    return res;
}

int main(){
    int n,k;cin>>n>>k;
    vector<int> p(n),c(n);
    for(int i=0;i<n;++i) cin>>p[i],--p[i];
    for(int i=0;i<n;++i) cin>>c[i];
    ll ans=-INF;
    vector<bool> used(n,false);
    vector<vector<ll> > ss;
    for(int i=0;i<n;++i){
        if(used[i]) continue;
        int cur=i;
        vector<ll> s;
        while(!used[cur]){
            used[cur]=true;
            s.push_back(c[cur]);
            cur=p[cur];
        }
        ss.push_back(s);
    }
    for(auto vec:ss){
        ll m=vec.size();
        vector<ll> sum(2*m+1,0);
        for(int i=0;i<2*m;++i) sum[i+1]=sum[i]+vec[i%m];
        
        vector<ll> rem(m,-INF);
        for(int i=0;i<m;++i){
            for(int j=0;j<m;++j){
                rem[j]=max(rem[j],sum[i+j]-sum[i]);
            }
        }

        for(int r=0;r<m;++r){
            if(r>k) continue;
            ll q=(k-r)/m;
            if(r==0&&q==0) continue;

            if(sum[m]>0) ans=max(ans,rem[r]+sum[m]*q);
            else if(r>0) ans=max(ans,rem[r]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int n,k; cin>>n>>k;
  vector<int> A(n);
  rep(i, k) {
    int d; cin>>d;
    rep(j, d) {
      int x; cin>>x;
      x--;
      A[x]++;
    }
  }
  int res=0;
  rep(i, n) {
    if (A[i]==0) res++;
  }
  cout<<res<<endl;
}


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

ll gcd(ll c, ll d) {
	return d ? gcd(d, c%d) : c;
}

ll lcm(ll c, ll d) {
	return c/gcd(c, d)*d;
}


ll f(ll x, int c, int d) {
	ll res = x;
	res -= x/c;
	res -= x/d;
	res += x/lcm(c, d);
	return res;
}

int main(void) {
	ll a, b;
	int c, d;
	cin >> a >> b >> c >> d;
	ll ans = f(b, c, d) - f(a-1, c, d);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int A, N;

int main() {
  scanf("%d", &N);
  int C = 1;
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A);
    if (A == C) {
      ++C;
    } else {
      ++ret;
    }
  }
  if (ret == N) {
    ret = -1;
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

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

	pii arr[100000];
	for (int i = 0; i < N; ++i) {
		cin >> arr[i].X;
		arr[i].Y = i;
	}

	sort(arr, arr + N);

	for (int i = 0; i < N; ++i)
		cout << arr[i].Y + 1 << ' ';

	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  int n,k; cin>>n>>k;
  vector<vector<int> > v(n+1);
  forn(i,k){
  	int d; cin>>d;
  	forn(j,d){
  		int m; cin>>m;
  		v[m].pb(i);
  	}
  }
  int c = 0;
  for1(i,n){
  	c+=v[i].size()<=0;
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 3648
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n=SI()
s=0
for c in n:s+=int(c)
if s%9:print("No")
else:print("Yes")


Measured memory_bytes: 9268
#3本目を選ぶ時に2本目と同じ長さのものを選べることに注意する
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        p=bisect.bisect_right(l,l[i]+l[j]-1)
        cnt+=max(p-j-1,0)
print(cnt)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{

  string s;
  cin>>s;
  int ans=s.size();
  rep(i,2){
    int cnt=0;
    rep(j,s.size()){
     if(j%2==0 && s[j]==(char)(i+'0')){
       //char(i+'0')で数字文字列が変わる
       //'0'+1=='1' etc...
      cnt++;
     }
     if(j%2==1 && s[j]!=(char)(i+'0')){
       cnt++;
     }
    }
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const int NAX=1005;
const long long  MOD=(long long)(998244353);

Int N,M,K;
Int X,Y,Z;
Int H,W;

Int perform(Int x){
    return (x*(x+1))/2LL;
}
vector<Int> A;
vector<int> adj[MAXN];
using D=long double;

bool inRange(Int a,Int b){
    return a*b<=0;
}

long long C[NAX][NAX];
const D pi=3.14159265359;


long long ModExpo(long long x,unsigned long long y,long long M){
    Int ans=1;
    ans=(long long)ans;
    
    while(y>0){
        if(y&1) ans=((ans%M)*(x%M))%M;
        y>>=1LL;
        x=((x%M)*(x%M))%M;
    }
    return ans%M;
}
long long fac[MAXN];
void fillFac(){
    fac[0]=1;
    for(int i=1;i<MAXN;++i){
        fac[i]=((fac[i-1]%MOD)*(i%MOD))%MOD;
    }
}

long long ModInv(long long x){
    return ModExpo(x,MOD-2,MOD);
}

long long FermatLast(long long n,long long r){
    if(r>n) return 0;
    if(!r) return 1;
    return (fac[n] * ModInv(fac[r]) % MOD * ModInv(fac[n - r]) % MOD) % MOD;
}

Int performMod(Int x){
    Int y=((x%MOD)*((x+1)%MOD))%MOD;
    return (y*ModInv(2))%MOD;
}

Int madd(Int x,Int y){
    return (x+y)%MOD;
}

Int mmul(Int x,Int y){
    return ((x%MOD)*(y%MOD))%MOD;
}


bool isMSB(int bit,Int x){
    return (int)(floor(log2l(x)))==bit;
}
bool VIS[MAXN];
void dfs(int u){
    VIS[u]=true;
        for(auto &v:adj[u]){
            if(!VIS[v]){
                dfs(v);
            }
        }
}
int main()
{
    cin>>N;
    A.resize(N);
    
            for(auto &x:A) cin>>x;
            
            map<int,int> mp;
            for(auto x:A) ++mp[x];
            
            vector<Int> allowed;
            vector<Int> squares;
            for(auto &itr:mp){
                if(itr.second>1) allowed.pb(itr.first);
                if(itr.second>3){
                    squares.pb(itr.first);
                }
            }
            if(allowed.size()<2){
                cout<<"0\n";
                exit(0);
            }
            Int best=0;
            if(!squares.empty()){
            
                sort(squares.rbegin(),squares.rend());
                for(auto x:squares){
                    best=max(best,x*x);
                }
                
            }
            
            
            sort(allowed.rbegin(),allowed.rend());
            Int ans=allowed.front();
            allowed.erase(allowed.begin());
            ans*=allowed.front();
            best=max(best,ans);
            cout<<best<<"\n";
            
}


Measured memory_bytes: 20280
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    ll ans = 0;
    for(int i = 0; i * r <= n; i++){
        for(int j = 0; j * g <= n; j++){
            int k = n - i * r - j * g;
            if(k % b || k < 0){ continue; }
            printde(i, j, k / b);
            ans++;
        }
    }
    cout << ans << '\n';
}


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

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

 int main() {
   ll N, tmp, ans;
   cin >> N;
   vector<ll> A(N);
   map<ll, ll> a;

   rep(i, N) {
     cin >> A.at(i);
     a[A.at(i)]++;
   }

   for (pair<ll, ll> p : a) {
     if (p.second == p.first) continue;
     else if (p.second < p.first) ans += p.second;
     else if (p.second > p.first) ans += p.second - p.first;
   }

   cout << ans << endl;
 }


Measured memory_bytes: 7040
using System;


    public static class Program
    {
    static void Main()
    {
        var line = Console.ReadLine().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var c = double.Parse(line[0]);
        var d = double.Parse(line[1]);
        Console.WriteLine("{0} {1} {2}",a/b ,a%b, (1.0*c/d).ToString("f12"));

    }
    }



Measured memory_bytes: 19972
N, W = [int(i) for i in input().split()]
w, v = [0]*N, [0]*N
 
for i in range(N):
  w[i], v[i] = [int(_) for _ in input().split()]
V = sum(v)
 
dp = [[float('inf')] * (V+1) for _ in range(N+1)]
# dp[i][j] i番目までの荷物で価値がj以上になるように選んだときの重さの最小値
dp[0][0] = 0
for i in range(N):
  for j in range(V+1):
    if v[i] <= j:# 荷物v[i]の価値がjに足りてないのでi番目の荷物を入れる可能性がある
      dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i])
    else:      
      dp[i+1][j] = dp[i][j]
 
ans = 0
for j in range(V + 1):
  if dp[N][j] <= W:
    ans = j    
      
print(ans)


Measured memory_bytes: 308168
// a + b = x
// 2a+b = y
package main

import "fmt"

func main() {
	var X, Y int
	fmt.Scan(&X, &Y)
	for i := 0; i <= 100; i++ {
		for j := 0; j <= 100; j++ {
			if i+j == X && 2*i+4*j == Y {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 1756
n, m = map(int, input().split())
hole_ids = {int(input()) - 1: 0 for _ in range(m)}
X = 1000000007


def solve(n, hole_ids):
    nums = []
    # nums = [0] * n
    for i in range(n):
        if i in hole_ids:
            nums.append(0)
            # nums[i] = 0
            continue

        if i == 0:
            nums.append(1)
            # nums[i] = 1
        elif i == 1:
            # 1つ前から1段上がるから2つ前から2個飛ばし
            nums.append(nums[-1] + 1)
            # nums[i] = nums[i-1] + 1
        else:
            nums.append((nums[-1] % X + nums[-2] % X) % X)
            # nums[i] = (nums[i-1] + nums[i-2]) % X
    return nums[-1]


print(solve(n, hole_ids))


Measured memory_bytes: 15072
n, a, b, c = map(int, input().split())
bamboo = [0]*n
for i in range(n):
  bamboo[i] = int(input())

answer = 10**10
for i in range(4**n):
  key = [0, 0, 0, 0]
  sub = [0, 0, 0]
  for j in range(n):
    k = 0
    if (i >> (2*j))&1:
      k += 1
    if (i >> (2*j+1))&1:
      k += 2
    key[k] += 1
    if k != 3:
      sub[k] += bamboo[j]
  if not all(sub):
    continue
  ans = (sum(key[:3])-3)*10+abs(sub[0]-a)+abs(sub[1]-b)+abs(sub[2]-c)
  if ans < answer:
    answer = ans
print(answer) 

Measured memory_bytes: 46428
void main() {
	(rs.count("o")*100 + 700).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 3e5;
const int mod = 1e9 + 7;
int n;
char str[N];
int dp[3003][3003], s[3003];
int main() {
	cin >> n;
	scanf("%s", str + 2);
	dp[1][1] = 1;
	for (int i = 2; i <= n; ++i) {
		for (int j = 1; j < i; ++j) 
			s[j] = (s[j - 1] + dp[i - 1][j]) % mod; 
		s[i] = s[i - 1];
		for (int j = 1; j <= n; ++j) {
			if (str[i] == '<') {
				dp[i][j] = s[j - 1];
			} else {
				dp[i][j] = (s[i - 1] - s[j - 1] + mod) % mod;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) (ans += dp[n][i]) %= mod;
	cout << ans;
}



Measured memory_bytes: 35456
n=int(input())
s=input()
c=s.count
a=c('R')*c('G')*c('B')
for i in range(n):
  for j in range(i+2,n,2):
    if s[i]!=s[i+j>>1]!=s[j]!=s[i]:
      a-=1
print(a)

Measured memory_bytes: 9148
<?php
  $ary = array();
  while (true) {
    $st = trim(fgets(STDIN));
    if ($st == "0") {
      break;
    }
    array_push($ary, $st);
  }
  $count = count($ary);
  foreach ($ary as $key => $val) {
    print ("Case " . ($key+1) . ": " . $val);
    if ($key+1 < $count) {
      print "\n";
    }
  }
?>

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

int main(){
  int n, k;
  string s;
  cin >> n >> s >> k;
  char S = s.at(k-1);
  for(int i = 0; i < n; i++){
    if(s.at(i) == S){
      cout << S;
    }
    else{
      cout << '*';
    }
  }
}


Measured memory_bytes: 256
day = input()
if day == "SUN":
  print(7)
elif day=="MON":
  print(6)
elif day=="TUE":
  print(5)
elif day=="WED":
  print(4)
elif day=="THU":
  print(3)
elif day=="FRI":
  print(2)
elif day=="SAT":
  print(1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;

const int N = 54 , M = 104;

int memo[N][N][M] , a[N] , n , K;

int solve(int i , int j , int k){
    if(i > j || !k)
        return 0;

    int &ret = memo[i][j][k];
    if(~ret)
        return ret;

    ret = 0;
    ret = max(ret , solve(i + 1 , j , k - 1) + a[i]);
    ret = max(ret , solve(i , j - 1 , k - 1) + a[j]);

    if(k >= 2){
        ret = max(ret , solve(i + 1 , j , k - 2));
        ret = max(ret , solve(i , j - 1 , k - 2));
    }

    return ret;
}

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n >> K;

    for(int i = 0 ; i < n ; ++i)
        cin >> a[i];

    memset(memo , -1 , sizeof memo);

    cout << solve(0 , n - 1 , K) << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    //入力
    ll N, K, Q;
    cin >> N >> K >> Q;

    vector<ll> vec(Q);

    for(ll i = 0; i < Q; i++) {
        cin >> vec.at(i);
    }

    vector<ll> score(N, K - Q);
    //処理
    for(ll i = 0; i < Q; i++) {
        score.at(vec.at(i) - 1)++;
    }

    for(ll i = 0; i < N; i++) {
        cout << ((score.at(i) > 0)? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 4816
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long

template <class T>
T mymax(T a,T b){
    if(a>=b) return a;
    return b;
}
template <class T>
T mymin(T a,T b){
    if(a<=b) return a;
    return b;
}

ll gcd(ll a, ll b){
    if(a<b){
        swap(a,b);
    }
    while(b){
        ll r = a%b;
        a=b;
        b=r;
    }
    return a;
}

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

struct XX{
    int a;
    int b;
    int z;
    int i;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.b) == (riRight.b)){
            return riLeft.i < riRight.i;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.b) > (riRight.b);
    }
};

//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}


int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //cin >> x >> y;
    //テスト用
    //ifstream ifs( "1_06.txt" );
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    int l=0;
    int r=N-1;
    string strl="";
    string strr="";
    
    cout << 0 << endl;
    cout << flush;
    string ans;
    cin >> ans;
    if(ans=="Vacant"){
        return 0;
    }else{
        strl=ans;
    }
    cout << N-1 << endl;
    cout << flush;
    cin >> ans;
    if(ans=="Vacant"){
        return 0;
    }else{
        strr=ans;
    }
    
    int index=0;
    while(index<18){
        int tout=0;
        if((r-l+1)%2==0){
            tout=l-1+(r-l+1)/2;
        }else{
            tout=l-1+(r-l+1)/2+1;
        }
        cout << tout << endl;
        cout << flush;
        string ans;
        cin >> ans;
        if(ans=="Vacant"){
            return 0;
        }else if(((tout-l-1)%2==0 && ans==strl) ||
                 ((tout-l-1)%2!=0 && ans!=strl)){
            r=tout;
            strr=ans;
        }else{
            l=tout;
            strl=ans;
        }

        index++;
    }
    
    //ここまで
    //cout << "debug" << endl;
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}



Measured memory_bytes: 852
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void LCS(char *x, char *y){
	int m = strlen(x+1);
	int n = strlen(y+1);
	int i, j, **c;
	
	c = malloc(sizeof(int)*(2000));
	for (i = 0; i <= m; i++)
		c[i] = malloc(sizeof(int)*(n+1));
	
	for (i = 0; i <= m; i++){
		for (j = 0; j <= n; j++){
			c[i][j] = 0;
		}
	}
	
	for (i = 1; i <= m; i++){
		for (j = 1; j <= n; j++){
			if (x[i] == y[j])
				c[i][j] = c[i - 1][j - 1] + 1;
			else if (c[i - 1][j] >= c[i][j - 1])
				c[i][j] = c[i - 1][j];
			else
				c[i][j] = c[i][j - 1];
		}
	}
	
	printf("%d\n", c[i-1][j-1]);
	for (i = 0; i < m; i++)free(c[i]);
	free(c);
	
}

int main(){
	int i, n;
	char x[1001], y[1001];

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%s%s", x + 1, y + 1);
		LCS(x, y);
	}
	return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;	
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll INF = 1LL << 61;

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

const ll mod = 1000000007;


int main() {
	ull x;
	cin >> x;
	ull c = 100;
	for (int i = 1; i < 100000; i++) {
		c = c + c / 100ULL;
		//cout << i << "," << x << endl;
		//cout << i << "," << c << endl;
		if (c >= x) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
  int a,b,x,balance;
  
  scanf("%d",&x);
  scanf("%d",&a);
  scanf("%d",&b);
  
  balance = x;
  balance -= a;
  do{
    balance -= b;
  }while(balance / b != 0);
  
  printf("%d",balance);
 
  return 0;
}


Measured memory_bytes: 128
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, m; cin >> n >> m;
    vector<int> a(m);
    int sum = 0;
    rep(i, m) {
        cin >> a[i];
        sum += a[i];
    }
    if(sum > n) {
        cout << -1 << endl;
    } else {
        cout << n - sum << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int[] alice = new int[101];
		int[] bob = new int[101];

		for (int i = a + 1; i <= b; i++) {
			alice[i] = 1;
		}
		for (int i = c + 1; i <= d; i++) {
			bob[i] = 1;
		}
		int ans = 0;
		for (int i = 0; i <= 100; i++) {
			if (alice[i] == 1 && bob[i] == 1) {
				ans++;
			}
		}

		System.out.println(ans);

	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
using namespace std;

int main() {
	string st;
	bool judge = true;
	int arr[27] = { 0 };
	cin >> st;
	int s_size = st.size();
	for (int i = 0; i < s_size; i++) {
		int num = st[i] - 'a';
		arr[num]++;
	}

	for (int i = 0; i < 27; i++) {
		if (arr[i] >= 2) {
			judge = false;
		}
	}

	if (judge == false) {
		cout << "no" << endl;
	}
	else {
		cout << "yes" << endl;
	}
}


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

int main(){
    int n;
    cin >> n;
    ll a[n];
    for(int i = 0;i < n;i++)cin >> a[i];
    
    ll ans = 0;
    for(int i = 1;i < n;i++){
        if(a[i] < a[i-1]){
            ans += (a[i-1]-a[i]);
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5156
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<long double> count(N);
    for (int i = 1; i <= N; ++i) {

        int counter = 0;
        int initial = i;

        do {
            if (initial >= K) {
                break;
            }

            ++counter;
            initial *= 2;
        } while (true);


        long double calc = 1;
        for (int j = 0; j < counter; ++j) {
            calc = calc * 0.50000000000000;
        }

        // cout << counter << endl;
        count[i - 1] = calc;
    }

    long double sum = 0;
    for (int i = 0; i < count.size(); ++i) {
        sum += count[i] / N;
    }

    cout << setprecision(100) << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    char a;
    cin>>a;
    if (a>='a')
    
    {
    	cout<<'a'<<endl;
	}
	else
	{
		cout<<"A"<<endl;
	}
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int S, W;
	cin >> S >> W;
	if(S<=W) cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3636
def next_step(n: int):
    # 一の位のステップを決定
    d1 = n % 10
    if d1 < 3:  # 0, 1, 2
        step = 3 - d1
    elif d1 == 3:
        step = 2
    elif d1 < 5:  # 4
        step = 5 - d1
    elif d1 == 5:
        step = 2
    elif d1 < 7:  # 6
        step = 7 - d1
    else:  # 7, 8, 9
        step = 13 - d1

    # 10のくらい以上のステップを決定
    loop = 1
    nn = (n + step) // 10
    while nn > 0:
        d = nn % 10
        if d < 3:
            step += (3 - d) * (10 ** loop)
            nn += (3 - d)
        elif 3 < d and d < 5:
            step += (5 - d) * (10 ** loop)
            nn += (5 - d)
        elif 5 < d and d < 7:
            step += (7 - d) * (10 ** loop)
            nn += (7 - d)
        elif 7 < d:
            step += (13 - d) * (10 ** loop)
            nn += (13 - d)
        loop += 1
        nn //= 10

    return step


def q755(N: int) -> int:
    count = 0
    n = 357
    while n <= N:
        s = str(n)
        if not ('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s):
            if '3' in s and '5' in s and '7' in s:
                count += 1
        n += next_step(n)

    return count


if __name__ == "__main__":
    N = int(input())
    ans = q755(N)
    print(ans)


Measured memory_bytes: 3064
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;


const int MOD = 1e9 + 7;

VVI matrix_multiply(const VVI& A, const VVI& B) {
   const int N = A.size();
   const int M = B.empty() ? 0 : B[0].size();
   const int K = A.empty() ? 0 : A[0].size();
   if (K != int(B.size())) return VVI();
   VVI R(N, VI(M));
   for (int i = 0; i < N; ++i) {
      for (int k = 0; k < K; ++k) {
         // Note: loops k and j are inverted to improve performance due to cache
         for (int j = 0; j < M; ++j) {
            R[i][j] = (R[i][j] + (llong(A[i][k]) * B[k][j])) % MOD;
         }
      }
   }
   return R;
}

VVI matrix_identity(const int N) {
   VVI R(N, VI(N, 0));
   for (int i = 0; i < N; ++i)
      R[i][i] = 1;
   return R;
}


VVI matrix_power(VVI A, llong k) {
   const int N = A.size();
   VVI R = matrix_identity(N);
   while (k > 0) {
      if (k & 1) {
         R = matrix_multiply(R, A);
         --k;
      }
      k >>= 1;
      if (k <= 0) break;
      A = matrix_multiply(A, A);
   }
   return R;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N;
   llong K;
   cin >> N >> K;

   VVI A(N, VI(N));
   REP(i, N) REP(j, N)
      cin >> A[i][j];

   VVI R = matrix_power(A, K);
   int res = 0;
   REP(i, N) REP(j, N) {
      res += R[i][j];
      if (res >= MOD)
         res -= MOD;
   }
   cout << res << '\n';

   return 0;
}


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

void maxHeapify(vector<int>& a, int i, int h)
{
	int l = 2 * i;
	int r = 2 * i + 1;
	int largest = i;
	if (1 <= l && l <= h && a[i] < a[l]) largest = l;
	if (1 <= r && r <= h && a[largest] < a[r]) largest = r;

	if (largest != i) {
		swap(a[i], a[largest]);
		maxHeapify(a, largest, h);
	}
}

void buildMaxHeap(vector<int>& a, int h)
{
	for (int i = h / 2; 1 <= i; i--) {
		maxHeapify(a, i, h);
	}
}

int main()
{
	int h;
	cin >> h;
	vector<int> a(h + 1);
	for (int i = 1; i <= h; i++) cin >> a[i];

	buildMaxHeap(a, h);

	for (int i = 1; i <= h; i++) cout << " " << a[i];
	cout << endl;
}


Measured memory_bytes: 4624
#include <iostream>
using namespace std;
int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int a;
  while (x>y || x>z) {
    a=x;
    x=y;
    y=z;
    z=a;
  }
  while (y>z) {
    a=y;
    y=z;
    z=a;
  }
  cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 1164
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n*3];
        for(int i=0; i<n*3; i++){
            a[i] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(a);

        long ans = 0;
        for(int i=0; i<n; i++){
            ans += a[3*n - 2*i - 2];
        }
        System.out.println(ans);
    }
}        

Measured memory_bytes: 95004
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b,c,n;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&n);
	ll ans=0;
	rep(i,0,a+1)rep(j,0,b+1)rep(k,0,c+1)if(i*500+j*100+k*50==n)ans++;
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
ll books(vector<ll> & a, vector<ll> & b, ll & k){
	ll ret = 0;
	for(ll i=0;i<a.size();i++){
		if(a[i] > k) break;
		ll idx = lower_bound(b.begin(), b.end(),k - a[i]) - b.begin(); 
		if(idx == b.size()) idx--;
		if(a[i] + b[idx] <= k) ret = max(ret, i+idx+2);
		else ret = max(ret, i+idx+1);
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n,m,k; cin>>n>>m>>k;
	vector<ll> b1(n), b2(m);
	for(int i=0;i<n;i++){
		cin>>b1[i];
		b1[i] += (i ? b1[i-1] : 0);
	}
	for(int i=0;i<m;i++){
		cin>>b2[i];
		b2[i] += (i ? b2[i-1] : 0);
	}
	cout<<max(books(b1,b2,k), books(b2,b1,k));
}

Measured memory_bytes: 5988
#include<stdio.h>
#include<math.h>
#include<string>
#include<cmath>
 
int main(void){
    int N;
    scanf("%d",&N);
    std::string str=std::to_string(N);
    for(int k=0;k<str.length();k++){
        if(str[k]=='7'){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 3220