akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;
using std::abs;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const vector<T>& vec) {
	os << '[';
	int fst = 1;

	for(auto& elem: vec) {
		if(fst == 0) {
			os << ' ';
		}

		os << elem;
		fst = 0;
	}

	os << ']';
	return os;
}

const int MAX_N = (int)1e5 + 777;

int fenwick[MAX_N];

void add(int pos) {
	for(; pos < MAX_N; pos |= pos + 1)
		++fenwick[pos];
}

int get(int r) {
	int acc = 0;

	for(; r >= 0; r = (r & (r + 1)) - 1)
		acc += fenwick[r];

	return acc;
}

int get(int l, int r) {
	return get(r) - get(l - 1);
}

void solve() {
	int n, m;
	cin >> n >> m;

	vector<pii> a;

	for(int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;

		a.emplace_back(l, r - 1);
	}

	auto comp = [&](const auto& lhs, const auto& rhs){
		return lhs.second < rhs.second;
	};

	sort(a.begin(), a.end(), comp);
	int answ = 0;

	for(auto& segment: a) {
		int l = segment.first, r = segment.second;

		if(get(l, r) == 0) {
			++answ;
			add(r);
		}
	}

	cout << answ << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 1524
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 bool is_prime(int x)
 {
   if(x==2) return true;
   else
   {
     for(int i=2;i<=sqrt(x);i++)
     {
       if(x%i==0) return false;        
     }    
     return true;
   }     
 }
 
 int main()
 {
   int N;
   cin>>N;
   int count=0;
   while(N--)
   {
     int x;
     cin>>x;
     int flag=is_prime(x);
     if(flag) count++;          
   }
   cout<<count<<endl;
   //while(1);
   return 0;
 }
 
 
 

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

int main(){
    string s; cin >> s;
    ll cnt = 0, flag = 0;
    for(auto x:s){
        if(x == 'R'){
            cnt++;
            flag = max(flag, cnt);
        }else{
            cnt = 0;
        }
    }
    put(flag);
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N,C,K;cin>>N>>C>>K;
  vector<int> passengers(N);
  REP(i,0,N)cin>>passengers[i];
  sort(ALL(passengers));
  int ans=0,left=-1,right=INF,n_c=1;
  REP(i,0,N){
    // debug(left);debug(right);
    if(passengers[i]>right||n_c>C){
      left=-1,right=INF,n_c=1;
    }
    if(left==-1){
      // debug(i);
      left=passengers[i];
      right=passengers[i]+K;
      ans++;
    }
    n_c++;
  }
  print(ans);

}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll X, Y, Z; cin >> X >> Y >> Z;
  
  //main
  vll a(3);
  a[0] = Z; a[1] = X; a[2] = Y; 
  
  FOR(i,3){cout << a[i] << endl;}
  return 0;
}

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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1LL * MX * MX;

int n;
int a[N];
PII in[N];
map <int, int> M;

void check(){
	int tmp[N];
	for(int i = 1; i <= n; ++i)
		tmp[i] = a[i];
	sort(tmp + 1, tmp + n + 1);
	
	for(int i = 1; i <= n; ++i)
		if(tmp[i] > in[i].st){
			puts("No");
			exit(0);
		}
	
	for(int i = 1; i < n; ++i)
		if(tmp[i] == tmp[i + 1]){
			puts("Yes");
			exit(0);
		}
	
	for(int i = 1; i <= n; ++i)
		M[tmp[i]] = i;
	
	for(int i = 1; i <= n; ++i)
		in[i].nd = M[in[i].nd];
	
	int cur = 1, cnt = 1;
	while(in[cur].nd != 1){
		++cnt;
		cur = in[cur].nd;
	}
	
	if(cnt < n){
		puts("Yes");
		exit(0);
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		in[i].nd = a[i];
	}

	for(int i = 1; i <= n; ++i)
		scanf("%d", &in[i].st);
	sort(in + 1, in + n + 1);

	check();	
	sort(a + 1, a + n + 1);
	for(int i = 1; i < n; ++i)
		if(a[i + 1] <= in[i].st){
			puts("Yes");
			exit(0);
		}
	
	puts("No");
	return 0;
}

Measured memory_bytes: 10240
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	string s;
	cin>>s;
	for(int i=0;i<2;i++){
		if(s[i]=='9') {
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 998244353
#define floop(i,a,b) for (int i=(a);i<(b);i++)
#define rloop(i,a,b) for (int i=(a);i>=(b);i--)
#define floopeq(i,a,b) for (int i=(a);i<(b);i++)
#define pa pair<int,int>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  
    {if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;  }  return res;  
}

void solve()
{
	int n;
	cin>>n;
	int a[n];unordered_map<int,int>mp;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	int cnt=0;
	if(mp.find(1)!=mp.end())
	{
		if(mp[1]==1)
		{
			cout<<1<<endl;return;
		}
		else{
			cout<<0;
			return;
		}
	}
	for(int i=0;i<n;i++)
	{
		int breaking=0;
		if(mp[a[i]]==1)
		{
			for(int j=1;j*j<=a[i];j++)
			{
				if(a[i]%j==0)
				{
					if(mp.find(j)!=mp.end())
					{
						breaking=1;
						break;
					}
					if(j!=1 && mp.find(a[i]/j)!=mp.end())
					{
						breaking=1;
						break;
					}
				}
			}
			if(breaking==0)
				cnt++;
		}
	}
	cout<<cnt;
	return;


}
int main() 
{ 
    
    int t;
    t=1;
    while(t--){
    	solve();
    }
    return 0; 

} 


Measured memory_bytes: 12056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
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(){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    
    ll dp[50][2];// i桁目を見ている　smaller?
    rep(i,50) dp[i][false]=dp[i][true]=-1;//default
    dp[45][false]=0;

    for(ll i=44;i>=0;i--){
        ll twopow=1ll<<i;//高い桁から順に見る
        ll num=0;

        rep(j,n) if(a[j]&twopow) num++;//i桁目に立っているbitの数(a[i]に関して)

        if(dp[i+1][true]>=0){
            //前の桁smallerの時->max(今1のとき,今0のとき)
            chmax(dp[i][true],dp[i+1][true]+twopow*max(num,n-num));
            chmax(dp[i][false],dp[i+1][true]+twopow*max(num,n-num));
        }
        if(dp[i+1][false]>=0){
            if(k&twopow){//今見ている桁が1の時(k)
                
                //今の桁に対してsmallerの場合->0なので、i桁目の個数は不変でnumのまま
                chmax(dp[i][true],dp[i+1][false]+twopow*num);
                
                //一致する時->1なので、i桁目の個数はxor1によって変化し,n-num
                chmax(dp[i][false],dp[i+1][false]+twopow*(n-num));
            }else{//今見ている桁は0(k)
                
                //i桁目に関しては0しかないので一致しかない->i桁目不変
                chmax(dp[i][false],dp[i+1][false]+twopow*num);
            }
        }
    }

    cout<<max(dp[0][true],dp[0][false])<<endl;
    return 0;
}

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


int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  rep(i, n) {
    int xi;
    cin >> xi;
    x = max(x, xi);
  }
  rep(i, m) {
    int yi;
    cin >> yi;
    y = min(y, yi);
  }

  for (int z = -100; z <= 100; ++z) {
    if (x < z && z <= y) {
      cout << "No War" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 3624
#include <iostream>
#define MAX 10000
using namespace std;

int P[MAX];

bool isprime(int n){
    if (n == 2) return true;
    if (n % 2 == 0 || n == 1) return false;
    for ( int i = 3; i * i <= n; i += 2 ) {
        if (n % i == 0) return false;
    }
    return true;
}

int main(void) {
    int n;
    while(cin >> n){
        int cnt = 0;
        for(int i = 1; i <= n; i++){
            if(isprime(i) && isprime(n + 1 - i)) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
import  heapq

N = int(input())
a = list(map(int, input().split()))
c_que = list(map(lambda x:x*(-1), a[2*N:]))
a_que = a[:N]

a_sum = sum(a_que)
c_sum = -sum(c_que)

heapq.heapify(a_que)
heapq.heapify(c_que)

ans = -(10**15)

score = [[0, 0] for _ in range(N+1)]
score[0][0] = a_sum
score[N][1] = c_sum

for i in range(N):
    heapq.heappush(a_que, a[N+i])
    heapq.heappush(c_que, -a[2*N-1-i])
    
    a_sum = a_sum + a[N+i] - heapq.heappop(a_que)
    c_sum = c_sum + a[2*N-1-i] + heapq.heappop(c_que)
    
    score[i+1][0] = a_sum
    score[N-1-i][1] = c_sum
    
for i in range(N+1):
    ans = max(ans, score[i][0]-score[i][1])
print(ans)

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

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int a = h1*60 + m1;
    int b = h2*60 + m2;

    cout << b - a - k << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        ans = 0;
        mn = INF;
        rep(i, n){
            cin >> a;
            ans += a;
            if(a % 10){
                mins(mn, a);
            }
        }
        if(mn == INF && ans % 10 == 0){
            print(0);
        }else{
            print(ans % 10 ? ans : ans - mn);
        }
    }
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, k;
	cin >> n >> k;
	int answer = n % k;
	if (answer > 1) answer = 1;
	cout << answer << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
double cst[1002][1002];
double dist[1002];
bool flag[1002];
double x[1002], y[1002], r[1002];
int main()
{
	scanf("%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1]);
	r[0] = r[1] = 0;
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%lf%lf%lf", &x[i + 2], &y[i + 2], &r[i + 2]);
	fill(flag, flag + 1002, false);
	num += 2;
	for (int i = 0; i < num; i++)for (int j = 0; j < num; j++)cst[i][j] = max(0.0, sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j])) - r[i] - r[j]);
	fill(dist, dist + num, 100000000000000000000000000000000000000000000000000000000000000000000000000.0);
	dist[0] = 0;
	for (int i = 0; i < num; i++)
	{
		double mini = 100000000000000000000000000000000000000000000000000000000.0;
		int rr;
		for (int j = 0; j < num; j++)
		{
			if ((!flag[j]) && mini>dist[j])
			{
				mini = dist[j];
				rr = j;
			}
		}
		flag[rr] = true;
		for (int j = 0; j < num; j++)dist[j] = min(dist[j], dist[rr] + cst[rr][j]);
	}
	printf("%.20lf\n", dist[1]);
}

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

int main() {

	int n; cin >> n;
	vector<int> w(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		sum += w[i];
	}
	int ans = 100000000;
	for (int i = 1; i < n; i++) {
		int left = 0;
		int right = 0;
		for (int j = 0; j < i; j++) {
			left += w[j];
		}
		right = sum - left;
		ans = min(ans, abs(left - right));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007


ll dp[102][100004],s[102][100004],a[102];

ll fsum(int i,int l,int r)
{
	if(l<0)
	l=0;
	/*if(l!=0 and s[i][r]<s[i][l-1])
	cout<<"here "<<i<<" "<<l-1<<" "<<r<<"  "<<s[i][l-1]<<" "<<s[i][r]<<endl;*/
	if(l==0)
	return (mod+s[i][r])%mod;
	
	else
	return (mod+(s[i][r]-s[i][l-1]))%mod;
	
}

main()
{ ll n,k;
fastread
	cin>>n>>k;
	
	for(int i=1;i<=n;i++)
	cin>>a[i];
	
	for(int i=1;i<=n;i++)
{
		dp[i][0]=1;
		s[i][0]=1;
	}
	for(int i=1;i<=k;i++)
{
		dp[0][i]=0;
		s[0][i]=0;
	}
	dp[0][0] =0;
	s[0][0]=0;
	
	ll sum=0;
	for(int i=1;i<=k;i++)
	{
		if(i<=a[1])
			dp[1][i]=1;
		
		else
		dp[1][i]=0;
		
	
		s[1][i]=(dp[1][i]+s[1][i-1])%mod;
	}

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

	for(int j=1;j<=k;j++)
	{
	
	ll val = fsum(i-1,j-a[i],j);
/*	if(val<0)
	cout<<"vuhdud" <<i<<" "<<j<<endl;*/
	dp[i][j]= val;
    s[i][j]= (s[i][j-1]+dp[i][j])%mod;
  /*  if(s[i][j]<0)
    cout<<"bvf df "<<i<<" "<<j<<endl;*/
}
}
/*cout<<endl;

for(int i=0;i<=n;i++)
{ cout<<i<<endl;
	for(int j=0;j<=k;j++)

	//cout<<"here is  "<<i<<" "<<j<<endl;
	cout<<s[i][j]<<" ";
	cout<<endl<<endl;
}
cout<<endl;*/
/*cout<<"helloo "<<endl;
for(int i=0;i<=n;i++)
{
	for(int j=0;j<=k;j++)
	cout<<dp[i][j]<<" ";
	cout<<endl<<endl;
}*/
cout<<dp[n][k];
}

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

using namespace std;

struct P
{
    int x,y;
} p[100000];
int ans[100000];
int main()
{
    int h,w,d,q;
    scanf("%d%d%d",&h,&w,&d);
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
        {
            int nub;
            scanf("%d",&nub);
            p[nub].x=i;
            p[nub].y=j;
        }
    memset(ans,0,sizeof(ans));
    for(int i=d;i<=h*w;i++)
    {
        ans[i]=(ans[i-d]+abs(p[i].y-p[i-d].y)+abs(p[i].x-p[i-d].x));
        
    }
    scanf("%d",&q);
    while(q--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",abs(ans[r]-ans[l]));
    }
    return 0;
}


Measured memory_bytes: 2176
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

C = [abs(A[i-1] - A[i]) for i in range(1, N+2)]
S = sum(C)

for i in range(1, N+1):
    x = C[i-1]
    y = C[i]
    z = abs(A[i-1] - A[i+1])
    print(S - x - y + z)


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

signed main() 
{
    IOS;    
    int n;
    cin>>n;
    int i;
    for( i=0;i<n;i++){
        if((i*(i+1))/2>=n)break;
    }
    for(int j=1;j<=i;j++){
        if(j!=(i*(i+1)/2-n))cout<<j<<endl;
    }

    
    return 0; 
} 

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

int main()
{
    long long h,n;
    cin >> h >> n;
    long long sum = 0;
    for(int i=0; i<n; i++){
        long long s;
        cin >> s;
        sum += s;
    }
    if(h <= sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=1e9;
char s1[2010],s2[2010];
int a[6010],b[6010];
int nexr[6010],nexl[6010];
struct node{
	int l,r,p;
}c[6010];
bool cmp(const node &A,const node &B){
	return A.l>B.l;
}
int tr[100100];
int n;
int ans=INF;
int Min(int x,int y){
	return x<y?x:y;
}
int Max(int x,int y){
	return x>y?x:y;
}
void getlr()
{
	for(int i=1;i<=n;i++)
		a[i]=(s1[i]=='1');
	for(int i=1;i<=n;i++)
		a[i+n]=a[i+n+n]=a[i];
	for(int i=3*n;i>=1;i--)
	{
		if(b[i]) nexr[i]=0;
		else nexr[i]=nexr[i+1]+1;
	}
	for(int i=1;i<=3*n;i++)
	{
		if(b[i]) nexl[i]=0;
		else nexl[i]=nexl[i-1]+1;
	}
	for(int i=1;i<=n;i++)
		c[i]=(node){nexl[i+n],nexr[i+n],i};
	sort(c+1,c+n+1,cmp);
}
bool vis[2010];
bool vis2[2010];
void solve(int x)
{
	for(int i=1;i<=n;i++)
		vis[i]=0,vis2[i]=0;
	int u=x;
	for(int i=1;i<=n;i++)
	{
		a[u]=(s1[i]=='1');
		u++;
		if(u>n) u-=n;
	}
	int cnttt=0;
	for(int i=1;i<=n;i++)
		if(a[i]!=b[i])
			vis[i]=1,cnttt++;
	for(int i=1;i<=n;i++)
	{
		if(!vis[c[i].p+x-1<=n?c[i].p+x-1:c[i].p+x-1-n])
		{
			tr[i]=tr[i-1];
		}
		else
		{
			vis2[i]=1;
			tr[i]=Max(tr[i-1],c[i].r);
		}
	}
	int p=n+1,ndr;
	int sum=INF;
	for(int i=0;i<=n;i++)
	{
		while(p>1&&(c[p-1].l<=i||!vis2[p-1]))
			p--;
		ndr=tr[p-1];
		if(x-1>=ndr)
			sum=Min(sum,x-1+i+i);
		else
			sum=Min(sum,i+i+ndr+ndr-(x-1));
		if(n+1-x>=i)
			sum=Min(sum,n+1-x+ndr+ndr);
		else
			sum=Min(sum,i+i+ndr+ndr-(n+1-x));
	}
	sum=sum+cnttt;
	if(sum<ans)
		ans=sum;
}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	n=strlen(s1+1);
	bool bo=1;
	for(int i=1;i<=n;i++)
		if(s2[i]=='1'){
			bo=0;
			break;
		}
	if(bo)
	{
		for(int i=1;i<=n;i++)
		{
			if(s1[i]=='1')
			{
				printf("-1\n");
				return 0;
			}
		}
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
		b[i]=(s2[i]=='1');
	for(int i=1;i<=n;i++)
		b[i+n]=b[i+n+n]=b[i];
	getlr();
	for(int i=1;i<=n;i++)
	{
		solve(i);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<int> dp(n, 1e9);
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    // for (int val : dp) {
    //     cout << val << " ";
    // }
    // cout << endl;
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
N, K = map(int,input().split())
monsters = [int(i) for i in input().split()]
monsters.sort(reverse=True)
deleted_monsters = []
for i in range(N):
    if i < K:
        deleted_monsters.append(0)
    else:
        deleted_monsters.append(monsters[i])
print(sum(deleted_monsters))

Measured memory_bytes: 26764
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const ll mod = 1e9 + 7;

int n;
vector<int> G[100005];
int vis[100005];
int dp[100005][2];

inline void mlt(int &x, int y){
    x = ll(x) * y % mod;
}

void dfs(int x){
    vis[x] = 1;
    dp[x][0] = dp[x][1] = 1;
    for(int u : G[x]){
        if(vis[u]) continue;
        dfs(u);
        mlt(dp[x][0], (dp[u][0] + dp[u][1]) % mod);
        mlt(dp[x][1],  dp[u][0]);
    }
}

int main(){
    fio;
    cin >> n;
    for(int i = 0, a, b; i < n-1; i++){
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(1);
    cout << (dp[1][0] + dp[1][1]) % mod << '\n';
}

Measured memory_bytes: 11136
A = [int(input()) for i in range(5)]
B = [A[i] % 10 for i in range(5)]
C = [10 - B[i] for i in range(5) if B[i] != 0]
if C == []:
    C.append(0)

ans = 0
for i in range(5):
    ans += A[i]
    if B[i]: ans += 10 - B[i]

print(ans - max(C))

Measured memory_bytes: 3064
package main;

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextInt()
	x := sc.NextIntArray()
	dp := make([][]int, N + 1)
	for i := 0; i < N + 1; i++ {
		dp[i] = make([]int, 50 * 50 + 1)
	}
	for j := 0; j < N; j++ {
		for i := 50 * 50; i >= 0; i-- {
			if i - x[j] < 0 {
				continue
			}
			for k := N - 1; k >= 0; k-- {
				dp[k + 1][i] += dp[k][i - x[j]]
				if k == 0 && i == x[j] {
					dp[k + 1][i] ++
				}
			}
		}
	}
	ans := 0
	for i := 50 * 50; i >= 0; i-- {
		for k := 0; k <= N; k++ {
			if dp[k][i] > 0 {
				if k * A == i {
					ans += dp[k][i]
				}
			}
		}
	}
	fmt.Println(ans)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func
NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,cnt = 0;
    cin >> N;
    int vcnt = 0;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    rep(i,1,N){
        if(V[i] == V[i-1]){
            vcnt++;
        }else{
            cnt += (vcnt+1) / 2;
            vcnt = 0;
        }
    }
    cnt += (vcnt+1) / 2;
    cout << cnt << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# ITP2_11_D: Bitset 2 - Enumeration of Combinations


def combination(n, k):
    """Yields all combinations of k numbers from n numbers.

    >>> list(combination(3, 2))
    [[0, 1], [0, 2], [1, 2]]
    """
    def _combination(i, j, a):
        if i > n:
            return
        if j == 0:
            yield nums(n, a)
        elif i <= n:
            yield from _combination(i+1, j-1, a | 1 << i)
            yield from _combination(i+1, j, a)

    yield from _combination(0, k, 0)


def nums(size, bit):
    """Returns list of bit positions where bit flag is on.

    >>> nums(4, 7)
    [0, 1, 2]
    """
    return [n for n in range(size) if bit & (1 << n)]


def bit(nums):
    """Returns a bit representation of nums.

    >>> bit([0, 1, 2])
    7
    """
    return sum(1 << n for n in nums)


def run():
    n, k = [int(i) for i in input().split()]
    for ns in sorted(combination(n, k), key=bit):
        print("{}: {}".format(bit(ns), " ".join([str(i) for i in ns])))


if __name__ == '__main__':
    run()



Measured memory_bytes: 17644
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

bool call(int x) {
	if (x == 2) return true; //2????´???°	

	if (x < 2 || x % 2 == 0) return false; //2??\?????¨2????????°????´???°??§?????????

	static int i = 3; //i=1,2???????????????????????§???????????????

	for (i = 3; i <= sqrt(x); i += 2) { //?\???°??§?????????????????????????????????????????°???????????§???i+=2
		if (x%i == 0) return false;		//??????????´???°x??????????´??????°???p<=???x??????????????§??????????????????
	}									//x?????????????????§??§??????

	return true;
}

int main() {
	int n, i,a[10000],sum = 0;

	cin >> n;

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

	for (i = 0; i < n; i++)
		if (call(a[i])) sum++;

	cout << sum << endl;

	return 0;
}

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


unsigned int xor128(){
	static unsigned int x=123456789;
	static unsigned int y=362436069;
	static unsigned int z=521288629;
	static unsigned int w=88675123;
	unsigned int t;
	t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct node{
	node*l,*r;
	int cnt,val,Min;
};
node pool[400000];
int p;

inline int cnt(node*t){return t?t->cnt:0;}
inline int Min(node*t){return t?t->Min:INF;}

inline node*update(node*t){
	t->cnt=cnt(t->l)+cnt(t->r)+1;
	t->Min=min({t->val,Min(t->l),Min(t->r)});
	return t;
}
inline node*merge(node*l,node*r){
	if(!l)return r;
	if(!r)return l;
	if(xor128()%(cnt(l)+cnt(r))<(unsigned int)cnt(l)){
		l->r=merge(l->r,r);
		return update(l);
	}
	else{
		r->l=merge(l,r->l);
		return update(r);
	}
}
inline pair<node*,node*>split(node*t,int k){
	if(!t)return make_pair((node*)NULL,(node*)NULL);
	if(k<=cnt(t->l)){
		auto p=split(t->l,k);
		t->l=p.second;
		return make_pair(p.first,update(t));
	}
	else{
		auto p=split(t->r,k-cnt(t->l)-1);
		t->r=p.first;
		return make_pair(update(t),p.second);
	}
}

int main(){
	int n,q;scanf("%d%d",&n,&q);
	node*root=NULL;
	rep(i,n){
		int a;scanf("%d",&a);
		node*t=&pool[p++];
		*t={NULL,NULL,1,a,a};
		root=merge(root,t);
	}
	rep(i,q){
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		if(x==0){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y-1);
			auto c=split(b.second,1);
			root=merge(merge(merge(a.first,c.first),b.first),c.second);
		}
		else if(x==1){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y);
			printf("%d\n",Min(b.first));
			root=merge(merge(a.first,b.first),b.second);
		}
		else{
			auto a=split(root,y);
			auto b=split(a.second,1);
			b.first->val=z;
			update(b.first);
			root=merge(merge(a.first,b.first),b.second);
		}
	}
}


Measured memory_bytes: 9476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader std = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        while(true){
            String data[] = std.readLine().split(" ");
            int a = Integer.parseInt(data[0]);
            int b = Integer.parseInt(data[1]);
            if(a == 0 && b == 0) break;
            
            for (int i = 1; i <= a; i++){
                for(int j = 1; j <= b; j++){
                    if ((i % 2 == 1 && j % 2 == 1)
                            || (i % 2 == 0 && j %2 == 0) ) {
                        sb.append("#");
                    } else {
                        sb.append(".");
                    }
            
            }
                sb.append("\n");
        }
            sb.append("\n");

    }
        System.out.print(sb);
    }
}

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

int main() {
  int n; cin >> n;

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

  sort(l.begin(), l.end());
  int count = 0;
  for (int a = 0; a < n - 2; a++) {
    int c = a + 2;
    for (int b = a + 1; b < n - 1; b++) {
      while (c < n && l[a] + l[b] > l[c]) {
        c++;
      }
      count += c - b - 1;
    }
  }

  cout << count << "\n";
  return 0;
}


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

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

    string S, T; cin >> S >> T;
    vector<char> v(26), w(26);
    for (int i = 0; i < S.size(); i++) {
        if (v[S[i]-'a'] == 0) v[S[i]-'a'] = T[i];
        else {
            if (v[S[i]-'a'] != T[i]) {
                cout << "No\n";
                return 0;
            }
        }
        if (w[T[i]-'a'] == 0) w[T[i]-'a'] = S[i];
        else {
            if (w[T[i]-'a'] != S[i]) {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, m;
	cin >> n >> m;

	vl indeg(n);
	vvl adj(n);
	while (m--) {
		ll a, b;
		cin >> a >> b;
		a--, b--;
		indeg[b]++;
		adj[a].pb(b);
	}
	
	queue<ll> q;
	FOR(i,0,n) if (!indeg[i]) q.push(i);

	vl dp(n);
	while (sz(q)) {
		ll i = q.front(); q.pop();
		for (ll j: adj[i]) {
			dp[j] = max(dp[j], dp[i]+1);
			if (!--indeg[j]) q.push(j);
		}
	}
	cout << *max_element(all(dp)) << endl;
}



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

// ref. https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#5-%E4%BA%8C%E9%A0%85%E4%BF%82%E6%95%B0-ncr
const int MOD = 1000000007;


// a^n mod を計算する
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
      if (n & 1) res = res * a % MOD;
      a = a * a % MOD;
      n >>= 1;
  }
  return res;
}


int main(){
  int N;
  cin >> N;
  long long num_zero = 0;
  map<pair<long long, long long>, pair<long long, long long>> A;  
  for(int ii=0; ii<N; ii++){
    long long x, y;
    cin >> x >> y;
    if(x==0&&y==0){
      num_zero++;
      continue;
    }
    long long g = gcd(x, y);
    x /= g;
    y /= g;
    if(y<0){
      x = -x;
      y = -y;
    }
    if(y==0&&x<0) x = -x;
    if(x>0){
      A[make_pair(x, y)].first++;
    }else{
      A[make_pair(y, -x)].second++;
    }
  }
  long long ans = 1;
  for(auto a : A){
    // cout << "(" << a.first.first << ", " << a.first.second << "): " << a.second.first << ", " << a.second.second << endl;
    ans *= modpow(2, a.second.first) + modpow(2, a.second.second) - 1;
    ans %= MOD;
  }
  ans--;
  ans += MOD;
  ans %= MOD;
  ans += num_zero;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19208
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
ll A, B;
ll X = 0;

signed main(){
    cin >> N >> A >> B;
    rep(i, N-2){
        ll tmp;
        cin >> tmp;
        X ^= tmp;
    }
    ll ans = A+B-X;
    if(ans < 0 || ans%2 == 1){
        cout << -1 << endl;
    }
    else{
        ans /= 2LL;
        ll a = ans;
        ll nokori = A+B - 2*ans;
        for(ll i=60; i>=0; i--){
            if(((nokori>>i)&1) == 1 && ((ans>>i)&1) == 1){
                cout << -1 << endl;
                return 0;
            }
            if(((nokori>>i)&1) == 1 && a+(1LL<<i) <= A){
                a += (1LL<<i);
            }
        }
        if(a == 0 || a > A) cout << -1 << endl;
        else cout << A-a << endl;
    }
}

Measured memory_bytes: 3472
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int H; cin >> H;
	int A; cin >> A;
	cout << (H + A - 1) / A << "\n";


	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x,y=map(int, input().split())
    ans='No'
    for i in range(x+1):
        a=i
        b=x-i
        if a*2+b*4==y:
            ans='Yes'
            break
    print(ans)
resolve()

Measured memory_bytes: 9084
//2019/3/14
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int nn = n;

		int a = String.valueOf(n).length();

		int Sn = 0;

		while(a>0) {

			Sn += nn % 10;

			nn /= 10;

			a--;
		}

		Sn += nn;

		if(n%Sn==0)System.out.println("Yes");

		else System.out.println("No");

	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define repl(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    int k,a,b;
    cin >> k >> a >> b;
    int cnt = 1;
    for(int i = a;i<=b;i++){
        if(i%k == 0){
            cout << "OK\n";
            return 0;
        }
    }
    cout << "NG\n";
    return 0;
}

Measured memory_bytes: 3648
class Card:
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value

    def __str__(self):
        return self.suit + ' ' + str(self.value)


""" merge_sort """

def merge(A, n, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]

    L.append(Card('None', 2000000000))  # これをしないとマージするとき、最後の１回でリスト外アクセスでエラー。
    R.append(Card('None', 2000000000))

    # global count
    i, j = 0, 0

    # print('left, mid, right')
    # print(left, mid, right)

    for k in range(left, right, 1):
        # count += 1
        # print('i, j, k')
        # print(i, j, k)

        if L[i].value <= R[j].value:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end')


def merge_sort(A, n, left, right):
    if right - left > 1:
        mid = (left + right) // 2
        merge_sort(A, n, left, mid)
        merge_sort(A, n, mid, right)
        merge(A, n, left, mid, right)


""" quick_sort """

def partition(A, n, p, r):
    x = A[r].value
    i = p - 1

    for j in range(p, r):
        if A[j].value <= x:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i+1], A[r] = A[r], A[i+1]
    return i + 1

def quick_sort(A, n, p, r):
    if p < r:
        q = partition(A, n, p, r)
        quick_sort(A, n, p, q-1)
        quick_sort(A, n, q+1, r)


N = int(input())
A = []
for i in range(N):
    suit, value = input().split()
    value = int(value)
    A.append(Card(suit, value))
B = list(A)

quick_sort(A, N, 0, N-1)
merge_sort(B, N, 0, N)

stable = True
for i in range(N):
    if A[i] != B[i]:
        stable = False

if stable is True:
    print('Stable')
else:
    print('Not stable')

for a in A:
    print(a)

# for b in B:
#     print(b)



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

int main()
{
    int64_t K;
    int64_t N;
    vector<int64_t> a(2000000);
    int64_t maxdis=0;
    int64_t count=0;
    cin >> K >> N;
    for(int i=0; i<N; i++)
    {
        cin >> a.at(i);
    }
    for(int i=0; i<N-1; i++)
    {
        if(maxdis<(a.at(i+1)-a.at(i)))
        {
            maxdis=(a.at(i+1)-a.at(i));
        }
    }
    if((K-(a.at(N-1)-a.at(0)))>maxdis)
    {
        maxdis=(K-(a.at(N-1)-a.at(0)));
    }
    cout << K-maxdis << endl;
}

Measured memory_bytes: 16000
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int inf = 10000000;

int main(){
  int N,ma,mb;
  cin >> N >> ma >> mb;
  int a[N],b[N],c[N];
  for(int i=0;i<N;i++) cin >> a[i] >> b[i] >> c[i];

  int dp[401][401];
  fill(dp[0],dp[401],inf);

  dp[0][0] = 0;
  for(int i=0;i<N;i++){
    for(int j=400;j>=0;j--){
      for(int k=400;k>=0;k--){
        if(dp[j][k]!=inf && j+a[i]<=400 && k+b[i]<=400){
          dp[j+a[i]][k+b[i]] = min(dp[j+a[i]][k+b[i]], dp[j][k] + c[i]);
        }
      }
    }
  }

  int ans = inf;
  for(int i=1 ; ; i++){
    if(i*ma > 400 || i*mb > 400) break;
    else {
      ans = min(ans, dp[i*ma][i*mb]);
    }
  }

  if(ans == inf) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1234567890
 
int main(){
    ll i,j,k;
    ll n,m;
    cin>>n>>m;
    VVI d(n,VI(n,INF));
    ll x[m],y[m],z[m];
    for(i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        d[a-1][b-1]=c;
        d[b-1][a-1]=c;
        x[i]=a-1;
        y[i]=b-1;
        z[i]=c;
    }
    for(k=0;k<n;k++){
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    ll ans=0;
    for(i=0;i<m;i++){
        if(z[i]!=d[x[i]][y[i]]) ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#include <string.h>
#define rep(i,a,n) for(int i=a;i<n;i++)

int main(){
	int m,h,len;
	while(1){
		char s[210],t[210]="";
		scanf("%s",s);
		if(strcmp(s,"-")==0) break;
		len=strlen(s);
		scanf("%d",&m);
		rep(i,0,m){
			scanf("%d",&h);
			rep(j,0,h){
				t[j+len-h]=s[j];
			}
			rep(j,h,len){
				t[j-h]=s[j];
			}
			sprintf(s,"%s",t);
		}
		printf("%s\n",s);
	}
	return 0;
}

Measured memory_bytes: 1020
d=int(input())
c=[int(i) for i in input().split()]
s=[]
for i in range(d):
  s.append([int(i) for i in input().split()])

#Score
Score=[0]*d
last=[0]*26
d_last=[0]*26
t=[]

for j in range(d):
  d_last=[(j+1)-i if i>0 else 0 for i in last]
  cd=[c*dd for (c,dd) in zip(c,d_last)]
  score1=[s-c for (s,c) in zip(s[j],cd)]
  Score[j]=max(score1)
  last[score1.index(max(score1))]=j+1
  t.append(score1.index(max(score1))+1)

for l in t:
  print(l)

Measured memory_bytes: 9244
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define HpOut(S) cout << setprecision(20) << S << endl;
#define print(x) cout << (x) << endl;
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

 
int main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll n,m;
    cin >> n >> m;
    vector<vector<int>> jobs(m);
    rep(i,n){
      ll a, b;
      cin >> a >> b;
      if(a > m) continue;
      jobs[m-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for(int i = m-1; i >= 0; --i){
      for(int b : jobs[i]){
        q.push(b);
      }
      if(!q.empty()){
        ans += q.top();
        q.pop();
      }
    }
    print(ans);
}

Measured memory_bytes: 5632
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){
        swap(a,b);
    }
    if(b>c){
        swap(b,c);
    }
    if(a>b){
        swap(a,b);
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,m;cin>>n>>m;
  vector<pair<int,int>> a(m);rep(i,m)cin>>a[i].fi>>a[i].se;
  sort(all(a));
  
  bool ok = true;
  string s(n,'0');
  s[0] = (n != 1)?'1':'0';
  rep(i,m){
    if(n != 1 && a[i].fi == 1 && a[i].se == 0)ok = false;
    if(i != m-1 && a[i].fi == a[i+1].fi && a[i].se != a[i+1].se)ok = false;
    
    s[a[i].fi-1] = a[i].se + '0';
  }

  if(ok)print(s);
  else print(-1);
  
  return 0;
}



Measured memory_bytes: 256