akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

void solve() {
	long long n;
	cin >> n;
	string pos = "zabcdefghijklmnopqrstuvwxy";
	string ans;
	while (n) {
		int rem = n % 26;
		n -= (rem == 0 ? 26 : rem);
		n /= 26;
		ans = pos[rem] + ans;
	}
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

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

Measured memory_bytes: 3644
//Pantyhose(black) + glasses = infinity

#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

int n;
vector<int> a;

void readInput() {
	cin >> n;

	a.resize(n);

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

void solve() {
	vector<int> res;

	while (a.size()) {
		for (int i=a.size()-1; i>=0; --i) {
			if (a[i]>i) {
				cerr << a[i] << ' ' << i << '\n';
				cout << -1;
				return;
			}
			if (a[i]==i) {
				res.push_back(i+1);
				a.erase(a.begin() + i);
				break;
			}
		}
	}

	reverse(res.begin(), res.end());
	for (auto v : res)
		cout << v << '\n';
}

int main() {
	#ifdef GLASSES_GIRL
		freopen(FILE_NAME".in", "r", stdin);
		freopen(FILE_NAME".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0); cin.tie(0);
	readInput();
	solve();
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
A = [int(i) for i in input().split()]
my_dict = defaultdict(int)
for i in A:
    my_dict[i] += 1
ans = sum(A) # sum up once
Q = int(input())
for q in range(Q):
    b, c = [int(i) for i in input().split()]
    if b in my_dict:
        my_dict[c] += my_dict[b]
        ans += my_dict[b] * (c-b)
        my_dict[b] = 0
    print(ans)

Measured memory_bytes: 21412
#include <iostream>  
#include <algorithm> 
#include <string> 
#include <cstdlib>
using namespace std;
int main(){
  string N;
  cin >> N;
  if(N[0] == N[2]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		Integer [] lst = new Integer[5];
		for (int i=0;i<5;i++) {
			lst[i] = s.nextInt();
		}
		Arrays.sort(lst, Collections.reverseOrder());
		String ans = "" + lst[0];
		for (int i=1;i<5;i++) {
			ans += " " + lst[i];
		}
		System.out.println(ans);
	}
}



Measured memory_bytes: 26132
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;

// print(x, y, z);
// print(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

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

  std::string s;
  std::cin >> s;

  std::string::iterator it;
  std::map< char, ll > mm;
  mm['S'] = 0;
  mm['E'] = 0;
  mm['N'] = 0;
  mm['W'] = 0;
  for (it = s.begin(); it != s.end(); ++it) {
    ++mm[*it];
  }

  std::string judge = "Yes";
  if ((mm['S'] == 0 && mm['N'] > 0) || (mm['S'] > 0 && mm['N'] == 0)) {
    judge = "No";
  }
  if ((mm['E'] == 0 && mm['W'] > 0) || (mm['E'] > 0 && mm['W'] == 0)) {
    judge = "No";
  }
  print(judge);

  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];
ll B[200005];
pll NA[200005];
pll NB[200005];

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

    ll N;
    cin >> N;
    memset(NA, 0, sizeof(NA));
    memset(NB, 0, sizeof(NB));
    REP(i, N) {
        cin >> A[i];
        NA[A[i] - 1].first = A[i];
        NA[A[i] - 1].second++;
    }
    REP(i, N) {
        cin >> B[i];
        NA[B[i] - 1].first = B[i];
        NA[B[i] - 1].second++;
    }

    REP(i, 200005) {
        ll mx = std::max(NA[i].second, NB[i].second);
        ll mn = std::min(NA[i].second, NB[i].second);
        if (N - mx < mn) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

#if false
    REP(i, v.size()) {
        cout << v[i].first << " " << v[i].second << endl;
    }
#endif
    vector<pll> v;
    while (true) {
        v.clear();
        REP(i, N) {
            if (A[i] != B[i])
                continue;
            pll p(i, 1);
            if (i > 0 && A[i - 1] == B[i - 1] && B[i] == B[i - 1]) {
                p.first = v.back().first;
                p.second = v.back().second + 1;
                v.pop_back();
            }
            v.push_back(p);
        }

        sort(v.begin(), v.end(), [](pll a, pll b) { return a.second > b.second; });
        if (v.size() <= 1)
            break;
        auto t = v;
        ll index = 1;
        REP(i, v.size()) {
            REP(j, v[i].second) {
                if (t[index].second == 0) {
                    index = (index + 1) % v.size();
                }
                B[v[i].first + j] = A[t[index].first];
                t[index].second--;
                t[index].first++;
            }
        }
    }

    if (v.size() >= 1) {
        ll p = B[v[0].first];
        queue<ll> q;
        REP(i, N) {
            if (A[i] != p && B[i] != p)
                q.push(i);
        }

        if (v[0].second > q.size()) {
            cout << "No" << endl;
            return 0;
        }
        REP(i, v[0].second) {
            ll k = q.front();
            q.pop();
            B[v[0].first + i] = B[k];
            B[k] = A[v[0].first + i];
        }
    }
    REP(i, N) {
        cout << B[i] << " ";
    }
    cout <<
         endl;
    return 0;
}


Measured memory_bytes: 18868
#include<iostream>
#include<vector>
#include<cmath>

int main(){
    int N;
    std::cin>>N;
    std::vector<int>cost(3*N);
    unsigned long long dp[3]={0,0,0};
    unsigned long long buf[3];
    for(int i=0;i<3*N;++i){
        std::cin>>cost[i];
    }
    for(int i=0;i<3;++i){
        dp[i]=cost[i];
    }
    for(int i=1;i<N;++i){
        for(int j=0;j<3;++j){
            buf[j]=std::max(dp[(j+1)%3],dp[(j+2)%3])+cost[3*i+j];
        }
        for(int j=0;j<3;++j){
            dp[j]=buf[j];
        }
    }
    std::cout<<std::max(std::max(dp[0],dp[1]),dp[2])<<std::endl;
}

Measured memory_bytes: 4576
#include <stdio.h>
int main()
{
  int N,a=1;
  
  scanf("%d",&N);
  
  do{
  a*=2;
  }while(a<N);
  
  if(a>N)
    a=a/2;
       
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 128
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int a[100001];
int main(void){
	int n=nextpint();
	int m=nextpint();
	for(int i=0; i<m; i++){
		a[nextpint()]++;
		a[nextpint()]++;
	}
	for(int i=0; i<n; i++){
		if((a[i]&1)!=0){
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}


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

vector<int> KMP(const string& S) {
	int N = S.size();
	vector<int> A(N + 1);
	A[0] = -1;
	int j = -1;
	for (int i = 0; i < N; i++) {
		while (j >= 0 && S[i] != S[j]) {
			j = A[j];
		}
		j++;
		A[i + 1] = j;
	}
	return A;
}

int main()
{
	cin.sync_with_stdio(false);
	string T, P;
	cin >> T >> P;
	auto A = KMP(P);
	int N = P.size(), j = 0;
	vector<int> res;
	for (int i = 0; i < (int)T.size(); i++) {
		while (j >= 0 && T[i] != P[j]) {
			j = A[j];
		}
		j++;
		if (j == N) {
			res.push_back(i - N + 1);
			j = A[j];
		}
	}
	for (auto ans : res) {
		printf("%d\n", ans);
	}
	return 0;
}

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

int main(){
    int a,b;

    cin >> a >> b;

    if (a < b){
        cout << "a < b" << endl;
    } else if ( a == b ){
        cout << "a == b" << endl;
    } else {
        cout << "a > b" << endl;
    }
    return 0;
}

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

int main() {
  int K,N;
  cin >> N>> K;
  vector <int> price(N);
  for (int i=0; i<N; i++) {
    cin >> price.at(i);
  }
  sort (price.begin(),price.end());
  
 int sum=0;
  for(int i=0;i<K;i++) {
    sum+=price.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int a,b;
  while(cin>>a>>b){
  int cnt = 1;
  a += b;
  
  while(a/=10)cnt++;
  cout<<cnt<<endl;
}
}

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

typedef long long ll;

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

    int N;

    cin >> N;

    ll S = 0;

    vector<ll> A(N);

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

    ll base = 0;

    for(int i = 1; i < N; i += 2) {
        base += A[i];
    }

    base *= 2;

    vector<ll> X(N);

    X[0] = S - base;

    for(int i = 1; i < N; i++) {
        X[i] = 2 * A[i - 1] - X[i - 1];
    }

    for(int i = 0; i < N; i++) {
        cout << X[i] << " ";
    }
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
int main()
{
    std::vector<int> time(0,0);
    int a;
    std::cin>>a;
    for(int i=0;i<a;i++){
        int b,c;
        std::cin>>b>>c;
        time.push_back(b*100+c);
    }
    std::cin>>a;
    for(int i=0;i<a;i++){
        int b,c;
        std::cin>>b>>c;
        time.push_back(b*100+c);
    }
    for(int i=0;i<time.size();i++){
        for(int j=i;j<time.size();j++){
            if(time[i]>time[j]){
                int c;
                c=time[i];
                time[i]=time[j];
                time[j]=c;
            }
        }
    }
    for(int i=0;i<time.size();i++){
        if(i!=time.size()-1 && time[i]!=time[i+1]){
        	if(time[i]%100>9)std::cout<<time[i]/100<<":"<<time[i]%100<<" ";
        	else std::cout<<time[i]/100<<":0"<<time[i]%100<<" ";
        }
        if(i==time.size()-1){
            if(time[i]%100>9)std::cout<<time[i]/100<<":"<<time[i]%100<<std::endl;
        	else std::cout<<time[i]/100<<":0"<<time[i]%100<<std::endl;
        }
    }
}

Measured memory_bytes: 1220
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        sc.close();

        int b = Y / 2 - X;
        int a = X - b;
        if (a < 0 || b < 0) {
            System.out.println("No");
        } else {
            if (2 * a + 4 * b == Y) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }

    }
}

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

using namespace std;

int main()
{
    int A, B, C,D;
    cin >> A>> B >> C>>D;
if(A+B>C+D)
    cout <<"Left";
else
    if(A+B==C+D)
    cout <<"Balanced";
else
    cout << "Right";


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var S = ReadText().ToCharArray();
            var count = S.Count(x => x == 'R');
            if(count == 2)
            {
                if(S[0] == S[2])
                {
                    return 1;
                }
            }
            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi arr(n);
	ll sum = 0;
	for(int &i:arr)cin>>i,sum+=i;
	ll rsum=0;
	ll mi=INT_MAX;
	for(int i=n-1;i>0;i--) {
		rsum+=arr[i];
		sum-=arr[i];
		mi=min(abs(sum-rsum),mi);
	}
	cout<<mi;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3848
package main
import (
  "fmt"
)
func main() {
  var n int
  fmt.Scan(&n)
  hs := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&hs[i])
  }
  result := 0
  for {
    start := 0
    end := n-1
    shouldBreak := false
    for i, h := range hs {
      if h != 0 {
        start = i
        break
      }
      if i == n-1 {
        shouldBreak = true
      }
    }
    if shouldBreak {
      break
    }
    for i := start+1; i < n; i++ {
      if hs[i] == 0 {
        end = i-1
        break
      }
    }
    for i := start; i <= end; i++ {
      hs[i]--
    }
    result++
  }
  fmt.Println(result)
}

Measured memory_bytes: 512
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}

func Solve() {
  NM := NextIntVec()
  N, M := NM[0], NM[1]
  G := make([][]int, N)
  for i := range G {
    G[i] = make([]int, N)
    for j := range G[i] {
      G[i][j] = 1
    }
  }
  for i := 0; i < M; i++ {
    AB := NextIntVec()
    a, b := AB[0] - 1, AB[1] - 1
    G[a][b] = 0
    G[b][a] = 0
  }
  D := make([]int, N)
  B := make([][]int, 0)
  for i, d := range D {
    if 0 < d { continue }
    D[i] = 1
    UV := make([]int, 2)
    UV[1]++
    Q := make([]int, 0)
    Q = append(Q, i)
    for 0 < len(Q) {
      q := Q[0]
      Q = Q[1:]
      for adj, e := range G[q] {
        if e < 1 { continue }
        if q == adj { continue }
        if 0 < D[adj] {
          if (D[q] - D[adj]) % 2 == 0 {
            Write(-1)
            return
          }
          continue
        }
        D[adj] = D[q] + 1
        Q = append(Q, adj)
        UV[D[adj] % 2]++
      }
    }
    B = append(B, UV)
  }
  DP := make([][]int, len(B) + 1)
  for i := range DP {
    DP[i] = make([]int, N + 1)
  }
  DP[0][0] = 1
  for i, b := range B {
    for _, v := range b {
      for j, dp := range DP[i] {
        if dp < 1 { continue }
        DP[i + 1][j + v] = 1
      }
    }
  }
  ans := N * (N - 1) / 2
  for j, dp := range DP[len(B)] {
    if dp < 1 { continue }
    ans = MinInt(j * (j - N) + N * (N - 1) / 2, ans)
  }
  Write(ans)
  return
}

func main() {
  Solve()
  Output()
}

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

int main(){
  	int a,b;
  	cin >> a >> b;
  	string ans;
  	ans = a % 2 != 0 && b % 2  != 0 ? "Yes" : "No";
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

void test(){
    ll a,b;
    cin >>a >>b;

    for(ll t=0; t<100; ++t){
        printf(" t %lld  t+ceil(b/(a+t)) %lld\n", t, t+(b+a+t-1)/(a+t));
    }
}

const ll INF = LLONG_MAX/3;
const int N = 200000;
ll d[N];

struct edge{
    int to;
    ll a,b;
};

vector<edge> G[N];

double f(ll t, ll a, ll b){
    // printf(" f %lld %lld %lld  -> %lld\n",t,a,b,  t+(b/(t+a)));
    return t+(double)b/(t+a);
}

ll COST(ll t, ll a, ll b){
    if(a+t > b) return t+1;

    // printf(" Q %lld %lld %lld\n",t,a,b);
    ll l=t, r=b;
    while(r-l>2){
        ll ml = (2*l+r)/3, mr = (l+2*r)/3;

        if(f(ml,a,b) < f(mr,a,b)) r = mr;
        else l = ml;
        // printf(" lr %d %d\n",l,r);
    }

    ll ret = INF;
    for(ll i=l; i<=r; ++i) ret = min(ret, i+((b+i+a-1)/(i+a)));
    return ret;
}

int main(){
    // test();

    int n,m,s,g;
    scanf(" %d %d %d %d", &n, &m, &s, &g);
    --s;
    --g;

    rep(i,m){
        int u,v;
        ll a,b;
        scanf(" %d %d %lld %lld", &u, &v, &a, &b);
        --u;
        --v;
        G[u].pb({v,a,b});
        G[v].pb({u,a,b});
    }

    fill(d,d+N,INF);
    d[s] = 0;
    using P = pair<ll,int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0,s});
    while(!pq.empty()){
        P now = pq.top();
        pq.pop();

        ll D = now.fi;
        int v = now.se;
        if(D > d[v]) continue;

        for(const auto &e:G[v]){
            ll nt = COST(d[v],e.a,e.b);
            if(d[e.to] > nt){
                // printf(" ----- v to nt %d %d %lld\n",v,e.to,nt);
                d[e.to] = nt;
                pq.push({d[e.to],e.to});
            }
        }
    }

    ll ans = d[g];
    if(ans == INF) ans = -1;
    printf("%lld\n", ans);
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairInt;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[])
{
  int N, D;

  scanf("%d%d", &N, &D);

  ll ans = 0;
  int floor = 1;
  int person = 0;
  int time = 0;
  int i = 0;
  while (i < N) {
    int t, f;
    scanf("%d%d", &t, &f);
    if (t - time >= floor + f - 2) {
      ans += (ll)person * (floor - 1);
      floor = f;
      person = 1;
      time = t;
    } else if (t - time >= abs(f - floor) && person < D) {
      ans += (ll)person * (t - time);
      floor = f;
      person++;
      time = t;
    } else {
      break;
    }
    i++;
  }

  if (i == N) {
    ans += (ll)person * (floor - 1);
    printf("%lld\n", ans);
  } else {
    printf("-1\n");
  }
  
  return 0;
}

Measured memory_bytes: 3152
N = int(input())
l = map(int, input().split())


new_l = map(lambda x, y: (x-y), l, range(1, N+1))

new_l = sorted(new_l)
if (N % 2 == 0):
    b1 = (new_l[N//2] + new_l[N//2-1]) // 2
    b2 = (new_l[N//2] + new_l[N//2-1]) // 2 + 1
    res1 = sum(map(lambda x, y: abs(x-y), new_l, [b1]*N))
    res2 = sum(map(lambda x, y: abs(x-y), new_l, [b2]*N))
    res = min(res1, res2)
else:
    b = new_l[N//2]
    res = sum(map(lambda x, y: abs(x-y), new_l, [b]*N))

print(res)


Measured memory_bytes: 26016
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Data::Dumper;

my @INPUT;
while (<>) {
    chomp;
    push @INPUT, $_;
}

my ($N, $H, $W) = split " ", shift @INPUT;
my @hoge = map {[split " ", $_]} @INPUT;

my $cnt = 0;
for my $a (@hoge) {
    my ($h, $w) = @$a;
    if ($h >= $H and $w >= $W) {
        $cnt++;
    }
}

say $cnt;

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2*1e5+5;
int n,m,a[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline bool check(int x){
	go(i,x+1,1)
		if(a[i]+a[2*x-i+1] >= m) return 1;
	go(i,n*2+1,x*2+1){
		if(i > 2*n-(i-x*2)+1) break;
		if(a[i] + a[2*n-(i-x*2)+1] < m) return 0;
	}
	return 1;
}

inline void gmax(int &a,int b){
	if(a < b) a=b; return ;
}

int main(){
	#ifndef ONLINE_JUDGE
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	#endif
	n=rd(); m=rd();
	go(i,n*2+1,1) a[i]=rd();
	sort(a+1,a+2*n+1);
	int l=0,r=n;
	while(l < r){
		int mid=l+r>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	int ans=0;
	int x=l;
	go(i,x+1,1)
		gmax(ans,a[i]+a[2*x-i+1]);
	go(i,n*2+1,x*2+1){
		if(i > 2*n-(i-x*2)+1) break;
		gmax(ans,(a[i]+a[2*n-(i-x*2)+1])%m);
	}
	printf("%d",ans);
	return 0;
}//Faze


Measured memory_bytes: 1152
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vi a(n);
  scan(a);
  map<int, int> mp;
  rep (i, n) {
    mp[a[i]] = 1 - mp[a[i]];
  }
  int ans = 0;
  for (auto&& p : mp) {
    ans += p.second;
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 5376
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	ll a,b,c,d;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	ll x,y;
	x=a*10+b;
	y=c*10+d;
	if(x==0 && y<=12 && y>0){
		cout << "YYMM";
		return 0;
	}
	if(y==0 && x<=12 && x>0){
		cout << "MMYY";
		return 0;
	}
	
	if(x<=12 && y>12 && x>0){
		cout << "MMYY";
	}
	else if(x>12 && y<=12 && y>0){
		cout << "YYMM";
	}
	else if(x<=12 && y<=12 && x>0 && y>0) cout << "AMBIGUOUS";
	else{
		cout << "NA";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    char s[4];
    int cnt = 0;
    for(int i = 0;i < 4;i++){
    cin >> s[i];
    }
    for(int i = 0;i < 4;i++){
        if(s[i] == '+'){
        cnt ++;
        }
        else if(s[i] == '-'){
        cnt --;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#define int long long
using namespace std;
int N, A[35];
int solve(){
    A[0] = 1;
    A[1] = 1;
    A[2] = 2;
    A[3] = 4;
    for(int i=4; i<=N; i++){
        A[i] = A[i-3] + A[i-2] + A[i-1];
    }
    return A[N];
}

signed main(){
    N = 30;
    solve();
    while(cin >> N && N > 0){
        cout << (A[N]-1)/3650+1 << endl;
    }
}


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

bool famula(string &s, int &i){
  //std::cout << s[i];
  i++;
  if(s[i - 1] == 'T'){
    return true;
  }else if(s[i - 1] == 'F'){
    return false;
  }else if(s[i - 1] == '-'){
    return !famula(s, i);
  }else if('a' <= s[i - 1] && s[i - 1] <= 'k'){
    return bit&(1 << (s[i - 1] - 'a'));
  }else{
    bool a = famula(s, i);
    char op = s[i++];
    bool b = famula(s, i);
    i++;
    if(op == '*'){
      return a & b;
    }else if(op == '+'){
      return a | b;      
    }else if(op == '>'){
      return (!a) | b;
    }
  }
}

bool equation(string &s, int &i){
  bool val = famula(s, i), val2;
  while(s[i++] == '='){
    val2 = famula(s, i);
  }
  return val == val2;
}

int main(int argc, char *argv[]){
  string s;
  while(cin >> s){
    if(s == "#")break;
    for (int i = 0; i < s.length(); i++) {
      if(s[i] == '-' && s[i + 1] == '>')s.erase(s.begin() + i--);
    }
    int ans = true;
    for (bit = 0; bit < (1 << 12); bit++) {
      int pos = 0;
      if(equation(s, pos) == false){
        ans = false;
        std::cout << "NO" << std::endl;
        break;
      }
    }
    if(ans)std::cout << "YES" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1244
a,b = map(int,input().split())
min_mod = 2018

if b-a > 2019:
	min_mod=0

else:	
	for aa in range(a,b):
	   for bb in range(aa+1,b+1):
	       if aa < bb:
	           cc=aa*bb
	 
	           if min_mod > cc%2019:
	               min_mod = cc%2019

print(min_mod)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;

int main() {
    int k;
    string s;
    cin >> k;
    cin >> s;
    int len = s.size();
    if (len <= k)
        cout << s << endl;
    else
        cout << s.substr(0, k) << "..." << endl;
}


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

int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}

int absolute(int x)
{
	if(x<0)
		return -1*x;
	else
		return x;
}

int main()
{
	int n;
	cin >> n;
	int arr[n];

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

	int dp[n+1];

	dp[0] = 0;

	for(int i=1;i<n;i++)
	{
		if(i==1)
			dp[i] = dp[i-1] + absolute(arr[i] - arr[i-1]);
		else
		{
			dp[i] = min((dp[i-1] + absolute(arr[i] - arr[i-1])),(dp[i-2] + absolute(arr[i] - arr[i-2])));
		}
	}

	cout << dp[n-1] << endl;


}

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


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

    if (N % 1000 == 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << 1000 - (N % 1000) << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(ll i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define inf 1000000000000
#define mod 1000000007

const ll max_n = 1e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    ll n , m , x;
    cin >> n >> m >> x;
    ll a[n][m] , c[n];
    for(ll i = 0 ; i < n ; i++)
    {
        cin >> c[i];
        for(ll j = 0 ; j< m ; j++)
            cin >> a[i][j];
    }

    ll min1 = inf , index = -1;
    for(ll i = 0 ; i < (1 << n) ; i++){
        ll algo[m] = {0} , sum = 0;
        for(ll j = 0 ; j < n ; j++){
            if(i & (1 << j)){
                sum += c[j];
                for(ll k = 0 ; k < m ; k++){
                    algo[k] += a[j][k];
                }
            }
        }

        ll flag = 1;
        for(ll j = 0 ; j < m ; j++){
            if(algo[j] < x){
                flag = 0;
                break;
            }
        }
        if(flag){
            min1 = min(min1 , sum);
            index = i;
        }
    }
    if(index == -1){
        cout << -1;
        return 0;
    }
    cout << min1 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

//Author: Jiangsu Nanjing Li Zongtai
//强壮标记*10000,手牌*10000,血量10000 lyl+hzj也打不死我哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈~~~~
//注意要不要long long

const int inf=2147483647;

int n;
int a[111111];
int ans;

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


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int N;
string S;

int main() {
    cin >> S;
    N = S.length();
    int num0 = count(All(S), '0');
    int num1 = count(All(S), '1');
    int num = min(num0, num1);
    cout << num * 2 << "\n";
    return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline

a = [int(x) for x in input().split()]

a.sort()

a, b, c = a

a += (c - b)
ans = c - b

if (c - a) % 2 == 0:
    ans += (c - a) // 2
else:
    ans += 1
    ans += (c + 1 - a) // 2

print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,k;
  cin>>k>>x;
  for(int i=x-k+1;i<x;i++)
  {
    cout<<i<<' ';
  }
  for(int i=x;i<x+k;i++)
  {
    cout<<i<<" ";
  }
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String n=scan.nextLine();
		if(n.charAt(0)==n.charAt(2)) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

}


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

ll n, a, b, ans;

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

inline void work(){
	n = read(), a = read(), b = read();
	if (a == 0) puts("0");
	else {
		ll m = n / (a + b);
		n %= a + b;
		ll ans = m * a;
		if (n > a) ans += a;
		else ans += n;
		printf("%lld\n", ans);
	}
}

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

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    s = S()
    nex = [[inf] * 10 for i in range(n+1)]
    for i in range(n - 1, -1, -1):
        a = int(s[i])
        for k in range(10):
            if k == a:
                nex[i][k] = i + 1
            else:
                nex[i][k] = nex[i+1][k]
    ans = 0

    for i in range(10):
        for k in range(10):
            for j in range(10):
                a = nex[0][i]
                if a == inf:
                    continue
                b = nex[a][k]
                if b == inf:
                    continue
                c = nex[b][j]
                if c == inf:
                    continue
                ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 52444
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
          var h1 = cin.ReadInt;
          var m1 = cin.ReadInt;
          var h2 = cin.ReadInt;
          var m2 = cin.ReadInt;
          var a = cin.ReadInt;
          WriteLine($"{(h2*60+m2)-(h1*60+m1) - a}");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 27904
#include <stdio.h>

int main(void) {
	int H, W;
	char map[100][104];
	int i, j, ans;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%103s", map[i]) != 1) return 1;
	}
	for (i = 0; i < H; i++) {
		ans = -1;
		for (j = 0; j < W; j++) {
			if (map[i][j] == 'c') {
				ans = 0;
			} else if (ans >= 0) {
				ans++;
			}
			printf("%d%c", ans, j + 1 < W ? ' ' : '\n');
		}
	}
	return 0;
}

Measured memory_bytes: 612
/*
*
*  Created By : Pritish Thakkar 
*  Hackerrank : ma5terdrag0n
*  CodeChef : solo_loser
*  Hackerearth : pritish9
*------------------------------------
*  OS : Ubuntu 16.04
*  Language : CPP14
*  Editor : Sublime Text 3
*  C++ compiler : g++
*
*/
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

bool isUpper(char c) {return (c >= 'A' && c <= 'Z');}
bool isLower(char c) {return (c >= 'a' && c <= 'z');}
bool iplpha(char c) {return (c >= 'A' && c <= 'Z')||(c >= 'a' && c <= 'z');}
bool isnum(char c){return (c >= '0' and c <= '9');}
bool isalnum(char c) {return (c >= 'A' && c <= 'Z')||(c >= 'a' && c <= 'z')||(c >= '0' && c <= '9');}
char toUpper(char c){return isUpper(c)?c:c-'a'+'A';}
char toLower(char c){return isLower(c)?c:c+'a'-'A';}
bool isvowel(char c){c = toLower(c); return (c == 'a' or c == 'e' or c == 'i' or c == 'i' or c == 'o' or c == 'u');}
template<typename t> t gcd(t a, t b){return ((b == 0) ? a : gcd(b, a%b));} 
template<typename t> t lcm(t a, t b){return (a * (b / gcd(a, b)));}
template <typename T> T modpow(T base, T exp, T modulus) {base %= modulus;T result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
string toLowerCase(string s){rep(s.size()){if(!isLower(s[i])){s[i] = toLower(s[i]);}}return s;}
string toUpperCase(string s){rep(s.size()){s[i] = toUpper(s[i]);}return s;}
template<typename T> void cumulative(T *a, T *b, T n){rep(n){i ? b[i] = b[i-1] + a[i] : b[i] = a[i];}}
bool ispal(string s){ll lo, hi;lo = 0;hi = s.length()-1;while(lo <= hi){if(s[lo] != s[hi]){return 0;}lo++;--hi;}return 1;}
template<class T >string toString(T n){string v = "";while(n){v.pb(n % 10 + '0');n /= 10;}reverse(all(v));return v;}

//--------------------------------------------------------------------

ll digs(ll n){
  ll ret= 0;
  while(n > 0){
    ret += n% 10;
    n /= 10;
  }
  return ret;
}
void solve(){
  ll n;
  cin >> n;
  ll x = digs(n);
  if(n % x){
    cout << "No\n";
  }else{
    cout << "Yes\n";
  }
}


int main(){
    std::ios::sync_with_stdio(0);
    // int start = clock();
    
    solve();
    // cout << n;
    // int stop = clock();
    // cout << (stop - start) / 1000.0000<< endl;
}





Measured memory_bytes: 256