akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[100000];
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    int flag = 0;
    int count = 1;

    for (int i = 0; i < N - 1; i++){
        if (flag == 0){
            if (A[i] - A[i + 1] < 0) flag = 1;
            else if (A[i] - A[i + 1] > 0) flag = -1;
        }
        else if (flag == 1){
            if (A[i] - A[i + 1] > 0) {
                flag = 0;
                count++;
            }
        }
        else if (flag == -1){
            if (A[i] - A[i + 1] < 0){
                flag = 0; 
                count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 640
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define CLR2d(x,m,n) memset(x, -1, sizeof(x[0][0]) * m * n)
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >


int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
ll po(ll b,ll p){
    ll res=1;
    while(p){
        res*=b;
        p--;
    }
    return res;
}
ll lg2(ll x){
    ll res=0;
    while(x>1){
        res++;
        x/=2ll;
    }
    return res;
}
void solve(){
    string s,t;
    cin>>s>>t;
    t+=s;
    cout<<t<<endl;
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef complex<double> P;

double EPS = 1e-7;

P a,b,t[1111];
int n;
double r[1111];
vector<int>A,B;
int dp1[1111],dp2[1111];
set<int>sA,sB;

int dfs1(int x){
  if(dp1[x]!=-1)return dp1[x];
  int res=0;
  r(i,n){
    if(!sA.count(i))continue;
    //if(x==i)continue;
    if(!(abs(t[x]-t[i])+EPS<r[x]-r[i]))continue;
    res=max(res,dfs1(i));
  }
  return dp1[x]=res+1;
}

int dfs2(int x){
  if(dp2[x]!=-1)return dp2[x];
  int res=0;
  r(i,n){
    if(!sB.count(i))continue;
    //if(x==i)continue;
    if(!(abs(t[x]-t[i])+EPS<r[x]-r[i]))continue;
    res=max(res,dfs2(i));
  }
  return dp2[x]=res+1;
}

signed main(){
  double t1,t2;
  while(cin>>n , n){
    int ans=0;
    A.clear();
    B.clear();
    sA.clear();
    sB.clear();
    memset(dp1,-1,sizeof(dp1));
    memset(dp2,-1,sizeof(dp2));
    cin>>t1>>t2;
    a=P(t1,t2);
    cin>>t1>>t2;
    b=P(t1,t2);
    r(i,n){
      cin>>t1>>t2>>r[i];
      t[i]=P(t1,t2);
      int AA = abs( a-t[i] ) < r[i];
      int BB = abs( b-t[i] ) < r[i];
      if( (!AA||!BB) && AA!=BB ){
        if(AA)A.push_back(i),sA.insert(i);
        else B.push_back(i),sB.insert(i);
      }
    }
    r(i,A.size())ans=max(ans,dfs1(A[i]));
    r(i,B.size())ans=max(ans,dfs2(B[i]));
    r(i,A.size()){
      r(j,B.size()){
        if( abs(t[A[i]]-t[B[j]])<EPS+r[A[i]]+r[B[j]])continue;
        ans=max(ans,dfs1(A[i])+dfs2(B[j]));
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3392
n=int(input())
c=[0]*(n+1)
for i in range(2,n+1):
	j=2
	while j*j<=i:
		while i%j==0:
			c[j]+=1
			i//=j
		j+=1
	if i>1:
		c[i]+=1
f=lambda x:sum(y+1>=x for y in c)
print(f(75)+f(25)*(f(3)-1)+f(15)*(f(5)-1)+f(5)*(f(5)-1)//2*(f(3)-2))

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

int main() {
    int N, K;
    cin >> N >> K;
	vector<int> s(N, 0);
	for(int i=0;i<K;i++){
		int d;
		cin >> d;
		for(int j=0;j<d;j++){
			int a;
			cin >> a;
			s[a-1]++;
		}
	}
	int n = 0;
	for(int i=0;i<N;i++){
		if(s[i]==0){
			n++;
		}
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

void receive(int *, int *);
int calc(int, int *);

int main(){
  int N, dislike[10] = {0};
  receive(&N, dislike);
  
  int ans = calc(N, dislike);

  printf("%d\n", ans);
  return 0;
}

void receive(int *N, int *dislike){
  int K;
  scanf("%d %d", N, &K);
  for(int i = 0; i < K; i++){
    int d;
    scanf("%d", &d);
    dislike[d] = 1;
  }
}

int calc(int N, int *dislike){
  int i = N;
  for(; i <= 10*N; i++){
    int j = i;
    while(j > 0 && !dislike[j%10]) j /= 10;
    if(j == 0) break;
  }
  return i;
}

Measured memory_bytes: 128
set = input()
words = []
for i in range(len(set)):
    if set[i] == "0":
        words.append("0")
    if set[i] == "1":
        words.append("1")
    if set[i] == "B":
        try:
            words.pop(-1)
        except:
            pass
word = ""
for i in words:
    word += i
print(word)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int fibdp[50];

int fib(int n){
	if(n == 1 || n == 0){
		return 1;
	}
	if (fibdp[n] != 0){
		return fibdp[n];
	}
	return fibdp[n] = fib(n - 1) + fib(n - 2);
}
int main(){
	int n;

	cin >> n;

	cout << fib(n) << endl;
}

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

using namespace std;

const int N = 2001, M = 1e9+7;
int n, dp[N] = {1};

inline void solve1() {
	for (register int i = 3; i <= n; ++i)
		for (register int j = i-3; j >= 0; --j)
			(dp[i] += dp[j]) %= M;
	printf("%d\n", dp[n]);
}

inline long long power(const long long &a, const long long &p) {
	if (!p) return 1;
	long long res = power(a, p >> 1);
	(res *= res) %= M;
	if (p & 1) res *= a;
	return res % M;
}

long long ans, k, den, nom, fact[N] = {1};
inline void solve2() {
	for (register int i = 1; i <= n; i++)
		fact[i] = fact[i-1] * i % M;
	for (register int i = 1; i <= n/3; i++) {
		k = n - i*3;
		den = (fact[k] * fact[i-1]) % M;
		nom = (fact[k+i-1] * power(den, M-2)) % M;
		(ans += nom) %= M;
	}
	printf("%lld\n", ans);
}

int main() {
	scanf("%d", &n);
	solve1();
	return 0;
}


Measured memory_bytes: 3812
// わからなかった
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

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

int main() {
    int H, W;
    cin >> H >> W;
    string field[H];
    rep(i, H) cin >> field[i];


    int dist[H][W];
    memset(dist, -1, sizeof(dist));
    queue<pair<int, int>> que;

    rep(i, H) {
        rep(j, W) {
            if (field[i][j] == '#') {
                dist[i][j] = 0;
                que.push(pair<int, int>(i, j));
            }
        }
    }

    int sum = 0;
    while(!que.empty()) {
        int vy = que.front().first;
        int vx = que.front().second;
        que.pop();

        for (int dir = 0; dir < 4; dir++) {
            int ny = vy + dy[dir];
            int nx = vx + dx[dir];

            if (ny < 0 || ny >= H || nx < 0 || nx >= W) {
                continue;
            }

            if (dist[ny][nx] == -1) {
                field[ny][nx] = '#';
                dist[ny][nx] = dist[vy][vx] + 1;
                sum = max(sum, dist[ny][nx]);
                que.push(pair<int, int>(ny, nx));
            }
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 13456
import heapq
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    next_n = [0] * n
    used[s] = False
    edgelist = []
    for e in edge[s]:
        e.append(s)
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        next_n[v] = minedge[2]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1],v])
    return d, next_n

################################
n,w = map(int,input().split()) #n:頂点数　w:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
    a,b = map(int,input().split())
    edge[b-1].append([1,a-1])
    edge[a-1].append([1,b-1]) 
res_list, next_list = dijkstra_heap(0)
if float('inf') in res_list:
  print("No")
else:
  print("Yes")
  for res in next_list[1:]:
    print(res+1)

Measured memory_bytes: 79284
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)1e5 + 228;

using namespace std;

int cnt[N];

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	int n, m;
	scanf("%d%d", &n, &m);
	forn(i, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		cnt[x]++, cnt[y]++;
	}
	forn(i, n)
	{
		if (cnt[i] & 1)
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}



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

/*
int vistd[10004];
vector<int>a[10004];
vector<int>dis(10004,0);
void dfs(int k){
   if(vistd[k]==0){
    vistd[k]=1;
    for(int i=0;i<a[k].size();i++){
        if(!vistd[a[k][i]]){
/// to find the distance between each node and their children dis[a[k][i]]=dis[k]+1;
            dfs(a[k][i]);
        }
    }
   }

}
int freq[2004];
*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);

 string s;
 cin>>s;
 ll sum=0;
 for(int i=0;i<s.length();i++)
    sum+=(s[i]-'0');
 cout << (sum%9?"No":"Yes") << endl;







/*
   int t;
   cin>>t;
   int hh=t;
   vector<string>last,f;
   while(t--){
    string s,m;
  cin>>s>>m;
    int countchar=0;
    for(int i=0;i<m.length();i++){
        if ((int(m[i])>=65 && int(m[i])<=90) || (int(m[i])>=97 && int(m[i])<=122))
           countchar++;
    }
    string tmp1="";
    for(int i=0;i<s.length();i++){
        if((int(s[i])>=65 && int(s[i])<=90) || (int(s[i])>=97 && int(s[i])<=122)){
            tmp1+=s[i];
        }
    }
    string tmp2="";
     if(countchar>1){
            int ff=0;
        for(int i=0;i<m.length();i++){
        if((int(m[i])>=65 && int(m[i])<=90) || (int(m[i])>=97 && int(m[i])<=122)){
                if(!ff){
                    m[i]=toupper(m[i]);
                    ff=1;
                }
            tmp2+=m[i];
        }
        last.push_back(tmp2);
        f.push_back(tmp1);
    }
     }
     else{
            tmp1[0]=toupper(tmp1[0]);
        last.push_back(tmp1);
        string c="";
        for(int i=0;i<m.length();i++){
            if((int(m[i])>=65 && int(m[i])<=90) || (int(m[i])>=97 && int(m[i])<=122)){
                    m[i]=toupper(m[i]);
            c+=m[i];
            c+=".";
            break;
        }
        }
        f.push_back(c);
     }
       sort(last.begin(),last.end());

   }
  for(int i=0;i<hh;i++)
    cout << last[i] << endl;
    */
}






Measured memory_bytes: 3784
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
//#define ivorysi
#define MAXN 200005
#define eps 1e-7
#define mo 974711
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
int64 A[MAXN],B[MAXN],sum;
int N;
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    scanf("%d",&N);
    for(int i = 1 ; i <= N ; ++i) scanf("%lld%lld",&A[i],&B[i]);
    int64 minn = 0x7fffffff;
    for(int i = 1 ; i <= N ; ++i) {
	sum += B[i];
	if(B[i] < A[i]) minn = min(B[i],minn);
    }
    if(minn == 0x7fffffff) puts("0");
    else printf("%lld\n",sum - minn);
}


Measured memory_bytes: 512
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict


class Solution:
    def main_old(self):
        N, M = map(int, input().split())
        self.memo = {}
        for _ in range(M):
            a = int(input())
            self.memo[a] = 0
        res = self.rec(N)
        print(res)

    def main(self):
        N, M = map(int, input().split())
        A = set()
        for _ in range(M):
            A.add(int(input()))
        dp = [0] * (N+1)
        dp[0] = 1
        for i in range(0, N+1):
            # print(dp)
            if i+1 <= N and i+1 not in A:
                dp[i+1] += dp[i]
                dp[i + 1] %= 1000000007
            if i+2 <= N and i+2 not in A:
                dp[i+2] += dp[i]
                dp[i + 2] %= 1000000007
        print(dp[N])

    def rec(self, n):
        if n < 0:
            return 0
        elif n == 0:
            return 1
        elif n in self.memo:
            return self.memo[n]
        else:
            val = (self.rec(n-1) + self.rec(n-2)) %1000000007
            self.memo[n] = val
            return val


if __name__ == '__main__':
    Solution().main()

Measured memory_bytes: 12268
#pragma region header
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
template <class T> ll size(const T& x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
#define MOD 1000000007;
#define MOD2 998244353;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
template <class T> T smod(T a, T b) {
	return (a % b + b) % b;
}

const int INF = ~(1 << 31);
const double pi = acos(-1);
const double EPS = 1e-9;

#pragma endregion

/*vector<int> edg[100100];
bool active[100100];
int depth[100100];
bool vis[100100];
bool print = false;
vector<int> ans;
void dfs(int at, int dep){
	if(vis[at]) return;
	if(print){
		ans.pb(at);
		return;
	}
	if(active[at] && dep-depth[at] >= 2){
		print = true;
		ans.pb(at);
		return;
	}
	depth[at] = dep;
	active[at] = true;
	vis[at] = true;
	rep(i,0,edg[at].size()){
		dfs(edg[at][i],dep+1);
	}
	active[at] = false;
}*/

vector<int> edg[300050];
bool vis[300050];
int dist[300050];

void bfs(int start) {
	memset(vis, 0, sizeof(vis));
	memset(dist, -1, sizeof(dist));
	queue<int> q;
	q.push(start);
	dist[start] = 0;
	vis[start] = true;
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		rep(i, 0, edg[cur].size()) {
			int nxt = edg[cur][i];
			if (!vis[nxt]) {
				vis[nxt] = true;
				dist[nxt] = dist[cur] + 1;
				q.push(nxt);
			}
		}
	}
}


int main() {
	ll n, x, y;
	cin >> n >> x >> y;
	rep(i, 0, n - 1)
	{
		edg[i].pb(i + 1);
		edg[i + 1].pb(i);
	}
	x--; y--;
	edg[x].pb(y);
	edg[y].pb(x);
	vi K(n+10000);
	rep(i, 0, n)
	{
		bfs(i);
		rep(j, 0, n)
		{
			if (i == j) continue;
			K[dist[j]]++;
		}
	}
	rep(i, 1, n) cout << K[i]/2 << endl;
}


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

int main() {
    int n;
    int r[200000];
    cin >> n;
    for(int i=0;i<n;i++) cin >> r[i];
    int max_diff = r[1] - r[0];
    int min_value = r[0];
    for(int i=1;i<n;i++){
        max_diff = max(max_diff, r[i]-min_value);
        min_value = min(min_value, r[i]);
    }
    cout << max_diff << endl;
    return 0;
}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	u64 N, K;
	cin >> N >> K;

    vector<u64> P(N);
    vector<s64> C(N);
    
    for(u64 i=0; i<N; i++) cin >> P[i], P[i]--;
    for(u64 i=0; i<N; i++) cin >> C[i];

    s64 ans = INT64_MIN;
    
    for(u64 i=0; i<N; i++) {
        u64 v = i;
        s64 csum = 0;
        u64 cnum = 0;

        do {
            csum += C[v];    
            cnum++;
            v = P[v];
        } while(v != i);

        u64 ccnt = 0;
        s64 pans = 0;

        do {
            pans += C[v];
            v = P[v];
            ccnt++;

            s64 off = (csum > 0) ? (K - ccnt) / cnum * csum : 0;
            ans = max(ans, pans + off);
        } while(v != i && ccnt < K);

    }

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

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

int main() {
    int N, M;
    string color;
    cin >> N >> M >> color;
    vector<set<int>> edges(N);
    rep(i,M) {
        int a, b; scanf("%d %d", &a, &b);
        a--; b--;
        edges[a].insert(b);
        edges[b].insert(a);
    }

    vvl cnts(N, vl(2, 0));
    rep(i,N) {
        for (auto v : edges[i]) {
            cnts[i][color[v]-'A']++;
        }
    }

    int count = 0;
    vector<bool> removed(N,false);
    queue<int> leaves;
    rep(i,N) {
        if (cnts[i][0] and cnts[i][1]) continue;
        leaves.push(i);
    }
    while (!leaves.empty()) {
        int v = leaves.front(); leaves.pop();
        if (removed[v]) continue;
        for (auto nv : edges[v]) {
            if (removed[nv]) continue;
            cnts[nv][color[v]-'A']--;
            if (v != nv) cnts[v][color[nv]-'A']--;
            if (cnts[nv][0] and cnts[nv][1]) continue;
            leaves.push(nv);
        }
        removed[v] = true;
        count++;
    }

    cout << (count==N?"No":"Yes") << endl;
    return 0;
}


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

int main() {

  ll a, b, c;
  cin >> a >> b >> c;
  ll d = c - a - b;
  if( d > 0 && d * d > 4*a*b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) (x-'0')
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return (t*t);
    else
        return (t*t*x);
}

bool prime(int x)
{
    if(x < 2) return false;
        for(int i=2; i<= sqrt(x); i++) {
            if ((x%i) == 0) return false;
        }
    return true;
}

bool vis[30][30];
char a[30][30];
int ans=0;
int n,m;
queue<pair<pii,int> >q;
void bfs(){
    if(q.empty())
        return;
    int i = q.front().fi.fi;
    int j = q.front().fi.se;
    vis[i][j]=1;
    ans = max(ans,q.front().se);
    if(i<n-1&&a[i+1][j]=='.'&&!vis[i+1][j])
        q.push({{i+1,j},q.front().se+1});
    if(i>0&&a[i-1][j]=='.'&&!vis[i-1][j])
        q.push({{i-1,j},q.front().se+1});
    if(j<m-1&&a[i][j+1]=='.'&&!vis[i][j+1])
        q.push({{i,j+1},q.front().se+1});
    if(j>0&&a[i][j-1]=='.'&&!vis[i][j-1])
        q.push({{i,j-1},q.front().se+1});
    q.pop();
    bfs();
}
vector<pii>point;
int main()
{
    weewoo;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a[i][j];
            if(a[i][j]=='.')
                point.push_back({i,j});
        }
    }
    for(int h=0;h<point.size();h++){
        memset(vis,0,sizeof vis);
        q.push({{point[h].fi,point[h].se},0});
        while(!q.empty()){
            int i = q.front().fi.fi;
            int j = q.front().fi.se;
            vis[i][j]=1;
            ans = max(ans,q.front().se);
            if(i<n-1&&a[i+1][j]=='.'&&!vis[i+1][j]){
                q.push({{i+1,j},q.front().se+1});
                vis[i+1][j]=1;
            }
            if(i>0&&a[i-1][j]=='.'&&!vis[i-1][j]){
                q.push({{i-1,j},q.front().se+1});
                vis[i-1][j]=1;
            }
            if(j<m-1&&a[i][j+1]=='.'&&!vis[i][j+1]){
                q.push({{i,j+1},q.front().se+1});
                vis[i][j+1]=1;
            }
            if(j>0&&a[i][j-1]=='.'&&!vis[i][j-1]){
                q.push({{i,j-1},q.front().se+1});
                vis[i][j-1]=1;
            }
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<algorithm>
#include<vector>
#include<cstring>
#include<iostream>
#include<cmath>

using namespace std;

const int  mod = 1e9+7;

int dp[22][1<<21];
int num_bits[1<<21];
vector<int> masks[22];

int main() {
	int n;
	scanf("%d", &n);

	int a[n+1][n+1];
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	dp[0][0] = 1;
	masks[0].push_back(0);
	for(int i=1; i<(1<<n); i++) {
		num_bits[i] = num_bits[i>>1] + (i&1);
		masks[num_bits[i]].push_back(i);
	}
	for(int i=1; i<=n; i++) {
		for(auto mask: masks[i-1]) {
			for(int j=0; j<n; j++) {
				if((mask&(1<<j)) || a[i][j+1]==0)
					continue;
				dp[i][mask|(1<<j)] += dp[i-1][mask];
				if(dp[i][mask|(1<<j)] >= mod) dp[i][mask|(1<<j)] -= mod;
			}
		}
	}
	printf("%d\n", dp[n][(1<<n)-1]);
    return 0;
}

Measured memory_bytes: 181692
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
int main()
{
  int a, b, c;
  double average;
  cin >> a >> b;

  average = ((double)(a+b)/2);
  c = (int)(average+0.9);

  cout << c << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(int argc, char const *argv[]) {
    double x1, y1, x2, y2, d;
    double dx, dy;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    dx = x1 - x2;
    dy = y1 - y2;


    d = sqrt(dx * dx + dy * dy);
    printf("%f\n", d);
    return 0;
}


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

int main() {
	int c5 = 0, c7 = 0;
	for (int i = 0, a; i < 3; i++) {
		cin >> a;
		if (a == 5)
			c5++;
		if (a == 7)
			c7++;
	}
	cout << (c5 == 2 && c7 == 1 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var HW = Sarray();
            var H = HW[0];
            var W = HW[1];
            var ban = new string[H];
            for (var h = 0; h < H; ++h)
                ban[h] = ReadLine();
            var dp = Enumerable.Range(0, (int)H).Select(_ => Enumerable.Repeat(long.MaxValue,(int)W).ToArray()).ToArray();
            dp[0][0] = 0;
            if ('#' == ban[0][0]) dp[0][0] = 1;
            for (var h = 0; h < H; ++h)
            {
                for (var w = 0; w < W; ++w)
                {
                    var left = long.MaxValue;
                    var up = long.MaxValue;
                    if (0 <= w - 1)
                    {
                        left = dp[h][w - 1];
                        if (ban[h][w - 1] != ban[h][w])
                            ++left;
                    }
                    if (0 <= h - 1)
                    {
                        up = dp[h - 1][w];
                        if (ban[h - 1][w] != ban[h][w])
                            ++up;
                    }
                    dp[h][w] = Min(dp[h][w], Min(left, up));
                }
            }
            if ('#' == ban[H - 1][(int)W - 1]) ++dp[H - 1][(int)W - 1];
            WriteLine(dp[H - 1][(int)W - 1] / 2);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13524
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int main(){
    int N,R;
    cin>>N>>R;
    if(N>=10){
        cout<<R<<endl;
    }
    else{
        cout<<R+(10-N)*100<<endl;
    }
    return 0;
}

Measured memory_bytes: 888
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll A, B;
	cin >> A >> B;
	--A, --B;

	enum {wh, bl};
	ll ans[100][100];
	rep(i, 100) rep(j, 100) {
		if (i < 50) ans[i][j] = wh;
		else ans[i][j] = bl;
	}

	for (ll i = 1; i < 50; i += 2) {
		for (ll j = 1; j < 100; j += 2) {
			if (B == 0) goto po;
			ans[i][j] = bl;
			--B;
		}
	}
po:

	for (ll i = 51; i < 100; i += 2) {
		for (ll j = 1; j < 100; j += 2) {
			if (A == 0) goto po2;
			ans[i][j] = wh;
			--A;
		}
	}
po2:

	cout << "100 100" << endl;
	rep(i, 100) {
		rep(j, 100) {
			if (ans[i][j] == bl) cout << "#";
			else cout << ".";
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
struct dish
{
	long long a,b;
	long long x,y;
	int p;
}a[100001],b[100001],c[100001];
bool cmp1(dish x,dish y)
{
	return x.x>y.x;
}
bool cmp2(dish x,dish y)
{
	return x.y>y.y;
}
bool v[100001];
int main()
{
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].a,&a[i].b);
		a[i].x=a[i].a+a[i].b;
		a[i].y=a[i].a+a[i].b;
		a[i].p=i;
		b[i]=a[i];
		c[i]=a[i];
	}
	sort(b+1,b+1+n,cmp1);
	sort(c+1,c+1+n,cmp2);
	long long ans=0;
	int d1=1,d2=1;
	int d=1;
	for(i=1;i<=n;i++)
	{
		if(d==1)
		{
			while(v[b[d1].p])
				d1++;
			ans+=b[d1].a;
			v[b[d1].p]=true;
		}
		else if(d==2)
		{
			while(v[c[d2].p])
				d2++;
			ans-=c[d2].b;
			v[c[d2].p]=true;
		}
		d=3-d;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	int ans = 1001001001;
	for (int i = 0; i <= n; i++) {
		int n6 = i;
		int n9 = n - i;
		int sum = 0;
		while (n6 != 0) {
			sum += n6 % 6;
			n6 /= 6;
		}
		while (n9 != 0) {
			sum += n9 % 9;
			n9 /= 9;
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;

int maxmove(int x){
  if(x == 0){
    return 0;
  }
  else{
    return maxmove(x - 1) * 3 + 1;
  }
}

int main(){
  while(1){
    int n,m;
    scanf("%d%d", &n, &m);
    if(n == 0 && m == 0){
      return 0;
    }
    stack<int> cups[3];
    for(int i = 0;i < 3;i++){
      int k,cup;
      scanf("%d", &k);
      for(int j = 0;j < k;j++){
	scanf("%d", &cup);
	cups[i].push(cup);
      }
    }
    int res = 0, lastto = -1, lastfrom = -1;
    while(cups[0].size() != n && cups[2].size() != n){
      bool moved = false;
      for(int i = 0;i < 3 && !moved;i++){
	for(int j = 0;j < 3 && !moved;j++){
	  if(abs(i - j) != 1 || cups[i].empty() || (j == lastfrom && i == lastto))continue;
	  if(cups[j].empty() || cups[i].top() > cups[j].top()){
	    cups[j].push(cups[i].top());
	    cups[i].pop();
	    res++;
	    lastfrom = i;
	    lastto = j;
	    moved = true;
	  }
	}
      }
    }
    res = min(res, maxmove(n) * 2 - res);
    if(res > m){
      res = -1;
    }
    printf("%d\n", res);
  }
}

Measured memory_bytes: 1036
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

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

using namespace std;

typedef long long ll;

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

  deque<char> deq;
  string s; cin >> s;
  int q; cin >> q;

  rep(i, s.length()) {
    deq.push_back(s[i]);
  }

  bool is_rev = false;
  rep(i, q) {
    int t; cin >> t;
    if (t == 1) {
      is_rev = !(is_rev);
    } else {
      int f; char c;
      cin >> f >> c;
      if ( (f == 1 && is_rev == false) || (f == 2 && is_rev ) ) {
        deq.push_front(c);
      } else {
        deq.push_back(c);
      }
    }
  }
  int n = deq.size();
  if (is_rev) {
    rep(i, n) {
      cout << deq[n-1-i];
    }
  } else {
    rep(i, deq.size()) {
      cout << deq[i];
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    int S = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        S += A[i];
    }
    int c = N;
    for (int i = 0; i < N; i++) {
        if (A[i]*(4*M) < S) {
            c--;
        }
    }
    if (c >= M) {
        puts("Yes");
    }
    else {
        puts("No");
    }
}

Measured memory_bytes: 256
ans = 0
while True:
    try:
        a = list(int(x) for x in input().split())
        b = list(int(x) for x in input().split())
    except EOFError:
        break
    hit = 0
    brow =0
    for i in range(4):
        if a[i] == b[i]:
            hit += 1
        else:
            for j in range(4):
                if(i != j and a[i] == b[j]):
                    brow += 1
                    
    print(str(hit)+' '+str(brow))


Measured memory_bytes: 5600
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        ((a)*((b)/gcd((a),(b))))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int x,y,z,K;
    cin>>x>>y>>z>>K;

    vi a(x),b(y),c(z);
    for(int i=0;i<x;++i)
        cin>>a[i];
    for(int i=0;i<z;++i)
        cin>>b[i];
    for(int i=0;i<y;++i)
        cin>>c[i];

    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    sort(c.rbegin(),c.rend());

    set<pair<int,array<int,3>>> st;
    st.ins({a[0]+b[0]+c[0],{0,0,0}});

    set<array<int,3>> vis;
    auto upd=[&st,a,b,c,x,y,z,K,&vis](array<int,3> arr)
    {
        if(arr[0]>=x || arr[1]>=y || arr[2]>=z || vis.find(arr)!=vis.end())
            return;

        vis.ins(arr);
        int sum=a[arr[0]]+b[arr[1]]+c[arr[2]];

        if(sz(st)==K)
        {
            int tmp=st.begin()->F;
            if(tmp<sum)
            {
                st.erase(st.begin());
                st.ins({sum,arr});
            }
        }
        else
            st.ins({sum,arr});
    };

    int sum;
    array<int,3> arr;
    while(!st.empty() && K--)
    {
        sum=st.rbegin()->F;
        arr=st.rbegin()->S;
        st.erase(--st.end());

        cout<<sum<<"\n";
        //show(arr);

        for(int i=0;i<3;++i)
        {
            ++arr[i];
            upd(arr);
            --arr[i];
        }
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



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

int main(){
    int N;
    int p[100001]={};
    int i;
    int count = 0;
    
    cin >> N;
    for(i=1;i<N+1;i++)
        cin >> p[i];
    
    for(i=1;i<N+1;i++){
        if(i == p[i]){
            count++;
            i++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    private BufferedReader in;
    private StringTokenizer tok;
    private PrintWriter out;

    //------------------------------------------------------------------------------
    public static void main(String[] args) {
        new Main().run();
    }

    private void solve() throws IOException {
        int n = readInt();
        char[] s = readString().toCharArray();
        int[] cntW = new int[n];
        int[] cntE = new int[n];
        for (int i = 0; i < n; i++) {
            if (i > 0) {
                cntW[i] += cntW[i - 1];
                cntE[i] += cntE[i - 1];
            }
            if (s[i] == 'W') {
                cntW[i]++;
            } else {
                cntE[i]++;
            }
        }
//        System.err.println(Arrays.toString(cntE));
//        System.err.println(Arrays.toString(cntW));
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int t = f(cntW, 0, i - 1) + f(cntE, i + 1, n - 1);
//            System.err.println("i = " + i + ", t = " + t);
            min = Math.min(min, t);
        }
        out.println(min);
    }

    private int f(int[] arr, int L, int R) {
        if (L > R) {
            return 0;
        }
        int ans = arr[R];
        if (L > 0) ans -= arr[L - 1];
        return ans;
    }

    private void run() {
        try {
            initIO();
            solve();
            in.close();
            out.close();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

    private void initIO() throws IOException {
        try {
            in = new BufferedReader(new FileReader(new File("input.txt")));
            out = new PrintWriter(new File("output.txt"));
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    private String readString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}


Measured memory_bytes: 31056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,j,tmp=1;
  cin>>n;
  vector<ll> a(n);
  for(i=0;i<n;i++){
	cin>>a[i];
  }
  
  sort(a.begin(),a.end());
  
  if(n%2==0){
    for(i=0;i<n/2;i++){
      if(a[2*i+1]!=2*i+1||a[2*i]!=2*i+1){
		cout<<0<<endl;
        return 0;
      }
    }
  }else{
     if(a[0]!=0){
		cout<<0<<endl;
        return 0;
     }else{
	  for(i=0;i<(n-1)/2;i++){
       if(a[2*i+1]!=2*i+2||a[2*i+2]!=2*i+2){
	      cout<<0<<endl;
          return 0;
       }
      }
     }
  }

    for(i=0;i<(n%2==0?n/2:(n-1)/2);i++){
		tmp*=2;
      	tmp%=(1000000007);
    }

  	cout<<tmp<<endl;

}

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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define delete

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

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

    llong a, b, c, d;
    cin >> a >> b >> c >> d;

    vector<llong> candidate({a*c, a*d, b*c, b*d});

    cout << *max_element(all(candidate)) << endl;
    
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    REP(i, N) cin >> m[i];
    X -= accumulate(All(m), 0);
    int ans = N;
    int mm = *min_element(All(m));
    while(X >= mm){
        ans++;
        X -= mm;
    }
    cout << ans << "\n";
    return 0;
}

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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define sort(vec) std::sort(all(vec))
#define rev(vec) std::reverse(all(vec))

void input(){return;}
template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}

void inputVector(){return;}
template<typename First,typename... Rest> void inputVector(std::vector<First> &first,Rest&... rest){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i];
    }
    inputVector(rest...);
}

template<typename First,typename Second> void inputTwoVector(std::vector<First> &first,std::vector<Second>& second){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i] >> second[i];
    }
}


void calculate(){
    int N;
    input(N);
    int sum = 0;
    int j = N;
    while(j != 0){
        sum += j % 10;
        j /= 10;
    }
    if(N % sum == 0){
        std::cout << "Yes\n";
    }
    else{
        std::cout << "No\n";
    }
}

int main(int,char**){
    calculate();    
}




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

int main()
{
    int N, A[2000], ans = 0;

    cin >> N;

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

    sort(A, A+N);
    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            for (int k = j+1; k < N; k++){
                if (A[i] < A[j]+A[k] && A[j] < A[i]+A[k] && A[k] < A[i]+A[j])
                    ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
MOD = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())

def getFact(n, MOD):
    fact = 1
    for i in range(1, n+1):
        fact = (fact * i) % MOD
    return fact
def getFacts(n, MOD):
    facts = [1] * (n+1)
    for x in range(2, n+1):
        facts[x] = (facts[x-1] * x) % MOD
    return facts
def getInvFacts(n, MOD):
    invFacts = [0] * (n+1)
    invFacts[n] = pow(getFact(n, MOD), MOD-2, MOD)
    for x in reversed(range(n)):
        invFacts[x] = (invFacts[x+1] * (x+1)) % MOD
    return invFacts

facts = getFacts(2*10**6+3, MOD)
invFacts = getInvFacts(10**6+3, MOD)

def f(r, c):
    ans = facts[r+c] * invFacts[r] * invFacts[c]
    return ans % MOD

#print(f(r2+1, c2+1), f(r2+1, c1), f(r1, c2+1), f(r1, c1))
ans = f(r2+1, c2+1) - f(r2+1, c1) - f(r1, c2+1) + f(r1, c1)
ans %= MOD

print(ans)


Measured memory_bytes: 64108
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  map<int, int> d;
  rep(i,n) {
    int a;
    cin >> a;
    d[a]++;
  }
  int m;
  cin >> m;
  map<int, int> t;
  rep(i,m){
    int b;
    cin >> b;
    t[b]++;
  }
  if (n < m) {
    cout << "NO" << endl;
    return;
  }
  for(auto p: t) {
    if (d[p.first] < p.second) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 22352
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>

using namespace std;

string S, T;

int main() {
    cin >> S >> T;
    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());
    int s = 0, t = 0;
    while (s != S.size() && t != T.size()) {
        if (S[s] == '?' || S[s] == T[t]) {
            ++s;
            ++t;
        } else {
            s = s - t + 1;
            t = 0;
        }
    }
    if (t != T.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    stringstream ss;
    for (int i = 0; i < s - T.size(); ++i) {
        ss << (S[i] == '?' ? 'a' : S[i]);
    }
    ss << T;
    for (int i = s; i != S.size(); ++i) {
        ss << (S[i] == '?' ? 'a' : S[i]);
    }

    string result = ss.str();
    reverse(result.begin(), result.end());
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        sc.close();
        long a = N/K;
        if(K % 2 != 0){
            System.out.println(a*a*a);
        }else{
            long b = (N + K/2) / K;
            System.out.println(a*a*a + b*b*b);
        }

    }

}

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

using namespace std;

void dfs(vector<long> &c, vector<vector<int>> &G, int cur, int d) {
    c[cur] += d;
    for(auto v: G[cur]) {
        dfs(c, G, v, c[cur]);
    }
    return;
}

int main(void) {
    long n, q;
    cin >> n >> q;

    vector<vector<int>> G(n);
    vector<long> c(n);

    for(int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    for(int i=0; i<q; i++) {
        int p, x;
        cin >> p >> x;
        p--;
        c[p] += x;
    }

    dfs(c, G, 0, 0);

    for(auto x: c) cout << x << ' ';
    cout << endl;
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
	// your code goes her
	string a,b;
	cin>>a>>b;
	int count=0;
	for(int i=0;i<a.size();i++)
	{  
	    if(a[i]!=b[i])
	      count++;
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 3916
#include <cstdio>
#include <utility>
#include <queue>

using namespace std;

bool input();
int bfs();

int W, H;
char tile[20][20];		//添え字は[縦][横]
const int INF = 1000;
typedef pair<int, int> P;
int sw, sh;
int d[20][20];		//各点への最短距離の配列
int dw[4] = {1, 0, -1, 0};
int dh[4] = {0, 1, 0, -1};		//左から順に　→↓←↑　を表す
int count=0;		//発見した黒いタイルの総数を記憶


int main()
{
	for (;;)
	{
		if (!input()) return 0;
		count = 0;
		int ans = bfs();
		printf("%d\n", ans);
	}
}


int bfs()
{
	// printf("bfs()\n");
	queue<P> que;
	for (int i=0; i<20; i++)
		for (int i2=0; i2<20; i2++)
			d[i][i2] = INF;
	que.push(P(sh, sw));
	d[sh][sw] = 0;
	count++;
	
	while (que.size())
	{
		P p = que.front();
		que.pop();
		
		for (int i=0; i<4; i++)
		{
			int nw = p.second + dw[i];
			int nh = p.first + dh[i];
			
			// printf("nw=%d nh=%d\n", nw, nh);
			// printf("tile[%d][%d]=%c\n", nh, nw, tile[nh][nw]);
			// printf("d[%d][%d]=%d\n", nh, nw, d[nh][nw]);
			
			if (0<=nw && nw < W && 0<=nh && nh<H && tile[nh][nw]!='#' && d[nh][nw]==INF)
			{
				que.push(P(nh, nw));
				d[nh][nw] = d[p.first][p.second] + 1;
				count++;
			}
		}
	}
	return count;
}




//１つのデータセットに対して１回呼ばれる
bool input()
{
	scanf("%d %d", &W, &H);
	// printf("W=%d H=%d\n", W, H);
	if (W==0) return false;

	for (int i=0; i<H; i++)
	{
		scanf("%s", tile[i]);
		for (int i2=0; i2<W; i2++)
		{
			if (tile[i][i2]=='@')
			{
				sw = i2;
				sh = i;
			}
		}
		// printf("tile[%d]=%s\n", i, tile[i]);
		// printf("%c\n",tile[i][5]);
	}
	
	return true;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

long long int max(long long int a,long long int b){
	if(a>b)return a;
	else return b;
}

int main(void) {
	int n,W;
	scanf("%d%d",&n,&W);
	long long int w[n],v[n];
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&w[i],&v[i]);
	}
	long long int dp[101][100000];//ナップサック
	for(int i=0;i<n;i++){
		for(int j=0;j<=W;j++){
			if(j>=w[i]){
				dp[i+1][j] =max(dp[i][j-w[i]]+v[i],dp[i+1][j]);
			}
				dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
		}
	}
	printf("%lld",dp[n][W]);
}


Measured memory_bytes: 79852
N=input()
A=map(int,raw_input().split())
for i in range(N-1):
	for k in range(N-1):
		print A[k],
	print A[N-1]
	v=A[i+1]
	j=i
	while j>=0 and A[j] >v:
		A[j+1]=A[j]
		j=j-1
	A[j+1]=v

for m in range(N-1):
	print str(A[m]),
print A[N-1]

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

int main() {
  ll n, k; cin >> n >> k;
  for(int i=1; i<10000;i++){
    if(std::pow(k,i-1)<= n && n < std::pow(k,i)){
      cout << i <<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256