akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
    char a[1000];
    int sum,i;
    while(1)
    {
        sum=0;
        cin>>a;
        if(a[0]=='0')
        {
            break;
        }
        else
        {
            for(i=0; a[i]!='\0';i++)
            {
                sum = sum + a[i] - '0';
            }
            cout<<sum<<endl;
        }
    }
}


Measured memory_bytes: 3092
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";
const int MAXN = 370;


int d;
int t[MAXN];
int c[MAXN];
int s[MAXN][26];
int last[MAXN];


ll calcCost() {
	for (int i = 1; i <= 26; i++) {
		last[i] = 0;
	}
	ll sat = 0;
	for (int i = 1; i <= d; i++) {
		sat += s[i][t[i]];
		last[t[i]] = i;
		for (int j = 1; j <= 26; j++) {
			sat -= c[j] * (i - last[j]);
		}
		cout << sat << '\n';
	}
	return sat;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	cin >> d;
	for (int i = 1; i <= 26; i++) {
		cin >> c[i];
	}
	for (int i = 1; i <= d; i++) {
		for (int j = 1; j <= 26; j++) {
			cin >> s[i][j];
		}
	}
	for (int i = 1; i <= d; i++) {
		cin >> t[i];
	}	
	calcCost();
	return 0;	 	
}


Measured memory_bytes: 3656
class PriorityQueue
  attr_accessor :data, :size

  def initialize(array = [])
    @data=[]
    array.each {|a| push(a) }
  end

  def push(element)
    current = @data.size
    while current > 0
      p = parent(current)
      break if @data[p] <= element
      @data[current] = @data[p]
      current = p
    end
    @data[current] = element
  end

  def pop
    ret = @data.first
    x = @data.last
    current = 0
    while have_child?(current)
      a = left_child_index(current)
      b = right_child_index(current)
      a = b if b < @data.size - 1 && @data[b] < @data[a]
      break if @data[a] >= x
      @data[current] = @data[a]
      current = a
    end
    @data[current] = x
    @data.pop

    ret
  end

  def size
    @data.size
  end

  def front
    @data.first
  end

  def empty?
    @data.empty?
  end

  private

  def parent(num)
    (num-1)/2
  end

  def left_child_index(num)
    2*num+1
  end

  def right_child_index(num)
    2*num+2
  end

  def have_child?(index)
    left_child_index(index) < @data.size
  end
end

n, m = gets.strip.split.map(&:to_i)
ab = readlines.map {|line| line.strip.split.map(&:to_i) }.sort!.reverse!

pq = PriorityQueue.new

n.times do |i|
  pq.push(ab[i].last)
  pq.pop if pq.size > m - ab[i].first + 1
end

p pq.data.inject(:+).to_i



Measured memory_bytes: 18808
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long MOD = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong H,W;
    cin >> H >> W;
    vector<string> Map;
    vector<vector<bool> > Mask(H, vector<bool>(W, true));
    string S;
    llong cnt;
    for(int i=0; i<H; i++){
        cin >> S;
        Map.push_back(S);
    }
    for(int i=0; i<H; i++){
        cnt = 0;
        for(int j=0; j<W; j++){
            if(Map[i][j]=='.'){
                cnt++;
            }
        }
        if(cnt==W){
            for(int j=0; j<W; j++){
                Mask[i][j] = false;
            }
        }
    }
    for(int i=0; i<W; i++){
        cnt = 0;
        for(int j=0; j<H; j++){
            if(Map[j][i]=='.'){
                cnt++;
            }
        }
        if(cnt==H){
            for(int j=0; j<H; j++){
                Mask[j][i] = false;
            }
        }
    }
    char flg;
    for(int i=0; i<H; i++){
        flg = 0;
        for(int j=0; j<W; j++){
            if(Mask[i][j]){
                flg = 1;
                cout << Map[i][j];
            }
        }
        if(flg){
            cout << endl;
        }
    }
    return 0;
}


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

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

    int n, k, arr[100000], dp[100000];
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    dp[0] = 0;
    fill(dp+1, dp+n, 2000000000);
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= min(k, i); j++) {
            dp[i] = min(abs(arr[i]-arr[i-j]) + dp[i-j], dp[i]);
        }
    }
    cout << dp[n-1];
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    string ans = "No";
    rep(i,3){
        if(n%10 == 7) ans = "Yes";
        n/=10;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    string c = "";
    if (a==b){
        for(int i=0; i<a; i++){
            c +=to_string(a);
        }
    }

    else if (a > b){
        for(int i=0; i<a; i++){
            c +=to_string(b);
        }
    }
    else {
        for(int i=0; i<b; i++){
            c +=to_string(a);
        }
    }
    cout << c;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<std::vector<int>> g(n);
	std::vector<std::pair<int, int>> edge;
	for(int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d%d", &a, &b);
		
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
		edge.push_back({a - 1, b - 1});
	}
	std::vector<int> c(n);
	for(int i = 0; i < n; i++) scanf("%d", &c[i]);
	sort(begin(c), end(c)); reverse(begin(c), end(c));
	
	int cur = 0;
	std::vector<i64> latte(n, -1);
	std::queue<int> qu; qu.push(0);
	while(!qu.empty()) {
		auto p = qu.front(); qu.pop();
		latte[p] = c[cur++];
		
		for(auto e: g[p]) {
			if(latte[e] != -1) continue;
			qu.push(e);
		}
	}
	
	i64 ans = 0;
	for(auto v: edge) ans += std::min(latte[v.first], latte[v.second]);
	
	printf("%lld\n", ans);
	for(auto v: latte) printf("%d ", v);
	printf("\n");
	return 0;
}


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

int main(){
    int n,pm=1;
    cin>>n;
    vector<int> a(n), m(n,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
        m[0] += a[i]*pm;
        pm *= -1;
    }
    cout<<m[0];
    for(int i=1;i<n;i++){
        m[i] = 2*a[i-1] - m[i-1];
        cout<<' '<<m[i];
    }
    return 0;
}


Measured memory_bytes: 2048
def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)

  dp = [[-INF] * (N+1) for _ in range(N+1)]
  dp[0][0] = 0

  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)

main()


Measured memory_bytes: 136012
import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

sys.setrecursionlimit(10**6)
t=int(input())
def cost(n):
    if n in dist:
        return dist[n]
    ret = min(
        D * n,
        D * abs(n - n//5*5) + C + cost(n//5),
        D * abs(n - (n+4)//5*5) + C + cost((n+4)//5),
        D * abs(n - n//3*3) + B + cost(n//3),
        D * abs(n - (n+2)//3*3) + B + cost((n+2)//3),
        D * abs(n - n//2*2) + A + cost(n//2),
        D * abs(n - (n+1)//2*2) + A + cost((n+1)//2)
    )

    dist[n]=ret
    return ret
for i in range(t):
    ans=0
    n,A,B,C,D=map(int,input().split())
    dist={0:0,1:D}
    print(cost(n))

Measured memory_bytes: 92684
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define REP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define REPI(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define REPITER(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a[100008],dp[100008];
    cin>>n;
    for(int i=1;i<=n;++i)
    cin>>a[i];
    dp[1]=0;
    dp[2]=abs(a[1]-a[2]);
    for(int i=3;i<=n;++i)
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >>N;
  vector<int> num(N);
  for (int i=0;i<N;i++){
    cin >>num.at(i);
  }
  vector<int> q(N);
  for(int i=0;i<N;i++){
    int count=N-1;
    for (int x=0;x<N;x++){
      if (x ==i){
        continue;
      }
      else if (num.at(i)<num.at(x)){
        continue;
      }
      else if (num.at(i)>num.at(x)){
        count --;
      }
      else if(num.at(i)==num.at(x) && i<x ){
        count--;
      }
    }
    q.at(count) = num.at(i);
  }
  int result=0;
  for (int i=0;i<N;i++){
    if (i%2==0){
      result += q.at(i);
    }
    else{
      result -= q.at(i);
    }
  }
  cout << result <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  long long K;
  cin >> S >> K;
  for (int i=0;i < min((long long)S.size(),K);i++){
    if (S[i]>='2'){
      cout << S[i];
      return 0;
    }
  }
  cout << 1;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0 ; i < s.size(); i++) {
    if (s[i] == '+') ans++;
    else ans--;
  }
  cout << ans << 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);
        String password = sc.next();  
      
     // int n = sc.nextInt();
        String ans = "Good";

        for(int i = 0; i < 3; i++) {
            if (password.substring(i,i+1).equals(password.substring(i+1,i+2))) {
                ans = "Bad";
            }
//            System.out.println(password.substring(i,i+2));
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 21844
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(19
3141592653589793238)X";
stringstream iss{text};
#endif

const string z9 = "0123456789";
class LuckyPIN
{
	ll N{0}, cnt{0};
	string s;
	void counting( ) {
		for (auto c1 : z9) {
			auto itr1 = find(begin(s), end(s), c1);
			if (itr1 == end(s)) continue;
			for (auto c2 : z9) {
				auto itr2 = find(itr1 + 1, end(s), c2);
				if (itr2 == end(s)) continue;
				for (auto c3 : z9) {
					auto itr3 = find(itr2 + 1, end(s), c3);
					if (itr3 != end(s)) {
						cnt++;
						//cout << c1 << c2 << c3 << "\n";
					}
				}
			}
		}
	}
public:
	void procedures( ) {
		iss >> N >> s;
		counting( );
		p(cnt);
	}
};

int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class LuckyPIN a; a.procedures( );
}

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

int main() {
    ll N, x;
    cin >> N >> x;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, N) {
        x -= a[i];
        if (x < 0) break;
        ans += 1;
        if (i == N - 1 && x > 0) ans -= 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;


int main() {

    int n;
    cin>>n;

    if(n==1)cout<<1;
    else cout<<pow(n,3);

	return 0;
}


/*
ll  modularExponentiation(ll x,ll n,ll M)
{

    ll result=1;

    while(n>0)
    {

	if(n%2==1)

 result=(result*x)%M;

  x=(x*x)%M;

  n=n/2;

}

  return result;
}



*/




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

using namespace std;


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

    int ans = 0;
    for (int i = A; i <= B; ++i) {
        auto s = to_string(i);
        if (s[0] == s[4] && s[1] == s[3]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

vector<int> primes;
void erat(unsigned int limit) {
    vector<bool> prime(limit + 1, true);
    const unsigned int n = sqrt(limit);
    unsigned int i, j;
    primes.push_back(2);
    for(i = 3; i <= n; i += 2) {
        if(prime[i]) {for(j = i * i; j <= limit; j += 2*i) prime[j] = false;}
    }
    for(i = 3; i <= limit; i += 2) {if(prime[i]) primes.push_back(i);}
}

void fact(int n,map<ll,int> &ret) { //O (cant primos)
    int idx=0;
    int p=primes[0];
    while (p*p<=n) {
        while(!(n % p)) {
            ++ret[p];//divisor found
            n /= p;
        }
        p = primes[++idx];
    }
    if(n > 1) ++ret[n];
}

void merge(map<ll,int> &source,const map<ll,int> &otro){
    auto it=source.begin();
    auto it2=otro.begin();
    while(it!=source.end() && it2!=otro.end()){
        if (it->first<it2->first) ++it;
        else if (it2->first<it->first){
            source.insert(it,*it2);
            ++it2;
        }else{
            it->second = max(it->second,it2->second);
            ++it; ++it2;
        }
    }
    while(it2!=otro.end()){
        source.insert(*it2);
        ++it2;
    }
}

void add(ui &x, ll y){
    x += y;
    if (x>=MOD) x-=MOD;
}

ui getb(ll b,const map<ll,int> &a){
    for(const auto p:a){
        b = b * powmod(powmod(p.first,p.second,MOD),MOD-2,MOD)%MOD;
    }
    return b;
}

int main() {
    READ(0);
    erat(2000);
    int n;cin>>n;
    vi a(n);
    vector<map<ll,int> > f(n);
    FOR(i,n) {cin>>a[i]; fact(a[i],f[i]);}
    map<ll,int> lcm=f[0];
    for(int i=1;i<n;++i){
        merge(lcm,f[i]);
    }
    ll b=1;
    for(auto p:lcm) b = b*powmod(p.first,p.second,MOD)%MOD;

    ui ret=0;
    for(int i=0;i<n;++i){
        add(ret,getb(b,f[i]));
    }
    cout << ret;
    return 0;
}



Measured memory_bytes: 3840
/*
    Ankit Singhal
 */
#define ll long long int
#include <bits/stdc++.h>
//#include <fstream>
using namespace std;
 
#define         ff               first
#define         ss               second
#define         mp               make_pair
#define         pb               push_back
#define         pf               push_front
#define         vi               vector<ll>
#define         pii              pair<ll,ll>
#define         qi               queue<ll>
#define         mem(a,b)         memset(a,b,sizeof(a))
#define         print(a)         cout<<a<<'\n'
#define         sorted(arr)      sort(arr.begin(),arr.end())
#define         gcd(a,b)         gcd((a),(b))
#define         lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define         all(v)           v.begin(),v.end()
#define         read(a)          scanf("%d", &a)
#define         f(a,n)           for(ll i=a;i<n;i++)
#define         in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define         debug(a)         cerr<<a<<" ";
#define         debug1(a)        cerr<<a<<'\n'
 
/*typedef tree<int, null_type, less<int>, rb_tree_tag , tree_order_statistics_node_update> Set;*/


const unsigned ll mod= (ll)1e9 ;
const ll inf = (ll)1e15 + 42;
const ll N = (ll)1e6 + 2;
 
ll power ( ll x , unsigned ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
 
/*struct node{
    ll x , y , z;
};
vector<set<ll>> tree;
vector<ll> ar , ans;
set<ll> s;
ll get(ll x)
{
    if(x == ar[x])
        return x;
    return ar[x] = get(ar[x]);
}
void merge(ll a ,ll b)
{
    a = get(a);
    b = get(b);
    if(a == b)
        return;
    ar[b] = ar[a];
    //ans[a] += ans[b];
 }

ll sev[1000001];


void seive()
{
    for(ll i = 2 ; i <= 1000000 ; i ++)
    {
        if(!sev[i])
        {
            for(ll j = i ; j <= 1000000 ; j += i)
            {
                if(!sev[j])
                    sev[j] = i;
            }
        }
    }
}
*/

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t ;
    t = 1;
    //cin >> t;
    while(t --)
    {
        ll n;
        cin >> n;
        string str;
        cin >> str;
        vector<vector<ll>> v;
        for(ll i = 0 ; i < 10 ;i ++)
        {
            for(ll j = 0 ;j < 10 ;j ++)
            {
                for(ll k = 0 ;k < 10 ;k ++)
                {
                    v.pb({i,j,k});
                }
            }
        }
        ll ans = 0;
        for(ll i = 0 ;i < v.size() ;i ++)
        {
            
            ll l = 0;
            for(ll j = 0; j < n ;j ++)
            {
                if(l >= 3)
                    break;
                if((str[j] - '0') == v[i][l])
                    l ++ ;
            }
            if(l == 3)
            {ans ++ ; }//for(ll o = 0 ; o < 3 ; o ++){cout << v[i][o] << " ";}  cout << '\n';}
        }
        print(ans);
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}
 


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;

signed main(){
    int m;
    cin >> n >> m;
    if(n%2==1){
        //平和
        REP(i,m){
            cout << m-i << " " << m+i+2 << endl;
        }
        return 0;
    }
    int t = n-2;
    int x = t/2;
    if(t%2==0){
        x--;
        x = x/2*2;
    }
    else{
        if(x%2==1) x++;
    }
    int l = min(m,(int)x/2+1);
    REP(i,l){
        cout << l-i << " " << l+i+1 << endl;
    }
    if(l==m) return 0;
    m -= l;
    l *= 2;
    int s = m;
    REP(i,s){
        cout << l+s-i << " " << l+s+i+2 << endl;
    }

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner ac = new Scanner(System.in);

		int W = ac.nextInt();
		int H = ac.nextInt();
		int x = ac.nextInt();
		int y = ac.nextInt();
		int r = ac.nextInt();
		
		if ((x - r) < 0 || W < ( x + r)){
			System.out.println("No");
		}else if ((y - r) < 0 || H < ( y + r)){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}

}



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

int main()
{
	int n, m;
	cin >> n >> m;
	auto p = vector<int>(n + 1);
	for(auto i = 1; i <= n; ++i) p[i] = i;
	auto parent = [&p](auto parent, int x) -> int {
		if(x == p[x]) return x;
		return p[x] = parent(parent, p[x]);
	};
	auto unite = [&p, &parent](int x, int y) -> void {
		x = parent(parent, x);
		y = parent(parent, y);
		if(x > y) swap(x, y);
		p[y] = x;
	};
	for(auto i = 0; i < m; ++i){
		int x, y, z;
		cin >> x >> y >> z;
		unite(x, y);
	}
	auto g = set<int>();
	for(auto i = 1; i <= n; ++i){
		g.insert(parent(parent, i));
	}
	cout << g.size() << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>

using namespace std;

int main() {
  string b;
  cin >> b;
  if (b == "A") {
    cout << "T" << endl;
  } else if (b == "C") {
    cout << "G" << endl;
  } else if (b == "G") {
    cout << "C" << endl;
  } else if (b == "T") {
    cout << "A" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) { return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}


Measured memory_bytes: 21732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }
  int n;
  cin >> n;
  for (int k = 0; k < n; k++) {
    int b;
    cin >> b;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (A[i][j] == b) {
          A[i][j] = 0;
          break;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    int cnt_row = 0;
    int cnt_col = 0;
    for (int j = 0; j < 3; j++) {
      cnt_row += A[i][j];
      cnt_col += A[j][i];
    }
    if (cnt_row == 0 || cnt_col == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  int cnt_diag = 0;
  int cnt_anti_diag = 0;
  for (int i = 0; i < 3; i++) {
    cnt_diag += A[i][i];
    cnt_anti_diag += A[i][2 - i];
  }
  if (cnt_diag == 0 || cnt_anti_diag == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  vector<ll> t(5);
  for (ll j=0; j < 5; ++j) cin >> t[j];
  sort(t.begin(), t.end(), [](ll x, ll y) -> bool {
        string xstr = to_string(x), ystr = to_string(y);
        if (xstr.back() == '0') {
          return true;
        }
        if (ystr.back() == '0') {
          return false;
        }
        return xstr.back() > ystr.back();
      });
  ll acc = t[0];
  for (ll j=1; j < 5; ++j) {
    acc += (acc % 10 == 0 ? 0 : (10 - (acc % 10))) + t[j];
  }
  cout << acc << endl;
  return 0;
}


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


def find_loop(x, mod):
    remainders = [x % mod]
    i = 1
    while True:
        i += 1
        r = (a * i) % b
        if r not in remainders:
            remainders.append(r)
        else:
            break
    return remainders


def judge(reminders, mod, c):
    result = [0]
    for rs in reminders:
        result = list({(x+r)%mod for x in result for r in rs})
    if c in result:
        return True
    return False


reminders = [find_loop(r, b) for r in find_loop(a, b)]
print('YES') if judge(reminders, b, c) else print('NO')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main() {
    string str;
    cin >> str;
    ull rez = 0, n = str.length();
    for(ull i = 0; i < (1<<(n-1)); ++i) {
        ull s = 0;
        for(int j = 0; j < n; ++j) {
            s *= 10;
            s += str[j] - '0';
            if((i & (1<<j)) > 0 )  {
                rez += s;
                s = 0;
            }
        }
        rez += s;
    }
    cout << rez << endl;
}

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

int main(int argc, char const * argv[])
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;


    if (n % 1000 == 0)
        cout << "0";
    else
    {
        int r = n % 1000;
        int res = 1000 - r;
        cout << res;
    }

}

Measured memory_bytes: 3628
N = gets.to_i
As = gets.split.map(&:to_i)

minus_cnt = 0
abs_min = Float::INFINITY
sum = 0
N.times{|x|
    if (As[x] < 0) then
        minus_cnt += 1
    end
    sum += As[x].abs
    abs_min = [abs_min, As[x].abs].min
}
ans = 0
if (minus_cnt % 2 === 0) then
    ans = sum
else
    ans = sum - (2 * abs_min)
end

puts ans


Measured memory_bytes: 11268
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include<map>
#define maxn 400+5
using namespace std;
char a[maxn][maxn];
int vis[maxn][maxn];
long long int  h=0,d=0;int n,m;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
void dfs(int x,int y){
    if(a[x][y]=='.')d++;
    else if(a[x][y]=='#')h++;
    vis[x][y]=1;
    for(int i=0;i<4;i++){
        int nx=x+dx[i],ny=y+dy[i];
        if(!vis[nx][ny]&&nx>=0&&nx<n&&ny>=0&&ny<m&&a[nx][ny]!=a[x][y]){
            dfs(nx,ny);
        }
       /* for(int i=0;i<4;i++){
        if((a[x][y]!=a[x+dx[i]][y+dy[i]])&&!vis[x+dx[i]][y+dy[i]])dfs(x+dx[i],y+dy[i],a[x][y]);
	}*/
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    getchar();
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            a[i][j]=getchar();
        }
        getchar();
    }
    long long int  ans=0;
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(a[i][j]=='#')
            {
            h=0,d=0;
            dfs(i,j);
            ans+=h*d;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 8576
N = int(input())
vA = list(map(int, input().split()))
vB = list(map(int, input().split()))
vC = list(map(int, input().split()))

res = 0

p = -100
for a in vA:
    ate = a - 1
    b = vB[ate]
    c = vC[p] if p+1==ate else 0
    res += b + c
    p = ate

print(res)


Measured memory_bytes: 3060
package main

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

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt, sum int

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	D, _ := strconv.Atoi(read())

	for i := 1; i <= N; i++ {
		for j := 10; j <= D; j++ {
			a := j / 10
			b := j % 10
			if 2 <= a && 2 <= b && a*b == i {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


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

int main() {
long long int n,k;cin>>n>>k;
  
  if(k%2==0)cout<<(n/k)*(n/k)*(n/k)+((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k)<<endl;
  
  else cout<<(n/k)*(n/k)*(n/k)<<endl;
  
}


Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int n,a,b;
ll power(int a,int b){
	int sum=1;
	for (; b; b>>=1){
		if (b&1)	sum=1ll*sum*a%MOD;
		a=1ll*a*a%MOD;
	}
	return sum;
}
ll calc(int n,int x){
	ll sum=1;
	for (int i=n; i>=n-x+1; i--)	
		sum=sum*i%MOD;
	for (int i=1; i<=x; i++)
		sum=sum*power(i,MOD-2)%MOD;
	return sum;
}
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll cnt1;
  cin >> n >> a >> b;
  cnt1=(power(2,n)-1+MOD)%MOD;
  cnt1=(cnt1-calc(n,a)-calc(n,b)+MOD)%MOD;
  cnt1=(cnt1+MOD)%MOD;
  cout << cnt1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,d;
  cin >> r >> d;
  vector<int> x(11);
  cin >> x.at(0);
  for(int i = 0; i < 10; i++){
    x.at(i + 1) = r * x.at(i) - d;
  }
  for(int i = 1; i < 11; i++){
  cout << x.at(i)  << endl;
}
}

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

constexpr int UNKNOWN=INT_MIN;

void solve(vector<int> ss)
{
	int n=ss.size();
	for(int i=0;i<n-1;i++){
		if(ss[i]==UNKNOWN && ss[i+1]==UNKNOWN){
			cout<<"none"<<endl;
			return;
		}
		if(ss[i]!=UNKNOWN && ss[i+1]!=UNKNOWN){
			if((i%2==0 && ss[i]>=ss[i+1]) || (i%2==1 && ss[i]<=ss[i+1])){
				cout<<"none"<<endl;
				return;
			}
		}
	}
	int mn=INT_MIN,mx=INT_MAX;
	for(int i=0;i<n;i+=2) if(ss[i]==UNKNOWN){
		if(0<=i-1) mx=min(mx,ss[i-1]-1);
		if(i+1<n)  mx=min(mx,ss[i+1]-1);
	}
	for(int i=1;i<n;i+=2) if(ss[i]==UNKNOWN){
		if(0<=i-1) mn=max(mn,ss[i-1]+1);
		if(i+1<n)  mn=max(mn,ss[i+1]+1);
	}
	if(mn==mx)
		cout<<mn<<endl;
	else if(mn>mx)
		cout<<"none"<<endl;
	else
		cout<<"ambiguous"<<endl;
}

int main()
{
	for(int n;cin>>n && n;){
		vector<int> ss(n);
		for(int i=0;i<n;i++){
			string s; cin>>s;
			ss[i]=s=="x"?UNKNOWN:atoi(s.c_str());
		}
		solve(ss);
	}
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> count(N);
  rep(i, N)
  {
    cin >> A[i];
    count[A[i]]++;
  }
  bool is_ok = true;
  if (N % 2 == 0)
  {
    if (count[0] != 0)
      is_ok = false;
    for (int i = 1; i < N; i++)
    {
      if (i % 2 == 1 && count[i] != 2)
        is_ok = false;
      else if (i % 2 == 0 && count[i] != 0)
        is_ok = false;
    }
  }
  else
  {
    if (count[0] != 1)
      is_ok = false;

    for (int i = 1; i < N; i++)
    {
      if (i % 2 == 0 && count[i] != 2)
        is_ok = false;
      else if (i % 2 == 1 && count[i] != 0)
        is_ok = false;
    }
  }
  long long ans = 0;
  if (is_ok)
  {
    ans = 1;
    int mod = 1e9 + 7;
    rep(i, N / 2)
    {
      ans *= 2;
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10,mod=1e9+7;
inline int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}
int fac[maxn],ifac[maxn];
struct point{
	int x,y;
	bool operator <(const point &rhs) const{
		return x<rhs.x || (x==rhs.x && y<rhs.y);
	}
}a[maxn];
int dp[maxn];
inline int C(int n,int m){
	if(n<0 || n<m || m<0) return 0;
	return (ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
	int n=maxn-10;
	fac[0]=1;
	REP(i,1,n) fac[i]=(ll)i*fac[i-1]%mod;
	ifac[n]=ksm(fac[n],mod-2);
	DREP(i,n,1) ifac[i-1]=(ll)i*ifac[i]%mod;
	int h=read()-1,w=read()-1;
	n=read();
	REP(i,1,n) a[i].x=read()-1,a[i].y=read()-1;
	sort(a+1,a+n+1);
	int ans=C(h+w,h);
	REP(i,1,n){
		dp[i]=C(a[i].x+a[i].y,a[i].x);
		REP(j,1,i-1) if(a[i].x>=a[j].x && a[i].y>=a[j].y) dp[i]=(dp[i]+mod-(ll)dp[j]*C(a[i].x-a[j].x+a[i].y-a[j].y,a[i].y-a[j].y)%mod)%mod;
		ans=(ans+mod-(ll)dp[i]*C(h+w-a[i].x-a[i].y,h-a[i].x)%mod)%mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
import itertools


n=int(input())
ans=0

for i in range(3,10):
  for lst in itertools.product(['3','5','7'],repeat=i):
    if '3' in lst and '5' in lst and '7' in lst:
      lst=''.join(lst)
      lst=int(lst)
      if n>=lst:
        ans+=1
        

print(ans)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_V = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

struct edge {
    int from, to, cost;
    edge(int u, int v, ll c) : from(u), to(v), cost(c){};
};

vector<edge> G[MAX_V][2];
ll dmin[MAX_V][2];

void add_edge(int u, int v, ll cost, int k) {
    G[u][k].push_back(edge(u, v, cost));
    G[v][k].push_back(edge(v, u, cost));
}

void dijkstra(int s, int k) {
    priority_queue<P, vector<P>, greater<P> > que;  //小さいものから取り出す
    REP(i,MAX_V){
        dmin[i][k] = LLINF;
    }
    dmin[s][k] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (dmin[v][k] < p.first) continue;
        for (auto &e : G[v][k]) {
            if (dmin[e.to][k] > dmin[v][k] + e.cost) {
                dmin[e.to][k] = dmin[v][k] + e.cost;
                que.push(P(dmin[e.to][k], e.to));
            }
        }
    }
}

int main() {
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    REP(i,m){
        int u,v;
        ll a,b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        add_edge(u,v,a,0);
        add_edge(u,v,b,1);
    }
    dijkstra(s,0);
    dijkstra(t,1);

    vector<P> ls;
    REP(i,n){
        ls.push_back({dmin[i][0]+dmin[i][1],i});
    }
    sort(ls.begin(),ls.end());
    int y=0,no=0;
    while(y<n){
        while(ls[no].second < y){
            no++;
        }
        cout << ll(1e15) - ls[no].first << endl;
        y++;
    }

    return 0;
}


Measured memory_bytes: 19388
long long n,a[100005];
long long mx[100005],mn[100005];
signed main()
{
	__builtin_scanf("%lld",&n);
	for (int i=0;i<n;++i) __builtin_scanf("%lld",&a[i]);
	mx[n]=2;mn[n]=2;
	for (long long i=n-1;i>=0;i--)
	{
		mx[i]=(mx[i+1]/a[i]+1)*a[i]-1;
		mn[i]=((mn[i+1]-1)/a[i]+1)*a[i];
		if (mx[i]<mn[i])
		{
			__builtin_printf("-1");
			return 0;
		}
	}
	__builtin_printf("%lld %lld",mn[0],mx[0]);
	return 0;
}

Measured memory_bytes: 2560
import sys
sys.setrecursionlimit(int(1e5+10))
N = int(input())
edge = [[] for i in range(N)]
depth = [0 for i in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append((b,c))
    edge[b].append((a,c))
Q, K = map(int, input().split())
K = K - 1

def dfs(v, p, c):
    depth[v] = c
    for nv, nc in edge[v]:
        if nv != p:
            dfs(nv, v, c + nc)
            
dfs(K, -1, 0)

for _ in range(Q):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    print(depth[a] + depth[b])


Measured memory_bytes: 131600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define Forn(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
int main()
{
      boost;
      int n,t,rem,ans=0;
      cin>>n>>t>>rem;
      int arr[n];
      forn(i,n)
      cin>>arr[i];
      for(int i=0;i<n;i++)
      {
            int cost=1,idx=1;
            while((idx*arr[i])+1<=t)
            {
                  idx++;
                  cost++;
            }
            ans+=cost;
      }
      cout<<rem+ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

inline int f(int x, int y, int z) {
	return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main() {
	int n;
	cin >> n;
	int x = 0;
	int y = 0;
	int z = 0;
	VI results(n + 1, 0);
	for(int x = 1; f(x, y, z) <= n; x++) {
		for(int y = 1; f(x, y, z) <= n; y++) {
			for(int z = 1; f(x, y, z) <= n; z++) {
				results[f(x, y, z)]++;
			}
		}
	}

	REP(i, n) { cout << results[i + 1] << endl; }
	return 0;
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    int d = 0;
    int ans = 1;
    REP(i, n) {
        int l;
        cin >> l;
        d += l;
        if(d <= x) ans++;
    }
    cout << ans << ln;
    return 0;
}


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

int cl[10101];
int clnum[2];
bool f = 0;

void dfs(vector<vector<int>> &G, int n, int col){
    if(cl[n] != -1){
        if(cl[n] == col){
            f = 1;
        }
        return;
    }
    cl[n] = (col+1)%2;
    clnum[cl[n]]++;
    for(auto &x: G[n]){
        dfs(G, x, cl[n]);
    }
}


int main(){
    int n, m;
    cin >> n >> m;
    while(n > 0){
        memset(cl, -1, sizeof(cl));
        memset(clnum, 0, sizeof(clnum));
        f = 0;
        vector<vector<int>> G(n);
        for(int i=0; i<m; i++){
            int x, y;
            cin >> x >> y;
            x--; y--;
            G[x].push_back(y);
            G[y].push_back(x);
        }
        dfs(G, 0, 0);
        int k = 0;
        if(f) cout << 0 << endl;
        else{
            set<int> ans;
            if(clnum[0] % 2 == 0){
                ans.insert(clnum[0]/2);
            }
            if(clnum[1] % 2 == 0){
                ans.insert(clnum[1]/2);
            }
            cout << ans.size() << endl;
            for(auto &x: ans){
                cout << x << endl;
            }
        }
        // cout << endl;
        cin >> n >> m;
    }
}


Measured memory_bytes: 3212