akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.algorithm;

void main() {
    auto p = new long[2001];
    foreach (i; 0 .. 1001) foreach (j; 0 .. 1001)
        p[i + j]++;
    while (true) {
        if (stdin.eof) break;
        int N; scanf("%d\n", &N);
        long ans;
        foreach (i; 0 .. min(N, 2000) + 1) if (0 <= N - i && N - i <= 2000)
            ans += p[i] * p[N - i];
        writeln(ans);
    }
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
ll rd()
{
    ll sum = 0;char c = getchar();bool flag = true;
    while(c < '0' || c > '9') {if(c == '-') flag = false;c = getchar();}
    while(c >= '0' && c <= '9') sum = sum * 10 + c - 48,c = getchar();
    if(flag) return sum;
    else return -sum;
}
ll n,x;
ll work(ll a,ll b)
{
    if(b % a == 0) return b*2-a;
    ll now = b/a*a*2;
    now += work(b%a,a);
    return now;
}
int main()
{
    n = rd(),x = rd();
    printf("%lld\n",work(x,n-x)+n);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}


int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();

    int n,m;cin>>n>>m;
    cout<< n*(n-1)/2+m*(m-1)/2; 

	return 0;
}
 



Measured memory_bytes: 256
c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))

num=0
if c1[1]-c1[0]==c2[1]-c2[0]==c3[1]-c3[0]:
    num+=0
else:
    num+=1
if c1[2]-c1[1]==c2[2]-c2[1]==c3[2]-c3[1]:
    num+=0
else:
    num+=1
if c2[0]-c1[0]==c2[1]-c1[1]==c2[2]-c1[2]:
    num+=0
else:
    num+=1
if c3[0]-c2[0]==c3[1]-c2[1]==c3[2]-c2[2]:
    num+=0
else:
    num+=1
    
if num==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x,i,j,y,flag=0;
    scanf("%d\n",&x);
    char s[100];
    gets(s);
    if(x%2==0)
    {
        y=x/2;
        for(i=0,j=y;i<y||j<x-1;i++,j++)
        {
            if(s[i]==s[j])
            {
                flag++;
            }
        }
        if(flag==y)
        {
            printf("Yes");
        }
        else
            printf("No");

    }
    else
    {
        printf("No");
    }
}


Measured memory_bytes: 128
#define scanf_s scanf
#include <iostream>
using namespace std;
int F[46] = { 0 };
int fib(int n) 
{
	if (n >= 0) {
		if (n <= 1) { return F[n] = 1; }
		if (F[n] != 0) {
			return F[n];
		}
		return F[n] = fib(n - 1) + fib(n - 2);
	}
}
int main(void)
{
	int n;
	scanf_s("%d", &n);
	printf("%d\n", fib(n));
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

bool isOK(int a,int b,int c,int d){
    if(a==0&&b==2&&c==1)return false;
    if(a==0&&b==1&&c==2)return false;
    if(a==0&&b==2&&d==1)return false;
    if(a==0&&c==2&&d==1)return false;
    if(a==2&&b==0&&c==1)return false;
    return true;
}
const int mod=1000000007;

int main(){
    int n;cin>>n;
    ll dp[n+1][4][4][4][4];
    memset(dp,0,sizeof(dp));
    dp[0][3][3][3][3]=1;
    rep(i,n){
        rep(j,4){
            rep(k,4){
                rep(l,4){
                    rep(m,4){
                        if(isOK(j,k,l,m)){
                            rep(x,4){
                                dp[i+1][j][k][l][m]+=dp[i][k][l][m][x]%mod;
                                dp[i+1][j][k][l][m]%=mod;
                            }
                        }
                        else{
                          dp[i+1][j][k][l][m]=0;
                        }
                    }
                }
            }
        }
    }
    ll ans=0;
    rep(j,4) rep(k,4) rep(l,4) rep(m,4){
        ans+=dp[n][j][k][l][m]%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;


int main() {


	int n, k;
	cin >> n;
	cin >> k;

	string s;
	cin >> s;
	
	
	s[k - 1] = s[k - 1] + 32;
	
	cout << s << endl;
	

	
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import functools

def gcd(x,y):
    if y == 0:
        return x
    return gcd(y,x%y)

def solve(N: int, X: int, x: "List[int]"):
    x2 = list(map(lambda x: abs(x-X),x))
    print(functools.reduce(gcd,x2))

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19848
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(ll i=0;i<(n);i++)
int main() {
	ll n, x, a, mi = 1e9;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a;
		x -= a;
		mi = min(a, mi);
	}
	cout << n + x / mi << endl;
	return 0;
}


Measured memory_bytes: 256
function Main(input){
  input = input.split("");
  var sum = 0;
  var g=0;
  var p=0;
  input.forEach(function(val){
      switch(val){
          case "g":
              if(p<g){
                  sum++;
                  p++;
              }else{
                  g++;
              }
              break;
          case "p":
              if(p<g){
                  p++;
              }else{
                  g++;
                  sum--;
              }
      }
  });
  console.log(sum);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 20040
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  long long ans=1e18;
  for(long long i=1;i*i<=n;i++){
    if(n%i!=0)continue;
    long long j=n/i;
    ans=min(ans,i+j-2);
  }
  cout<<ans<<endl;
}

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

int main(){
    int N, H[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> H[i];
    for(int i=N-2; i>0; i--){
        if(H[i] > H[i+1]){
            H[i]--;
            if(H[i] > H[i+1]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;
#define int long long


signed main(){
    string w;
    cin >> w;
    
    map<char,int> mp;
    for(int i=0;i<w.length();i++){
        mp[w[i]]++;
    }
    
    for(int i=0;i<w.length();i++){
        if(mp[w[i]]%2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 素数判定O(√n)
bool is_prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return n!=1; //1の場合は除外
}

int prime[100010];     // i番目の素数
bool isprime[100010];   // isprime[i]がtrueならiは素数

// n以下の素数の数を返す
int eratos(int n){
    int p=0;
    for(int i=0;i<=n;i++) isprime[i]=true;
    isprime[0]=isprime[1]=false;
    for(int i=2;i<=n;i++){
        if(isprime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i) isprime[j]=false;
        }
    }
    return p;
}

int a[100010];

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

    for(int i=2;i<=100010;i++){
        if(is_prime(i) && is_prime((i+1)/2)) a[i]=1;
    }

    vector<int> s(100010,0);
    rep(i,100010){
        s[i+1]=s[i]+a[i];
    }

    while(q--){
        int l,r;
        cin>>l>>r;
        cout<<s[r+1]-s[l]<<endl;
    }

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int d;
    int n;
    cin>> d>>n;
    vector<int> v(n);
    vector<int> dis(n);
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        // sum+=v[i];
    }

    for(int i=0;i<n-1;i++)
    {
        dis[i]=v[i+1]-v[i];
    }
    dis[n-1]=d-v[n-1]+v[0];

    int mx=*max_element(dis.begin(),dis.end());
    sum=d-mx;
    cout<<sum;
    return 0;


}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
   long A,B,K;
   scanf("%ld %ld %ld",&A,&B,&K);
   if(A>=K){
      A -=K;
   }else if(A+B<K){
      A=0;
      B=0;
   }else{
      B -=K;
      B +=A;
      A=0;
   }
   printf("%ld %ld",A,B);
   return 0;
}


Measured memory_bytes: 1696
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n,a,b,c,d;
  string s;
  cin >> n >> a >> b >> c >> d;
  --a;--b;--c;--d;
  cin >> s;
  string sa=s;
  string sb=s;
  sa[a] = 'o';
  sb[b] = 'o';
  REP(i,n) {
    FOR(j,1,3) {
      if(i+j<n) {
        if(sa[i] == 'o' && sa[i+j] =='.') sa[i+j] = 'o';
        if(sb[i] == 'o' && sb[i+j] =='.') sb[i+j] = 'o';
      }
    }
  }
  LL bl = b;
  s[b] = 'o';
  FOR(i,1,n) {
    if(s[i] == 'o' && (s[i+1] == '#' || s[i-1] == '#')) {
      FOR(j,1,3) {
        if(i+j<n) {
          if(s[i] == 'o' && s[i+j] =='.') {
            s[i+j] = 'o';
            bl = i+j;
            break;
          }
        }
      }
    }
  }
  bool flag = sa[c] == 'o' && sb[d] == 'o' && (c < d || bl <= d);
  cout << (flag?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vvb vector<vector<bool> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

vector<ll> P(1001, 0), c(1001, 0), x(1001);
vvl G = vv(1001, 0, 0, ll);
vvl num = vv(1001, 2, -1, ll);
deque<ll> w;
void dfs(ll now){
  if(num[now][0]!=-1) return;
  if(G[now].size()==0) num[now][0] = x[now], num[now][1] = 0;
  else{
    ll f=0, s=0;
    for(int i=0;i<G[now].size();i++) f+=num[G[now][i]][0], s+=num[G[now][i]][1];
    if(x[now]<s){
      std::cout << "IMPOSSIBLE" << '\n';
      exit(0);
    }
    vvb dp = vv(G[now].size()+1, 5001, false, bool);
    dp[0][0] = true;
    for(int i=1;i<=G[now].size();i++){
      for(int j=0;j<=5000;j++){
        dp[i][j] = (dp[i][j] || dp[i-1][j]);
        if(j+num[G[now][i-1]][0]<=5000){
          dp[i][j+num[G[now][i-1]][0]] = (dp[i][j+num[G[now][i-1]][0]] || dp[i-1][j]);
        }
        if(j+num[G[now][i-1]][1]<=5000){
          dp[i][j+num[G[now][i-1]][1]] = dp[i][j+num[G[now][i-1]][1]] || dp[i-1][j];
        }
      }
    }
    int k;
    for(k=x[now];k>=0;k--) if(dp[G[now].size()][k]) break;
    num[now][0] = max(x[now], f+s-k), num[now][1] = min(x[now], f+s-k);
  }
  c[P[now]]++;
  if(c[P[now]]==G[P[now]].size()) w.push_back(P[now]);
}
int main(int argc, char const *argv[]) {
  ll N, a;
  std::cin >> N;
  for(int i=2;i<=N;i++){
    std::cin >> a;
    P[i] = a;
    G[a].push_back(i);
  }
  for(int i=1;i<=N;i++) std::cin >> x[i];
  for(int i=1;i<=N;i++) if(G[i].size()==0) w.push_back(i);
  while(!w.empty()){
    ll W = w.front();
    w.pop_front();
    dfs(W);
  }
  /*
  for(int i=1;i<=N;i++){
    std::cout << "now" << i << " " <<  num[i][0] << " " << num[i][1] << '\n';
  }*/
  std::cout << "POSSIBLE" << '\n';
  return 0;
}


Measured memory_bytes: 1656
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
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; }

#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(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll n;
	in(n);

	outn(pow(n, 3));

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
map<int,int>mp;
int a[300000];
int ans[300000];
int tri(int n){
    return n*(n-1)/2;
}
signed main(){
    int n;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    int cnt=0;
    for(auto x:mp){
        cnt+=tri(x.second);
    }
    for(auto x:mp){
        int nor=tri(x.second);
        int sma=tri(x.second-1);
        ans[x.first]=cnt-(nor-sma);
    }
    rep(i,n){
        cout<<ans[a[i]]<<endl;
    }
    return 0;
}


Measured memory_bytes: 13056
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Double> A = new ArrayList<Double>();
        ArrayList<Double> B = new ArrayList<Double>();
        int N = sc.nextInt();
        // int D = sc.nextInt();
        double ans = 0;
        for (int i = 0; i < N; i++) {
            ans += sc.nextDouble() * (sc.next().equals("JPY") ? 1.0 : 380000.0);
        }
        System.out.println(ans);
    }
}

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

int main()
{
    ll n;
    cin >> n;
    map<string, bool> m;
    ll count = 0;
    rep(i, n)
    {
        string s;
        cin >> s;
        if (m.count(s) == 0)
        {
            count++;
            m[s] = true;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 19204
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

string s;
string t;

int main()
{
	cin >> s;
	cin >> t;
	int slen = s.length();
	int tlen = t.length();
	vector<string>v;

	for (int i = slen - 1; i >= tlen - 1; i--) {
		int ope = 0;
		string ans = s;
		for (int j = i; j >= i - tlen + 1; j--) {
			if (s[j] != t[tlen - 1 - (i - j)] && s[j] != '?') {
				ope++; break;
			}
		}
		if (ope == 0) {
			for (int j = i; j >= i - tlen + 1; j--) {
				ans[j] = t[tlen - 1 - (i - j)];
			}
			for (int i = 0; i < slen; i++) {
				if (ans[i] == '?')ans[i] = 'a';
			}
			v.push_back(ans);
		}
	}
	/*
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << endl;
	}
	*/
	if (v.empty()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	sort(v.begin(), v.end());

	cout << v[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

int a, b, c, d1;
LL res;

int main() {
scanf("%d %d %d", &a, &b, &c);
d1 = min(b, c);
res += 2LL * d1;
b -= d1;
c -= d1;
if (c == 0) res += b;
else {
	d1 = min(a, c);
	res += d1;
	a -= d1;
	c -= d1;
	if (c > 0) res++;
}
cout << res << endl;
return 0;
}



Measured memory_bytes: 256
use whiteread::parse_line;

fn fight(hp: usize) -> usize {
    match hp {
        1 => 1,
        _ => fight(hp / 2) * 2 + 1,
    }
}

fn main() {
    let h: usize = parse_line().unwrap();
    println!("{}", fight(h));
}


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

int main(){
  long N;cin >> N;
  long ans=0,exp=1;
  vector<vector<long>> sl(10,vector<long>(10,0));
  for(int i=1; i<=N; i++){
    if(i/exp>9)exp*=10;
    int s=i/exp,l=i%10;
    sl[s][l]++;
  }
  for(int i=1; i<10; i++){
    for(int j=1; j<10; j++){
      ans+=sl[i][j]*sl[j][i];
    }
  }
  cout << ans << endl;
}

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

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long long ,long long >
#define pi pair<int ,int >
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define ct(i) cout<< i << "\n"
#define sv(v) sort(v.begin(),v.end())
#define mod 1000000007
#define M 100005
#define endl "\n"


void solve(){
    ll n,m,ans=0,x,y,k,m1=0,m2=0;
    cin>>n>>m>>k;
    set<pair<ll,ll>> pa;
    ll f[3*M]={},s[3*M]={};
    for(int i=0;i<k;i++){
        cin>>x>>y;
        pa.insert({x,y});
        f[x]++;
        s[y]++;
        m1=max(m1,f[x]);
        m2=max(m2,s[y]);
    }
    ll v1=0,v2;
    for(int i=0;i<3*M;i++){
        if(m1==f[i]) v1=i;
        if(m2==s[i]) v2=i;
    }
    for(int i=0;i<3*M;i++){
        ll tem1 = f[i]+m2-pa.count({i,v2});
        ll tem2 = s[i]+m1-pa.count({v1,i});
        ans = max({ans,tem1,tem2});
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int q;
    //cin>>q; while(q--)
        solve();
    return 0;
}


Measured memory_bytes: 27104
#include <bits/stdc++.h>
using namespace std;
#define long long int int
#define endl '\n'
int comp(const void* a, const void* b)  
{ return *(int*)a > *(int*)b ; }  
  
// Function to count all possible triangles with arr[]  
// elements
int findNumberOfTriangles(int arr[], int n)  
{  
    // Sort the array elements in non-decreasing order  
    qsort(arr, n, sizeof( arr[0] ), comp);  
  
    // Initialize count of triangles  
    int count = 0;  
  
    // Fix the first element. We need to run till n-3  
    // as the other two elements are selected from  
    // arr[i+1...n-1]  
    for (int i = 0; i < n - 2; ++i)  
    {  
        // Initialize index of the rightmost third  
        // element  
        int k = i + 2;  
  
        // Fix the second element  
        for (int j = i + 1; j < n; ++j)  
        {  
            // Find the rightmost element which is  
            // smaller than the sum of two fixed elements  
            // The important thing to note here is, we  
            // use the previous value of k. If value of  
            // arr[i] + arr[j-1] was greater than arr[k],  
            // then arr[i] + arr[j] must be greater than k,  
            // because the array is sorted.  
            while (k < n && arr[i] + arr[j] > arr[k])  
            ++k;  
  
            // Total number of possible triangles that can  
            // be formed with the two fixed elements is  
            // k - j - 1. The two fixed elements are arr[i]  
            // and arr[j]. All elements between arr[j+1]/ to  
            // arr[k-1] can form a triangle with arr[i] and arr[j].  
            // One is subtracted from k because k is incremented  
            // one extra in above while loop.  
            // k will always be greater than j. If j becomes equal  
            // to k, then above loop will increment k, because arr[k]  
            // + arr[i] is always greater than arr[k]  
            if(k > j)  
            count += k - j - 1;  
        }  
    }  
  
    return count;  
}  
int main()
{
    int n,s=0,j=0,k=1;
    cin>>n;
    int l[n],m[n][n]={0};
    for(int i=0;i<n;i++)
    {
        cin>>l[i];
    }
    sort(l,l+n);
    cout<<findNumberOfTriangles(l,n); 
    return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int K,A,B,i;
  scanf("%d",&K);
  scanf("%d%d",&A,&B);
  for(i=1;i<=1000;i++)
  {
    if(A<=K*i&&K*i<=B)
    {
      printf("OK");
      exit(0);
    }
  }
  printf("NG");
}

Measured memory_bytes: 1732
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

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

    cout << (n % 2 == 0 ? n / 2 : (n / 2) + 1);

    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
charge = 0
score = 0
for i in range(n):
    if s[i] == 'g':
        if charge > 0:
            score += 1
            charge -= 1
        else:
            charge += 1
    else:
        if charge > 0:
            charge -= 1
        else:
            score -= 1
            charge += 1

print(score)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define MAXN 100005
using namespace std;
//scp_05_tqr(也就是大号的提交，别棕qwq)
int x[MAXN],bb[MAXN],w[MAXN];
int i,j,k,l,r,s,t,n,m;
ll c;

template<class T>inline void read(T &res)
{
	static char ch;T flag=1;
	while((ch=getchar())<'0'||ch>'9')if(ch=='-')flag=-1;res=ch-48;
	while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;res*=flag;
}

int main()
{
	read(n);read(l);read(t);
	for (int i=1;i<=n;i++)
    	scanf("%d%d",&x[i],&w[i]);
    for (int i=1;i<=n;i++)
    {
        if (w[i]==2)
        	w[i]=-1;
        r=x[i]+w[i]*t;
        if (r>0)
        	(c+=r/l)%=n;
        else if (r<0) (c+=(r+1)/l-1)%=n;
        bb[i]=(r%l+l)%l;
    }
    sort(bb+1,bb+n+1);
    c=(c+n)%n;
    for (int i=c+1;i<=n;i++)
    	printf("%d\n",bb[i]);
    for (int i=1;i<=c;i++)
    	printf("%d\n",bb[i]);
    return 0;
}

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

int main() {
    int a;
    cin >>a;
    if(a==1){
        cout<<"Hello World"<<endl;
    }
    if(a==2){
        int b,c;
        cin >>b>>c;
        cout<<c+b<<endl;   
    }
}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,a[10000],i,j=0,k;
    scanf("%d",&n);
    for(i=3;i<=n;i++){
        if(i%3==0){
            a[j]=i;
            j++;
        }else{
            k=i;
            while(1){
                if(k%10==3){
                    a[j]=i;
                    j++;
                    break;
                }
                if(k/10==0)break;
                k=k/10;
            }
        }
    }
    for(i=0;i<j;i++){
        printf(" %d",a[i]);
    }
	 printf("\n");
  return 0;
}



Measured memory_bytes: 2112
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
int n;
int main(void) {
    cin>>n;
    cout << n / 3 << endl;
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
s = list(input())
s_ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = s
for i in range(len(s)):
    fd = s_.find(s[i]) + n
    if fd >= 26:
        fd -= 26
    ans[i] = s_[fd]
print(''.join(ans))

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    
    int min = 1000000;
    int max = -1000000;
    long long int sum = 0;
    for (int i = 0; i < n; i++)
    {
        int m;
        cin >> m;
        if (m < min)
        {
            min = m;
        }
        if (max < m)
        {
            max = m;
        }
        sum += m;
    }
    
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
const long long LINF=1e18;
 
signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  if(!v[0])fin(0);
  int a=1;
  for(int i=0;i<n;i++){
    if(LINF/a+100<v[i])fin(-1);
    a*=v[i];if(a>LINF)fin(-1);
  }
  fin(a);
}

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

typedef long long ll;
typedef long double ld;

int niz[10005];

const int MOD = 1000000007;

ll mul(ll a, ll b){
    return ((ll)a*b)%MOD;
}

ll add(ll a, ll b){
    return (a+b)%MOD;
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n, k;
    cin >> n >> k;
    int res = 0;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
        for(int j=1; j<i; j++){
            if(niz[i] < niz[j]) res++;
        }
    }
    res = mul(res, k);
    ll jos = 0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(niz[i] > niz[j]){
                jos = add(jos, (ll)k*(k-1)/2);
            }
        }
    }
    res = add(res, jos);
    cout << res;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();
        int ans = solve(P, Q, R);

        System.out.println(ans);
    }

    private static int solve(int P, int Q, int R) {
        return Math.min(P+Q, Math.min(Q+R, R+P));
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long

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

	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	for (int i = 0; i < y2-y1; i++)
	{
		cout << "U";
	}
	for (int i = 0; i < x2 - x1; i++)
	{
		cout << "R";
	}
	for (int i = 0; i < y2 - y1; i++)
	{
		cout << "D";
	}
	for (int i = 0; i < x2 - x1; i++)
	{
		cout << "L";
	}
	cout << "L";
	for (int i = 0; i < y2 - y1+1; i++)
	{
		cout << "U";
	}
	for (int i = 0; i < x2 - x1+1; i++)
	{
		cout << "R";
	}
	cout << "D";
	cout << "R";
	for (int i = 0; i < y2 - y1+1; i++)
	{
		cout << "D";
	}
	for (int i = 0; i < x2 - x1+1; i++)
	{
		cout << "L";
	}
	cout << "U";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import string

n = int(input())

Ans = [[] for _ in range(n+1)]
Ans[1].append('a')
Strs = [x for x in string.ascii_lowercase]

for i in range(1,n):
    for ans in Ans[i]:
        Use_str = [x for x in ans]
        Use_str = set(Use_str)
        for moji in Use_str:
            add = ans + moji
            Ans[i+1].append(add)
        add = ans + Strs[len(Use_str)]
        Ans[i+1].append(add)

Answer = sorted(Ans[n])
for ans in Answer:
    print(ans)

Measured memory_bytes: 16148
ss = raw_input()
X=map(int, raw_input().split(' '))
N = []
S = []

dR = dict()
for n in range(len(X)) + [len(X)]:
    if n >= len(X): k = -100
    else: 
        #print n
        k = X[n]
    while len(S) > 0 and k < S[-1][1]:
        dR[S[-1][0]] = n - S[-1][0]
        S.pop()

    S.append((n, k))

dL = dict()
for n in list(reversed(range(len(X)))) + [-1]:
    if n < 0: k = -100
    else: 
        k = X[n]
    while len(S) > 0 and k < S[-1][1]:
        dL[S[-1][0]] = abs(n - S[-1][0])
        S.pop()
    S.append((n, k))


ts = 0
for n in xrange(len(X)):
    left = dL[n]
    right = dR[n]
    ts += ((left-1) * (right-1) + left + right - 1) * X[n]

print ts


Measured memory_bytes: 60408
#include <iostream>
#include <algorithm>

long long find(long long, long long);

long long find(long long a, long long b) {
	if (a < b) {
		return std::min(a, b - a);
	}
	else {
		return find(a % b, b);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	
	long long a;
	long long b;
	std::cin >> a >> b;

	std::cout << find(a, b);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>

using namespace std;

bool cmp1(pair<int, pair<int, long long int> > a, pair<int, pair<int ,long long int> > b) {
    if(a.second.first!=b.second.first) {
        return a.second.first<b.second.first;
    } else {
        return a.second.second<b.second.second;
    }
}
bool cmp2(pair<int, pair<int, long long int> > a, pair<int, pair<int ,long long int> > b) {
    return a.first<b.first;
}

int main() {
    int N, M;
    cin >> N >> M;
    
    vector<pair<int, pair<int, long long int> > > recpy;
    vector<pair<int, pair<int, int> > > ans;
    
    for(int i=0; i<M; i++) {
        int p;
        long long int y;
        cin >> p >> y;
        
        recpy.push_back(make_pair(i, make_pair(p, y)));
    }
    
    sort(recpy.begin(), recpy.end(), cmp1);
    
    int pp=recpy[0].second.first;
    int count=1;
    for(int i=0; i<M; i++) {
        if(pp==recpy[i].second.first) {
            ans.push_back(make_pair(recpy[i].first, make_pair(pp, count)));
            count++;
        } else {
            count=1;
            pp=recpy[i].second.first;
            ans.push_back(make_pair(recpy[i].first, make_pair(pp, count)));
            count++;
        }
    }
    
    sort(ans.begin(), ans.end(), cmp2);
    
    for(int i=0; i<M; i++) {
        printf("%06d%06d\n", ans[i].second.first, ans[i].second.second);
    }

    return 0;
    
}

Measured memory_bytes: 6896
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


int count(u32 x)
{
    int ret = 0;
    while (x)
    {
        if (x & 1) ++ret;
        x >>= 1;
    }
    return ret;
}

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

    int n;
    cin >> n;
    string s;
    map<char, s64> m;
    rep (i, n)
    {
        cin >> s;
        ++m[s[0]];
    }

    s = "MARCH";
    s64 ans = 0;
    rep (i, (1 << 5))
    {
        if (count(i) == 3)
        {
            int temp = i;
            int cnt = 0;
            s64 sum = 1;
            while (temp)
            {
                if (temp & 1)
                {
                    sum = (sum * m[s[cnt]]);
                }
                ++cnt;
                temp >>= 1;
            }
            ans = (ans + sum);
        }
    }

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



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

int main(){
  const long mod = 1000000007;
  long n, k;
  cin >> n >> k;
  long ans = 0, min = n * (n + 1) / 2, max = min;
  for(long i = n + 1; i >= k; i--){
    ans += max - min + 1;
    ans %= mod;
    max -= n + 1 - i;
    min -= i - 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
//Code by: Nikhil Shukla, MMMUT GKP
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define V vector
#define pb push_back
#define all x x.begin(),x.end()
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc ll t; cin>>t; while(t--)
#define tc1 ll tt=1; while(tt--)
#define fir first
#define sec second
#define mod 998244353
#define out1(x) cout<<x<<"\n";
#define out2(x,y) cout<<x<<" "<<y<<"\n";
#define debug() cout<<"I am in\n";
#define Vll vector<long long>
#define FOR(i,x,n) for(ll i=x;i<n;i++)
#define RFOR(i,x,n) for(ll i=x;i>=n;i--)
////////////////////////////////////////////////////////////////////////////////////////
/*vector<ll>graph[100001];
vector<ll>temp;
vector<bool>visited(100001,false);
//long long count=0;
void dfs(long long node)
{
       // count++;
        temp.pb(node);
        visited[node]=1;
        for(ll i=0;i<graph[node].size();i++)
        {
            if(!visited[graph[node][i]])
            dfs(graph[node][i]);
        }
}*/
void solve(string a,string b)
{
    ll i,j;
    ll n=a.length();
    ll m=b.length();
    ll lcs[n+1][m+1];
    for(i=0;i<=m;i++)
    lcs[0][i]=0;
    for(i=0;i<=n;i++)
    lcs[i][0]=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(a[i-1]==b[j-1])
            lcs[i][j]= 1+lcs[i-1][j-1];
            else
            lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
    }
    string ans;
    for(i=n,j=m;i>0,j>0;)
    {
        if(a[i-1]==b[j-1])
        {
            ans.push_back(a[i-1]);
            i--;
            j--;
        }
        else if(lcs[i-1][j]>lcs[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}
int main()
{
    fast()
    tc1
    {
        string a,b;
        cin>>a>>b;
        solve(a,b);
    }
    return 0;
}


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

int main() {
    string S; cin >> S;
    vector<int> cnt(26);
    ll ans = 1;
    rep(i, 0, S.size()) {
        cnt[S[i] - 'a']++;
        ans += i;
        ans -= (cnt[S[i] - 'a'] - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define endl '\n'

int n,a,b;
vector<vector<int>> adj;
vector<int> db;

void dfs1(int v = b, int p = -1, int cur = 0){
    db[v] = cur;
    for (int c : adj[v]){
        if (c == p) continue;
        dfs1(c, v, cur+1);
    }
}

int dfs2(int v = a, int p = -1, int cur = 0, int distb = 0){
    int ans = cur + db[a] - distb - 1;
    for (int c : adj[v]){
        int distc = distb + 2 * (db[c] < db[v]);
        if (c == p || distc >= db[a]) continue;
        ans = max(ans, dfs2(c, v, cur+1, distc));
    }
    return ans;
}

void solvetask(){
    cin >> n >> a >> b;
    adj.resize(n+1);
    db.resize(n+1);
    for (int i=1; i<n; i++){
        int u,v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1();
    cout << dfs2() << endl;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solvetask();
}

Measured memory_bytes: 14216
from bisect import bisect_left, bisect_right  # return index
from math import ceil, floor

N, H = map(int, input().split())
A, B = [], []

for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

amax = max(A)
B = sorted(B)
ix = bisect_right(B, amax)
l = [amax] + B[ix:]
l = list(reversed(l))

if sum(l) > H:
    cnt = 0
    for i in range(len(l)):
        cnt += l[i]
        if cnt >= H:
            print(i + 1)
            exit()
else:
    cnt = len(l)
    amari = H - sum(l)
    cnt += ceil(amari / amax)
    print(cnt)

Measured memory_bytes: 18804
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  string S,T;
  cin >> S >> T;
  int ans = 0;
  for(int i = 0;i < 3;i++) {
    if(S.at(i) == T.at(i)) ans++;
  }

  cout << ans << endl;
}



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

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	const T init;
	const F f;
	int sz;
	vector<T> seg;
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	void add(int id, T x){
		id += sz;
		seg[id] += x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

int main() {
	int n, q; cin >> n >> q;
	SegmentTree<int> seg(n, (1ll<<31)-1, [](int a, int b){return min(a,b);});
	while(q--) {
		int com, x, y; cin >> com >> x >> y;
		if(com == 0) seg.replace(x, y);
		else cout << seg.get(x, y+1) << "\n";
	}
	return 0;
}


Measured memory_bytes: 3852
N,M = map(int, input().split(" "))
XList = list(map(int,input().split()))

XList = sorted(XList)
deltaList = [0]

for i in range(M-1) :
    deltaList.append(XList[i+1] - XList[i])
deltaList = sorted(deltaList, reverse=True)


for i in range(N-1) :
    deltaList[i] = 0
    if i == len(deltaList)-1 :
        break
print(sum(deltaList))

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

void solve(){
    char a;
    cin>>a;
    if(a>=65 && a<97){
        cout<<"A\n";
    }
    else{
        cout<<"a\n";
    }
}

int32_t main(){
    fastio
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n;cin>>n;
	string s; cin>>s;
	//cout<<"PPP"<<endl;
	vector<bool> so(10,false);
	vector<int> fom(n);
	fom[n-1] = 1;
	so[s[s.size()-1]-'0'] = true;
	for(int i = s.size()-2; i>=0; --i){
		if(!so[s[i]-'0']){
			fom[i] = fom[i+1]+1;
			so[s[i]-'0'] = true;
		}else{
			fom[i] = fom[i+1];
		}
	}
	vector<bool> al(110,false);
	int ans = 0;
	rep(i,n-2){
		for(int j = i+1; j<n-1; j++){
			int ch = (s[i]-'0')*10+s[j]-'0';
			if(!al[ch]){ans += fom[j+1]; al[ch] = true;}
		}
	}
	cout<<ans<<endl; return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main(void){
  long int x;
  long int hp=0;
  int voo=0;
  int v=0;
  scanf("%ld",&x);

  while(x>=500){
    x=x-500;
    hp=hp+1000;
  }
  while(x>=5){
    x=x-5;
    hp=hp+5;
  }
  printf("%d",hp);
  return 0;
  }

Measured memory_bytes: 1704
#include<stdio.h>

int adj[102][102],d[102],f[102],visited[102],n,time;

void DFS(int s){
	if(visited[s])return;

	int i;
	++time;
	d[s]=time;	visited[s]=1;

	for(i=1;i<=n;i++){
		if(adj[s][i]==1)DFS(i);
	}

	++time;
	f[s]=time;
}

int main(){
	int i,j,u,k,v;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d",&v);
			adj[u][v]=1;
		}
	}

	for(i=1;i<=n;i++)DFS(i);

	for(i=1;i<=n;i++){
		printf("%d %d %d\n",i,d[i],f[i]);
	}

	return 0;
}



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

int main() {
  int n; cin >> n;
  map<string, int> cnt_map;
  string ans = "Yes";

  char last_char = '\0';
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    
    if (last_char != '\0' && last_char != s[0]) {
      ans = "No";
      break;
    }
    last_char = s[s.size() - 1];
    
    if (cnt_map[s] != 0) {
      ans = "No";
      break;
    }
    ++cnt_map[s];
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
People = [[] for i in range(N)]
Language = [[] for i in range(M)]
for i in range(N):
    language = list(map(int, input().split()))[1:]
    for l in language:
        l -= 1
        People[i].append(l)
        Language[l].append(i)


people_visited = [False] * N
language_visited = [False] * M


stack = [(0, 'people')]
while stack:
    n, n_type = stack.pop()

    if n_type == 'people':
        people_visited[n] = True
        for to in People[n]:
            if language_visited[to]:
                continue
            stack.append((to, 'language'))

    elif n_type == 'language':
        language_visited[n] = True
        for to in Language[n]:
            if people_visited[to]:
                continue
            stack.append((to, 'people'))

print('YES' if all(people_visited) else 'NO')


Measured memory_bytes: 44036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

long long lb = 0, ub = 0;
string s;

bool C1(long long c) {
	string ss;
	cout << c << endl;
	cin >> ss;
	if (ss == "Vacant") exit(0);
	if ((s == ss && lb%2 == c%2) || (s != ss && lb%2 != c%2)) {
		// cout << (s == ss && lb%2 == c%2) << " " << (s != ss && lb%2 != c%2) << " aaa" << endl;
		s = ss;
		return true;
	} else {
		return false;
	}
}

int main(){	
	ll N;
	cin >> N;
	cout << lb << endl;
	cin >> s;
	if (s == "Vacant") exit(0);
	ub = N;
	while (ub - lb > 1) {
		long long mid = (lb + ub) / 2;
		if (C1(mid)) lb = mid;
		else ub = mid;
	}
	return 0;
}



Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


int main(){
    string s;   cin >> s;
    int k; cin >> k;

    vector<vector<vector<ll>>> dp(s.size(), vector<vector<ll>>(k+1, vector<ll>(2, 0LL)));
    dp[0][0][0] = 1;
    dp[0][1][0] = s[0] - '0' - 1;
    dp[0][1][1] = 1;
    for(int i = 1; i < s.size(); i++){
        for(int j = 0; j <= k; j++){
            if(s[i] - '0' == 0){
                dp[i][j][1] += dp[i-1][j][1];
                dp[i][j][0] += dp[i-1][j][0];
                if(j+1 <= k){
                    dp[i][j+1][0] += dp[i-1][j][0] * 9;
                }
            }
            else{
                if(j+1 <= k){
                    dp[i][j+1][1] += dp[i-1][j][1];
                    dp[i][j+1][0] += (s[i] - '0' - 1) * dp[i-1][j][1];
                    dp[i][j+1][0] += 9 * dp[i-1][j][0];
                }
                dp[i][j][0] += dp[i-1][j][0];
                dp[i][j][0] += dp[i-1][j][1];
            }
//            cout << i << " " << j << " " << dp[i][j][0] << " " << dp[i][j][1] << endl;
        }
    }


    cout << dp[s.size()-1][k][0] + dp[s.size()-1][k][1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;

const int maxn = 20;
const int maxm = 1<<19;
const int mod = 1e9+7;

int dp[2][maxm],op;
int nex[maxn][maxm];
int lim[maxn][maxn];
int n,m,K,S;

void inc(int &x,int y) {
	x+=y;x>=mod?x-=mod:0;
}
int main()
{
	#ifdef Amberframe
		freopen("agc017f.in","r",stdin);
		freopen("agc017f.out","w",stdout);
	#endif
	scanf("%d %d %d",&n,&m,&K);S=1<<n-1; 
	for (int i=0;i<n-1;i++)
	for (int j=0;j<S;j++)
	if (j>>i&1) nex[i][j]=j^(1<<i);
	else {
		nex[i][j]=j^(1<<i);
		int k=i+1;while (k<n-1&&!(j>>k&1)) ++k;
		if (k<n-1) nex[i][j]^=1<<k;
	}
	
	for (int i=0;i<m;i++)
	for (int j=0;j<n-1;j++) lim[i][j]=-1;
	for (int a,b,c,i=1;i<=K;i++)
		scanf("%d %d %d",&a,&b,&c),lim[a-1][b-1]=c;
		
	for (int j=0;j<S;j++)
	{
		bool tag=true;
		for (int k=0;k<n-1;k++)
		if (j>>k&1) {
			if (lim[0][k]==0) tag=false;
		}
		else {
			if (lim[0][k]==1) tag=false;
		}
		if (tag) dp[0][j]=1;
	}
	for (int i=1;i<m;i++)
	for (int k=0;k<n-1;k++) {
		op^=1;
		for (int j=0;j<S;j++)
		if (int w=dp[op^1][j]) {
			dp[op^1][j]=0;
			if (j>>k&1) {
				if (lim[i][k]!=0)
					inc(dp[op][j],w);
			}
			else {
				if (lim[i][k]!=1)
					inc(dp[op][j],w);
				if (lim[i][k]!=0)
					inc(dp[op][nex[k][j]],w);
			}
		}
	}
	int ans=0;
	for (int j=0;j<S;j++)
		inc(ans,dp[op][j]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 45312