akhauriyash/Code-Regression huggingface dataset:
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for _ in range(M)]
pay = 0
min_pay = 0
for i in range(M):
  pay = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]
  if i == 0:
    min_pay = pay
  min_pay = min(min_pay,pay)
min_pay = min(min_pay,min(a)+min(b))
print(min_pay)

Measured memory_bytes: 38560
from collections import defaultdict
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
s = defaultdict(int)
for i in range(n):
  s[input()]+=1
m = readInt()
t = defaultdict(int)
for i in range(m):
  t[input()]+=1

ans = 0
for i in s:
  ans = max(ans,s[i]-t[i])
print(ans)

Measured memory_bytes: 9340
## C - Half and Half
import math
A, B, C, X, Y = map(int, input().split())
money = []
for i in range(0, max(X,Y) + 1 ):
    val = 0
    val += A * (X - i) if X - i > 0 else 0
    val += B * (Y - i) if Y - i > 0 else 0
    money.append(  val + C * 2*i )
print(min(money))

Measured memory_bytes: 7100
#include<bits/stdc++.h>
using namespace std;
signed main(){
	string s;cin>>s;
	int len=s.size();
	bool flag=1;
	for(register int i=1;i<len;i++)
		if(s[i]!='9'){
			flag=0;
			break;
		}
	printf("%d\n",(len-1)*9+s[0]-'0'-1+flag);
	return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <map>
#include <cstdio>
#include <cmath>
#include <unordered_map>
#include <iomanip>
using namespace std;

int main() {
  int a, b,c;
  cin >> a >> b >> c;
  if (a+b+c >= 22){
    cout << "bust" << endl;
  }
  else{
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

vector<bool> visited(105);
vector<vector<int>> edge(105);
bool dfs(int cur, int par) {
    // if a cycle doesn't exist, return true
    visited[cur] = true;
    bool ic = false;
    if (edge[cur].size() == 0) {
        return true;
    } else {
        for (int i = 0; i < edge[cur].size(); i++) {
            if (edge[cur][i] == par) {
                continue;
            }
            if (visited[edge[cur][i]]) {
                ic = true;
                break;
            } else {
                visited[edge[cur][i]] = true;
            }
            if (!dfs(edge[cur][i], cur)) {
                ic = true;
            }
        }
        if (ic) {
            return false;
        } else {
            return true;
        }
    }
}
int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % 2019;
    } else {
        return modpow(m, n - 1) * m % 2019;
    }
}
signed main() {
    long long v, e;
    cin >> v >> e;
    vector<int> ans;
    queue<int> zeros;
    vector<vector<int>> graph(v);
    vector<int> degree(v);
    REP(i, e) {
        // https/chess.com
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        degree[b]++;
    }
    REP(i, v) {
        if (degree[i] == 0) {
            zeros.push(i);
        }
    }
    while (zeros.size() > 0) {
        int cur = zeros.front();
        zeros.pop();
        ans.push_back(cur);
        for (int i = 0; i < graph[cur].size(); i++) {
            degree[graph[cur][i]]--;
            if (degree[graph[cur][i]] == 0) {
                zeros.push(graph[cur][i]);
            }
        }
    }
    REP(i, ans.size()) { cout << ans[i] << endl; }
}


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

using namespace std;

void Main() {
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (U == S) {
        cout << (A - 1) << " " << B << endl;
    }
    else {
        cout << A << " " << (B - 1) << endl;
    }
}

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


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <algorithm>

using ii = std::pair<int, int>;

int main()
{
	long long int q, h, s, d, n;

	scanf("%lld %lld %lld %lld %lld", &q, &h, &s, &d, &n);

	s = std::min({ q * 4, h * 2, s });

	long long int total = 0;

	if (s * 2 > d)
	{
		if (n % 2 == 0)
			total = n / 2 * d;
		else
			total = n / 2 * d + s;
	}
	else
	{
		total = n * s;
	}

	printf("%lld", total);

	return 0;
}

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

#define ll long long
#define pll pair<ll,ll> 

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


	ll n;
	cin>>n;
	ll x=n/1000;
	x++;
	ll ans=(x*1000)-n;
	cout<<ans%1000<<endl;
}


Measured memory_bytes: 3636
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int N;cin>>N;
  int A[N+10];
  REP(i,N) {
    cin>>A[i];
  }
  REP(i,N) {
    if(A[i] % 2 == 0) {
      if(!(A[i]%5==0 || A[i]%3==0)) {
        p("DENIED");
        return 0;
      }
    }
  }
  p("APPROVED");
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = (ll)1e9;
const ll MOD = 1000000007;
long long modpow(long long a, long long n) {
  long long res = 1;
  long long mod = n + 2;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long inverse(long long x, long long modding) {
  return modpow(x, modding - 2);
}
long long combination(long n, long r, long long mod) {
  // nCrを返す　O(r)
  // 逆元はその場で対応
  if (n < r) return 0;
  if (n < r) swap(n, r);
  long long bunbo = 1;
  long cnt = r;
  while (0 < cnt) {
    bunbo *= cnt;
    bunbo % mod;
    cnt--;
  }
  if (bunbo == 0) return 1;
  long long bunsi = 1;
  cnt = 0;
  while (cnt < r) {
    bunsi *= (n - cnt);
    bunsi %= mod;
    cnt++;
  }
  return (((bunsi % mod) * inverse(bunbo, mod))) % mod;
}
long long longpow(long long n, long long a, long long mod) {
  if (a == 0) return 1;
  if (a == 1) return n % mod;
  if (a % 2 == 1) return (n * longpow(n, a - 1, mod)) % mod;
  ll t = longpow(n, a / 2, mod) % mod;
  return (t * t) % mod;
}
struct Combination {
  // Combnation(x)　xCxまでを生成
  // RetCombination(n,r) nCrを返す
  vector<vector<long long>> combination;
  Combination(int x) {
    combination.resize(x + 1);
    for (int i = 0; i < x + 1; i++) {
      combination[i].resize(x + 1);
    }
    combination[0][0] = 1;
    for (int i = 0; i < x; i++) {
      for (int j = 0; j <= i; j++) {
        combination[i + 1][j] += combination[i][j];
        combination[i + 1][j + 1] += combination[i][j];
        combination[i + 1][j] %= MOD, combination[i + 1][j + 1] %= MOD;
      }
    }
  }
  long long RetCombination(int n, int r) { return combination[n][r]; }
};
int main() {
  ll N, K;
  cin >> N >> K;
  Combination cm(N + 10);
  ll blue = K, red = N - K;
  REP(i, blue) {
    /*ll ans = combination(K - 1, i, MOD);
    while (ans < 0) ans += MOD;
    ans *= combination(N - K + 1, i + 1, MOD);
    while (ans < 0) ans += MOD;*/
    cout << (cm.RetCombination(K - 1, i) *
             cm.RetCombination(N - K + 1, i + 1)) %
                MOD
         << endl;
  }
}

Measured memory_bytes: 35288
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int N;
double dp[3123][3123]; //i枚目まで投げた時にj枚表が出ている確率
double p[3123];
double ans;
signed main(){
    cin>>N;

    for(int i=1;i<=N;i++){
        cin>>p[i]; 
    }

    dp[0][0]=1.0;


    for(int i=1;i<=N;i++){
        rep(j,3123){
            dp[i][j+1]+=dp[i-1][j]*p[i];
            dp[i][j]+=dp[i-1][j]*(1.0-p[i]);
        }
    }

 
    rep(j,3123){
        if((N+1)/2 -1<j)ans+=dp[N][j];
    }
    
    cout<<fixed<<setprecision(10)<<ans<<endl;
 
}

Measured memory_bytes: 73984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
int n,cnt;
ll ans;
char s[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
	if(s[i]=='A')cnt++;
	else if(s[i]=='B'&&s[i+1]=='C')ans+=cnt,i++;
	else cnt=0;
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){

  int a,b;
  int i;

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

  i = 0;
  while(a*i - i + 1 < b) i++;

  printf("%d\n", i);

  return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

int dp[100002];

void solve() {
  int N;
  cin >> N;
  vector<int> H(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  dp[1] = abs(H[1] - H[0]);
  for (int i = 2; i < N; i++) {
    int cost1 = abs(H[i] - H[i - 1]);
    int cost2 = abs(H[i] - H[i - 2]);
    dp[i] = min(dp[i - 1] + cost1, dp[i - 2] + cost2);
  }
  cout << dp[N - 1] << endl;
}

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

  solve();

  return 0;
}


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

int main(){
  int n,k,q;
  cin >> n >> k >>q;
  vector<int> score(n+2);
  for(int i=1;i<=n;i++) score[i] = k-q;
  for(int i=1;i<=q;i++){
    int temp;
    cin >> temp;
    score[temp]++;
  }
  for(int i=1;i<=n;i++){
    if(score[i] <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;
}
  

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("kmp.in","r",stdin);freopen ("kmp.out","w",stdout);
#define mod 1000000009
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum;

int main()
{
	fast;
	cin>>n>>m;
	cout<<max(max(n+m,n-m),n*m);



}



/*     cd onedrive\desktop\kod
cls


*/

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
mod = 998244353
dp = Array.new(N, 0)
dp[0] = 1
lr = K.times.map {gets.split.map(&:to_i)}

N.times do |i|
  dp[i + 1] += dp[i] if 0 < i && i + 1 < N
  lr.each do |l, r|
    dp[i + l] = (dp[i + l] + dp[i]) % mod if i + l < N
    dp[i + r + 1] = (dp[i + r + 1] - dp[i]) if i + r + 1 < N
  end
end

puts dp[-1] % mod

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

using namespace std;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n;i++){
        string ss=s.substr(i, 3);
        if(ss=="ABC"){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m = list(map(int,input().split()))
left = []
right = []
for i in range(m):
  l,r = list(map(int,input().split()))
  left.append(l)
  right.append(r)
start = max(left)
end = min(right)
cnt = 0 
for i in range(1, n+1):
  if(start <=i and i <= end):
    cnt += 1
print(cnt)

Measured memory_bytes: 11024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	while (true) {
		bool f = true;
		rep(i, n)if (a[i] % 2)f = false;
		if (!f)break;
		rep(i, n)a[i] /= 2;
		ans++;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
int a[9][9],b[9][9],c[10],n;
int main()
{
    scanf("%d", &n);
    while (n--) {
        rep(i, 9) rep(j, 9) b[i][j] = 0;
        rep(i, 9) rep(j, 9) scanf("%d", &a[i][j]);
        rep(i, 9) rep(j, 9) rep(k, 9) {
            if (j == k) continue;
            if (a[i][j] == a[i][k]) b[i][j] = b[i][k] = 1;
        }
        rep(i, 9) rep(j, 9) rep(k, 9) {
            if (i == k) continue;
            if (a[i][j] == a[k][j]) b[i][j] = b[k][j] = 1;
        }
        for (int i = 0; i < 9; i += 3) {
            for (int j = 0; j < 9; j += 3) {
                rep(k, 10) c[k] = 0;
                rep(k, 3) rep(l, 3) c[a[i+k][j+l]]++;
                rep(k, 3) rep(l, 3) if (c[a[i+k][j+l]] > 1) b[i+k][j+l] = 1;
            }
        }

        rep(i, 9) {
            rep(j, 9) { putchar(b[i][j] ? '*' : ' '); printf("%d", a[i][j]); }
            puts("");
        }
        if (n > 0) puts("");
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <thread>///////////////////

#define rep(i,m,n) for(int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;

int N, Y;
int mode = 0;

//tuple<int, int, int> calc(int A, int B, int C) {}



int main() {
	int N, K,last;
	cin >> K >> N;
	v.resize(N);
	w.resize(N);
	rep(i, 0, N) {
		cin >> v[i];
		if (i == 0)w[i] = v[i];
		else w[i] = v[i] - v[i - 1];
	}
	w[0] += K - v[N - 1];
	int max = *max_element(w.begin(), w.end());
	max = K - max;
	cout << max << '\n';
	return 0;
}

Measured memory_bytes: 1792
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    dp = [[0,0] for i in range(N)]
    dp[0][0] = A[0]
    dp[0][1] = - A[0]
    for i in range(N-2):
        dp[i+1][0] = max(dp[i][0]+A[i+1],dp[i][1] - A[i+1])
        dp[i+1][1] = max(dp[i][0] - A[i+1],dp[i][1] + A[i+1])
    dp[N-1][0] = dp[N-2][0] + A[N-1]
    dp[N-1][1] = dp[N-2][1] - A[N-1]
    return max(dp[N-1])

if __name__ == '__main__':
    print(main())

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i, h) cin >> a[i];
  vector<bool> row(h);
  vector<bool> line(w);
  rep(i, h) {
    rep(j, w) {
      if(a[i][j] == '#') {
        row[i] = true;
        line[j] = true;
      }
    }
  }
  rep(i, h) {
    if(row[i]) {
      rep(j, w) {
        if(line[j]) cout << a[i][j];
      }
    }
    cout << endl;
  }
  return 0;
}

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

const int maxn=2e5+10;

int n,sz[maxn],mx[maxn],root;
int tote,FIR[maxn],NEXT[maxn],TO[maxn],W[maxn];
LL Ans;
bool flag;

void addedge(int u,int v,int w)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	W[tote]=w;
	FIR[u]=tote;
}

void dfs(int u,int F)
{
	sz[u]=1;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p],w=W[p];
		if (v==F) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		mx[u]=max(mx[u],sz[v]);
		Ans+=2ll*min(sz[v],n-sz[v])*w;
		if (sz[v]*2==n) Ans-=w,flag=1;
	}
	mx[u]=max(mx[u],n-sz[u]);
	root=mx[root]<mx[u]?root:u;
}

int main()
{
#ifdef h10
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
	int i,u,v,w;
	scanf("%d",&n);
	for (i=1;i<n;i++)
	{
		scanf("%d%d%d",&u,&v,&w);
		addedge(u,v,w);
		addedge(v,u,w);
	}
	mx[0]=n;
	dfs(1,0);
	if (!flag)
	{
		int minp=1e9;
		for (int p=FIR[root];p;p=NEXT[p])
			minp=min(minp,W[p]);
		Ans-=minp;
	}
	printf("%lld\n",Ans);
}


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

using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define N 2000001
#define M 1000000007
#define INF 1000000000000000


int main()
{
 ll n;
 cin>>n;
 ll i;
 
 ll a[n];
 for(i=0;i<n;i++)cin>>a[i];
 sort(a,a+n);
 ll j,k,ans=0;
 for(i=0;i<n;i++)
 {
     for(j=i+1;j<n;j++)
     {
         for(k=j+1;k<n;k++)
         {
             if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]){ans++;}
         }
     }
 }
 cout<<ans;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    printf("%d\n",sum-n);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
typedef pair<int,int> pii;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

    
void solve()
{
	int n;string s;cin>>n>>s;
    vector<vector<int> >a(n+1,vector<int>(10,-1));
    for(int i=n-1;i>=0;i--){
        REP(j,10)if(a[i+1][j]!=-1)a[i][j]=a[i+1][j];
        a[i][s[i]-'0']=i;
    }
    //REP(i,n){REP(j,10)cout<<setw(2)<<a[i][j]<<" ";cout<<endl;}cout<<endl;
    int ans=0;
    REP(i,10)REP(j,10)REP(k,10){
        int x=0;
        if(a[x][i]==-1)continue;
        x=a[x][i]+1;
        if(a[x][j]==-1)continue;
        x=a[x][j]+1;
        if(a[x][k]==-1)continue;
        ans++;
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 2432
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    string S;
    ll N, i, a, b, ans=0;

    cin >> N >> a >> b;

    i = N % (a+b);

    if(i==0){
        cout << N/(a+b)*a << endl;
    }

    else{
        ans += N/(a+b)*a;

        if(i <= a){
            ans += i;
        }
        else{
            ans += a;
        }

        cout << ans << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

int main()
{
    int n;
    cin >> n;
    cout << prec(20);
    int a[n];
    ld ans = 0;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    
    sort(a, a+n);

    ans = (a[0]+a[1])/pow(2, n-1);

    for(int i=2;i<n;i++)
    {
        ans += a[i]/pow(2, n-i);
    }

    cout << ans << "\n";
}




Measured memory_bytes: 256
# import math
import functools
import fractions


def main():
    div = 10**9 + 7

    N = int(input())
    A = list(map(int, input().split()))

    L = functools.reduce(lcm, A)


    C = [L // a for a in A]

    print(sum(C)%div)



def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 264668
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;

const int mod=1e9+7;
const int M=1e5+55;
const int N=1e5;

int bas[M];
int psum[M];
int n;
int w[M];
int ans;

int quickPow(int a,int b)
{
	int ret=1,bas=a;
	while(b!=0)
	{
		if(b&1)
			ret=(1ll*ret*bas)%mod;
		bas=(1ll*bas*bas)%mod;
		b>>=1;
	}
	return ret;
}

int getInv(int b)
{
	return quickPow(b,mod-2);
}

void init()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&w[i]);
	bas[1]=1;
	for(int i=2;i<=N;i++)
		bas[i]=(bas[i-1]+1ll*getInv(i))%mod;
	for(int i=1;i<=n;i++)
		psum[i]=(bas[i-1+1]+bas[n-i+1]-1)%mod;
}

void solve()
{
	ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+1ll*w[i]*psum[i])%mod;
	for(int i=1;i<=n;i++)
		ans=1ll*i*ans%mod;
	printf("%d\n",ans);
}

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

/*

2
1 2

1:1.5*1=1.5
2:1.5*2=3
4.5*2=9

*/




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

int main(void){
       int a;
       scanf("%d",&a);
       a=a%10;
       if(a==3){
               printf("bon\n");
       }else if(a==0||a==1||a==6||a==8){
               printf("pon\n");
       } else {
               printf("hon\n");
       }
       return 0;

       
}



Measured memory_bytes: 1648
# -*- coding: utf-8 -*-
from pprint import pprint
from collections import defaultdict
from scipy.sparse.csgraph import floyd_warshall
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

dist = floyd_warshall(c, directed=True)

A_cnt = defaultdict(int)
for h in range(H):
    for w in range(W):
        if A[h][w] != -1 and A[h][w] != 1:
            A_cnt[A[h][w]] += 1

ans = 0
for k,v in A_cnt.items():
    ans += dist[k][1] * v

print(int(ans))


Measured memory_bytes: 25992
## coding: UTF-8
from itertools import permutations, combinations,combinations_with_replacement,product
N = input()
#print(N)
#print(N[0])
#print(N[1])
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])


a=list(product(['-','+'],repeat=3)) #組み合わせを全パターン出してくれる ['', '+', '', '', '+']みたいなのを2^nケース出してくれる。

for i in a:
    ans = N[0]+i[0]+N[1]+i[1]+N[2]+i[2]+N[3]
    #print(ans)
    if(eval(ans)==7):
        print(ans+'=7')
        break
'''
if(A+B+C+D == 7):
    print('{}+{}+{}+{}=7'.format(A,B,C,D))
elif(A+B+C-D == 7):
    print('{}+{}+{}-{}=7'.format(A,B,C,D))
elif(A+B-C+D == 7):
    print('{}+{}-{}+{}=7'.format(A,B,C,D))
elif(A+B-C-D == 7):
    print('{}+{}-{}-{}=7'.format(A,B,C,D))
elif(A-B+C+D == 7):
    print('{}-{}+{}+{}=7'.format(A,B,C,D))
elif(A-B+C-D == 7):
    print('{}-{}+{}-{}=7'.format(A,B,C,D))
elif(A-B-C+D == 7):
    print('{}-{}-{}+{}=7'.format(A,B,C,D))
elif(A-B-C-D == 7):
    print('{}-{}-{}-{}=7'.format(A,B,C,D))
'''



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0)
        cout<<1<<endl;
    else if(x2==0)
        cout<<2<<endl;
    else if(x3==0)
        cout<<3<<endl;
        else if(x4==0)
        cout<<4<<endl;
        else
            cout<<5<<endl;


}


Measured memory_bytes: 3564
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[][] a = new int[N][N];
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) a[i][j] = scanner.nextInt();

    long[] dp = new long[1 << N];
    for (int i = 1; i < (1 << N); i++) {
      int msb = msb(i);
      dp[i] = dp[i ^ (1 << msb)];

      int k = i;
      int j = 0;
      while (k > 0) {
        if (k % 2 == 1) {
          dp[i] += a[msb][j];
        }
        k /= 2;
        j++;
      }
    }

    for (int i = 1; i < (1 << N); i++) {
      for (int j = i; j > 0; j = (j - 1) & i) {
        dp[i] = Math.max(dp[i], dp[j] + dp[i ^ j]);
      }
    }

    long max = 0;
    for (int i = 0; i < (1 << N); i++) {
      max = Math.max(max, dp[i]);
    }
    System.out.println(max);
  }

  private static int msb(int n) {
    int i = -1;
    while (n > 0) {
      n /= 2;
      i++;
    }
    return i;
  }
}


Measured memory_bytes: 22868
#include<iostream>

using namespace std;

int main(){
    int r,D,x;
    long long ans[10];

    cin>>r>>D>>x;
    ans[0] = r * x - D;
    cout<<ans[0]<<endl;
    for(int i=0;i<9;i++){
        ans[i+1] = r * ans[i] - D;
        cout<<ans[i+1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/**
    BISMILLAH
    @Author : Arham
*/
#include <bits/stdc++.h>
#define endl "\n"
#define found true
#define infinity 1e+10+10
#define not_found false
#define FOR(limit) for(int i = 0; i < limit; i++)
#define __FOR(limit) for(int j = 0; j < limit; j++)
#define __FOR__(limit) for(int k = 1; k <= limit; k++)
#define ALL(X) (X).begin(), (X).end()
#define hello(a) a ? "Yes" : "No"
#define HELLO(a) a ? "YES" : "NO"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pof pop_front
#define pob pop_back
#define I insert
#define fr front
#define B back
#define P push
#define pp pop
#define T top
#define F first
#define S second
/// getline (cin, string);
/// find (lower_bound(inclusive), upper_bound(exclusive), value);
/// set.find (value):
typedef long long lld;
using namespace std;

void solving_f() {
    int d, t, s, count = not_found;
    cin >> d >> t >> s;
    double a = d * 1.0;
    double b = t * 1.0;
    double c = s * 1.0;
    double res = a / c;
    if(res <= b)
        count = found;
    string str = hello(count);
    cout << str << endl;
}

int main(string hello_world) {
    ios_base :: sync_with_stdio(not_found);
    cin.tie(NULL);
//    cout.tie(0);

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    solving_f();

    return not_found;
}


Measured memory_bytes: 3648
import std.algorithm;
import std.array;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

T[] readToArray(T)() {
    return readln.split.to!(T[]);
}

void readInto(T...)(ref T ts) {
    auto ss = readln.split;
    foreach(ref t; ts) {
        t = ss.front.to!(typeof(t));
        ss.popFront;
    }
}

// 冪乗をmod取りつつ計算
@nogc @safe pure ulong modPow(ulong a, ulong n, ulong m) {
    ulong r = 1;
    while (n > 0) {
        if(n % 2 != 0) r = r * a % m;
        a = a * a % m;
        n /= 2;
    }
    return r;
}

// フェルマーの小定理から乗法逆元を計算
// 定理の要請により法は素数
@nogc @safe pure ulong modInv(ulong a, ulong m) {
    return modPow(a, m-2, m);
}

// mod取りつつ順列を計算
@nogc @safe pure ulong modPerm(ulong n, ulong k, ulong m) {
    if (n < k) return 0;

    ulong r = 1;
    for (ulong i = n-k+1; i <= n; i++) {
        r *= i;
        r %= m;
    }
    return r;
}

// mod取りつつ順列を計算
@nogc @safe pure ulong modFact(ulong n, ulong m) {
    return modPerm(n, n, m);
}

// mod取りつつ組み合わせを計算
// modInvを使っているので法は素数
@nogc @safe pure ulong modComb(ulong n, ulong r, ulong m) {
    return modPerm(n, r, m)*modInv(modFact(r, m), m) % m;
}

immutable ulong MOD = 1000000007;

// [min, max] に n の倍数がいくつあるか
ulong countMuls(ulong min, ulong max, ulong n) {
    return max/n - (min-1)/n;
}

ulong mod_2019(ulong l, ulong r) {
    if (l == 0) {
        return 0;
    }
    const ulong mul_3 = countMuls(l, r, 3);
    const ulong mul_673 = countMuls(l, r, 673);
    if (mul_3 != 0 && mul_673 != 0) return 0;
    if (mul_3 == 0) {
        // r - l == 1
        return (l * r % 2019);
    }

    // mul_3 != 0 && mul_673 == 0
    return naive(l, r);
}

ulong naive(ulong l, ulong r) {
    ulong min_mod = 2019;
    for(ulong i = l; i < r; i++) {
        for(ulong j = i + 1; j <= r; j++) {
            const ulong tmp = (cast(BigInt)i * cast(BigInt)j) % 2019;
            if (tmp < min_mod) {
                min_mod = tmp;
            }
        }
    }
    return min_mod;
}

void main() {
    ulong l, r;
    readInto(l, r);

    writeln(mod_2019(l, r));
}


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c , x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 0;
  if(x > y){
    swap(x, y);
    swap(a, b);
  }
  if(2 * c >= a + b){
    ans = x * a + y * b;
  }else{
    ans = x * 2 * c;
    c *= 2;
    ans += min((y - x) * b, (y - x) * c);
  }
  cout << ans << endl;
  return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> ans;
  while (true) {
    ans.push_back(n%k);
    n = n / k;
    if (n == 0) break;
  }
  
  cout << ans.size() << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; ++i)
		cin >> d[i];
	ll ans = 0;
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j)
			ans += (ll)d[i] * d[j];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
c1 = 0
c2 = 0
c3 = 0
ans = 0
for _ in range(N):
    s = input()
    for i in range(len(s) - 1):
        if s[i:i + 2] == 'AB':
            ans += 1
    if s[0] == 'B' and s[-1] == 'A':
        c3 += 1
    elif s[0] == 'B':
        c2 += 1
    elif s[-1] == 'A':
        c1 += 1


if c3 == 0:
    ans += min(c1, c2)
elif c1 == c2 == 0:
    ans += c3 - 1
elif c1 == 0 or c2 == 0:
    ans += c3
else:
    ans += min(c1, c2) + c3
print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;
    ll N=S.size();
    bool ok=true;
    rep(i,N){
        if(S[i]!=S[N-1-i]) ok=false;
    }
    rep(i,(N-1)/2){
        if(S[i]!=S[(N-1)/2-1-i]) ok=false;
        if(S[N-1-i]!=S[(N+1)/2+i]) ok=false;
    }
    cout<< ( ok ? "Yes" : "No" )<<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 256
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}



fn main(){
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let m: usize = scan.next();
    let q: usize = scan.next();
    let mut sc: Vec<(usize,usize,usize,i32)> = Vec::with_capacity(q);
    for _ in 0..q {
        let a: usize = scan.next();
        let b: usize = scan.next();
        let c: usize = scan.next();
        let d: i32 = scan.next();
        sc.push((a,b,c,d));
    }

    let mut deq: VecDeque<Vec<usize>> = VecDeque::new();
    let mut ans = 0;
    deq.push_back(vec![1]);

    while let Some(v) = deq.pop_front(){
        if v.len() == n {
            let mut score = 0;
            for i in 0..q{
                if v[sc[i].1-1] - v[sc[i].0 - 1] == sc[i].2 {
                    score += sc[i].3;
                }
            }
            ans = cmp::max(ans, score);
        }else{
            let last = v[v.len()-1];
            for d in last..m+1 {
                let mut vv = v.clone();
                vv.push(d);
                deq.push_back(vv);
            }
        }
    }
    
    println!("{}", ans);
}


Measured memory_bytes: 11116
#include <stdio.h>

int main(void)
{
    int x, y;

    while(1) {
        scanf("%d", &x);
        if(x == 0) break;
        y = 1000-x;
        int cnt[6] = {0};
    
        while(y > 0) {
            if(y >= 500) {
                y -= 500;
                cnt[0]++;
            } else if(y >= 100) {
                y -= 100;
                cnt[1]++;
            } else if(y >= 50) {
                y -= 50;
                cnt[2]++;
            } else if(y >= 10) {
                y -= 10;
                cnt[3]++;
            } else if(y >= 5) {
                y -= 5;
                cnt[4]++;
            } else if(y >= 1) {
                y -= 1;
                cnt[5]++;
            } else {
                break;
            }
        }
    
        printf("%d\n", cnt[0]+cnt[1]+cnt[2]+cnt[3]+cnt[4]+cnt[5]);
    }

    return (0);
}

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

#define rep(i, j, k) for(int i = (int) j; i < (int) k; ++i)
#define sz(x) ((int) (x).size())
#define ll long long
#define mp make_pair
#define pii pair<int, int >
#define fi first
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define zero(x) memset((x), (0), sizeof (x))
#define zerox(x, y) memset((x), (y), sizeof (x))

using namespace std;

int main()
{
#ifdef PIT
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif //PIT

	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	int l, r;
	cin >> n;
	int ans = 0;
	rep(i, 0, n) {
		cin >> l >> r;
		ans += r-l+1;
	}
	cout << ans << endl;
	
#ifdef PIT
flush(cout);
cerr << endl << "Time: " << (clock() / double(CLOCKS_PER_SEC)) << endl;
#endif //PIT
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int array[3];
	int i, j, tmp;
	scanf("%d %d %d", &array[0], &array[1], &array[2]);

	for (j = 3; j > 0; j--) {
		for (i = 0; i < j - 1; i++) {
			if (array[i] > array[i + 1]) {
				tmp = array[i];
				array[i] = array[i + 1];
				array[i + 1] = tmp;
			}
		}
	}

	printf("%d %d %d\n", array[0], array[1], array[2]);
	return 0;
}

Measured memory_bytes: 596
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input, "index" : 0, "max" : input.length,
  "hasNext" : function(){return (this.index < this.max);},
  "next" : function(){
    if(!this.hasNext()){return "";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  }
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  list.sort(function(a,b){
  	return b - a;
  });
  //myerr(list);
  var output = 0;
  for(var i = 0; i < N - 2; i++){
    for(var j = i + 1; j < N - 1; j++){
      var a = i;
      var b = j;
      var L = j;
      var R = N;
      var c;
      while(Math.abs(R - L) > 1){
        c = Math.floor((R + L) / 2);
        if(list[c] < list[a] + list[b] && 
          list[a] < list[c] + list[b] && 
          list[b] < list[a] + list[c]){
          L = c;
        }else{
          R = c;
        }
      }
      //myerr(list[a] + " " + list[b] + " " + list[c]);
      //myerr("L:" + L + " R:" + R);
      if(R != j + 1){
         //myerr("追加通過:" + (L - j));
         output += L - j;
      }
    }
  }
  myout(output);
}
function binary_search(list,search){
  //listはあらかじめ昇順ソート済みとする。右側が有効エリア、左側が無効エリアと
  //仮定し、searchによって返す要素(インデックス)は有効な部分の最小値である。
  //逆に無効な部分の最大値を返すなら↑のインデックスを1引いて返せばいい
  var ng = -1;
  var ok = list.length;
  var center;
  while(Math.abs(ok - ng) > 1){
    center = Math.floor((ok + ng) / 2);
    if(list[center] >= search){
       ok = center;
    }else{
       ng = center;
    }
  }
  return list[center];
  //return list[center - 1];
}

Measured memory_bytes: 9796
#include<iostream>
using namespace std;
int main(){
	int a,b,c,i,ans,sum=0;
	cin>>a>>b>>c;
	for(i=a;i<=b;i++){
		ans=c/i*i;
			if(ans==c){
				sum++;
			}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int ans = 0;
		while (N > 0) {
			ans += N % 10;
			N /= 10;
		}
		if (ans == 1) ans = 10;
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 21204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine();
            int time;
            Int32.TryParse(read, out time);
            int hour = time / 3600;
            int minute = (time - hour * 3600) / 60;
            int second = (time - hour * 3600 - minute * 60);
            Console.WriteLine(hour.ToString() + ":" + minute.ToString() + ":" + second);
            Console.ReadKey();
        }
    }
}



Measured memory_bytes: 15952
#include <iostream>
#include <vector>
#define BTC_RATE 380000.0
using namespace std;

int main() {
  int N; cin >> N;
  vector<double> x(N);
  vector<string> u(N);
  for (int i=0; i<N; i++) {
    cin >> x[i] >> u[i];
  }

  double ret = 0;
  for (int i=0; i<N; i++) {
    ret += x[i] * (u[i] == "BTC" ? BTC_RATE : 1.0);
  }
  
  cout << ret << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
a = []
stair = [1 for i in range(N+2)]
for i in range(M):
    stair[int(input())] = 0

dp = [0 for i in range(N+2)]
dp[0] = 1

MOD = 1000000007

for i in range(1, N+1):
    if stair[i] == 1:
        if i == 1:
            dp[i] = dp[i - 1] % MOD
        else:
            dp[i] = (dp[i-1] % MOD + dp[i-2] % MOD) % MOD

print(dp[N])


Measured memory_bytes: 7832
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll h, w;
    cin >> h >> w;

    vvll d(10, vll(10));
    REP(i, 10){
        REP(j, 10){
            cin >> d[i][j];
        }
    }
    REP(k, 10){
        REP(i, 10){
            REP(j, 10){
                if(d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
            }
        }
    }
    ll a, res = 0;
    REP(i, h){
        REP(j, w){
            cin >> a;
            if(a >= 0) res += d[a][1];
        }
    }
    cout << res << endl;
    return 0;
}

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

UL cmp = 0;

void merge(UL* A,UL l,UL m,UL r){
 UL n1=m-l, n2=r-m;
 vector<UL> L(n1+1);
 vector<UL> R(n2+1);
 rep(i,n1) L[i]=A[l+i]; L[n1]=~0u;
 rep(i,n2) R[i]=A[m+i]; R[n2]=~0u;
 UL i,j; i=j=0;
 for(UL k=l; k<r; k++){
  cmp++;
  if(L[i]<=R[j]){ A[k]=L[i]; i++; }
  else{ A[k]=R[j]; j++; }
 }
}
void mergeSort(UL* A,UL l,UL r){
 if(l+1<r){
  UL m=(l+r)>>1;
  mergeSort(A,l,m);
  mergeSort(A,m,r);
  merge(A,l,m,r);
 }
}

int main() {
 UL N; scanf("%u",&N);
 UL A[500000]; rep(i,N) scanf("%u",&A[i]);
 mergeSort(A,0,N);
 rep(i,N){ if(i)printf(" "); printf("%u",A[i]); }
 printf("\n");
 printf("%u\n", cmp);
 return 0;
}



Measured memory_bytes: 6788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

int n, q;

bool f[100100];

struct LCA {
	int s;
	vector<int> G[100100];//????????°??????
	int p[30][100100];
	int depth[100100] = {};

	void init() {
		REP(i, 30) {
			REP(j, 100100)p[i][j] = -1;
		}
	}
	void dfs(int now,int d,int pre){
		if (pre != -1)p[0][now] = pre;
		depth[now] = d;
		REP(i, G[now].size()) {
			dfs(G[now][i], d + 1, now);
		}
	}
	void make_p() {
		FOR(i, 1, 30) {
			REP(j, 100100) {
				p[i][j] = p[i - 1][p[i - 1][j]];
			}
		}
	}
	int query(int u, int v) {
		if (depth[u] > depth[v]) swap(u, v);
		for (int i = 30 - 1; i >= 0; i--) {
			int d = depth[v] - depth[u];
			if (d >= (1 << i)) v = p[i][v];
		}
		for (int i = 30 - 1; i >= 0; i--) {
			if (p[i][u] != p[i][v]) {
				u = p[i][u];
				v = p[i][v];
			}
		}
		if (u == v)return u;
		return p[0][u];
	}
};

LCA lca;

int main() {
	cin >> n;
	REP(i, n) {
		int k;
		cin >> k;
		REP(j, k) {
			int c;
			cin >> c;
			f[c] = 1;
			lca.G[i].push_back(c);
		}
	}
	REP(i, n) {
		if (!f[i]) {
			lca.s = i;
			break;
		}
	}
	lca.init();
	lca.dfs(lca.s, 0, -1);
	lca.make_p(); 
	cin >> q;
	REP(i, q) {
		int u, v;
		cin >> u >> v;
		cout << lca.query(u, v) << endl;
	}
}

Measured memory_bytes: 23552