akhauriyash/Code-Regression huggingface dataset:
def main():
    N, K = map(int, input().split())
    S = input()

    ary = [0]
    t = S[0]
    for s in S:
        if s == t:
            ary[-1] += 1
        else:
            ary.append(1)
            t = s

    ans = sum(ary[:K*2+1])-1
    for i in range(K*2+1, len(ary)):
        ans += ary[i]-1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46064
#include<iostream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>

using namespace std;

int main() {
	int l, r;
	cin >> l >> r;
	int ans = 2019;
	if (r - l > 2019)cout << 0;
	else{
		for (int i = l; i < r; i++) {
			for (int j = i + 1; j <= r; j++) {
				//cout << i << " "<<j << endl;
				int lef, ri;
				lef = i % 2019;
				ri = j % 2019;
				//cout << i * j << endl;
				if ((lef*ri) % 2019 < ans)ans = (lef*ri) % 2019;
			}
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  int sum=0;
  
  vector<int> W(N);
  for(int i=0;i<N;i++){
    cin>>W[i];
    sum+=W[i];
  }
  
  int ans=100000;
  
  int sum_1=0;
  
  for(int i=0;i<N;i++){
      sum_1+=W[i];
      
    int sum_2=sum-sum_1;
    
    ans=min(abs(sum_1-sum_2),ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
k, s = gets.strip.split.map(&:to_i)
count = 0
(0..k).each do |x|
  (0..k).each do |y|
    if s-x-y >= 0 && s-x-y <= k
      count+=1 if s == x+y+(s-x-y)
    end
  end
end
puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, ans=0, i, j, k, tmp;
    vector<long long> l;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> tmp;
        l.push_back(tmp);
    }
    sort(l.begin(), l.end());
    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
            for(k=j+1;k<n;k++){
                if(l[i]<l[j]+l[k] && l[j]<l[i]+l[k] && l[k]<l[i]+l[j]) ans++;
            }
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class AtCoderC
{
    private static long a;
    private static long b;
    private static long c;
    private static long d;

    static void Main()
    {
        {
            string line = Console.ReadLine();
            var words = line.Split(' ');
            a = long.Parse(words[0]);
            b = long.Parse(words[1]);
            c = long.Parse(words[2]);
            d = long.Parse(words[3]);
        }

        long lcm = Lcm(c, d);
        long answer1 = b - b / c - b / d + b / lcm;
        long answer2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;
        long answer = answer1 - answer2;

        Console.WriteLine(answer);
    }


    // 最小公倍数（long）
    private static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }

    // 最大公約数（long）
    private static long Gcd(long a, long b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            long r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> tmp(H + 2, vector<int>(W + 2));
    rep(i, H + 2) {
        rep(j, W + 2) {
            tmp[i][j] = 0;
        }
    }
    for (int i = 1; i < H + 1; i++) {
        for (int j = 1; j < W + 1; j++) {
            char s;
            cin >> s;
            if (s == '#') {
                tmp[i][j] = 1;
            }
        }
    }
    for (int i = 1; i < H + 1; i++) {
        for (int j = 1; j < W + 1; j++) {
            if (tmp[i][j] == 1) {
                cout << '#';
                continue;
            }
            int ans = tmp[i - 1][j - 1] + tmp[i][j - 1] + tmp[i + 1][j - 1] + tmp[i - 1][j] + tmp[i + 1][j] + tmp[i - 1][j + 1] + tmp[i][j + 1] + tmp[i + 1][j + 1];
            cout << ans;
        }
        cout << '\n';
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int ans = 0;
  int tmp = 0;
  for (int i = 0; i < n - 1; i++) {
    if (arr[i+1] <= arr[i]) tmp++;
    else tmp = 0;
    ans = max(ans, tmp);
    // cout << ans << " " << tmp << " " << arr[i] << " " << arr[i+1] << '\n'; 
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n;
string a[10],b[10];
string y,d;

int dfs(int cur,string in){
	if(in.size()>=d.size()){
		if(in==d)
			return cur;
		else
			return inf;
	}
	int res=inf;
	rep(i,n){
		string next=in;
		string::size_type pos = next.find(a[i]);
		while(pos != string::npos){
 			next.replace(pos, a[i].size(), b[i]);
			pos = next.find(a[i], pos + b[i].size());
		}
		if(in!=next)
			res=min(res,dfs(cur+1,next));
	}
	return res;
}

int main(void){
	while(cin >> n){
		if(n==0)
			break;
		rep(i,n) cin >> a[i] >> b[i];
		cin >> y >> d;
		int res=dfs(0,y);
		if(res==inf)
			cout << -1 << endl;
		else
			cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<int> a(n + 1), b(n);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];

    int ans = 0;
    for(int i = n - 1; i >= 0; i--){
        int x = min(a[i+1], b[i]);
        ans += x;
        b[i] -= x;

        x = min(a[i], b[i]);
        ans += x;
        a[i] -= x;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum,ans, dp[10000][2], a[110000],b[110000];
string str, ss;
bool f[100];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<LL>v;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (a[i] >= 3200) {
			ans++;
			cnt++;
		}
		else if (f[a[i] / 400] == 0) {
			f[a[i] / 400] = 1;
			ans++;
		}
	}
	cout<< max(ans-cnt,(LL)1) <<" " << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

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

	int x, t;
	cin >> x >> t;

	cout << max(x - t, 0) << endl;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<int> x(3);
	for (int i=0; i<3; i++) cin>>x[i];
	sort(x.begin(), x.end(), greater<int>());
	cout << x[0]*10 + x[1] + x[2] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l, A[1000000], n;
vector<int> G;

//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g) {
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while(j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	//数列G = {1, 4, 13, 40, 121, 364, 1093, ...}
	for (int h = 1; ; ) {
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}

	for (int i = G.size() - 1; i >= 0; i--) { //逆順にG[i] = gを指定
		insertionSort(A, n, G[i]);
	}
}

int main() {
	cin >> n;
	//より速い入力scanf関数を使用
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) printf("%d\n", A[i]);

	return 0;
}


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

int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;
  
  if (op == "-"){
   cout << A - B << endl;
  }
  
  else if(op == "+"){
    cout << A + B << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int cc[305];
int dp[305][305][305];
int pre[305][305];
int suf[305][305];
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
     cout.tie(0);   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif
 
// -------------------------------------Code starts here---------------------------------------------------------------------     

   fill_n(&dp[0][0][0],305*305*305,1e17);
   dp[0][0][0]=0;
   int n,k;
   cin>>n>>k;
   int h[n+1];
   for(int i=1;i<=n;i++)
   {
      cin>>h[i];
      cc[i]=h[i];
   }

   sort(cc+1,cc+n+1);
   cc[n+1]=1e17;
   fill_n(&pre[0][0],305*305,1e17);
   fill_n(&suf[0][0],305*305,1e17);
   pre[0][0]=cc[n];
   for(int j=1;j<=n;j++)
   {
      pre[j][0]=cc[n];
   }
   suf[0][0]=0;
   for(int i=1;i<=n;i++)
   {
      for(int j=0;j<=n;j++)
      {
         for(int l=0;l<=k;l++)
         {
            if(cc[j]==h[i])
            {
               dp[i][j][l]=min(suf[j][l],pre[j][l]-(cc[n]-cc[j]));
            }
            else
            {
               if(l>0)
                  dp[i][j][l]=min(suf[j][l-1],pre[j][l-1]-(cc[n]-cc[j]));
            }
         }
      }
      fill_n(&pre[0][0],305*305,1e17);
      fill_n(&suf[0][0],305*305,1e17);
      for(int l=0;l<=k;l++)
      {
         for(int j=0;j<=n;j++)
         {
            if(j==0)
               pre[j][l]=dp[i][j][l]+cc[n];
            else
               pre[j][l]=min(dp[i][j][l]+cc[n]-cc[j],pre[j-1][l]);  
         }
      }
      for(int l=0;l<=k;l++)
      {
         for(int j=n;j>=0;j--)
         {
            suf[j][l]=min(dp[i][j][l],suf[j+1][l]);
         }
      }
   }

   int mn=1e17;
   for(int i=0;i<=n;i++)
      for(int j=0;j<=k;j++)
         mn=min(mn,dp[n][i][j]);
   cout<<mn;


// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }
 

Measured memory_bytes: 223360
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  int a,b,c;
  cin>>a>>b;
  co(a-b+1);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a, b, ans;

int main()
{
	cin >> a >> b;
	
	for(int i=0; i <= a; i++)
		for(int h=0; h <= a; h++)
			if(b-i-h >= 0 && b-i-h <= a)
				ans++;
	
	cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll ans = 0;
  if (A >= K) {
    ans = K;
  } else if (A + B >= K) {
    ans = A;
  } else {
    ans = A - (K - (A + B));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <limits>//setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
long long MOD = 1000000007;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    long long N;cin >> N;
    if(N == 0){
        cout << 0 << endl;
        return 0;
    }
    string ans = "";
    long long div = 1;
    while(N){
        if(N % (2*abs(div)) != 0){
            ans += "1";
            N -= div;
        }
        else{
            ans += "0";
        }
        div *= -2;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 3672
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    if n == 7 || n == 5 || n == 3 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

struct Data{
    ll v;
    ll m;
    ll t;
    Data(ll v, ll m, ll t):v(v), m(m), t(t){}
    bool operator<(const Data& a) const{
        return t > a.t;
    }
};
struct edge{
    ll to, rate, time;
    edge(ll to, ll rate, ll time):to(to), rate(rate), time(time){}
};

int main() {
    ll N, M, S;
    cin >> N >> M >> S;
    ll tmp1, tmp2, a, b;
    vector<vector<edge>> e(N);
    REP(i, M){
        cin >> tmp1 >> tmp2 >> a >> b;
        tmp1--;
        tmp2--;
        e[tmp1].push_back(edge(tmp2, a, b));
        e[tmp2].push_back(edge(tmp1, a, b));
    }
        //cout << "Hi" << endl;
    vector<P> convert(N);
    REP(i, N){
        cin >> a >> b;
        convert[i] = P(a, b);
    }
    vector<vector<ll>> dp(51, vector<ll>(2505, INF));
    priority_queue<Data> q;
    q.push(Data(0, min(2504, S), 0));

    while(!q.empty()){
        Data hoge = q.top();
        q.pop();
        if (hoge.t < dp[hoge.v][hoge.m]){
            dp[hoge.v][hoge.m] = hoge.t;
            
            if (hoge.m + convert[hoge.v].first < 2501)q.push(Data(hoge.v, hoge.m + convert[hoge.v].first, hoge.t + convert[hoge.v].second));
            for(auto e: e[hoge.v]){
                if (hoge.m - e.rate >= 0 && hoge.t + e.time < dp[e.to][hoge.m - e.rate]) q.push(Data(e.to, hoge.m - e.rate, hoge.t + e.time));
            }
        }
    }

    REP(i, N-1){
        ll tmp = INF;
        REP(j, 2505) tmp = min(tmp, dp[i+1][j]);
        cout << tmp << endl;
    }



    return 0;
}


Measured memory_bytes: 10084
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

ll cnt[26];

void solve()
{
       ll n; cin>>n;
       string s;
       cin>>s;
       for(char x:s)
       {
              cnt[x-'a']++;
       }
       ll ans = 1;
       rep(i,0,26)
       {
              ans = (ans*(cnt[i]+1))%mod;
       }
       ans = (ans-1+mod)%mod;
       cout<<ans;
}


int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 512
#ifdef HIRO
#include "../stdc++.h"
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#include <bits/stdc++.h>
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;

int main() {
#ifdef HIRO
  string file_path(QUIZ);
  ifstream cin(file_path + "/input.txt");
  std::cin.rdbuf(cin.rdbuf());
#endif
  int n;
  // int m;
  cin >> n;
  // cin >> m;
  long x[n];
  long min = 100000000000;
  int ans = 0;
  for(int i =0;i<n;i++) {
    cin >> x[i];
    if(x[i] <= min) {
      ans++;
      min = x[i];
    }

  }


  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n;
	cin >> n;
	ll a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	reverse(a, a + n);
	ll ma = a[n - 1], ans = 0;
	for (int i = n - 2; i >= 0; i--){
		if (a[i] < ma){
			ans += ma - a[i];
		}else{
			ma = a[i];
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 5252
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,n;
	cin>>a>>b>>c>>d;
	if(c<b){
		if(a<=c&&b<d)
		n=b-c;
		else if(a<=c&&b>d)
		n=d-c;
		else if(a>c&&b>d&&a<d)
		n=d-a;
		else if(a>c&&b<d)
		n=b-a;
		else if (a==c&b==d)
        n=d-a;
        else if (a>c&&b==d)
        n=d-a;
        else if (a<c&&b==d)
        n=d-c;
        else if (a>c&&a==d)
        n=0;
		else if(a>c&&a>d)
		n=0;
	}

    else if(c>=b)
    n=0;
    cout<<n;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;

#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define ROF(i, a, b) for(int i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

int main(){
    FAST
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> red, green, colourless;
    ll val;
    FOR(i,1,a){
        cin >> val;
        red.pb(val);
    }
    FOR(i,1,b){
        cin >> val;
        green.pb(val);
    }
    FOR(i,1,c){
        cin >> val;
        colourless.pb(val);
    }

    sort(ALL(red), greater<ll>());
    sort(ALL(green), greater<ll>());
    sort(ALL(colourless), greater<ll>());

    vector<ll> eaten;
    FOR(i,0,x-1) eaten.pb(red[i]);
    FOR(i,0,y-1) eaten.pb(green[i]);

    sort(ALL(eaten));
    ll sz = (ll)(colourless.size())-1;

    FOR(i,0,sz){
        if (colourless[i] > eaten[i]) eaten[i] = colourless[i];
        else break;
    }

    ll ans=0;
    sz = (ll)(eaten.size())-1;
    FOR(i,0,sz){
        ans+=eaten[i];
    }
    cout << ans;
}

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

int main()
{
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
    scanf("%d",&n);
    int array[n];
    int i,j;
    int ans=0;

    for(i=1;i<=n;i++){
        scanf("%d",&array[i]);
    }

    for(i=1;i<n;i++){
        for(j=i+1;j<=n;j++){
            ans+=array[i]*array[j];
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let mut ans = 0f64;
    for i in 1..(n + 1) {
        let mut p = 1.0;
        let mut v = i;
        while v < k {
            p /= 2.0;
            v *= 2;
        }
        ans += p;
    }
    ans /= n as f64;
    println!("{:.10}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main()
{
	int a[33] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << a[k-1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n, a, b;
	scanf("%d", &n);
	scanf("%d %d", &a, &b);
	int flag=0;
	for(int i=a; i<=b; i++){
		if(i%n==0){
			printf("OK\n");
			flag=1;
			break;
		}
	}
	if(flag==0){
		printf("NG\n");
	}
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N, M; cin >> N;
	vvint S = makeVector(N, N, 0);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			char c; cin >> c;
			S[i][j] = c-'0';
		}
	}
	int ans = -1;
	for (int s = 0; s < N; s++) {
		queue<int> que;
		vint mc(N, -1);
		mc[s] = 1; que.emplace(s);
		int maxv = 1;
		while (!que.empty()) {
			int u = que.front(); que.pop();
			bool flag = false;
			for (int v = 0; v < N; v++) {
				if (!S[u][v]) continue;
				if (mc[v] == -1) {
					mc[v] = mc[u]+1;
					chmax(maxv, mc[v]);
					que.emplace(v);
					continue;
				}
				if (mc[v] != mc[u]+1 && mc[v] != mc[u]-1) { flag = true; break; }
			}
			if (flag) break;
		}
		if (que.empty()) chmax(ans, maxv);
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3844
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,a[100005],ma[100005]={0},j=0,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(a[i]==a[i+1])ma[j]++;
		else{
			ma[j]++;
			j++;
		}
	}
	for(int l=0;l<n;l++){
		if(ma[l]%2==1)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  M1 += H1 * 60, M2 += H2 * 60;
  cout << max(M2 - M1 - K, 0) << endl;
}


Measured memory_bytes: 3604
Sz=list(input())
T=list(input())
Flag=0

for i in range(len(Sz)-len(T),-1,-1):
    Flag=1
    for s in range(len(T)):

        if not (Sz[i+s]=="?" or Sz[i+s]==T[s]):
            Flag=0
            break
    if Flag:
        for s in range(len(T)):
             Sz[i+s]=T[s]
        break
for i in range(len(Sz)):
    if Sz[i]=="?":Sz[i]="a"

if Flag:print("".join(Sz))
else:print("UNRESTORABLE ")


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

int main(){
    int D, G;
    cin >> D >> G;
    vector<vector<int>> board(D, vector<int>(3));//得点、問題数、ボーナスを入力する二次元配列
    for(int i=0;i<D;i++){//入力
        board.at(i).at(0) = 100*(i+1); //得点
        cin >> board.at(i).at(1) >> board.at(i).at(2);
    }

    int result = 100000;
    //bit全探索でどのボーナスを取るか決めてその後点数が高い順に入れていく
    for(int bit=0;bit < (1<<D); bit++){
        int sum = 0;
        int count = 0;
        for(int i=0;i<D;i++){//対応する問題を全て取り、ボーナスを獲得する
            if(bit & (1<<i)){
                sum += board.at(i).at(0) * board.at(i).at(1) + board.at(i).at(2);
                count += board.at(i).at(1);   
            }
        }
        if(sum >= G){
            if(result > count) result = count;
        }

        for(int i=D - 1;i>=0;i--){//sumがGを超えるまで点数が高い順に追加していく
            if(!(bit & (1<<i))){//ボーナスを獲得していない問題群について実行 
                for(int j=1;j<=board.at(i).at(1);j++){
                    sum += board.at(i).at(0);
                    
                    if(j == board.at(i).at(1)) sum += board.at(i).at(2);//問題が最大まで行ったらボーナス追加

                    count++;

                    if(sum >= G){
                        if(result > count) result = count;
                        break;
                    }
                }   

            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    int N,K;
    cin>>N>>K;
    string s;
    cin>>s;
    s[K-1]+='a'-'A';
    cout<<s<<endl;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int A = a + b;
    int B = c + d;
    string ans = "Balanced";
    if (A > B) ans = "Left";
    else if(A < B) ans = "Right";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, k;
    cin >> n >> k;
    int arr[n+1];
    int i;
    vector<int> vi;
    unordered_set<int> s1;
    for(i=0; i<n; i++){
        cin >> arr[i+1];
    }
    int currTown = 1;
    int flag = 0;
    vi.push_back(currTown);
    s1.insert(currTown);

    for(i=0; i<n; i++){
        currTown = arr[currTown];
        k -= 1;
        if(k==0){
            cout << currTown;
            flag = 1;
            break;
        }
        if(s1.find(currTown) != s1.end()){
            break;
        }
        else{
            vi.push_back(currTown);
            s1.insert(currTown);
        }
    }

    if(flag != 1){
        auto it = find(vi.begin(), vi.end(), currTown);
        int ind = it - vi.begin();
        currTown = vi[k%(vi.size()-ind)+ind];     
        cout << currTown;
    }
}

Measured memory_bytes: 11488
N = int(input())
S = list(input())

z_ascii = ord('Z')
a_ascii  = ord('A')-1
for s in range(len(S)):
    s_ascii = ord(S[s])
    s_ascii = s_ascii + N
    if s_ascii > z_ascii:
        s_ascii = s_ascii - z_ascii 
        s_ascii = a_ascii + s_ascii
    S[s] = chr(s_ascii)

print(*S,sep="")



Measured memory_bytes: 4724
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
#include <queue>
#include <tuple>

using namespace std;

int main(){

    int s;
    cin >> s;

    int num[4];
    for(int i = 3; i >= 0; i--){
        num[i] = s % 10;
        s /= 10;
     }
    
    int ans = num[0];
    char ope[3], pm[2] = {'+', '-'};
    int flag = 0;

    for(int i = 0; i < 2; i++){
        if(flag == 1) break;
        ope[0] = pm[i];    
        for(int j = 0; j < 2; j++){
            if(flag == 1) break;
            ope[1] = pm[j];
            for(int k = 0; k < 2; k++){
                if(flag == 1) break;
                ope[2] = pm[k];
                
                for(int l = 0; l < 3; l++){
                    if(ope[l] == '+'){
                        ans += num[l+1];
                    }else{
                        ans -= num[l+1];
                    }
                }
                if(ans == 7){
                    cout << num[0] << ope[0] << num[1] << ope[1] << num[2] << ope[2] << num[3] << "=7";
                    flag = 1;
                }
                ans = num[0];
                
            }
        }
    }


}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
const ll maxint=2e18;
const ll minint =-2e18;
/*******\
(͡ ° ͜ʖ ͡ °) : Hello there, relax.
\*     */

int main(){
    string s;
    cin>>s;
    if(s == "RRR"){
        cout<<3<<'\n';

    }else if(s=="SSS"){
        cout<<0<<'\n';
    }else if(s[1]=='R'){
        if(s[0]=='R' || s[2]=='R'){
            cout<<2<<'\n';
        }else 
        cout<<1<<'\n';
    }else{
        cout<<1<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3596
n=int(input())
*a,=map(int, input().split())
from collections import Counter
ca=Counter(a)
q=int(input())
sm=sum(a)
for _ in range(q):
    bi,ci=map(int, input().split())
    if ci in ca:
        if bi in ca:
            sm+=(ci-bi)*ca[bi]
            ca[ci]+=ca[bi]
            del ca[bi]
    else:
        if bi in ca:
            sm+=(ci-bi)*ca[bi]
            ca[ci]=ca[bi]
            del ca[bi]
    print(sm)
        
        

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n;
	string s, ans = "";
	cin >> n >> s;
	n /= 2;
	for (int i = 0; i < n; i++) {
		ans += s[i];
	}
	if (ans + ans == s ) cout << "Yes" << "\n";
	else cout << "No" << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int k , a , b ;
	cin>> k ;
	if( ! ( k & 1 )) a = ( k >> 1 ) ;
	else a = ( k >> 1 ) + 1 ;
	b = ( k >> 1 ) ;
	cout << a * b ;
	return 0;
 }


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

const int limit = 100001;
int memo[limit];

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

    fill(memo, memo+limit, 1e9+1);

    set<int> st;
    st.insert(1); memo[0] = 0;
    for(int i = 6; i <= n; i *= 6) {
        st.insert(i);
    }
    for(int i = 9; i <= n; i *= 9) {
        st.insert(i);
    }

    queue<int> que;
    que.push(0);
    while(!que.empty()) {
        int p = que.front(); que.pop();
        for(auto e : st) {
            if(p + e <= n && memo[p + e] > memo[p] + 1) {
                memo[p + e] = memo[p] + 1;
                que.push(p + e);
            }
        }
    }

    cout << memo[n] << endl;

    return 0;
}

Measured memory_bytes: 768
import sys

input = sys.stdin.buffer.readline

h, w = map(int, input().split())
AA = [list(map(int, input().split())) for _ in range(h)]
BB = [list(map(int, input().split())) for _ in range(h)]

kouho = [[0] * (w) for _ in range(h)]
delta = abs(AA[0][0] - BB[0][0])
kouho[0][0] |= 1 << delta
for y in range(h):
    for x in range(w):
        nx = x + 1
        ny = y
        if nx < w:
            delta = abs(AA[ny][nx] - BB[ny][nx])
            temp = 0
            for i in range(1, delta + 1):
                if (kouho[y][x] >> i) % 2:
                    temp |= 1 << (delta - i)
            # print(x,y,kouho[y][x],temp,delta)
            kouho[ny][nx] |= kouho[y][x] << delta
            kouho[ny][nx] |= kouho[y][x] >> delta
            kouho[ny][nx] |= temp

        nx = x
        ny = y + 1
        if ny < h:
            delta = abs(AA[ny][nx] - BB[ny][nx])
            temp = 0
            for i in range(1, delta + 1):
                if (kouho[y][x] >> i) % 2:
                    temp |= 1 << (delta - i)
            # print(x,y,kouho[y][x],temp,delta)
            kouho[ny][nx] |= kouho[y][x] << delta
            kouho[ny][nx] |= kouho[y][x] >> delta
            kouho[ny][nx] |= temp
# print(kouho)
for i in range(81):
    if (kouho[h - 1][w - 1] >> i) % 2:
        print(i)
        exit()

Measured memory_bytes: 83936
N = int(input())
S = list(map(int,input().split()))
counter = int(0)
minNum = S[0]

if N == 1:
  print("1")

else:
  for i in range(N):
    if minNum >= S[i]:
      minNum = S[i]
      counter = counter + 1
    
  print(counter)

Measured memory_bytes: 24744
#include <stdio.h>
#include <math.h>

int main()
{
    int n, i, j, k, buff[3];
    
    scanf("%d", &n);
    
    for (i = 1; i <= n; i++) {
        scanf("%d %d %d", buff, buff + 1, buff + 2);
        
        if (
            pow(buff[0], 2) == pow(buff[1], 2) + pow(buff[2], 2)
            || pow(buff[1], 2) == pow(buff[2], 2) + pow(buff[0], 2)
            || pow(buff[2], 2) == pow(buff[0], 2) + pow(buff[1], 2)
        ) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    
    return 0;
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

bool exist[10][10][10];

int main() {
    lli n;
    cin1(n);
    string s;
    cin1(s);
    vlli x[10];
    REP(i,0,n) {
        x[s[i]-'0'].push_back(i);
    }

    lli ans = 0;
    //REP(i,0,x[3].size()) {
    //    cout << x[3][i] << endl;
    //}
    REP(i,0,10) {
        lli loc = -1;
        // i がある最初を探す
        auto it1 = lower_bound(x[i].begin(), x[i].end(), loc+1);
        if (it1 == x[i].end())
            continue;
        loc = (*it1);
        //cout2(i, loc);

        REP(j,0,10) {
            lli loc2 = loc;
            auto it2 = lower_bound(x[j].begin(), x[j].end(), loc2+1);
            if (it2 == x[j].end())
                continue;
            loc2 = (*it2);
            //cout3(i, j, loc2);
            REP(k,0,10){
                lli loc3 = loc2;
                auto it3 = lower_bound(x[k].begin(), x[k].end(), loc2+1);
                if (it3 == x[k].end())
                    continue;
                ans++;
                //cout3(i,j,k);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<math.h>

int main(){
  int a, b;
  while(scanf("%d %d", &a, &b) != EOF){
    int gcd=1;
    int n = 2;
    while(a!=1 && b!=1){
      if(a%n==0 && b%n==0){
	a = a/n;
	b = b/n; 
	gcd = gcd * n;
      }
      else{
	if(n > a)
	  break;
	else
	  n++;}
    }
    printf("%d %d\n", gcd, a*b*gcd);
  }
  return 0;
}

Measured memory_bytes: 2664
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  //取り除く橋の最小値は,ai,biを仕事の始点・終点と思った時の区間スケジューリング問題と考えて求めればよい.
  //取ることのできる仕事の最大値が求める最小値になる.(ネットの証明参照.任意の仕事wiに対し,sjk<=ti<=tjkなる仕事wjkが存在する.)

  int N,M;
  cin >> N >> M;

  vector<pair<int,int>> w;

  for(int i = 0;i < M;i++){
    int a,b;
    cin >> a >> b;
    b--;
    w.push_back(make_pair(b,a));
  }

  sort(w.begin(),w.end());

  int ans = 0;
  int t = 0;
  for(int i = 0;i < M;i++){
    if(t < w[i].second){
      ans++;
      t = w[i].first;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1400
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

//??°?????????????????°

void function()
{
	//??¢??°
}

int main()
{
	int n, m;
	int a[100][100];
	int b[100];

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

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

	for (int i = 0; i < n; i++)
	{
		int ans = 0;
		for (int j = 0; j < m; j++)
		{
			ans += a[i][j] * b[j];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] T = new int[5];
		int[] AT = new int[5];
		int[] TAT = new int[5];
		
		int max = 0;
		
		for(int i = 0; i < 5; i++) {
			T[i] = sc.nextInt();
			if(T[i] % 10 != 0) {
				AT[i] = 10 - (T[i] % 10);
			} else {
				AT[i] = 0;
			}
			TAT[i] = T[i] + AT[i];
			if(max <= AT[i] ) {
				max = AT[i];
			}
		}
		
		int sum = 0;
		
		for(int i = 0; i < 5; i++) {
			sum += TAT[i];
		}
		
		sum -= max;
		
		System.out.println(sum);
		
	}
}


Measured memory_bytes: 21844
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

template<typename T>
T upmin(const T& l, const T& r) {//SegmentTreeのupdate関数
    T res;
    res = min(l,r);
    return res;
}
template<typename T>
T upmax(const T& l, const T& r) {//SegmentTreeのupdate関数
    T res;
    res = max(l,r);
    return res;
}

template<typename T>
class SegmentTree {
public:
    using F = function<T(T&, T&)>;
    vector<T> seg;
    int sz = 1;
    T unit;
    F up;
    //T (*up)(const T& l,const T& r);
    SegmentTree(int n, F up, T unit = 0) {
        this->unit = unit;
        //int sz = 1;
        while (sz < n) sz <<= 1;
        seg.resize(sz * 2, unit);
        this->up = up;
    }
    void set(const int& k, const T& x) {//左からk番目の葉にxを代入する
        seg[sz - 1 + k] = x;
    }
    T get(const int& k) {//左からk番目の葉を得る
        return seg[sz - 1 + k];
    }
    void update(int k, const T& v) {// k 番目の値をvに変更
        k += sz - 1;
        seg[k] = v;
        while (k > 0) {
            k = (k - 1) / 2;
            seg[k] = up(seg[2 * k + 1], seg[2 * k + 2]);
        }
    }
    T query(int a, int b, int k, int l,int r) {//[a,b)のupの合成を求める(a,b,0,0,sz)のように使う
        if (r <= a || b <= l) {
            return unit;
        }
        if (a <= l && r <= b) {
            return seg[k];
        }
        else {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return up(vl, vr);
        }
    }
};

int main(){
    int n;
    cin >> n;
    vector<P> p(n);
    REP(i,n){
        cin >> p[i].first;
        p[i].second = i;
    }
    sort(all(p));
    
    SegmentTree<int> sgmin(n,upmin<int>,n);
    SegmentTree<int> sgmax(n,upmax<int>,-1);
    ll res = 0;
    int sz = sgmin.sz;
    Rep(i,n){
        int t = p[i].second-sgmax.query(0,p[i].second,0,0,sz);
        int t2 = sgmin.query(p[i].second+1,sz,0,0,sz)-p[i].second;
        res+=(double)t*t2*(i+1);
        sgmax.update(p[i].second,p[i].second);
        sgmin.update(p[i].second,p[i].second);
    }
    put(res);
    return 0;
}


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

int main() {
  long double A, B, H, M;
  cin >> A >> B >> H >> M;
  long double  pi, dh, dm, div, raddiv,czizyou;
  bool flag = true;
  pi = 2.00000000000 * asin(1.0);
  dm = 6.00000000000 * M;
  dh = 30.00000000000 * H + M * 0.50000000000;
  /*radh = pi / dh;
  radm = pi / dm;*/
  if( dm == dh ) {
    if( A >= B ) {
      cout << A - B << endl;
    }
    else {
      cout << B - A << endl;
    }
    flag = false;
  }
  div = dh - dm;
  if( div < 0) {
    div = -1.00000000000 * div;
  }
  if( div == 180.0) {
    cout << A + B << endl;
    flag = false;
  }
  if( div > 180.00000000000) {
    div = 360.00000000 - div;
  }
  raddiv = div * pi / 180.000000000000;
  czizyou = A * A + B * B - 2.0000000000000000 * A * B * cos(raddiv);
  if(flag) {
    cout << fixed << setprecision(20) << sqrt(czizyou) << endl;
  }
}
  
  
  
  

Measured memory_bytes: 4060