akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

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

  int N, M;
  cin >> N >> M;
  vector<lint> A(N);
  rep(i, N) cin >> A[i];
  priority_queue<lint> que;
  rep(i, N) que.push(A[i]);

  rep(i, M) {
    lint tmp = que.top();
    que.pop();
    tmp /= 2;
    que.push(tmp);
  }
  lint res = 0;
  rep(i, N) {
    lint tmp = que.top();
    que.pop();
    res += tmp;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>
 
int main() {
 
char ch[2000] = {0};
char W[15] = {0};
int i,j,k,l,m,n,o,p; 
 
m=0; /* ??????W?????\??? */
while(1) {
 
scanf("%c" , &W[m]);
/* printf("W[%d]???%c ",m,W[m]); /*W[m]????¢????*/
if(W[m] == '\n') {
break;
}
m = m+1;
}
 
n=0; /* ?????????T?????\??? */
while(1) {
 
scanf("%c",&ch[n]);
 
 /*printf("ch[%d]???%c ",n ,ch[n]); /*  ch[n]????¢???? */
  
 
if(ch[n] =='T' && ch[n-1] == 'X' && ch[n-2] == 'E' && ch[n-3] == 'T' && ch[n-4] == '_' && ch [n-5] == 'F' && ch[n-6] == 'O' && ch[n-7] == '_' && ch[n-8] == 'D' && ch[n-9] == 'N' && ch[n-10] == 'E') {
/* printf("break??????\n"); */
break;
}
n +=1;
} /*while??\????????????*/
 
 
/*??????????????¨?????????????¢????*/
p=0;
for(i=0; i<n; i++){
if(W[0] == ch[i] || W[0] == ch[i]+32 || W[0] == ch[i]-32) {
/* printf("????????????????¢????ch[%d]\n",i); /**/
if(ch[i+m] == ' ' || ch[i+m] == '\n' || W[0] == ch[0]  ) { 
if(ch[i-1] == ' ' || ch[i-1] == '\n' ||  W[0] == ch[0]+32 || W[0] == ch[0]-32){
o=o+1;
/*printf("ch[%d]???%c?????????\n",i,ch[i]); /*??????????¢????*/
 
for(j=0;j<m; j++) {
if(W[j] == ch[i+j] || W[j] == ch[i+j]+32 || W[j] == ch[i+j]-32){
/*printf("W[%d]???%c ch[%d]???%c\n",j,W[j],i+j,ch[i+j]); /*???= ????¢???????*/
o=o+1;
}
}
}
}
 
if(o==m+1){
p=p+1;
}
o=0;
}
}
 
printf("%d\n",p);
 
return 0;
 
}


Measured memory_bytes: 2016
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define ll long long int
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int mod = 2019;

ll desc(ll x, ll y)
{
    return x > y;
}

int main() {
    fastIO
    ll l, r, i, j;
    cin >> l >> r;
    ll ans = -1;
    if(r < 2019)
    {
        ans = (l * r) % 2019;
        Fo(i, l, r + 1)
        {
            Fo(j, i + 1, r + 1)
            {
                ll temp = (i * j) % 2019;
                if(temp < ans)
                    ans = temp;
            }
        }
        cout << ans << endl;
    }
    else{
        ll templ = (l - 1) / 2019;
        ll tempr = r / 2019;
        if(templ == tempr)
        {
            ans = INT_MAX;
            Fo(i, l, r + 1)
            {
                Fo(j, i + 1, r + 1)
                {
                    ll temp = (i * j) % 2019;
                    if(temp < ans)
                        ans = temp;
                }
            }
            cout << ans << endl;
        }
        else
            cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Rest {
	public String s;
	public int p;
	public int index;	
	public Rest left;
	public Rest right;
	
	public Rest(String s, int p, int i) {
		this.s = s;
		this.p = p;
		this.index = i;
		this.left = this.right = null;
	}
	public void show() {
		if(this.left != null) {
			this.left.show();
		}
		System.out.println(this.index);
		if(this.right != null) {
			this.right.show();
		}
	}
};


public class Main {
	public static int compare(String a, String b) 
	{
		for(int i = 0; i < a.length() && i < b.length(); i++) {
			if(a.charAt(i) < b.charAt(i)) {
				return -1;
			}
			if(a.charAt(i) > b.charAt(i)) {
				return 1;
			}
		}		
		if(a.length() == b.length()) {
			return 0;
		}
		if(a.length() < b.length()) {
			return -1;
		} else {
			return 1;
		}	
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String buf;
		int count = sc.nextInt();
		buf = sc.nextLine();
		Rest top = null;
		for(int i = 0; i < count; i++) {
			String s=sc.next();
			int p = sc.nextInt();			
			Rest r = new Rest( s , p , i+1 );
			if(top == null) {
				top = r;
			} else {
				Rest tmp = top;
				while(true) {
					int ans = compare( tmp.s , r.s );
					if(ans == 1) {
						if(tmp.left == null) {
							tmp.left = r;
							break;
						}
						tmp = tmp.left;
					} else {
						if(ans == -1) {
							if(tmp.right == null) {
								tmp.right = r;
								break;
							}
							tmp = tmp.right;
						} else {
							if(r.p > tmp.p ) {
								if(tmp.left == null) {
									tmp.left = r;
									break;
								}
								tmp = tmp.left;
							} else {
								if(tmp.right == null) {
									tmp.right = r;
									break;
								}
								tmp = tmp.right;
							}
						}
					}
				}
			}
		}
		top.show();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
int a[1000];
signed main() {
  int N, M;
  while(cin>>N>>M,N+M!=0) {
    for (int i = 0; i < N; i++) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (i == j || a[i]+a[j]>M) continue;
        ans = max(a[i]+a[j], ans);
      }
    }
    if (ans==0) {
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
    //why i cant use this
    //cout << ((ans==0) ? "NONE" : ans) << endl;
  }
}




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

using namespace std;
int n=1e5+5;
bool prime[100005];
int main()
{
  memset(prime, true, sizeof(prime));
  int x;
  cin>>x;
  prime[1]=false;
  for(int i=2;i*i<=n;++i){
      if(prime[i]){
          for(int j=i*i;j<=n;j+=i){
              prime[j]=false;
          }
      }
  }
  if(prime[x])cout<<x;
  else {
      for(int i=x;;++i){
          if(prime[i]){
              cout<<i;
              return 0;
          }
      }
  }
   return 0;
}

Measured memory_bytes: 3736
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i)

hash = {}
# 10 ** 6 と定数でおいても構わない
max = 0
# aごとに個数の数え上げ
a_arr.each do |a|
  hash[a] ||= 0
  hash[a] += 1
  max = a if a > max
end

hash.each do |a, count|
  # 重複がある場合は自身(a)も削除対象
  from_i = count > 1 ? 1 : 2
  to_i = max / a
  # aが1のときにループの回数が一番多い(max回)
  # aがmaxのときにループの回数は一番少ない(1回)
  # max/1 + max/2 + ... + max/max (調和級数:O(log(max)))
  from_i.upto(to_i) do |i|
    # ループ対象を途中で削除しても, 外側のループには影響がない
    hash.delete(a * i)
  end
end

puts hash.size


Measured memory_bytes: 38204
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe

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;}


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


int n,p[100]={},ans=0;
cin >> n;
rep(i,n){
    cin >>p[i];
}

for(int i=1;i<n-1;i++){
    if ((p[i-1]>p[i]&&p[i]>p[i+1])||(p[i-1]<p[i]&&p[i]<p[i+1]))
    {
        ans++;
    }
    
}
cout << ans << endl;


//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
n = int(raw_input())

slist = []
for i in range(0, 26):
	slist.append(50)
	
for i in range(0, n):
	alphabet = []
	for j in range(0, 26):
		alphabet.append(0)
	s = raw_input()
	for j in range(0, len(s)):
		alphabet[ord(s[j])-97] += 1
	for j in range(0, 26):
		if alphabet[j] < slist[j]:
			slist[j] = alphabet[j]

ans = ''
for i in range(0, 26):
	c = chr(i+97)
	for j in range(0, slist[i]):
		ans += c

print ans

Measured memory_bytes: 2696
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int a[5], k;
    REP(i, 5) cin >> a[i];
    cin >> k;
    if (a[4] - a[0] > k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
S=input()
can=True
kazu=0
for i in range(len(S)):
    s=S[i]
    if i==0:
        if s!="A":
            can=False
        continue
    if 2<=i<=len(S)-2:
        if s=="C":
            kazu+=1
            continue
    if s.isupper():
        can=False
if kazu!=1:
    can=False
if can:
    print("AC")
else:
    print("WA")

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

typedef long long int ll;

int main()
{
    string x;
    cin >> x;

    stack<ll> ans;
    for(ll i = 0;i < x.size();i++){
        if(x[i] == 'S'){
            ans.push(x[i]);
        }
        else{
            if(!ans.empty() && ans.top() == 'S'){
                ans.pop();
            }
            else{
                ans.push(x[i]);
            }
        }
    }

    cout << ans.size();

    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll mod = 1000000007;


ll s_calc(ll a){
	if(a==1)return 1;
	if(a%2==0){
		return a/2*(a/2+1);
	}else{
		return a/2*(a/2+1)+a/2+1;
	}

}

ll fib(ll a){
	ll v[2][2];
	v[0][0] = 1;
	v[0][1] = 1;
	v[1][0] = 1;
	v[1][1] = 0;
	ll res[2][2];
	res[0][0] = 1;
	res[0][1] = 0;
	res[1][0] = 0;
	res[1][1] = 1;
	
	while(a){
		if(a & 1){
			ll tmp[2][2]={};
			rep(i,2){
				rep(j,2){
					rep(k,2){
						tmp[i][j] = (tmp[i][j]+res[i][k]*v[k][j])%mod;
					}
				}
			}
			rep(i,2){
				rep(j,2){
					res[i][j] = tmp[i][j];
				}
			}
		}
		ll tmp[2][2]={};
		rep(i,2){
			rep(j,2){
				rep(k,2){
					tmp[i][j] = (tmp[i][j]+v[i][k]*v[k][j])%mod;
				}
			}
		}
		rep(i,2){
			rep(j,2){
				v[i][j] = tmp[i][j];
			}
		}
		a >>= 1;
	}
	return res[0][0]%mod;
}

int main(){
	ll k;	
	cin >> k;
	ll lb = 0,ub=(ll)2000000000;
	while(ub-lb!=1){
		ll mid = (ub+lb)/2;
		if(s_calc(mid)>=k){
			ub = mid;
		}else{
			lb = mid;
		}
	}
	k -= s_calc(ub-1);
	ll ans;
	if(ub==1){
		ans = 1;
	}else if(ub%2==0){
		ans = 2*(k-1)+1;
	}else{
		//cout << k << " " << ub/2 << endl;
		if(k>ub/4+1){
			ans = 2*(k-1);
		}else{
			ans = 2*(k-1)+1;
		}
	}
	ll ans2 = ub+1-ans;
	//cout << ans << " " << ans2 << endl;
	cout << (fib(ans)*fib(ans2))%mod << endl;
	return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
struct Pair {
	mutable int64_t first;
	mutable int64_t second;
	bool operator < (const Pair &rhs) const {
		if (first != rhs.first) return first < rhs.first;
		return second < rhs.second;
	}
};
void add(std::set<Pair> &set, Pair x) {
	if (!set.size()) {
		set.insert({-8000000000000000000, -8000000000000000000});
		set.insert({8000000000000000000, 8000000000000000000});
	}
	
	auto tmp = set.insert(x);
	if (!tmp.second) return;
	auto itr = tmp.first;
	auto prev = std::prev(itr);
	if (prev->second >= itr->first) {
		itr->first = prev->first;
		itr->second = std::max(itr->second, prev->second);
		set.erase(prev);
	}
	auto next = std::next(itr);
	while (itr->second >= next->first) {
		itr->second = std::max(itr->second, next->second);
		set.erase(next);
		next = std::next(itr);
	}
}
int64_t mod(int64_t a, int64_t b) {
	if (a >= 0) return a % b;
	if (-a % b == 0) return 0;
	return b - (-a % b);
}
int main() {
	int n = ri(), x = ri();
	int d = ri();
	if (d == 0) {
		if (!x) std::cout << 1 << std::endl;
		else std::cout << n + 1 << std::endl;
		return 0;
	}
	int64_t d_sum = 0, d_sum_back = 0;
	std::vector<Pair> ranges;
	for (int i = 0; i <= n; i++) {
		int64_t start = i;
		start *= x;
		int64_t end = start;
		start += d_sum;
		end += d_sum_back;
		d_sum += (int64_t) d * i;
		d_sum_back += (int64_t) d * (n - i - 1);
		ranges.push_back({start, end});
	}
	d = std::abs(d);
	for (auto &i : ranges) if (i.first > i.second) std::swap(i.first, i.second);
	std::map<int64_t, std::set<Pair> > range_map;
	for (auto &i : ranges) {
		add(range_map[mod(i.first, d)], i);
	}
	int64_t res = 0;
	for (auto &i : range_map) {
		for (auto j : i.second) {
			if (j.first != -8000000000000000000 && j.first != 8000000000000000000)
				res += (j.second - j.first) / d + 1;
		}
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 60396
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
    int N;
    int A,B;
    cin>>N>>A>>B;
    int count=0;
    for(int i=1;i<=N;i++){
        int wa;
        wa=i/10000+(i/1000)%10+(i/100)%10+(i/10)%10+i%10;
        if(A<=wa && wa<=B){
            count+=i;
        }
    }
    cout<<count<<endl;
    
    return 0;
}






Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>
 
#define pb(a) push_back(a)
#define mp make_pair
 
int main(){

  SCIN(s);
  int n = s.size();
  V vec(n);
  REP(i,n)vec[i]=s[i];
  int min_=INF;
  REP(i,n){
    // 指定させる文字
    int num = vec[i];
    V v = vec;
    int cou=0;
    while(count(ALL(v),num)!= v.size()){
      // 文字列が全て共通になるまで
      REP(j,v.size()-1){
        //各文字に対して処理を行う
        v[j]=(v[j]==num||v[j+1]==num?num:v[j]);
      }
      v.pop_back();
      cou++;
    }
    min_=min(cou,min_);
  }
  COUT(min_);
  return 0;
}


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

int n;
string s[MAXN];
struct QwQ{
	string s;
	int v;
}a[MAXN];
QwQ con(string s,int v){
	QwQ t;
	t.s = s; t.v = v;
	return t;
}
bool cmp(QwQ a,QwQ b){
	return (a.v==b.v?a.s<b.s:a.v>b.v);
}
int main()
{
	cin>>n;
	for(int i = 1;i<=n;i++)
		cin>>s[i];
	sort(s+1,s+1+n);
	int top = 0;
	for(int i = 1;i<=n;i++){
		if(s[i]!=s[i-1]){
			a[++top] = con(s[i],1);
		}
		else{
			a[top].v++;
		}
	}
	sort(a+1,a+1+top,cmp);
	cout<<a[1].s<<endl;
	for(int i = 2;i<=top;i++){
		if(a[i].v!=a[i-1].v){
			break;
		}
		cout<<a[i].s<<endl;
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

ll f(ll x) {
    if (x == 1) return 1;
    ll a = f(x/2);
    return a*2 + 1;
}

int main(){
    ll h;
    cin >> h;
    cout << f(h) << endl;
}

Measured memory_bytes: 256
n = int(input())
p = [[int(_) for _ in input().split()] for __ in range(n)]
aem = [p[0][0]]; bem = [p[0][1]]; cem = [p[0][2]]
for i in range(1,n):
    atmp = p[i][0] + max(bem[-1], cem[-1])
    btmp = p[i][1] + max(aem[-1], cem[-1])
    ctmp = p[i][2] + max(aem[-1], bem[-1])
    aem.append(atmp); bem.append(btmp); cem.append(ctmp)
print(max(aem[-1], bem[-1], cem[-1]))

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

int main() {
  int N, a, b = 0, c;
  cin >> N;
  c = N;
  for (int i = 0; i < 10; i++){
    a = N % 10;
    N = (N - a) /10;
    b += a;
  }
  if (c % b == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

    
    

Measured memory_bytes: 256
class Tree:
  C, RL = {}, {}
  R, N, D, S, P = None, None, None, None, None
  SN = None
  def __init__(s, num):
    s.N = num
  def set(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def makeRank(s, root):
    s.R = [0] * s.N #各ノードのランク
    s.R[root] = 1
    s.RL[1] = [root] #各ランクのノード
    s.S = [[] for _ in range(s.N)] #各ノードの子ノード
    s.P = [-1] * s.N #各ノードの親ノード
    F = [root]
    s.D = 2
    while F != []:
      Ft = []
      s.RL[s.D] = []
      for i in F:
        for j in s.C[i]:
          if s.R[j] == 0:
            s.R[j] = s.D
            Ft.append(j)
            s.RL[s.D].append(j)
            s.S[i].append(j)
            s.P[j] = i
      s.D += 1
      F = Ft
  def dfs(s, x): #最遠のノード,距離
    t = [-1] * s.N
    S = [x]
    ans = x
    ansn = 0
    t[x] = 0
    while S != []:
      k = S.pop()
      for i in s.C[k]:
        if t[i] == -1:
          t[i] = t[k] + 1
          S.append(i)
          if t[i] > ansn:
            ansn = t[i]
            ans = i
    return ans, ansn
  def getDi(s, x = 0): #直径
    a, _ = s.dfs(x)
    b, ans = s.dfs(a)
    return ans
  def getDeep(s, x): #xの子孫のうち一番深い深さ
    ans = 0
    if x in s.S:
      for i in s.S[x]:
        ans = max(ans, s.getDeep(i))
      return ans + 1
    else:
      return 0
  def getParent(s, x, n): #xのn世代前の親
    if n == 0:
      return x
    if s.P[x] == -1:
      return -n
    return s.getParent(s.P[x], n - 1)
  def countSon(s):
    s.SN = [0] * s.N
    for i in range(s.D - 1, 0, -1):
      for j in s.RL[i]:
        cnt = 1
        for k in s.S[j]:
          cnt += s.SN[k]
        s.SN[j] = cnt

class powmod():
  F = [1, 2]
  Fi = [1, 2]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    k = 2
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * k) % mod)
      self.I.append(mod - self.I[mod % k] * (mod // k) % mod)
      self.Fi.append(self.Fi[-1] * self.I[k] % mod)

class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invL(s, a, n):
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L


N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

T = Tree(N)
L = [0] * N
for a, b in AB:
  T.set(a - 1, b - 1)
  L[a - 1] += 1
  L[b - 1] += 1

for i in range(N):
  if L[i] == 1:
    root = i

T.makeRank(root)
T.countSon()

MOD = 10 ** 9 + 7
ans = 0


PM = powmod(N, MOD)
I = Inv(MOD)
y = I.invx(PM.F[N])

ans = 0
for i in range(N):
  if i == root: continue
  if T.S[i] == []: continue
  L = []
  cnt = 0
  for j in T.S[i]:
    L.append(T.SN[j])
    cnt += T.SN[j]
  L.append(N - cnt - 1)

  t = PM.F[N - 1] - 1
  for j in L:
    t = t - PM.F[j] + 1
    if t < 0:
      t += MOD
  ans = (ans + t * y) % MOD

print(ans)




Measured memory_bytes: 181960
a, b = map(int,input().split())


result = 0

if a > b:
    result = result + a
    a = a - 1
else :
    result = result + b
    b = b - 1

if a > b:
    result = result + a
    a = a - 1
else :
    result = result + b
    b = b - 1
print (result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,12){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  if(n%sum(n)==0){
    co("Yes")
  }
  else{
    co("No")
  }
}


Measured memory_bytes: 256
n=input()
l=len(n)
dp=[[0,0] for i in range(l)]
dp[0][1]=int(n[0])
dp[0][0]=int(n[0])-1
for i in range(1,l):
  t=int(n[i])
  if t>0:dp[i][0]=max(dp[i-1][0]+9,dp[i-1][1]+t-1)
  else:dp[i][0]=dp[i-1][0]+9
  dp[i][1]=dp[i-1][1]+t
print(max(dp[l-1][0],dp[l-1][1]))

Measured memory_bytes: 3064
n = int(input())
info = list(map(int, input().split()))

for i in range(n + 1):
    if i == n:
        print("APPROVED")
    else:
        if info[i] % 2 == 0:
            if info[i] % 3 == 0 or info[i] % 5 == 0:
                continue
            else:
                print("DENIED")
                break
    



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define double long double

const int N= 1e6+10;

int n,t,k;
string str;

int32_t main()
{
	IOS;
	cin>>n;
	int x= n%10;
	  
	if(x== 2|| x== 4|| x== 5|| x==7||x==9)
	    cout<<"hon"<<endl;
     else if(x== 0|| x== 1|| x==6|| x==8 )
	    cout<<"pon"<<endl;
	 else
	 	
	    cout<<"bon"<<endl;
	return 0;
	
	
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
	int n;
	cin >> n;
	VI t(n);
	REP(i,n) cin >> t[i];
	int m;
	cin >> m;
	int sum = 0;
	REP(i,n) sum += t[i];
	while (m--){
		int p, x;
		cin >> p >> x;
		p--;
		cout << sum - t[p] + x << endl;
	}
    return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<pair<pair<string, int>, int> > a(n);
	for (int i = 0; i < n; i++) {
		string name;
		int s;
		cin >> name >> s;
		a[i] = make_pair(make_pair(name, -s), i);
	}

	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++)
		cout << (a[i].second + 1) << endl;


	return 0;
}


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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vector<vector<pair<int,int> > > g(n);
    rep(i,n-1){
        int u,v,w; cin >> u >> v >> w;
        u--;v--;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }
    vl dists(n,L_INF);
    function<void(int,int,int) > dfs = [&](int node,int pre_node,int col){
        dists[node] = col;
        for(auto nv:g[node]){
            if(nv.first == pre_node)continue;
            if(nv.second & 1) dfs(nv.first, node, 1-col);
            else dfs(nv.first, node, col);
        }
    };
    dfs(0, -1 ,1);
    rep(i,n){
        out(dists[i]);
    }
}

Measured memory_bytes: 18156
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,m,flag,i,j;
  char a,b;
  vector<pair<char,char> > V;
  while(1){
    cin >> n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> a >> b;
      V.push_back(make_pair(a,b));
    }
    cin >> m;
    for(i=0;i<m;i++){
      cin >> a;
      flag=0;
      for(j=0;j<n;j++){
	if(V[j].first==a){
	  cout << V[j].second;
	  flag=1;
	  break;
	}
      }
      if(flag==0) cout << a;
    }
    cout << endl;
    V.clear();
  }
  return 0;
}

Measured memory_bytes: 1188
#0WA n==1 mod saikikilimit exit
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))
a.sort()
cnt = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
    if a[i] == 0:
        cnt = -1
res = 0
if cnt == -1:
    for i in range(n):
        res += abs(a[i])
elif cnt % 2 == 0:
    for i in range(n):
        res += abs(a[i])
else:
    if cnt == n:
        for i in range(n-1):
            res += abs(a[i])
        res += a[-1]
    else:
        for i in range(cnt-1):
            res += abs(a[i])
        res +=  max(abs(a[cnt-1])-a[cnt],a[cnt-1]+a[cnt])
        for i in range(cnt+1,n):
            res += abs(a[i])
print(res)



Measured memory_bytes: 14412
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = set()

for i in range(n):
    a.add(ns())

print(len(a))

Measured memory_bytes: 31164
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << (n < 1000 ? "ABC" : "ABD") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
ll gcd(ll a, ll b){
	return (a%b)?gcd(b, a%b):b;
}
ll lcm(ll a, ll b){
	return a/gcd(a,b)*b;
}
ll sumof1ton(ll n){
	return n*(n+1)/2;
}
int main(){
	ll n,m;
	while(cin>>n>>m,n){
		ll sum = n*(n+1)/2;
		ll cnt = n;
		vector<ll> v(m);
		bool one = false;
		REP(i,m){
			cin>>v[i];
			if(v[i] == 1) one = true;
		}
		if(one){
			cout<<0<<endl;
			continue;
		}
		for(int S = 1; S < 1<<m; S++){
			//cout<<cnt<<endl;
			int ope = -1;
			ll mul = 1;
			for(int i = 0; i < m; i++){
				if(S>>i & 1){
					ope *= -1;
					mul = lcm(mul, v[i]);
				}
			}
			cnt -= n / mul * ope;
			sum -=  sumof1ton(n / mul) * mul * ope;
		}
		//printf("%lld/%lld ",sum,cnt);
		assert(cnt);
		printf("%0.10f\n",(double)sum/cnt);
	}
	return 0;
}

Measured memory_bytes: 976
#include <stdio.h>
int main(){
  char a,b;
  scanf ("%c %c",&a,&b);
  if(b=='H') printf("%c",a);
  else if(b=='D'&&a=='H') printf("D");
  else if(b=='D'&&a=='D') printf("H");
  else printf("%c",b);
  
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
   
public class Main {
     
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
     
    public void exec() throws IOException {
        SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        out.print(new SectionDiagram().analyze(in.br.readLine()));
        out.flush();
    }
}

class SectionDiagram {
	public static final String EOF = System.lineSeparator();

	Deque<Integer> downhillDeque = new ArrayDeque<>();
	Deque<WaterHazardElement> waterHazardDeque = new ArrayDeque<>();
	int A = 0;
	int k = 0;
	StringBuilder sbL = new StringBuilder();
	
	public SectionDiagram analyze(String s) {
		int len = s.length();
		for(int i=0; i<len; i++) {
			switch(s.charAt(i)) {
			case '\\':
				downhillDeque.push(i);
				break;
			case '/':
				if(!downhillDeque.isEmpty()) {
					int start = downhillDeque.pop();
					WaterHazardElement wh = new WaterHazardElement(start,i);
					while(true) {
						if(!waterHazardDeque.isEmpty()){
							WaterHazardElement whPre = waterHazardDeque.getFirst();
							if(wh.include(whPre)) {
								if(!wh.merge(waterHazardDeque.removeFirst())){
									waterHazardDeque.addFirst(wh);
									break;
								}
							} else {
								waterHazardDeque.addFirst(wh);
								break;
							}
						}else{
							waterHazardDeque.addFirst(wh);
							break;
						}
					}
				}
				break;
			}
		}
		
		for(k=0; !waterHazardDeque.isEmpty(); k++){
			int c = waterHazardDeque.removeLast().getCapacity();
			A += c;
			sbL.append(" ").append(c);
		}
		return this;
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(A).append(EOF);
		sb.append(k).append(sbL).append(EOF);
		return sb.toString();
	}
	
}

class WaterHazardElement {
	int st = -1;
	int ed = -1;
	int childCapacity = 0;
	
	public WaterHazardElement(int st, int ed) {
		this.st = st;
		this.ed = ed;
	}
	
	public boolean merge(WaterHazardElement s) {
		childCapacity += s.getCapacity();
		return (s.st - this.st >= 3);
	}
	
	public int getCapacity() {
		return childCapacity + ed - st;
	}
	
	public boolean include(WaterHazardElement s) {
		return this.st < s.st && s.ed < this.ed;
	}
	
}
 
class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
        return br.readLine().split(delim);
    }
     
    public int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(br.readLine());
    }
     
    public int[] readIntArray(int[] a) throws NumberFormatException, IOException{
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
                if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
                }
            }
        }
        return a;
    }
 
     
}

Measured memory_bytes: 25600
//package AtCoder;
//package ;
import java.io.*;
import java.util.*;

public class Main {
	static long dp(int i)
	{
		if(i==n-1)
			return 0;
		if(dp[i]!=-1)return dp[i];
		long ans=(long)1e9;
		for(int j=i+1;j<n && j-i<=k;j++)
			ans=Math.min(ans, (long)Math.abs(a[i]-a[j])+dp(j));
		return dp[i]=ans;
	}
	static int n,k;
	static long dp[],a[];
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		n=sc.nextInt();k=sc.nextInt();
		a=new long[n];
		for(int i=0;i<n;i++)a[i]=sc.nextLong();
		dp=new long[n];
		Arrays.fill(dp, -1);
		System.out.println(dp(0));
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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

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

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

		char[] nextCharArray() throws IOException {
			return br.readLine().toCharArray();
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] ans = new double[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextDouble();
			return ans;
		}

	}
}


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

const int INF = 1e9;

int main() {
    int N; cin >> N;
    vector<int> t(N + 1), v(N + 2);
    for (int i = 1; i <= N; i++) {cin >> t[i]; t[i] *= 2;} // 全部スケール 2 倍にしておく
    for (int i = 1; i <= N; i++) {cin >> v[i]; v[i] *= 2;}

    vector<int> l(N + 2), r(N + 2);
    l[0] = r[0] = 0; v[0] = 0;
    for (int i = 1; i <= N; i++) {
        l[i] = r[i - 1];
        r[i] = l[i] + t[i];
    }
    l[N + 1] = r[N + 1] = r[N]; v[N + 1] = 0;

    int T = r[N + 1];
    vector<int> min_v(T + 1, INF);
    for (int i = 0; i <= N + 1; i++) {
        for (int j = 0; j <= T; j++) {
            if (j < l[i]) min_v[j] = min(min_v[j], v[i] + l[i] - j);
            else if (r[i] < j) min_v[j]= min(min_v[j], v[i] + j - r[i]);
            else min_v[j] = min(min_v[j], v[i]);
        }
    }

    double ans = 0;
    for (int i = 1; i <= T; i++) {
        ans += ((double)min_v[i - 1] + (double)min_v[i])/2.0;
    }

    cout << fixed << ans/4.0 << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, W;
  cin >> n >> W;
  vll v(n), w(n);
  REP(i,n) cin >> v[i] >> w[i];

  vll dp(W+1,0);

  for(ll i = 1; i <= W; i++){
    for(ll j = 0; j < n; j++){
      if(i - w[j] < 0) continue;
      dp[i] = max(dp[i], dp[i - w[j]] + v[j]);
    }
  }

  cout << dp[W] <<endl;
  
  return 0;
}




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

int main() {
    int n;
    cin >> n;
    string ans = "APPROVED";
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)) ans = "DENIED";
    }

    cout << ans << endl;
}


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

using namespace std;

#define int long long
#define N 100005
#define MOD 1000000007

vector < pair < int , int > > a[N];
int vis[N];
int n;

void init(int s,int t, vector < int > &dp, vector < int > &dist)
{
    priority_queue < pair < int , int > , vector < pair < int ,int > > , greater < pair < int , int >> > pq;

    pq.push({0, s});
    for(int i=1;i<=n;i++)  
    {
        vis[i] = 0;
    }
    dist[s] = 0;

    while(!pq.empty())
    {
        pair < int , int > cur = pq.top();
        pq.pop();
        int u = cur.second;
        if( vis[u] )
            continue;
        dist[u] = cur.first;
        vis[u] = 1;
        for(int i=0; i<a[u].size();i++)
        {
            int v = a[u][i].first;
            int w = a[u][i].second;

            if( dist[v] > (dist[u] + w))
            {
                pq.push({ dist[u] + w, v});
            }
        }
    }

    vector < pair < int , int > > temp;
    for(int i=1;i<=n;i++)
    {
        temp.push_back({dist[i], i});
    }
    sort(temp.begin(), temp.end());
    dp[s] = 1;
    for(int i=1;i<temp.size();i++)
    {
        int u = temp[i].second;
        for(int j=0;j<a[u].size();j++)
        {
            if( (dist[a[u][j].first] + a[u][j].second) == dist[u] )
            {
                dp[u]+=dp[a[u][j].first];
            }
        }
        dp[u]%=MOD;
    }

}

int32_t main()
{
    int m;
    cin>>n>>m;
    int s, t;
    cin>>s>>t;

    for(int i=0;i<m;i++)
    {
        int u, v, w;
        cin>>u>>v>>w;
        a[u].push_back({v, w});
        a[v].push_back({u, w});
    }

    vector < int > dp1(n+1, 0);
    vector < int > dp2(n+1, 0);
    vector < int > dist1(n+1, 1e15);
    vector < int > dist2(n+1, 1e15);
    init(s, t, dp1, dist1);
    init(t, s, dp2, dist2);

    int ans = dp1[t]*dp1[t];
    ans%=MOD;
    int tot = dist1[t];
    tot/=2;
    for(int i=1;i<=n;i++)
    {
        if(dist1[i] == tot && dist2[i] == tot && dist1[i]+dist2[i] == dist1[t])
        {
            int temp = (dp1[i]*dp2[i])%MOD;
            temp*=dp1[i];
            temp%=MOD;
            temp*=dp2[i];
            temp%=MOD;
            ans-=temp;
        }
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<a[i].size();j++)
        {
            int w = a[i][j].second;
            int u = i;
            int v = a[i][j].first;
            if( dist1[u] < tot && dist2[v] < tot && (dist1[u]+dist2[v]+w) == dist1[t])
            {
                int temp = (dp1[u]*dp2[v])%MOD;
                temp*=dp1[u];
                temp%=MOD;
                temp*=dp2[v];
                temp%=MOD;
                ans-=temp;
                ans%=MOD;
            }
        }
    }
    ans = (ans % MOD + MOD ) %MOD;
    cout<<ans<<endl;

    return 0;
}

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

int main(){
  long long ans=0;
  int x;
  cin >> x;
  for(int i=1; i<x; i++){
    if(x%i == 0){
      ans = ans+(x/i)-1;
    }else{
      ans = ans+(x/i);
    }
  }
  
  cout << ans;
}

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

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

  ll A, B; cin >> A >> B;
  ll C, D; cin >> C >> D;

  string ans = "Yes";
  while (A > 0 || C > 0) {
    C -= B;
    if (C <= 0) {
      break;
    }
    A -= D;
    if (A <= 0) {
      ans = "No";
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3640
import Control.Applicative
import Control.Monad
import qualified Data.IntMap as IM
import qualified Data.IntSet as IS

main :: IO()
main = do
    [h,w,d] <- map read . words <$> getLine
    ass <- replicateM h $ map read . words <$> getLine
    q <- readLn
    lrs <- replicateM q $ map read . words <$> getLine
    let m = fromll ass IM.empty 0
    mapM_ (print . solve m d (h*w)) lrs
    where
        fromll [] m _ = m
        fromll (xs:xss) m i = fromll xss (froml xs m i 0) (i+1)
        froml [] m _ _ = m
        froml (x:xs) m i j = froml xs (IM.insert x (i,j) m) i (j+1)
        solve m d u [l,r] = if r == l then 0 else table r - table l
            where
                table = (IM.fromSet f (IS.fromList [1..u]) IM.!)
                f z
                    | y == 0 = 0
                    | otherwise = cost (z-d) z + table (z-d)
                    where
                        y = snd $ conv z
                        conv x = ((x-1) `mod` d + 1,(x-1) `div` d)
                cost a b = abs (ax-bx) + abs (ay-by)
                    where
                        (ax,ay) = m IM.! a
                        (bx,by) = m IM.! b


Measured memory_bytes: 144380
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

typedef long long LL; 
LL n,m,ans;

void check(LL a,LL b,LL c){
	LL t1,t2;
	t1=max(max(a,b),c);
	t2=min(min(a,b),c);
	ans=min(ans,t1-t2);
}

int main(){
	LL i,t1,t2,t3;
	scanf("%lld%lld",&n,&m);
	if(!(n%3) || !(m%3)){puts("0"); return 0;}
	ans=min(n,m);
	for(i=1;i<=n;i++){
		t1=m/2*i; t2=(m-m/2)*i; t3=(n-i)*m;
		check(t1,t2,t3);
	}
	for(i=1;i<=m;i++){
		t1=n/2*i; t2=(n-n/2)*i; t3=(m-i)*n;
		check(t1,t2,t3);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

long long dijkstra(WGraph G, int s, int t) {
    int n = (int)G.size();
    std::vector<long long> dis(n, 1e16);
    dis.at(s) = 0;
    std::priority_queue<std::pair<long long, int>> que;
    que.push(std::make_pair(0, s));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        if (dis.at(v) < p.first) {
            continue;
        }
        for (auto e : G.at(v)) {
            if (dis.at(e.first) > dis.at(v) + e.second) {
                dis.at(e.first) = dis.at(v) + e.second;
                que.push(std::make_pair(dis.at(e.first), e.first));
            }
        }
    }
    return dis.at(t) == 1e16 ? -1 : dis.at(t);
}

int main () {
    int n = 0, m = 0;
    cin >> n >> m;
    int a = 0, b = 0, tmp = 0, two = 0, to = 0;
    int len = (int)pow(2, n);
    WGraph G(len);
    for (int i=0; i<m; i++) {
        cin >> a >> b;
        two = 0;
        for (int j=0; j<b; j++) {
            cin >> tmp;
            tmp--;
            two += (int)pow(2, tmp);
        }
        for (int j=0; j<len; j++) {
            to = (j | two);
            if (to != j) {
                G.at(j).push_back(make_pair(to, a));
            }
        }
    }
    cout << dijkstra(G, 0, len-1) << endl;
    return 0;
}


Measured memory_bytes: 130176
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 998244353
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
#define INF (int)1e18


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}


int modpow(int a,int n)
{
	int ans=1;
	while(n)
	{
		if(n%2)
			ans=(ans*a)%mod;
		n/=2;
		a=(a*a)%mod;
	}
	return ans;
}


signed main()
{
	fio
	inp(n)
	inpa(a,n)
	int count[n]={0};
	fo(i,n)
		count[a[i]]++;
	if(a[0]!=0 || count[0]!=1)
	{
		cout<<0<<'\n';
		return 0;
	}
	int ans=1;
	bool done=0;
	for(int i=1;i<n;i++)
	{
		if(count[i]==0)
		{
			done=1;
			continue;
		}
		if(done)
		{
			cout<<0<<'\n';
			return 0;
		}
		ans=(ans*modpow(count[i-1],count[i]))%mod;
	}
	cout<<ans<<'\n';
	printclock;
}

Measured memory_bytes: 1920