akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define MAX 200001
#define VMAX 10000

int main(){
  int C[VMAX+1], n, i, j;
  unsigned short *A, *B;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0; i<=VMAX; i++) C[i]=0;

  for(i=0; i<n; i++){
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1; i<=VMAX; i++) C[i]=C[i]+C[i-1];

  for(j=1; j<=n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1; i<=n; i++){
    if(i>1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 9600
#include<stdio.h>

int main (void)

{

int a,b,c,x;

scanf("%d %d %d",&a,&b,&c);

if(a>b)

{

      x=a;

      a=b;

      b=x;

}

if(b>c)

{

      x=b;

      b=c;

      c=x;

}

if(a>b)

{

      x=a;

      a=b;

      b=x;

}

printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int g[2000][2000][2];

int f(int x1, int y1, int x2, int y2, int index){
  int tmp=g[x2][y2][index];
  if(x1>0 && y1>0)tmp+=g[x1-1][y1-1][index];
  if(x1>0)tmp-=g[x1-1][y2][index];
  if(y1>0)tmp-=g[x2][y1-1][index];
  return tmp;
}

int main(void) {
  int i,j;
  int n,k;
  cin>>n>>k;
  int b=0,w=0;
  int k2=2*k;
  rep(i,n){
    int x,y;
    string s;
    cin>>x>>y>>s;
    x=x%k2;
    y=y%k2;
    if(s[0]=='B')g[x][y][0]++,b++;
    else g[x][y][1]++,w++;
  }

  rep(i,k2)rep(j,k2-1){
    g[i][j+1][0]+=g[i][j][0];
    g[i][j+1][1]+=g[i][j][1];
  }

  rep(j,k2)rep(i,k2-1){
    g[i+1][j][0]+=g[i][j][0];
    g[i+1][j][1]+=g[i][j][1];
  }


  int ans=0;
  rep(i,k)rep(j,k){
    int tmp1=f(i,j,i+k-1,j+k-1,0);
    int tmp2=f(i,j,i+k-1,j+k-1,1);
    if(i>0 && j>0){
      tmp1+=f(0,0,i-1,j-1,0);
      tmp2+=f(0,0,i-1,j-1,1);
    }
    if(i>0){
      tmp1+=f(0,j+k,i-1,k2-1,0);
      tmp2+=f(0,j+k,i-1,k2-1,1);
    }
    if(j>0){
      tmp1+=f(i+k,0,k2-1,j-1,0);
      tmp2+=f(i+k,0,k2-1,j-1,1);
    }
    tmp1+=f(i+k,j+k,k2-1,k2-1,0);
    tmp2+=f(i+k,j+k,k2-1,k2-1,1);
    int t=max(tmp1+w-tmp2,b-tmp1+tmp2);
    ans=max(ans,t);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 31488
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

const int MSQ = sqrt(N) + 5;


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();

	int n;

	scanf("%d",&n);
	std::vector<int> a(n);
	multiset<int>s;
	for(int i=0;i<n;i++)scanf("%d",&a[i]),s.insert(a[i]);

	for(int i=0;i<n;i++){
		auto it = --s.end();

		if(*it == a[i])it--;
		printf("%d\n",*it );
	}
}		



Measured memory_bytes: 11776
import sys
input = sys.stdin.readline  #文字列入力では注意！

def main():
        #ttps://atcoder.jp/contests/abc134/submissions/6459172
    from bisect import bisect
    import sys
    input = sys.stdin.readline
    n = int(input())
    A = [int(input()) for _ in range(n)]
    dp = [1]
    for a in A:
        a *= -1
        i = bisect(dp,a)   #既存に-aを挿入した時のindex

        if i < len(dp):    #挿入位置が長さより小さい時（要はabsが一番小さくない時
            dp[i] = a     #-aにする
        else:
           dp.append(a)    #右端に-aを普通に追加

    print(len(dp))

if __name__ == '__main__':
    main()

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

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  
  vector<int> at_cnt(N + 1, 0);
  
  for (int i = 0; i < N; i++) {
    at_cnt.at(i + 1) = at_cnt.at(i) + (S.substr(i, 2) == "AC");
  }

  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << at_cnt.at(r - 1) - at_cnt.at(l - 1) << endl;
  }
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

struct Tree
{
	vector <int> child;
	int toWin;
} tree[10000];

int treeN;
vector <vector <int> > dp[10000];

pair<int, int> parse(char str[], int ind)
{
	int ret = treeN++;
	tree[ret].child.clear();

	ind++;

	if(str[ind] != '[')
	{
		tree[ret].toWin = 0;
		while(str[ind] >= '0' && str[ind] <= '9') tree[ret].toWin = tree[ret].toWin * 10 + (str[ind++] - '0');
		tree[ret].toWin = (tree[ret].toWin + 1) / 2;
	}
	else
	{
		do
		{
			pair<int, int> res = parse(str, ind);
			tree[ret].child.push_back(res.first);
			ind = res.second;
		} while(str[ind] == '[');
	}

	return make_pair(ret, ind + 1);
}

int getAns(int ind, int cind, int reqWin)
{
	if(tree[ind].child.size() == 0) return tree[ind].toWin;

	if(cind >= tree[ind].child.size())
	{
		if(reqWin == 0) return 0;
		return 99999999;
	}

	int &ret = dp[ind][cind][reqWin];
	if(ret != -1) return ret;

	ret = getAns(ind, cind + 1, reqWin);
	if(reqWin > 0)
	{
		int tarInd = tree[ind].child[cind];
		int nReqWin = (tree[tarInd].child.size() + 1) / 2;
		ret = min(ret, getAns(ind, cind + 1, reqWin - 1) + getAns(tarInd, 0, nReqWin));
	}

	return ret;
}

void printinfo(int ind)
{
	if(tree[ind].child.size() == 0) printf("leafnode %d with people %d\n", ind, tree[ind].toWin);
	else
	{
		printf("node %d with child:", ind);
		for(int i=0;i<tree[ind].child.size();i++) printf(" %d", tree[ind].child[i]);
		printf("\n");
		for(int i=0;i<tree[ind].child.size();i++) printinfo(tree[ind].child[i]);
	}
}

int main(void)
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		char inp[100001];
		scanf("%s", inp);

		treeN = 0;
		int root = parse(inp, 0).first;

//		printinfo(root);

		for(int i=0;i<treeN;i++)
		{
			dp[i].resize(tree[i].child.size());
			for(int j=0;j<dp[i].size();j++) dp[i][j] = vector<int>((dp[i].size() + 1) / 2 + 1, -1);
		}

		printf("%d\n", getAns(root, 0, (tree[root].child.size() + 1) / 2));
	}

	return 0;
}

Measured memory_bytes: 23708
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        long n = Long.parseLong(f.readLine());
        long increasal = 26;
        long current = 1;
        int length = 1;
        while (increasal + current <= n) {
            length++;
            current += increasal;
            increasal *= 26;
        }
        int[] charValue = new int[length];
        for (int i = 0; i < length; i++) {
            increasal /= 26;
            while(current + increasal <= n) {
                current += increasal;
                charValue[i]++;
            }
        }
        char[] seq = new char[length];
        for (int i = 0; i < length; i++) {
            seq[i] = (char) ('a' + charValue[i]);
        }
        out.println(new String(seq));
        out.close();
    }
}


Measured memory_bytes: 32860
using System;
using System.Collections.Generic;
using System.IO;
namespace I_am_the_brown_coder{
    class ABC10000000{
        static void Main(){
            var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
            Console.SetOut(sw);

            string[] n_q = Console.ReadLine().Split();
            int n = int.Parse(n_q[0]);
            int q = int.Parse(n_q[1]);
            int[][] events = new int[2*n][];
            for(int i=0;i<n;i++){
                string[] stxs = Console.ReadLine().Split();
                int x = int.Parse(stxs[2]);
                events[2*i] = new int[]{int.Parse(stxs[0])-x,1,x};
                events[2*i+1] = new int[]{int.Parse(stxs[1])-x,-1,x};
            }
            Array.Sort(events,TCompare);
            int[] d = new int[q];
            for(int i=0;i<q;i++){
                d[i] = int.Parse(Console.ReadLine());
            }
            SortedSet<int> stopSet = new SortedSet<int>();
            int now = 0;
            for(int i=0;i<2*n;i++){
                if(events[i][0]>d[now]){
                    if(now==q-1){
                        if(stopSet.Count>0){
                            Console.WriteLine(stopSet.Min);
                        }else{
                            Console.WriteLine(-1);
                        }
                        Console.Out.Flush();
                        return;
                    }else{
                        now ++;
                        if(stopSet.Count>0){
                            Console.WriteLine(stopSet.Min);
                        }else{
                            Console.WriteLine(-1);
                        }
                    }
                    i--;
                    continue;
                }
                if(events[i][1]>0){
                    stopSet.Add(events[i][2]);
                }else{
                    stopSet.Remove(events[i][2]);
                }
                //Console.WriteLine(events[i][0].ToString()+":"+events[i][1].ToString());
            }
            for(int i=now;i<q;i++){
                Console.WriteLine(-1);
            }
            Console.Out.Flush();
        }

        static int TCompare(int[] a, int[] b){
            if(a[0]>b[0]) return 1;
            if(a[0]<b[0]) return -1;
            if(a[1]>b[1]) return 1;
            if(a[1]<b[1]) return -1;
            return 0;
        }
    }
}

Measured memory_bytes: 47556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong ans = 0;

int main() {
    cin >> n;

    llong ans = 0;
    // km + k = k(m + 1)
    for (llong i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            llong d = i - 1;

            if (d != 0 && n / d == n % d) {
                ans += d;
            }

            d = n / i - 1;
            if (d != 0 && n / d == n % d) {
                ans += d;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int store = scan.nextInt();
		int drink = scan.nextInt();
		Map<Long,Integer> sansyo = new TreeMap<Long,Integer>();

		for(int i=0;i<store;i++) {
			long money = scan.nextLong();
			int honsu = scan.nextInt();
			if(sansyo.containsKey(money)) {
				sansyo.put(money,sansyo.get(money)+honsu);
			}else {
			sansyo.put(money, honsu);
		}
		}

		long sum = 0l;
		loop:for(Long x:sansyo.keySet()) {

			if(sansyo.get(x) >=drink) {
				sum += drink*x;
				break loop;
			}else {
				sum += sansyo.get(x)*x;
				drink -= sansyo.get(x);
			}
		}
		System.out.println(sum);
		scan.close();

	}

}


Measured memory_bytes: 56104
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        n = int(lines[0])
        for i in range(n):
            lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        n = int(lines[0])
    
    st = []
    for i in range(1, n+1):
        (s, t) = lines[i].split(" ")
        st.append((s, int(t)))
    x = lines[n+1]

    return (n, st, x)


def solve(n, st, x):

    index = None
    for i in range(n):
        (s, _) = st[i]
        if s == x:
            index = i
    
    st2 = st[index + 1:]
    result = sum([e[1] for e in st2])

    return result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
n = int(input())
S = input()
s = []
for i in range(n):
    s.append(S[i])
q = int(input())
BIT = []
for i in range(26):
    B = [0]*(n+1) #1-indexed
    BIT.append(B)

def sum_of_1_to_i(i, LIST):
    z = 0
    while i > 0:
        z += LIST[i]
        i -= i & (-i)
    return z

def update(i, j, LIST):
    while i <= n:
        LIST[i] += j
        i += i & (-i)

for i in range(n):
    k = ord(s[i])-97
    update(i+1, 1, BIT[k])

ans = []

for i in range(q):
    a,b,c = input().split()
    a = int(a)
    b = int(b)
    if a == 1:
        temp = s[b-1]
        if temp == c:
            None
        else:
            update(b, -1, BIT[ord(temp)-97])
            update(b, 1, BIT[ord(c)-97])
            s[b-1] = c
    else:
        c = int(c)
        cur = 0
        for j in range(26):
            if sum_of_1_to_i(c, BIT[j])-sum_of_1_to_i(b-1, BIT[j]) != 0:
                cur += 1
        ans.append(cur)
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 169056
#include <bits/stdc++.h>
 
using namespace std;
 
string t[3] = {"Sunny", "Cloudy", "Rainy"};

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") puts("Cloudy");
	if (s == "Cloudy") puts("Rainy");
	if (s == "Rainy") puts("Sunny");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

bool f(Int x) {
   Int t = x;
   Int y = 0;
   while( t != 0 ) {
      Int u = t % 10;
      y = y * 10 + u;
      t /= 10;
   }
   return x == y;
}

int main() {
   Int a, b;
   std::cin >> a >> b;
   Int res = 0;
   for(Int i = a; i <= b; ++i)
      if( f(i) )
         res += 1;
   printf("%ld\n", res);
}


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

int used[23][23]; // 0=まだ訪れていない　。　１＝すでに訪れた
int answer;
int h,w;   // フィールドの縦幅＝h、横幅＝w；　
string s[23];

// 「 再帰 」でググると分かります。

void dfs(int y,int x){  //　今いる座標が（y,x）

	answer++; //座標 (y,x) に到達できたので答えに１を足す
	used[y][x] = 1;   //座標 (y,x) に到達した。（　この座標は二度と使わない　）

	/* 4方向に移動するのを実際にシミュレーション  */

    // 1つ上に動けるか？　座標(y-1,x)がフィールドの外に出ていなくて、座標( y-1,x )にまだ訪れていなければ　移動します。　（　座標(y-1,x)が#じゃなければ移動　）
	if( y-1 >= 0 && used[y-1][x]==0 && s[y-1][x]!='#') dfs( y-1,x );  

	// 1つ下に動けるか？　座標(y+1,x)がフィールドの外に出ていなくて、座標( y-1,x )にまだ訪れていなければ　移動します。　（　座標(y+1,x)が#じゃなければ移動　）
	if( y+1 <  h && used[y+1][x]==0 && s[y+1][x]!='#') dfs( y+1,x );  

	// 1つ右に動けるか？　座標(y,x-1)がフィールドの外に出ていなくて、座標( y-1,x )にまだ訪れていなければ　移動します。　（　座標(y,x-1)が#じゃなければ移動　）
	if( x-1 >= 0 && used[y][x-1]==0 && s[y][x-1]!='#') dfs( y,x-1 );  

	// 1つ左に動けるか？　座標(y,x+1)がフィールドの外に出ていなくて、座標( y-1,x )にまだ訪れていなければ　移動します。　（　座標(y,x+1)が#じゃなければ移動　）
	if( x+1 <  w && used[y][x+1]==0 && s[y][x+1]!='#') dfs( y,x+1 );   
}

int main(){

	while( cin>>w>>h,w){

		int y,x;

		answer = 0;

		memset( used,0,sizeof(used) ); // 配列usedの中身を全て０にする　（ memsetでは　0 と -1 以外の値を使うとバグります ）

		for(int i=0;i<h;i++) cin>>s[i]; //フィールドを文字列で読み込む

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(s[i][j]=='@'){  //  スタート地点を探す。
					y = i;
					x = j;
				}
			}
		}

		dfs(y,x);

		cout<< answer <<endl;
	}
}


Measured memory_bytes: 3152
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
#include <list>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef vector<int> vi;

int main(void) {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(((a + b) - n), 0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

matrix prog(31,Vi(100030));
void solve(){
    ll n,C;
    cin >> n >> C;
    rp(i,n){
        ll s,t,c;
        cin >> s >> t >> c;
        if(prog[c][s]==-1) prog[c][s]=0;
        else prog[c][s-1]++;
        if(prog[c][t-1]==1) prog[c][t-1]=0;
        else prog[c][t]--;
    }
    repi(i,1,C+1){
        rp(j,100020){
            prog[i][j+1]=prog[i][j+1]+prog[i][j];
        }
    }
    ll ans=0;
    rp(j,100020){
        ll ctr=0;
        repi(i,1,C+1){
            if(prog[i][j]>0) ctr++;
        }
        chmax(ans,ctr);
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 28144
s=input()

def dfs(i,j):
    ans = 0
    if i == len(s) - 1:
        return sum(list(map(int,j.split("+"))))
    return dfs(i+1,j + s[i+1]) + dfs(i+1,j+"+"+s[i+1])

print(dfs(0,s[0]))

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

int main() {
	string s, t;
	int ans=1e9;
	cin>>s>>t;
	for(int start=0;start<=s.size()-t.size();++start) {
		int now=0;
		for(int j=0;j<t.size();++j){
			if(t[j]!=s[start+j])++now;
		}
		ans=min(ans,now);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll n, a, b,ans;
	in(n);
	in(a);
	in(b);


	ans = (n - 2) * b - (n - 2) * a + 1;
	if (ans < 0) {
		ans = 0;
	}
	outn(ans);


	return 0;


}


Measured memory_bytes: 256
fun main() {
    var n = readLine()!!.toInt()
    var a = readLine()!!.split(" ").map { it.toInt() }

    var b = 0
    for(i in 0 until n) {
        b = b.xor(a[i])
    }
    for(i in 0 until n) {
        if(i == n - 1) println(b.xor(a[i]))
        else print("${b.xor(a[i])} ")
    }
}

Measured memory_bytes: 75436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;
    ll ans = 0;
    while (*max_element(all(a)) >= n) {
        ll sum = 0;
        each(i, a)sum += i / n;
        each(i, a)i = i % n + sum - i / n;
        ans += sum;
    }
    cout << ans << "\n";
}

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

using namespace std;

void Main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << min(C, B / A) << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
builds = [[[0 for x in range(10)] for y in range(3)] for z in range(4)]
for i in range(n):
	b, f, r, v = map(int, input().split())
	b -= 1; f -= 1; r -= 1;
	builds[b][f][r] += v;

for i in range(4):
	for j in range(3):
		for k in range(10):
			print(" " + str(builds[i][j][k]), end = "")
		print()
	if (i < 3):
		print(20*'#')


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

int32_t main(){
   int a, b, c, k;
   cin >> a >> b >> c >> k;
   int sum = 0;
   bool flag = true;
   if(a >= k){
       sum += k;
       flag = false;
   } else {
       sum += a;
       k = k - a;
   }
   if(flag){
       if(b >= k){
           flag = false;
       } else {
           k = k - b;
       }
   }
   if(flag){
       if(c >= k){
           sum += k*(-1);
           flag = false;
       } else {
           sum += c*(-1);
           k = k - c;
       }
   }
   cout << sum << "\n";
}

Measured memory_bytes: 3604
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
#define F first
#define S second

ll k, a[50];

void solve(){
    cin >> k;
    
    for(int i = 0; i < 50; ++i) a[i] = k/50 + i;
    for(int i = 0; i < k%50; ++i) ++a[49-i];

    cout << "50\n";
    for(int i = 0; i < 50; ++i) cout << a[i] << " ";
    cout << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

int a[N],vis[N];

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        vis[a[i]]++;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=1ll*(vis[i]-1)*vis[i]/2;
    }
    for(int i=1;i<=n;i++){
        printf("%lld\n",ans-1ll*(vis[a[i]]-1)*vis[a[i]]/2+1ll*(vis[a[i]]-1)*(vis[a[i]]-2)/2);
    }
}


Measured memory_bytes: 7040
#include <stdio.h>
int main(void){
    int a,b,c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    
    if(a<b && b<c){
        printf("Yes\n");

    }
    else{
        printf("No\n");
    }
    return 0;
    
}


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int h[112345];
    for (int i = 0; i < n;i++){
        cin >> h[i];
    }
    int ans = 0, tmp = 0;
    for (int i = 0; i < n - 1; i++){
        if(h[i]>=h[i+1]){
            tmp++;
        }
        else{
            tmp = 0;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
N = int(input())
Nlist = [k*(k-1)//2 for k in range(10**3)]
if N not in Nlist:
    print('No')
    exit()
print('Yes')
k = Nlist.index(N)
S = [[0]*i for i in range(k)]
S[0] = [i+1 for i in range(k-1)]
for i in range(k-1):
    S[i+1] = [S[j][i] for j in range(i+1)]
    S[i+1] += [S[i][k-2]+j+1 for j in range(k-1-(i-1))]
print(k)
S = [[str(S[i][j]) for j in range(k-1)] for i in range(k)]
for i in range(k):
    print(' '.join([str(k-1)]+S[i]))

Measured memory_bytes: 20724
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N;

bool input() {
  cin >>N;
  return true;
}

void solve() {
  for (int i=1; i<=N; i++){
    int x = i;
    if (x % 3 == 0){
      cout <<" " <<i;
      continue;
    }
    while (x){
      if (x % 10 == 3){
        cout <<" " <<i;
        break;
      }
      x /= 10;
    }
  }
  cout <<endl;
}

int main() {
  input();
  solve();
}



Measured memory_bytes: 3152
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

int W, H, N;
bool m[105][105];

signed main()
{
  cin >> W >> H >> N;
  for (int k = 0; k < N; ++k) {
    int x, y, a;
    cin >> x >> y >> a;

    if (a == 1) {
      for (int i = 0; i < H; ++i) for (int j = 0; j < x; ++j) m[i][j] = 1;
    }
    else if (a == 2) {
      for (int i = 0; i < H; ++i) for (int j = x; j < W; ++j) m[i][j] = 1;
    }
    else if (a == 3) {
      for (int i = 0; i < y; ++i) for (int j = 0; j < W; ++j) m[i][j] = 1;
    }
    else if (a == 4) {
      for (int i = y; i < H; ++i) for (int j = 0; j < W; ++j) m[i][j] = 1;
    }
  }

  int ans = 0;
  for (int i= 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (!m[i][j]) ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s1, s2;
  cin >> s1 >> s2;
  
  if(s1.at(0) == s2.at(2) && s1.at(1) == s2.at(1) && s1.at(2) == s2.at(0)) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    string s, t;
    cin >> s >> t;

    ll cnt = 0;
    rep(i, 3){
      if(s[i]==t[i]) cnt++;
    }
    p(cnt);
    
    return 0;
}

Measured memory_bytes: 256
import sys
grid=[line.strip() for line in sys.stdin.readlines()]
xgrid=["0"+grid[i]+"0" for i in xrange(9) if i%2==0]
ygrid=[grid[i] for i in xrange(9) if i%2==1]
ygrid.insert(5,"0"*5)
ygrid.insert(0,"0"*5)
graph=[[None]*5 for i in xrange(5)]
for y in xrange(5):
    for x in xrange(5):
        graph[y][x]=[ygrid[y][x],xgrid[y][x+1],ygrid[y+1][x],xgrid[y][x]]
nx,ny,dir=0,0,1
DIRECTION=["U","R","D","L",]
dx=[0,1,0,-1]
dy=[-1,0,1,0]
log=[]
while True:
    for i in xrange(4):
        if graph[ny][nx][(dir+3)%4]=="1":
            dir=(dir+3)%4
            log.append(DIRECTION[dir])
            nx,ny=nx+dx[dir],ny+dy[dir]
            break
        dir=(dir+1)%4
    if nx==0 and ny==0:break
print "".join(log)

Measured memory_bytes: 23000
n=int(input())
l=list(map(int,input().split()))



for i in range(len(l)):
    v=l[i]
    j=i-1

    while j>=0 and l[j]>v:
        l[j+1]=l[j]
        j=j-1
    l[j+1]=v

    print(*l)



Measured memory_bytes: 5984
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			if(N + M == 0) break;
			
			int[] h = new int[N+1];
			int[] w = new int[M+1];
			for(int i=1; i<=N; i++) {
				h[i] = sc.nextInt();
			}
			for(int i=1; i<=M; i++) {
				w[i] = sc.nextInt();
			}
			
			int[] hs = new int[1500001];
			int[] ws = new int[1500001];
			
			for(int i=1; i<=N; i++) {
				int sum = 0;
				for(int j=i; j<=N; j++) {
					sum += h[j];
					hs[sum]++;
				}
			}
			for(int i=1; i<=M; i++) {
				int sum = 0;
				for(int j=i; j<=M; j++) {
					sum += w[j];
					ws[sum]++;
				}
			}
			int cnt = 0;
			for(int i=1; i<=1500000; i++) {
				cnt += hs[i] * ws[i];
			}
			System.out.println(cnt);
		}
	}
}


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

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

    int MIN = 1001, MAX = -1;

    int a[100];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (MIN > a[i]) {
            MIN = a[i];
        }
        if (MAX < a[i]) {
            MAX = a[i];
        }
    }

    cout << MAX - MIN << endl;

    return 0;
}

Measured memory_bytes: 256
class Dice:
    def __init__(self, data):
        self.data = data
    
    def __eq__(self, value):
        for a in range(0,6,5):
            self.moveTopTo(self.getSortedList()[a])
            value.moveTopTo(value.getSortedList()[a])
            for b in range(4):
                if self.data == value.data:
                    return True
                else:
                    value.move('R')
        return False

    def move(self, direction):
        if direction == 'E':
            self.data[0], self.data[3], self.data[5], self.data[2] = \
                self.data[3], self.data[5], self.data[2], self.data[0]
        elif direction == 'N':
            self.data[0], self.data[4], self.data[5], self.data[1] = \
                self.data[1], self.data[0], self.data[4], self.data[5]
        elif direction == 'S':
            self.data[0], self.data[1], self.data[5], self.data[4] = \
                self.data[4], self.data[0], self.data[1], self.data[5]
        elif direction == 'W':
            self.data[0], self.data[2], self.data[5], self.data[3] = \
                self.data[2], self.data[5], self.data[3], self.data[0]
        elif direction == 'R':
            self.data[1], self.data[2], self.data[4], self.data[3] = \
                self.data[3], self.data[1], self.data[2], self.data[4]
        elif direction == 'L':
            self.data[1], self.data[2], self.data[4], self.data[3] = \
                self.data[2], self.data[4], self.data[3], self.data[1]

    def moveTopTo(self, target):
        for a in range(4):
            if self.data[0] == target:
                break
            self.move('W')
        if self.data[4] == target:
            self.move('S')
        elif self.data[1] == target:
            self.move('N')
    
    def moveFrontTo(self, target):
        for a in range(4):
            if self.data[1] == target:
                break
            self.move('R')

    def getTop(self):
        return self.data[0]
    
    def getRight(self):
        return self.data[2]

    def getSortedList(self):
        tmp = self.data[:]
        tmp.sort()
        return tmp


a = Dice(input().split())
b = Dice(input().split())
if a == b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 6828
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;


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

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

	int prev = -1,ans = 1;
	for(int i=0;i<n;i++){
		if(a[i] == prev) continue;
		ans = max(ans,(int)(upper_bound(a,a+n,a[i]+1)-lower_bound(a,a+n,a[i]-1)));
		prev = a[i];
	}
	cout << ans << "\n";
				
	return 0;
}


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

int main()
{
	int a,b,c;
	int cnt=0;
	cin >> a>>b>>c;
	for (int i = a; i <= b; ++i) {
		if (c % i == 0) {
			++cnt;
		}
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();
        if(a >= k){
            print(a-k,b);
        }else if(a+b >= k){
            print(0,b-(k-a));
        }else{
            print(0,0);
        }
    }
    public static void print(long a, long b){
        System.out.println(a+" "+b);
    }
}

Measured memory_bytes: 22996
#!/usr/bin/env python3

def main():
    a, b, c, d = map(int, input().split())
    if (abs(a - c) <= d) or (abs(a - b) <= d and abs(b - c) <= d):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
n,a,b=map(int,input().split())
if (a+b)%2==0:print(abs(a-b)//2)
else:
  aa,bb=1,b-a
  ans=a+abs(b-a)//2
  aa,bb=a+(n-b+1),n
  ans=min((n-b+1)+abs(b-a)//2,ans)
  print(ans)

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

int K, T;
int a[105];

signed main()
{
	cin >> K >> T;

	int mx = -1;
	rep(i,T) {
		cin >> a[i];
		mx = max(mx, a[i]);
	}

	cout << max(mx - 1 - (K - mx), 0) << endl;
}


Measured memory_bytes: 256
/*
    Problem 6
    https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
void solve1() {
    int N; string S;
    cin >> N >> S;
    int ans = 0;
    // 000 ~ 999までがSに含まれるか全探索
    // O(10^3 * 3 * 10^4) = O(3 * 10^7)
    for (int i = 0; i < 1000; i++) {
        vector<int> v{i / 100, (i / 10) % 10, i % 10};
        int t = 0;
        for (int s = 0; s < N; s++) {
            if (S[s] == ('0' + v[t])) t++;
            if (t >= 3) {
                ans++;
                break;
            }
        }
    }
    cout << ans << '\n';
}

void solve2() {
    int N; string S;
    cin >> N >> S;
    vector<vector<bool>> dp(1000, vector<bool>(4));
    for (int pos = 0; pos < N; pos++) {
        int cur = S[pos] - '0';
        for (int num = 0; num < 100; num++) if (dp[num][2]) dp[cur + num * 10][3] = true;
        for (int num = 0; num < 10; num++) if (dp[num][1]) dp[cur + num * 10][2] = true;
        dp[cur][1] = true;
    }
    int ans = 0;
    for (int i = 0; i < 1000; i++) if (dp[i][3]) ans++;
    cout << ans << '\n';
}
/* main */
int main(){
    // solve1();
    solve2();
}

Measured memory_bytes: 3704
n = gets.chomp.to_i

points = []
n.times do
  points << gets.chomp.split(' ').map(&:to_i)
end
combs = points.permutation(n).to_a

ranges = []
combs.each do |comb|
  calc = []
  for i in 0...(comb.size-1) do
    calc << Math.sqrt((comb[i][0]-comb[i+1][0])**2 + (comb[i][1]-comb[i+1][1])**2)
  end
  ranges << calc.reduce(:+)
end

print ranges.reduce(:+)/ranges.size


Measured memory_bytes: 10748
s = list(input())
for i in range(len(s)):
    if i%2==0:
        if s[i] == 'R' or s[i] == 'U' or s[i] == 'D':
            s[i] = '*'
    else:
        if s[i] == 'L' or s[i] == 'U' or s[i] == 'D':
            s[i] = '*'
print(['No','Yes'][set(s)=={'*'}])

Measured memory_bytes: 3064
N, A, B = map(int, input().split())
total = 0
for i in range(N+1):
	if i < 10:
		n = i
	else:
		li = list(str(i))
		n = 0
		for num in li:
			n += int(num)
	if n >= A and n <=B:
		total += i

print(total)

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

int main() {
  int X,Y;
  cin >> X >> Y;
  if (Y%2==0&&Y>=X*2) {
    if (Y<=X*4) {
      cout << "Yes";
    }
    if (Y>X*4) {
      cout << "No";
    }
  }
  if (Y%2!=0||Y<X*2) {
    cout << "No";
  }
  cout << endl;
}


Measured memory_bytes: 3624
import sys
input = sys.stdin.buffer.readline


class BinaryIndexedTree:
    """一点加算、区間総和クエリをそれぞれO(logN)で答えるデータ構造。"""
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def build(self, array):
        """arrayを初期値とするBinaryIndexedTreeを構築する。O(N)"""
        for i, val in enumerate(array):
            self.bit[i + 1] = val
        for i in range(1, self.size):
            if i + (i & -i) > self.size:
                continue
            self.bit[i + (i & -i)] += self.bit[i]

    def _sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, val):
        """i番目の要素にvalを加算する。O(logN)"""
        i += 1
        while i <= self.size:
            self.bit[i] += val
            i += i & -i

    def sum(self, l, r):
        """区間[l, r)の和を求める。O(logN)"""
        return self._sum(r) - self._sum(l)

    def bisect_left(self, val):
        """区間[0, ind)の和がval以上になる最小のindを求める。O(logN)"""
        if val <= 0:
            return 0
        ind = 0
        k = 1 << self.size.bit_length()
        while k:
            if ind + k <= self.size and self.bit[ind + k] < val:
                val -= self.bit[ind + k]
                ind += k
            k >>= 1
        return ind + 1


n, q = map(int, input().split())
a = list(map(int, input().split()))
queries = [list(map(int, input().split())) for _ in range(q)]


bit = BinaryIndexedTree(n)
bit.build(a)
ans = []
for flag, l, r in queries:
    if flag:
        ans.append(bit.sum(l, r))
    else:
        bit.add(l, r)  # l = index, r = val

print("\n".join(map(str, ans)))

Measured memory_bytes: 199320
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int wi[222];
LL DP[222][11111];

int main(){
	int n,w;
	LL ret=0;
	cin>>n>>w;
	REP(i,n)scanf("%d", &wi[i]);
	sort(wi, wi+n);
	int sum = 0;
	REP(i,n)sum += wi[i];
	if(sum <= w){
		cout << 1 << endl;
		return 0;
	}
	int mw;
	FOR(i,0,n){
		memset(DP, 0, sizeof(DP));
		DP[0][0]=1;
		mw = wi[i];
		REP(j,n){
			REP(k,w+1){
				if(i!=j && k+wi[j]<=w){
					DP[j+1][k+wi[j]] += DP[j][k];
					DP[j+1][k+wi[j]] %= MOD;
				}
				if(i<=j){
					DP[j+1][k] += DP[j][k];
					DP[j+1][k] %= MOD;
				}
			}
		}
		FOR(j, w-mw+1, w+1){
			ret += DP[n][j];
			ret %= MOD;
		}
	}
	cout <<ret << endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	unordered_set<int> s;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		s.insert(tmp);
	}
	cout << s.size();
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, A, B) = listOfLong()
    if (A == 0L) {
        println(0)
        return
    }
    val m = N / (A + B)
    val r = N - (m * (A + B))
    val ans = A * m + Math.min(A, r)
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 37948