akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define ll long long int


int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v[3];
    set<int> r,g,b;
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            v[0].push_back(i);
            r.insert(i);
        }
        else if(s[i]=='G'){
            v[1].push_back(i);
            g.insert(i);
        }
        else{
            v[2].push_back(i);
            b.insert(i);
        }
    }
    //for(auto w:b) cout<<w<<endl;
    for(int i=0;i<v[0].size();i++){ //r
        for(int j=0;j<v[1].size();j++){ //g
            if(v[0][i]>=v[1][j]) continue;
            int d = lower_bound(v[2].begin(),v[2].end(),v[1][j]+1)-v[2].begin();
            //cout<<d<<endl;
            ans+=v[2].size()-d;
            if(b.count(2*v[1][j]-v[0][i])){
                ans--;
            }

        }
    }
    for(int i=0;i<v[1].size();i++){ //r
        for(int j=0;j<v[0].size();j++){ //g
            if(v[1][i]>=v[0][j]) continue;
            int d = lower_bound(v[2].begin(),v[2].end(),v[0][j]+1)-v[2].begin();
            //cout<<d<<endl;
            ans+=v[2].size()-d;
            if(b.count(2*v[0][j]-v[1][i])){
                ans--;
            }

        }
    }
    for(int i=0;i<v[0].size();i++){ //r
        for(int j=0;j<v[2].size();j++){ //b
            if(v[0][i]>=v[2][j]) continue;
            int d = lower_bound(v[1].begin(),v[1].end(),v[2][j]+1)-v[1].begin();
            //cout<<d<<endl;
            ans+=v[1].size()-d;
            if(g.count(2*v[2][j]-v[0][i])){
                ans--;
            }

        }
    }
    for(int i=0;i<v[2].size();i++){ //r
        for(int j=0;j<v[0].size();j++){ //b
            if(v[2][i]>=v[0][j]) continue;
            int d = lower_bound(v[1].begin(),v[1].end(),v[0][j]+1)-v[1].begin();
            //cout<<d<<endl;
            ans+=v[1].size()-d;
            if(g.count(2*v[0][j]-v[2][i])){
                ans--;
            }

        }
    }
    for(int i=0;i<v[1].size();i++){ //g
        for(int j=0;j<v[2].size();j++){ //b
            if(v[1][i]>=v[2][j]) continue;
            int d = lower_bound(v[0].begin(),v[0].end(),v[2][j]+1)-v[0].begin();
            //cout<<d<<endl;
            ans+=v[0].size()-d;
            if(r.count(2*v[2][j]-v[1][i])){
                ans--;
            }

        }
    }
    for(int i=0;i<v[2].size();i++){ //g
        for(int j=0;j<v[1].size();j++){ //b
            if(v[2][i]>=v[1][j]) continue;
            int d = lower_bound(v[0].begin(),v[0].end(),v[1][j]+1)-v[0].begin();
            //cout<<d<<endl;
            ans+=v[0].size()-d;
            if(r.count(2*v[1][j]-v[2][i])){
                ans--;
            }

        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3828
N = int(input())

q = []
visited = [0] * N
ans = [0] * N
A = [[] for _ in range(N)]  # tree
W = [[] for _ in range(N)]  # weight

for i in range(N-1):
    u,v,w = map(int, input().split())
    u -= 1
    v -= 1
    A[u].append(v)
    A[v].append(u)
    W[u].append(w)
    W[v].append(w)

q.append(0)  # start
for _ in range(N):
    u = q.pop(0)
    visited[u] = 1
    k = 0
    for v in A[u]:
        if visited[v]==0:
            q.append(v)
            ans[v] = ans[u] + W[u][k]
        k += 1

for a in ans:
    print(a%2)

Measured memory_bytes: 42736
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pb push_back
#define pq priority_queue
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vvll vector<vector<ll>>
#define vvi vector<vector<int>>
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define MODNUM 1000000007
#define lp(i,a,b) for(ll i=a; i<b; i++)
#define all(v) v.begin(), v.end()

using namespace std;
 
ll mex(ll a, ll b, ll m) {
	if(b==0) return 1;
	if(b%2) return a*mex((a*a)%m,(b-1)/2,m)%m;
	else return mex((a*a)%m,b/2,m);
}
 
int x,y;
void exteu(ll a, ll m) {
	if(m==0) { x=1;y=0; }
	else {
		exteu(m,a%m);
		ll temp = x;
		x=y;
		y=temp-(a/m)*y;
	}
}
 
ll fact(ll n) 
{	ll prod=1;
	for(ll i=2; i<=n; i++) {
		prod*=i;
	}
	return prod;
}
 
ll gcd(ll a, ll b) {
	if(b==0) return a;
	return gcd(b, a%b);
}
 
// bool isprime[100001];
// void makesieve() {
// 	memset(isprime, true, sizeof(isprime));
// 	for (int i = 2; i <= sqrt(200000); ++i)
// 	{
// 		if(isprime[i]) {
// 			for (int j = i*i; j <= 200000; j+=i)
// 			{
// 				isprime[j]=false;
// 			}
// 		}
// 	}
// }
// 
// 1 2 4 5 8
vvll D = {{-1,-1}, {1,1}, {1,-1}, {-1,1}};
void solve() {
	ll n; cin>>n;
	// ll i=0; vll a(3,2);
	vll c(n+1,0);
	for (ll i =1; i <= 144; ++i)
	{
		for (ll j = 1; j <= 144; ++j)
		{
			for (ll k = 1; k <= 144; ++k)
			{
				ll s = ((i+j)*(i+j) + (j+k)*(j+k) + (k+i)*(k+i));
				if(s%2==0) {
					s/=2;
					if(s <= n) {
						// cout<<i<<" "<<j<<" "<<k<<" "<<s<<endl;
						c[s]++;
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<c[i]<<endl;
	}
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1;
	// cin >> TESTS;
	// makesieve();
	while(TESTS--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

typedef unsigned int ui;

ui trans(string s){
  ui res = 0, k = 1, tmp;
  for(int i=7;i>=0;i--){
    if('0'<=s[i] && s[i]<='9')tmp = s[i]-'0';
    else tmp = s[i]-'a' + 10;
    res += k*tmp; k*=16;
  }
  return res;
}

int main(){
  int q; string s; ui u;
  cin >> q;
  for(int x=0;x<q;x++){
    cin >> s;
    u = trans(s);
    double ans = 0,k = 1.0/(1<<7);
    for(int i=0;i<31;i++){
      ans += k * ((u>>i)&1U); k *= 2;
    }
    if(((u>>31)&1U))ans *= -1;

    cout.precision(20);
    cout << ans;
    if(!(u&((1U<<7)-1)))cout << ".0";
    cout << endl;
  }
}

Measured memory_bytes: 1284
use std::cmp::{max,min};
fn main() {
    let (d,g) = {
        let s=rv::<usize>();
        (s[0],s[1]/100)
    };
    let mut pc=Vec::with_capacity(d);
    for _ in 0..d {
        let s=rv::<usize>();
        pc.push((s[0],s[1]/100));
    }
    let m=pc.iter().map(|pc|pc.0).sum::<usize>();
    let mut dp = vec![0;m+1];
    for (i,(p,c)) in pc.into_iter().enumerate() {
        let i=i+1;
        for j in (1..m+1).rev() {
            if j>=p {
                dp[j]=max(dp[j],dp[j-p]+i*p+c);
            }
            for k in 1..min(p,j+1) {
                dp[j]=max(dp[j],dp[j-k]+i*k);
            }
        }
    }
    for i in 1..m+1 { if dp[i]>=g {
        println!("{}",i);
        break;
    }}
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using std::cin;
using std::cout;
typedef long long ll;
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e6 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
struct str
{
	int cnt, *addr;
	bool operator<(str A) const { return cnt < A.cnt; }
} d[Maxn];
int Disc(int t)
{
	rg int tmp = 0;
	std::sort(d + 1, d + t + 1);
	for (int i = 1; i <= t; i++)
	{
		if (i == 1 || d[i].cnt != d[i - 1].cnt)
			d[++tmp] = d[i];
		*d[i].addr = tmp;
	}
	return tmp;
}
int prime[Maxn], cnt, ans;
bool P[Maxn];
ll A, B;
ll gcd(ll x, ll y)
{
	ll z = x % y;
	while (z)
	{
		x = y;
		y = z;
		z = x % y;
	}
	return y;
}
int main()
{
	for (int i = 2; i <= 1000000; i++)
	{
		if (!P[i])
			prime[++cnt] = i;
		for (int j = 1; j <= cnt && i * prime[j] <= 1000000; j++)
		{
			P[i * prime[j]] = true;
			if (i % prime[j] == 0)
				break;
		}
	}
	rg ll x;
	cin >> A >> B;
	x = gcd(A, B);
	for (int i = 1; i <= cnt && x != 1; i++)
		if (x % prime[i] == 0)
		{
			ans++;
			while (x % prime[i] == 0)
				x /= prime[i];
		}
	if (x != 1)
		ans++;
	cout << ans + 1 << '\n';
	return 0;
}
//D

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b,int c){
	return __gcd(__gcd(a,b),c);
}
int main(){
	int k,ans = 0;
	cin >> k;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			for(int g = 1; g <= k; g++){
				ans += gcd(i,j,g);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<pair<int, int>> dp(n+1);
    set<pair<int, int>> q;
    dp[0] = {0, -1};
    q.insert({0, 0});
    for (int i = 1; i <= n; i++) {
        if (s[i] == '0' && !q.empty()) {
            auto it = q.begin();
            int d = it->first + 1;
            dp[i] = {d, it->second};
            q.insert({d, i});
        } else {
            dp[i] = {-1, -1};
        }
        int j = i-m;
        if (j >= 0) {
            q.erase({dp[j].first, j});
        }
    }
    if (dp[n].first == -1) {
        cout << -1 << endl;
    } else {
        int v = n;
        vector<int> ans;
        while (v != 0) {
            int from = dp[v].second;
            ans.push_back(v-from);
            v = from;
        }
        reverse(ans.begin(), ans.end());
        for (int d: ans) {
            cout << d << " ";
        }
    }
}


Measured memory_bytes: 6516
#include<iostream>
#include<vector>
#include<algorithm>
#define inf 1000000009
using namespace std;
int main(){
	int n,W;
	cin>>n>>W;
	vector<long long > dp(W+1);
	for(int i=0;i<n;i++){
		int w,v;
		cin>>w>>v;
		for(int j=W-w;j>=0;j--){
			dp[j+w]=max(dp[j+w],dp[j]+v);
		}
	}
	long long ans=0;
	for(int i=0;i<=W;i++){
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    bool x;
    cin >> x;
    cout << !x << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)

int main(){
    set<string> x,y,z;
    int N;
    string S;
    cin >> N >> S;
    FOR(i,0,S.size()){
        string a = "2";
        a[0] = S[i];
        for(auto b:y){
            z.insert(b+a);
        }
        for(auto b:x){
            y.insert(b+a);
        }
        x.insert(a);
    }
    cout << z.size() << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string.h>

// nCrを求める式
int compination (int n, int r) {
  int answer = 1;
  for (int i = 1; i <= n; i++) {
    answer = answer * i;
  }  
  for (int i = 1; i <= r; i++) {
    answer = answer / i;
  }
  for (int i = 1; i <= n-r; i++) {
    answer = answer / i;  
  }
  return answer;
}

int main () {
  int sx,sy,tx,ty;
  std::cin >> sx >> sy >> tx >> ty;
  
  int x = tx - sx;
  int y = ty - sy;

  // std::cout << compination(x+y,y) << std::endl;
  std::string answer = "";
  for (int j = 0; j < 2; j++) {
    
    if (j == 1) {
      answer = answer + "L";  
    }
    for (int i = 0; i < y; i++ ){
      answer = answer + "U";  
    }
    if (j == 1) {
      answer = answer + "UR";  
    }
    for (int i = 0; i < x; i++) {
      answer = answer + "R";  
    }
    if (j == 1) {
      answer = answer + "DR";  
    }
    for (int i = 0; i < y; i++) {
      answer = answer + "D";  
    }
    if (j == 1 ){
      answer = answer + "DL";  
    }
    for (int i = 0; i < x; i++) {
      answer = answer + "L";  
    }
    if (j == 1) {
      answer = answer + "U";  
    }
  }
  std::cout << answer << std::endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	int ans=0;
	for(int v=(1<<28);v;v>>=1){
		for(int i=0;i<n;i++){
			a[i]&=(v*2-1);
			b[i]&=(v*2-1);
		}
		sort(a.begin(),a.end());
		sort(b.begin(),b.end());
		int t=0;
		for(int i=n-1,j=0,k=0,l=0;i>=0;i--){
			while(j<n&&a[i]+b[j]<v)j++;
			while(k<n&&a[i]+b[k]<2*v)k++;
			while(l<n&&a[i]+b[l]<3*v)l++;
			t+=k-j+n-l;
			t&=1;
		}
		if(t)ans|=v;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
int dp[MAX_N];

int main2() {
  CLR(dp, 0);
  const int INF = 1001001001;
  REP(i, MAX_N) dp[i] = INF;
  dp[0] = 0;
  for (int i = 0; i+1 < MAX_N; i++) {
    chmin(dp[i+1], dp[i]+1);
    for (int j = 6; i+j < MAX_N; j *= 6) chmin(dp[i+j], dp[i]+1);
    for (int j = 9; i+j < MAX_N; j *= 9) chmin(dp[i+j], dp[i]+1);
  }
  int N = nextInt();
  cout << dp[N] << endl;

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 640
// ConsoleApplication3.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include "bits/stdc++.h"

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

using namespace std;

int main() {
	string s;
	int K;
	cin >> s >> K;
	int N = s.size();
	vector<string> vec;
	rep1(len, K) {
		rep(i, N + 1 - len) {
			vec.pb(s.substr(i, len));
		}
	}
	sort(all(vec));
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	cout << vec[K - 1] << endl;
}

Measured memory_bytes: 1660
N,L=gets.chomp.split(' ').map{|n| n.to_i}
sum = (L-1)*N+(N+1)*N/2
if(L+1-1 <= 0 && 0 <= L+N-1)
	puts sum
elsif(L+N-1 < 0)
	puts sum-(L+N-1)
else
	puts sum-(L+1-1)
end



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

const int N=300100,M=20;

int a[N],dp[N],dq[N],b[M],V,n,le[M][N],ri[M][N],c[N];
int m;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>V;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(;V>>m;++m)b[m]=V>>m;
	for(int i=0;i<=m;++i){
		ri[i][n]=n;ri[i][n+1]=n+1;
		for(int j=n-1;j;--j)
			ri[i][j]=(a[j+1]-a[j]<=b[i]?ri[i][j+1]:j);
		le[i][0]=0;le[i][1]=1;
		for(int j=2;j<=n;++j)
			le[i][j]=(a[j]-a[j-1]<=b[i]?le[i][j-1]:j);
	}
	fill(dq,dq+N,n+1);
	for(int i=1;i<(1<<m);++i)
		for(int j=0;j<m;++j)
			if(i>>j&1){
				dp[i]=max(dp[i],ri[j+1][dp[i-(1<<j)]+1]);
				dq[i]=min(dq[i],le[j+1][dq[i-(1<<j)]-1]);
				dp[i]=min(dp[i],n);
				dq[i]=max(dq[i],1);
			}
	for(int i=0;i<(1<<m);++i){
		int l=dp[i]+1,r=dq[(1<<m)-1-i]-1;
		if(r<=ri[0][l]){
			if(l>r)++c[1];
			else ++c[l],--c[r+1];
		}
	}
	for(int i=1;i<=n;++i){
		c[i]+=c[i-1];
		cout<<(c[i]?"Possible\n":"Impossible\n");
	}
	return 0;
}


Measured memory_bytes: 53120
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    bool even = true;
    int a;
    REP(i, n) {
        cin >> a;
        if (a % 2 != 0) even = false;
    }
    cout << (even ? "second" : "first") << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    ll N, K;
    cin >> N >> K;

    vector<ll> dv = {0};
    for (int n = 1; n * n <= N; ++n) {
        if (n * (n + 1) > N) {
            dv.push_back(n);
        }
        else {
            dv.push_back(n);
            dv.push_back(N / n);
        }
    }
    sort(all(dv));

    // 隣り合うことのできる数字の数: divisor[size - i - 1]

    int M = dv.size() - 1;
    vv<ll> dp = vvec(K + 1, M, 0LL);
    dp[0][0] = 1;
    rep(i, K) {
        ll sum = 0;
        for (int j = M - 1; j >= 0; --j) {
            sum = (sum + dp[i][M - j - 1] % MOD) % MOD;
            dp[i + 1][j] = (dv[j + 1] - dv[j]) * sum % MOD;
        }
    }

    ll ans = 0;
    rep(j, M) ans = (ans + dp[K][j]) % MOD;
    write(ans);
}

Measured memory_bytes: 51448
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
w,h,n = gets.chomp.split.map(&:to_i)

left = bottom = 0
right = w
up = h
n.times do
  x,y,a = gets.chomp.split.map(&:to_i)
  if a == 1
    left = [left,x].max
  elsif a == 2
    right = [right,x].min
  elsif a == 3
    bottom = [bottom, y].max
  elsif a == 4
    up = [up, y].min
  end
end

puts [(up-bottom), 0].max * [(right - left), 0].max


Measured memory_bytes: 2556
import heapq
n, m = map( int, input().split() )
adj_list = [ [] for i in range( n+1 ) ]
for _ in range( m ):
    a, b, c = map( int, input().split() )
    adj_list[ a ].append( ( b, c ) )
    adj_list[ b ].append( ( a, c ) )

# dijkstra
def dijkstra( start ):
    prev_node = [ -1 ] * ( n + 1 )
    INF = 10 ** 10
    VISITED = 1
    NOT_VISITED = 0
    cost = [ INF ] * ( n + 1 )
    cost[ start ] = 0
    visit = [ NOT_VISITED ] * ( n + 1 )
    queue = [ ( cost[ start ], start ) ]
    while len( queue ) > 0:
        c, v = heapq.heappop( queue )
        visit[ v ] = VISITED
        for u, cost_vu in adj_list[v]:
            if visit[ u ] == VISITED:
                continue
            if cost[u] > cost[v] + cost_vu:
                cost[u] = cost[v] + cost_vu
                heapq.heappush( queue, ( cost[u], u ) )
                prev_node[ u ] = v
    return prev_node

used_edge = [ [ False ] * ( n+1 ) for i in range( n+1 ) ]

used_count = 0
for s in range( 1, n+1 ):
    prev_node = dijkstra( s )
    for i in range( 1, n+1 ):
        j = prev_node[ i ]
        if j == -1:
            continue
        if used_edge[ i ][ j ] == False:
            used_count += 1
            used_edge[ i ][ j ] = True
            used_edge[ j ][ i ] = True

print( m - used_count )

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  bool is_ordered = true;
  int prev = -1e6 - 5;
  int ma = -1e6 - 5;
  int ma_idx;
  int mi = 1e6 + 5;
  int mi_idx;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] > ma) {
      ma_idx = i;
      ma = a[i];
    }

    if (a[i] < mi) {
      mi_idx = i;
      mi = a[i];
    }
    if (a[i] < prev) is_ordered = false;
    prev = a[i];
  }

  if (is_ordered) {
    printf("%d\n", 0);
    return 0;
  }

  vector< pair<int, int> > ans;

  int add;
  int add_idx;
  bool reverse = false;
  if (abs(ma) >= abs(mi)) {
    add = ma;
    add_idx = ma_idx;
  } else {
    add = mi;
    add_idx = mi_idx;
    reverse = true;
  }
  for (int i = 0; i < n; ++i) ans.push_back(make_pair(add_idx + 1, i + 1));

  if (reverse) {
    for (int i = n - 1; i >= 1; --i) ans.push_back(make_pair(i + 1, i));
  } else {
    for (int i = 1; i < n; ++i) ans.push_back(make_pair(i, i + 1));
  }

  cout << ans.size() << endl;
  for (auto e: ans) cout << e.first << " " << e.second << endl;
  return 0;
}



Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

A, B, C, D = MII_split()

while True:
    C -= B
    if C <= 0:
        print('Yes')
        exit()
    A -= D
    if A <= 0:
        print('No')
        exit()

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

int main() {
    long long N,A,B,C,D,E;
    cin >> N >> A >> B >> C >> D >> E;

    long long ans = 0;
    cout << max({(N - 1)/ A,(N - 1)/ B,(N - 1)/ C,(N - 1)/ D,(N - 1)/ E}) + 5 << endl;
}


Measured memory_bytes: 256
A,B=(input().split(' '))
A=int(A)
B=int(B)
AplusB=A+B
AminusB=A-B
AmultiplyB=A*B
ans=AplusB if AplusB>AminusB else AminusB
ans=ans if ans>AmultiplyB else AmultiplyB
print(ans)


Measured memory_bytes: 2940
from collections import defaultdict

N, M = map(int, input().split())

prime = defaultdict(int)
m = M
for i in range(2, 10 ** 5):
    while m % i == 0 and m > 1:
        prime[i] += 1
        m //= i

if m > 1:
    prime[M] = 1
MOD = 10 ** 9 + 7

def comb(n, k):
    a = 1
    for i in range(1, k + 1):
        a *= n - i + 1
        a %= MOD
        
        a *= pow(i, MOD - 2, MOD)
        a %= MOD
        
    return a

ans = 1
for _, t in prime.items():
    ans *= comb(N - 1 + t, t)
    ans %= MOD
    
print(ans)



Measured memory_bytes: 38512
#include "bits/stdc++.h"
using namespace std;

// #define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  // array<int, 10000> A;
  // string S;
  // string T;

  int H, W;

  array<array<char, 100>, 100> A;

  cin >> H >> W;
  for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) cin >> A[i][j];

  
  bool changed = true;

  while (changed) {
    changed = false;

    for (int i = 0; i < H; ++i) {
      bool flag = true;
      
      for (int j = 0; j < W; ++j) if (A[i][j] == '#') flag = false;
      
      if (flag) {
        flag = false;
        for (int j = 0; j < W; ++j) if (A[i][j] == '.') flag = true;
      }

      if (flag) {
        for (int j = 0; j < W; ++j) A[i][j] = ' ';
        changed = true;
        break;
      } 
    }

    if (changed) continue;

    for (int j = 0; j < W; ++j) {
      bool flag = true;

      for (int i = 0; i < H; ++i) if (A[i][j] == '#') flag = false;

      if (flag) {
        flag = false;
        for (int i = 0; i < H; ++i) if (A[i][j] == '.') flag = true;
      }

      if (flag) {
        for (int i = 0; i < H; ++i) A[i][j] = ' ';
        changed = true;
        break;
      }
    }

    if (changed) continue;
  }
  
  // while (changed){
  //   changed = false;

  //   if (H <= 1 && W <= 1) break;
    
  //   for (int i = 0; i < H; ++i) {
  //     int flag = true;
  //     for (int j = 0; j < W; ++j) if (A[i][j] != '.') flag = false;
  //     if (flag) {
  //       for (int k = i + 1; k < H; ++k) for (int j = 0; j < W; ++j) A[k - 1][j] = A[k][j];
  //       H = H - 1;
  //       // H = max(H - 1, 1);
  //       changed = true;
  //       break;
  //     }
  //   }
    
  //   if (changed) continue;

  //   for (int j = 0; j < W; ++j) {
  //     int flag = true;
  //     for (int i = 0; i < H; ++i) if (A[i][j] != '.') flag = false;
  //     if (flag) {
  //       // for (int i = 0; i < H; ++i) for (int l = j + 1; l < W; ++l) A[i][l - 1] = A[i][l];
  //       W = W - 1;
  //       // W = max(W - 1, 1);
  //       changed = true;
  //       break;
  //     }
  //   }

  //   if (changed) continue;
  // }

  for (int i = 0; i < H; ++i) {
    int n = 0;
    for (int j = 0; j < W; ++j) {
      if (A[i][j] != ' ') {
        cout << A[i][j];
        ++n;
      }
    }
    if (n > 0) cout << endl;
  }
  
  // cin >> N;
  // for (auto it = A.begin(); it < A.begin() + N; ++it)
  //   cin >> *it;
  // for (auto it = A.begin(); it < A.begin() + N; ++it)
  //   if (*it % 2 == 0) ++num;
  // cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  lli H,W;
  cin>>H>>W;
  if (H%3==0 || W%3==0){
      cout <<0<<"\n";
      return 0;
  }else{
  lli ans=INF;
  REP(k,2){
    lli m=W/2;
    FORS(i,1,H-1){
        lli Smax=max(m*i,W*(H-i));
        if (W%2==1)Smax=max(Smax,(m+1)*i);
       lli Smin=min(m*i,W*(H-i));
        if (W%2==1)Smin=min(Smin,(m+1)*i);
        if (ans>Smax-Smin)ans=Smax-Smin;

    }
    swap(W,H);
  }
    cout <<min({H,W,ans})<<"\n";
  }
}

Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int q,cnt=0,t,f;
  cin >> s >> q;
  deque<char> dq;
  for(auto p:s) {
    dq.push_back(p);
  }
  while(q--) {
    int t;
    cin >> t;
    if(t==1) {
      cnt++;
    }
    else {
      int f;
      char c;
      cin >> f >> c;
      if(f==1) {
        if(cnt%2) {
          dq.push_back(c);
        }
        else {
          dq.push_front(c);
        }
      }
      else {
        if(cnt%2) {
          dq.push_front(c);
        }
        else {
          dq.push_back(c);
        }
      }
    }
  }
  if(cnt%2) {
    reverse(dq.begin(),dq.end());
  }
  for(auto p:dq) {
    cout << p;
  }
  cout << "\n";
}

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

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

using ll = long long;
using namespace std;

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

    cout << n*(n-1) / 2 + m*(m-1) / 2 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
int main(){
int i,j,l, k[6],s[6], n[6], n2[6];
char c;
 
 for (i = 0; i<6; i++){
   scanf("%d", &s[i]);
   n[i] = i;
 }
 for (i = 0; i<6; i++){
   scanf("%d", &k[i]);
 }
 for (j = 0; j < 5000; j++){
   if (j%6<3&&j%5==4){
     n2[0] = n[1]; 
     n2[1] = n[5]; 
     n2[3] = n[3]; 
     n2[4] = n[0]; 
     n2[2] = n[2]; 
     n2[5] = n[4];
   }
   else {
     n2[0] = n[3]; 
     n2[1] = n[1]; 
     n2[3] = n[5]; 
     n2[4] = n[4]; 
     n2[2] = n[0]; 
     n2[5] = n[2];
   }
   for (i = 0; i < 6; i++){
     n[i] = n2[i];
   }
   for (l = 0; l < 6; l++){
     if (s[l] != k[n[l]])break;
                  
   }
   if (l == 6){ printf("Yes\n"); break; }
 }
 if (j == 5000)printf("No\n");
 return 0;
}



Measured memory_bytes: 2112
L = [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]
N = int(input())
print(L[N-1])


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

using namespace std;

int main(void){
    int N;

    cin >> N;

    string out = "APPROVED";

    for(int i=0; i<N; i++){
        int a;
        cin >> a;

        if(a % 2 == 0 && !(a % 3 == 0 || a % 5 == 0)){
            out = "DENIED";
        }
    }
    
    cout << out << endl;

    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int s, int d, Weight w)
    : src(s), dst(d), weight(w) {
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addEdge(Graph &g, int a, int b, Weight w = 1) {
  g[a].emplace_back(a, b, w);
  g[b].emplace_back(b, a, w);
}

void addArc(Graph &g, int a, int b, Weight w = 1) {
  g[a].emplace_back(a, b, w);
}

void solve() {
  int n;
  cin >> n;
  Graph g(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    u--;
    while (k--) {
      int v;
      cin >> v;
      v--;
      addArc(g, u, v);
    }
  }
  int c = 1;
  vi distance(n, -1);
  vi done(n);
  queue<int> q;
  distance[0] = 0;
  done[0]     = true;
  q.push(0);
  while (q.size()) {
    int x = q.front();
    q.pop();
    for (Edge e : g[x]) {
      if (done[e.dst]) continue;
      done[e.dst]     = true;
      distance[e.dst] = distance[e.src] + 1;
      q.push(e.dst);
    }
  }
  rep(i, n) {
    cout << i + 1 << ' ' << distance[i] << endl;
  }
}

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

template <unsigned Mod> struct ModularInt {
  using M = ModularInt;
  unsigned v;
  ModularInt(long long a = 0) : v((a %= Mod) < 0 ? a + Mod : a) {}
  M operator-() const { return M() -= *this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % Mod; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= Mod) v -= Mod; return *this; }
  M& operator-=(M r) { if ((v += Mod - r.v) >= Mod) v -= Mod; return *this; }
  friend M operator*(M l, M r) { return l *= r; }
  friend M operator/(M l, M r) { return l /= r; }
  friend M operator+(M l, M r) { return l += r; }
  friend M operator-(M l, M r) { return l -= r; }
  M pow(long long n) const {
    assert(n >= 0);
    M res = 1;
    for (M t = *this; n; t *= t, n >>= 1) if (n & 1) res *= t;
    return res;
  }
  M inv() const { assert(v != 0); return pow(Mod - 2); }
  friend string to_string(M a) { return to_string(a.v); }
};
constexpr unsigned mod = 1e9 + 7;
using Mint = ModularInt<mod>;

template<class T> void fzt(vector<T>& a) {
  int n = a.size();
  assert(__builtin_popcount(n) == 1);
  for (int i = 0; 1 << i < n; ++i) {
    for (int S = 0; S < n; ++S) if (~S & 1 << i) {
      a[S] += a[S | 1 << i];
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vector<int> a(1 << 20);
  int n;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    ++a[x];
  }
  fzt(a);
  Mint res;
  for (int s = 0; s < 1 << 20; ++s) {
    if (__builtin_parity(s)) {
      res -= Mint(2).pow(a[s]);
    } else {
      res += Mint(2).pow(a[s]);
    }
  }
  cout << res.v << '\n';
}



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

int main() {
  int n,k;
  cin>>n>>k;
  int a=0;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    if(x*2<(k-x)*2){
      a+=x*2;
    }
    else{
      a+=(k-x)*2;
    }
  }
cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    long long q(1);//cin>>q;
    while(q--){
       long long n,m,k,tot(0);string s;cin>>n>>m>>k;
       if(n<=m*k) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3604
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(arr):  # fix inputs here
    console("----- solving ------")
        

    brr = [arr[0]]

    for a in arr[1:]:
        if a == brr[-1]:
            continue
        brr.append(a)

    brr = [999] + brr + [0]

    console(brr)

    pos = []
    neg = []
    
    for a,b,c in zip(brr, brr[1:], brr[2:]):
        if a < b and b > c:
            pos.append(b)
        elif a > b and b < c:
            neg.append(b)
        
    console(pos, neg)

    cash = 1000
    for n,p in zip(neg, pos):
        stock_bought = cash//n
        gains = stock_bought * (p-n)
        cash = cash + gains


    # return a string (i.e. not a list or matrix)
    return cash


def console(*args):  # the judge will not read these print statement
    # print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
# sys.stdin.readlines()

for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    _ = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    lst = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(list(map(int,input().split())))

    res = solve(lst)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(res)


Measured memory_bytes: 76664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

int main() {
  string s;
  cin>>s;
  cout<<s.substr(0,s.length()-8)<<endl;
}


Measured memory_bytes: 256
let cnt = ref 0

let selection_sort a n =
  let rec select j minj =
    if j = n then minj
    else select (j + 1) (if a.(j) < a.(minj) then j else minj)
  and doit i =
    if i < n then begin
      let j = select i i in
      if j <> i then (let t = a.(i) in a.(i) <- a.(j); a.(j) <- t; incr cnt);
      doit (i + 1)
    end in
  doit 0

let () =
  let n = read_int () in
  let a = Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (read_line ()))) in
  selection_sort a n;
  Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) a;
  print_newline ();
  Printf.printf "%d\n" !cnt

Measured memory_bytes: 2308
#-*- using:utf-8 -*-

N, K = map(int, input().split())
C = list(map(int, input().split())) 

for i in reversed(range(N-K)):
    i = N-i
    if C[i-K-1] < C[i-1]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 31608
/*
  AUTHOR:SOURABH
  CREATED:29:11:19
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll n,x,i,j,k,l,r,ans=0;
    cin>>n;
    string s;
    cin>>s;
    mll b;
    mll::iterator it;
    vector<set<ll> > c(10);
    vll a(10);
    fn(i,10)
    {c[i].insert(s[0]-48);a[i]=1;}
    fs(i,2,n)
    b[s[i]-48]++;
    fs(i,1,n-1)
    {
        k=s[i]-48;
        l=a[k];
        r=b.size();
        //cout<<l<<" "<<r<<endl;
        ans+=l*r;
        a[k]=0;
        fn(j,10)
        {
            if(c[j].find(k)==c[j].end())
            {a[j]++;c[j].insert(k);}
        }
        it=b.find(s[i+1]-48);
        it->se--;
        if(it->se==0)
            b.erase(it);
    }
    cout<<ans;
    return 0;
}

















Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
	string s;
	string a = "CODEFESTIVAL2016";
	int cnt = 0;

	cin >> s;
	for (int i = 0; i < 16; i++) {
		if (s.at(i) != a.at(i)) {
			cnt++;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

int N, K;

int main() {
    vector<int> cnt(5);
    for (int i = 0; i < 3; i++) {
        int x, y;
        cin >> x >> y;
        cnt[x]++;
        cnt[y]++;
    }
    sort(cnt.begin(), cnt.end());
    bool flag = cnt[0] == 0 && cnt[1] == 1 && cnt[2] == 1 && cnt[3] == 2 && cnt[4] == 2;
    cout << (flag? "YES": "NO") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  ull a, p;
  cin >> a >> p;

  cout << ((a * 3) + p) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  string s;
  cin >> s;
  int n = s.size();
  vint eng(26);
  rep(i,0,n){
    eng[s[i] - 'a']++;
  }
  int ans = n*(n-1)/2 + 1;
  if(n == 1) cout << 1 << endl;
  else{
    rep(i,0,26){
      if(eng[i] >= 2){
        ans -= eng[i]*(eng[i]-1)/2;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 640
/*
Problem : https://atcoder.jp/contests/abc125/tasks/abc125_c
Algorithm : math
Status : AC
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

int n,ans;
int a[MAXN],l[MAXN],r[MAXN];

int gcd(int a,int b){
	if(b == 0)
	    return a;
	else
	    return gcd(b,a % b);
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
	    scanf("%d",&a[i]);
	for(int i = 1;i <= n;i++)
	    l[i] = gcd(l[i - 1],a[i]);
	for(int i = n;i >= 1;i--)
	    r[i] = gcd(r[i + 1],a[i]);
	for(int i = 1;i <= n;i++)
	    ans = max(ans,gcd(l[i - 1],r[i + 1]));
	printf("%d\n",ans);
	return 0;
}


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

int N;
int a[102];

int main()
{
    cin >> N;
    rep(i, N) cin >> a[i];

    sort(a, a + N, greater<int>());

    int alice = 0, bob = 0;
    rep(i, N)
    {
        if (i % 2 == 0)
            alice += a[i];
        else
            bob += a[i];
    }

    cout << alice - bob << endl;
    return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (((a + b) > (c + d)) ? "Left" : (((a + b) < (c + d)) ? "Right" : "Balanced")) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

count = 0
for i in range(len(L)-2):
    l1 = L[i]
    for j in range(i+1,len(L)-1):
        l2 = L[j]
        for k in range(j+1,len(L)):
            l3 = L[k]
            if (l1-l2)*(l2-l3)*(l3-l1) == 0:
                continue
            l_max = max(l1,l2,l3)
            l_left = l1+l2+l3-l_max
            if l_left > l_max:
                count += 1
print(count)


Measured memory_bytes: 9200
s = input()
lr = []
if s[len(s)-1] == '>':
    s_add = s + '<'
else:
    s_add = s + '>'
cnt = 1
for i in range(1,len(s_add)):
    if s_add[i] == s_add[i-1]:
        cnt += 1
    else:
        lr.append(cnt)
        cnt = 1
# print(lr)
if s[0] == '<':
    num = 0
    for i,val in enumerate(lr):
        if val != 1:
            for j in range(1,val):
                num += j
        if i%2 == 0:
            if i+1 > len(lr)-1:
                num += lr[i]
            else:
                num += max(lr[i],lr[i+1])
else:
    num = 0
    for i,val in enumerate(lr):
        if val != 1:
            for j in range(1,val):
                num += j
        if i%2 == 1:
            if i+1 > len(lr)-1:
                num += lr[i]
            else:
                num += max(lr[i],lr[i+1])
        if i == 0:
            num += lr[i]
    

print(num)

Measured memory_bytes: 6812
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)
#define SWAP(x,y) 		((x!=y)&&(x^=y,y^=x,x^=y))

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

int main(int argc, char* argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL H,W;

	cin >> H >> W;

	vector<string> s(H);

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

	for(int i=0;i<H;i++){
		cout << s[i] << endl;
		cout << s[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from collections import Counter
S = raw_input()
c = Counter(S)
if len(c.keys()) == 2:
    print 'Second'
    exit()
c[S[0]] -= 1
c[S[-1]] -= 1
if S[0] == S[-1]:
    print 'First' if sum(c.values()) % 2 == 0 else 'Second'
else:
    print 'First' if sum(c.values()) % 2 == 1 else 'Second'


Measured memory_bytes: 10992