akhauriyash/Code-Regression huggingface dataset:
/* 
 Author:N_o_o_B 
 Created:November 26 2019 21:10:21
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;
    string s;
    cin >> s;
    int w;
    cin >> w;
    for(int i=0;i<sz(s);i+=w){
        cout << s[i];
    }
    cout << endl;




    time_taken();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n,start,ans=1,realans=1000000;
vector<L>v[100010];
L chk[100010];
L dwn[100010];
L bel[100010];

void dfs1(L x){
	L i;
	for(i=0;i<v[x].size();i++)
	{
		if(!chk[v[x][i]])
		{
			chk[v[x][i]]=1;
			dwn[x]++;
			dfs1(v[x][i]);
			bel[x]|=bel[v[x][i]];
		}
	}
	if(dwn[x]>=2) bel[x]=1;
}

void dfs2(L x,L bury){
	L i,passed=0;
	//printf("%lld %lld\n",x,bury);
	for(i=0;i<v[x].size();i++)
	{
		if(!chk[v[x][i]])
		{
			if(!bel[v[x][i]])
			{
				if(!passed)
				{
					passed=1;
				}
				else
				{
					//printf("*%lld*\n",x);
					ans++;
					bury=0;
				}
			}
			else
			{
				chk[v[x][i]]=1;
				dfs2(v[x][i],1);
				bury=0;
			}
		}
	}
	if(bury) ans++;
}

int main()
{
	srand((int)time(NULL));
	scanf("%lld",&n);
	L i;
	for(i=1;i<n;i++)
	{
		L s,e;
		scanf("%lld %lld",&s,&e);
		s++;
		e++;
		v[s].push_back(e);
		v[e].push_back(s);
	}
	vector<L>starts;
	for(i=1;i<=n;i++)
	{
		if(v[i].size()==1) starts.push_back(i);
	}
	L lop=30;
	while(lop--)
	{
		ans=1;
		for(i=1;i<=n;i++)
		{
			chk[i]=dwn[i]=bel[i]=0;
		}
		start=starts[rand()%starts.size()];
		chk[start]=1;
		dfs1(start);
		for(i=1;i<=n;i++)
		{
			chk[i]=0;
		}
		chk[start]=1;
		dfs2(start,0);
		realans=min(realans,ans);
	}
		printf("%lld",realans);
}

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

int main(){
    int N;
    long long int D;
    //入力
    cin >> N >> D;
    long long int X[N+1];
    long long int Y[N+1];
    X[0]=Y[0]=0;
    for(int i=1;i<=N;i++){
        cin >> X[i];
        cin >> Y[i];
        }

    int ans=0;
    for(int i=1;i<=N;i++){
        if(pow(X[i],2)+pow(Y[i],2) <= pow(D,2)){
            ans = ans + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6760
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
ll n;
int func(ll num,int th,int fi,int se){
    int ans=0;
    if(num*10+3<=n){
    ans+=func(num*10+3,th+1,fi,se);
    }
    else{
        if(th>0&&fi>0&&se>0) return 1+ans;
        else return ans;
    }
    if(num*10+5<=n){
    ans+=func(num*10+5,th,fi+1,se);
    }
    else{
        if(th>0&&fi>0&&se>0) return 1+ans;
        else return ans;
    }
    if(num*10+7<=n){
    ans+=func(num*10+7,th,fi,se+1);
    }
    else{
        if(th>0&&fi>0&&se>0) return 1+ans;
        else return ans;
    }
        if(th>0&&fi>0&&se>0) return 1+ans;
        else  return ans;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cout<<func(0,0,0,0)<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define pb push_back
ll pwr(ll a, ll b){
    if(b == 0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b == 0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}

int main(){
    #ifndef ONLINE_JUDGE    
    freopen("../../input", "r", stdin);
    freopen("../../output", "w", stdout);
    #else
    // online submission
    #endif

    boost
    int tt = 1;
    // cout << 0 << endl;
    // cin >> tt;
    while(tt--){
        ll n;
        cin >> n;
        ll a[n];
        for(int i = 0; i < n; i++) cin >> a[i];
        // in(a, n);
        ll ans = 0;
        ll sum[n] = {0};
        for(int i = n - 2; i >= 0; i--){
            sum[i] = (sum[i + 1] + a[i + 1]) % MOD;
            sum[i] %= MOD;
            ans += (sum[i] * a[i]) % MOD;
            ans %= MOD;
        }
        cout << ans;
    }
}


Measured memory_bytes: 6744
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}

signed main() {
	int n, k;
	cin >> n >> k;
	int ans = 1;
	int now = 1;
	while (now <= n) {
		ans++;
		now *= k;
	}
	cout << ans - 1 << endl;

	return 0;
}

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

ll pow(ll a, ll x, ll p){
  	ll tmp=1;
  	while(x>0){
    	if(x%2 == 1){
          	tmp = (a*tmp)%p;
        }
      	a = (a*a)%p;
      	x /= 2;
    }
  	return(tmp);
}

ll inv(ll a, ll p){
  	return pow(a,p-2,p);
}

vector<ll> fact;
ll factorial(ll n, ll p){
  	ll res = 1;
  	for(ll i=1;i<=n;i++){
      	res = (res*i)%p;
    }
  	return res;
}

/*
ll combination(ll n, ll r, ll p){
    ll res=1;
  	ll tmp1 = fact.at(n);
  	ll tmp2 = fact.at(n-r);
  	ll tmp3 = fact.at(r);
  	res = ( ( (tmp1 * inv(tmp2,p) ) % p) * inv(tmp3,p) ) % p;
  	return res;
}
*/

ll combination(ll n, ll r, ll p){
  ll ans = 1;
  for(ll i=1;i<=r;i++){
    ll x = (n+1-i)*inv(i,p) % p;
    ans = (ans * x) % p; 
  }
  return(ans);
}

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  
  //cout << combination(5,3,7) << endl;
  
  ll ans=pow(2,n,mod)-1;
  
  ll ban_a = combination(n,a,mod);
  ll ban_b = combination(n,b,mod);
  
  if(ans < ban_a){
    ans = (mod + ans - ban_a) % mod;
  }else{
    ans = (ans - ban_a) % mod;
  }
  
  if(ans < ban_b){
    ans = (mod + ans - ban_b) % mod;
  }else{
    ans = (ans - ban_b) % mod;
  }
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int k,a,b;
signed main(){
	cin>>k>>a>>b;
	if(a>=b-1)cout<<1+k<<endl;
	else{
		cout<<(k-(a-1))/2*(b-a)+a+((k-(a-1))%2?1:0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Question question = new Question();
        question.solve(sc);
    }

    static class Question {
        public void solve(Scanner sc) {
            int len = sc.nextInt();
            int n = sc.nextInt();
            int[] distances = new int[n];
            for (int i = 0; i < n; ++i) {
                distances[i] = sc.nextInt();
            }
            int[] distanceFromPrev = new int[n];
            distanceFromPrev[0] = len - distances[n - 1] + distances[0];
            int max = distanceFromPrev[0];
            for (int i = 1; i < n; ++i) {
                distanceFromPrev[i] = distances[i] - distances[i - 1];
                max = Math.max(max, distanceFromPrev[i]);
            }
            System.out.println(len - max);
        }
    }
}


Measured memory_bytes: 84316
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;

int main(){
  int n;
  string s;
  int MS[10000];
  int MI[10000];
  int mmax,mmin;

  scanf("%d",&n);
  while(n-- > 0){
    cin >> s;
    for(int i=0;i<s.length();i++){
      MS[i] = MI[i] = s[i]-'0';
    }
    sort(MI,MI+s.length());
    sort(MS,MS+s.length(),greater<int>());
    mmax=mmin=0;
    for(int i=0;i<s.length();i++){
      mmax += MS[i]*pow(10,s.length()-i-1);
      mmin += MI[i]*pow(10,s.length()-i-1);
    }
    cout << mmax-mmin << endl;

  }
  return 0;
}

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

int dp[200005][2];

void Main() {
    string s;
    cin >> s;
    int n = s.size();
    if (n == 1) {
        cout << 1 << endl;
        return;
    }

    if (s[0] == s[1]) {
        dp[0][0] = 1;
        dp[0][1] = 0;
        dp[1][0] = 1;
        dp[1][1] = 1;
    } else {
        dp[0][0] = 1;
        dp[0][1] = 0;
        dp[1][0] = 2;
        dp[1][1] = 1;
    }

    rep2(i, 2, n){
        if(s[i-1] == s[i]){
            dp[i][0] = dp[i-1][1] + 1;
            dp[i][1] = dp[i-2][0] + 1;
        }else{
            dp[i][0] = dp[i-1][0] + 1;
            dp[i][1] = dp[i-2][0] + 1;
        }
    }
    cout << max(dp[n - 1][0], dp[n - 1][1]) << endl;

}

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


Measured memory_bytes: 2196
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int height[n], cost[n];
    for (int i = 0; i < n; i++) cin >> height[i];
    cost[0] = 0;
    cost[1] = abs(height[1] - height[0]);
    for (int i = 2; i < n; i++)
        cost[i] = min(cost[i - 1] + abs(height[i] - height[i - 1]), cost[i - 2] + abs(height[i] - height[i - 2]));
    cout << cost[n - 1] << "\n";
}

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

typedef long long LL;
const int MOD=1e9+7;
const int N=1e5+10;
LL inv[N],fac[N],finv[N];//fac阶乘，finv逆元阶乘

void make()
{
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N;i++)
    {
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(LL) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

LL C(int a,int b)//从a中取b个，组合数
{
    if(a<b||b<0) return 0;
    return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}

int a[N],b[N]; 

int main()
{
    make();
    int n,s,t;
    scanf("%d",&n);
    for(int i=1;i<=n+1;i++)
    {
        scanf("%d",&a[i]);
        if(b[a[i]]==0) b[a[i]]=i;
        else {s=b[a[i]];t=i;break;}
    }
    for(int i=1;i<=n+1;i++)
    {
        LL ret=C(n+1,i);
        ret-=C(s+(n-t),i-1);
        if(ret<0) ret+=MOD;
        printf("%lld\n",ret);
    }
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int j = 1, cnt = 0;
  rep(i,n) {
    if (a[i] == j) j++;
    else cnt++;
  }
  if (cnt == n) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int Q;
string s;

int main() {
  cin>>Q;
  REP(i,0,Q){
    cin>>s;
    int ans = 0;
    set<string> se;
    while(1){
      if(se.find(s)!=se.end()){
        cout<<-1<<endl;
        break;
      }
      se.insert(s);
      if(s.size()==1){
        cout<<ans<<endl;
        break;
      }
      ans++;
      int m = 0;
      REP(pos,1,s.size()){
        string left = s.substr(0,pos);
        string right = s.substr(pos,s.size()-pos);
        m = max(m, stoi(left)*stoi(right));
      }
      s = to_string(m);
    }
  }

  return 0;
}

Measured memory_bytes: 3264
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

int N, A;
int x[111];
ll coudp[111][111][5555];

int main() 
{
      string a,b,c;
         cin>>a>>b>>c;
        cout<<a[0]<<b[0]<<c[0];

}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  int N;
  vector<int> vec;

  void init() {
    cin >> N;
    int a;
    rep(i, N) {
      cin >> a;
      vec.push_back(a);
    }
  }

  ll calc(int l, int r, int li, int ri) {
    ll res = 0;
    while(li <= ri) {
      int l_l = abs(l - vec[li]);
      int l_r = abs(l - vec[ri]);
      int r_l = abs(r - vec[li]);
      int r_r = abs(r - vec[ri]);
      int maxv = max({l_l, l_r, r_l, r_r});
      res += maxv;
      if(maxv == l_l) {
        l = vec[li];
        li++;
      } else if(maxv == l_r) {
        l = vec[ri];
        ri--;
      } else if(maxv == r_l) {
        r = vec[li];
        li++;
      } else {
        r = vec[ri];
        ri--;
      }
    }
    return res;
  }

  void solve() {
    sort(vec.begin(), vec.end());
    ll ans = 0;
    ans = max(ans, calc(vec.front(), vec.front(), 1, vec.size()-1));
    ans = max(ans, calc(vec.back(), vec.back(), 0, vec.size()-2));
    cout << ans << "\n";
  }
}

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

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;



int main()
{
    ll n,m,k;
    cin>>n>>m>>k;
    vll v1(n+1),v2(m+1);
    for(ll i=1; i<=n; i++)
    {
        cin>>v1[i];
        v1[i]+=v1[i-1];
    }

    for(ll i=1; i<=m; i++)
    {
        cin>>v2[i];
        v2[i]+=v2[i-1];
    }

    ll ans=0;

    for(ll i =0; i<=n; i++)
    {
        if(v1[i]<=k)
        {
            ll z=upper_bound(all(v2),k-v1[i])-v2.begin()-1;
            ans=max(ans,i+z);
        }
    }
    cout<<ans<<nn;



}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***

*/





Measured memory_bytes: 6448
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
typedef pair<char,int>P;
map<P,int>m1;
map<char,int>m2;
int n;
string s[1009];
int get(string t){
  int res=0,p=0;
  if(isdigit(t[p]))while(isdigit(t[p]))res+=res*10+(t[p++]-'0');
  else{
    P x=P(t[0],get(t.substr(2,t.size()-3)));
    if(m1.find(x)==m1.end())return -1;
    else return m1[x];
  }
  return res;
}
bool ch(int x){
  int f=0;
  r(i,s[x].size())if(s[x][i]=='=')f=i;
  if(!f)m2[s[x][0]]=get(s[x].substr(2,s[x].size()-3))-1;
  else{
    int l=get(s[x].substr(2,f-3));
    int r=get(s[x].substr(f+1,(int)s[x].size()-f));
    if(l==-1||r==-1||m2[s[x][0]]<l)return 0;
    m1[P((char)s[x][0],l)]=r;
  }
  return 1;
}
 main(){
  while(1){
    n=0;
    m1.clear();
    m2.clear();
    while(cin>>s[n],s[n++]!=".");
    if(!(--n))break;
    int flag=0;
    r(i,n)if(!ch(i)){
      flag++;
      cout<<i+1<<endl;
      break;
    }
    if(!flag)cout<<0<<endl;
  }
}

Measured memory_bytes: 3276
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cassert>

using namespace std;

string str[2];
int s, n, t, m, lt, rt, t_w, t_t;
long double p;

int conv(string s){
  string data[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};  
  for(int i=0;i<7;i++) if(s == data[i]) return i;
  if(s == "All") return -1;
  assert(false);
}

bool check(int s_w, int s_t, int f_w, int f_t){
  if(!(t_w == -1 || (t_w == s_w && t_w == f_w))) return false;
    if(str[1] == "All"){
      if(0 <= s_t && s_t < 24 * 60 && 0 <= f_t && f_t < 24 * 60) return true;
    }else
    if(str[1] == "Day"){
      if(6 * 60 <= s_t && s_t < 18 * 60 && 6 * 60 <= f_t && f_t < 18 * 60) return true;
    }else
    if(str[1] == "Night"){
      if(((18 * 60 <= s_t && s_t < 24 * 60) || (0 <= s_t && s_t < 6 * 60))
         && ((18 * 60 <= f_t && f_t < 24 * 60) || (0 <= f_t && f_t < 6 * 60))) return true;
    }else assert(false);
    return false;
}

main(){
  while(cin >> s >> n >> t >> str[0] >> str[1] >> p >> m && (s|n|t|m) && str[0] != "None" && str[1] != "None"){
    t_w = conv(str[0]);
    long double ans = 0.0;
    for(int i=0;i<7;i++){
      for(int j=0;j<24*60;j++){
        int s_w = i;
        int s_t = j;
        long double cnt = 0.0;
        for(int k=0;k<m;k++){
          int f_w = s_w;
          int f_t = s_t + s;
          if(f_t >= 24 * 60){
            f_t -= 24 * 60;
            f_w = (f_w + 1) % 7;
          }
          if(check(s_w, s_t, f_w, f_t)) cnt++;
          s_t += t;
          if(s_t >= 24 * 60){
            s_t -= 24 * 60;
            s_w = (s_w + 1) % 7;
          }
        }
        ans = max(ans, 1.0 - pow((p - 1.0) / p, n * cnt));
      }
    }
    cout << setiosflags(ios::fixed) << setprecision(10) << ans << endl;
  }
}

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

using namespace std;
const int maxn=1e5;

int n;
int deg[maxn+5];
int vis[maxn+5];
vector <int> G[maxn+5];
queue <int> Q;

void solve()
{
    memset(deg,0,sizeof(deg));
    memset(vis,0,sizeof(vis));
    while (!Q.empty()) Q.pop();
    for (int i=1;i<=n;++i)
    {
        G[i].clear();
    }

    int u,v;
    for (int i=1;i<=n-1;++i)
    {
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
        ++deg[u];
        ++deg[v];
    }

    for (int i=1;i<=n;++i)
    {
        if (deg[i]==1)
        {
            Q.push(i);
        }
    }

    int cnt=0;
    while (!Q.empty())
    {
        int x = Q.front();
        Q.pop();
        for (int i=0;i<G[x].size();++i)
        {
            int e=G[x][i];
            if (!vis[e])
            {
                vis[e]=true;
                vis[x]=true;
                cnt+=2;
                for (int j=0;j<G[e].size();++j)
                {
                    int ee=G[e][j];
                    if (vis[ee]) continue;
                    --deg[ee];
                    if (deg[ee]==1) Q.push(ee);
                }
            }
        }
    }

    if (cnt!=n)
    {
        printf("First\n");
    }
    else
    {
        printf("Second\n");
    }
}

int main()
{
    #ifdef ex
    freopen ("/home/zhongwang/Desktop/in","r",stdin);
    #endif // ex

    while (scanf("%d",&n)==1)
    {
        solve();
    }
}


Measured memory_bytes: 6784
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int f = 0;
  int j = N;
  while (j != 0) {
    f += j % 10;
    j /= 10;
  }
  if (N % f == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

      String str = in.next();

      if(str.indexOf("AC") != -1)
      {
          System.out.println("Yes");
      }
      else
      {
          System.out.println("No");
      }

    }
}

Measured memory_bytes: 21972
from sys import *
from math import *
from collections import deque
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n = int(input())
arr = lmi()
freq = [0]*(n+1)
for i in arr:
    freq[i] += 1
tot = 0
for i in range(n+1):
    tot += freq[i]*(freq[i]-1)//2
for i in arr:
    print(tot-freq[i]+1)

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

int main(){
	
	int n , sum ;
	int m[101] = {} ;
	
	while(1){
		cin >> n ;
		if( cin.eof() ) break ;
		
		for( int i=0 ; i<n ; i++ ) cin >> m[i] ;
		
		sum = 0 ;
		sort( m , m+n ) ;
		
		for( int i=0 ; i<n ; i++ )
			sum += m[i] * ( n-i ) ;
		
		cout << sum << endl ;
	}
	
return 0 ;
}

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

#define INF 1e9
using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

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

typedef long long ll;


// https://atcoder.jp/contests/abc143/tasks/abc143_b
// B - TAKOYAKI FESTIVAL 2019
int main() {
    int N;
    cin >> N;
    int d[N];
    REP(i, N) {
        cin >> d[i];
    }

    int ans = 0;
    // NC2
    REP(i, N) {
        for (int j = i + 1; j < N; ++j) {
            ans += (d[i] * d[j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools

n,m = map(int,input().split())
ship = []
for _ in range(m):
    a,b = map(int,input().split())
    if a==1:
        ship.append(b)
    if b==n:
        ship.append(a)
ship = sorted(ship)
g = itertools.groupby(ship)
for k,v in g:
    if len(list(v))==2:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')


Measured memory_bytes: 13412
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

char c[100][100];
int n,m;
int ans[100][100];

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n >> m;
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			cin >> c[i][j];
		}
	}
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			if(c[i][j] == '.')
			{
				if(c[i - 1][j] == '#') ans[i][j]++;
				if(c[i - 1][j - 1] == '#') ans[i][j]++;
				if(c[i - 1][j + 1] == '#') ans[i][j]++;
				if(c[i][j - 1] == '#') ans[i][j]++;
				if(c[i][j + 1] == '#') ans[i][j]++;
				if(c[i + 1][j - 1] == '#') ans[i][j]++;
				if(c[i + 1][j] == '#') ans[i][j]++;
				if(c[i + 1][j + 1] == '#') ans[i][j]++;
			}
		}
	}
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			if(c[i][j] == '#') cout << "#";
			else cout << ans[i][j];
		}
		cout << '\n';
	}	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define debug(x) cerr << #x << ": " << x << "\n";
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=(int) 1e5;
static const int MOD=(int) 1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
string S,T;

void solve(){
    for(int i=0;i<S.size();i++){
        if(!strcmp(S.c_str(),T.c_str())) {
            cout << "Yes" <<"\n";
            return;
        }
        S=S[S.size()-1]+S.substr(0,S.size()-1);
    }
    cout << "No" <<"\n";
}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<sstream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N = 4005;
const int inf = 0x3f3f3f3f;
vector<int>VR,VG,VB;
char a[N];
ll ans=0;
void fun(vector<int>VR,vector<int>VG,vector<int>VB)
{
	for(int i=0;i<VR.size();i++)
	{
		int x=upper_bound(VG.begin(),VG.end(),VR[i])-VG.begin();
		if(x==VG.size())break;
		for(int j=x;j<VG.size();j++)
		{
			int y=upper_bound(VB.begin(),VB.end(),VG[j])-VB.begin();
			if(y==VB.size())break;
			ans+=VB.size()-y;
			int id=2*VG[j]-VR[i];
			if(id<=VB.back()&&a[id]==a[VB[0]])ans--;
		}
	}
}
int main()
{
	int n;scanf("%d%s",&n,a);
	for(int i=0;i<n;i++)
	if(a[i]=='R')VR.push_back(i);
	else if(a[i]=='G')VG.push_back(i);
	else VB.push_back(i);
	fun(VR,VG,VB);
	fun(VR,VB,VG);
	fun(VG,VR,VB);
	fun(VG,VB,VR);
	fun(VB,VR,VG);
	fun(VB,VG,VR);
	cout<<ans;
	return 0;
}

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

int main() {

    int n;
    while (cin >> n and n) {

        int w, h;
        cin >> w >> h;

        int f[101][101];
        fill(f[0], f[101], 0);

        rep(i, n) {
            int x, y;
            cin >> x >> y;
            x--; y--;
            f[y][x] = 1;
        }

        int s, t, ans = 0;
        cin >> s >> t;

        for (int i=0; i+t<=h; ++i) {
            for (int j=0; j+s<=w; ++j) {

                int cnt=0;

                for (int k=i; k<i+t; ++k) {
                    for (int l=j; l<j+s; ++l) {
                        if (f[k][l] == 1) cnt++;
                    }
                }

                ans = max(ans, cnt);

            }
        }

        cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 3108
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

const (
	yes = "Yes"
	no  = "No"
)

func main() {
	var txt string
	var s = bufio.NewScanner(os.Stdin)
	if s.Scan() {
		txt = s.Text()
	}

	if !strings.Contains(txt, "A") {
		fmt.Println(no)
		return
	}

	if !strings.Contains(txt, "B") {
		fmt.Println(no)
		return
	}

	fmt.Println(yes)
}


Measured memory_bytes: 640
#include <stdio.h>
 
#define MAX 250
 
int h[MAX];
 
main(){
   
  int i, n;
   
  scanf("%d", &n);
   
  for(i = 1; i <= n; i++) scanf("%d", &h[i]);
       
  for(i = 1; i <= n; i++){
     
    printf("node %d: key = %d, ", i, h[i]);
     
    if(i != 1) printf("parent key = %d, ", h[i / 2]);
     
    if(2 * i <= n) printf("left key = %d, ", h[2 * i]);  
     
    if(2 * i + 1 <= n) printf("right key = %d, ", h[2*i+1]);
     
    printf("\n");
     
  }
   
  return 0;
   
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  int n, m; cin>>n>>m;
  vector<long long> a(n);
  rep(i, n) cin>>a[i];

  vector<int> acc(n);
  acc[0] = a[0] % m;
  rep(i, n-1) acc[i+1] = (acc[i] + a[i+1]) % m;

  map<int, long long> b;
  rep(i, n) ++b[acc[i]];
  long long ans = 0;
  ans += b[0];
  for (auto x: b) {
    ans += x.second * (x.second - 1) / 2;
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 5376
#include<iostream>
    #include<vector>
    #include<math.h>
    #include<bits/stdc++.h>
     
    using namespace std;
     
    int main()
    {
        int n, a, b, passed = 0, os = 0;
        string input;
     
        cin >> n >> a >> b >> input;
     
        for(int i = 0; i < input.length(); i++)
        {
            if(input[i] == 'a')
            {
                if(passed < a + b)
                {
                    cout << "Yes" << "\n";
                    passed++;
                }
                else
                    cout << "No" << "\n";
            }
     
            else if(input[i] == 'b')
            {
                if(passed < a + b)
                {
                    if(os < b)
                    {
                        cout << "Yes" << "\n";
                        os++;
                        passed++;
                    }
     
                    else
                        cout << "No" << "\n";
                }
     
                else
                {
                    cout << "No" << "\n";
                }
                
            }
     
            else
            {
                cout << "No" << "\n";
            }
      
        }
    }

Measured memory_bytes: 3704
N,M = map(int,input().split())
tmp = [0]*N

for _ in range(M):
  a,b = map(int,input().split())
  if a == 1:
    if tmp[b-1] == 1:
      print('POSSIBLE')
      exit()
    else:
      tmp[b-1] = 1
  elif b == N:
    if tmp[a-1] == 1:
      print('POSSIBLE')
      exit()
    else:
      tmp[a-1] = 1
print("IMPOSSIBLE")

Measured memory_bytes: 45784
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<map>
using namespace std;
int main(){
  int n,d;
  cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++)cin >> x[i][j];
  }
  int ans=0;
  for(int i=1;i<n;i++){
    for(int j=0;j<i;j++){
      int D=0;
      for(int k=0;k<d;k++){
        D+=pow(x[i][k]-x[j][k],2);
      }
      if(sqrt(D)==(int)sqrt(D))ans++;
      //cout << D << endl;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define MN 250000
char s[MN+5];
ll x=233,y=7204522363551799129,f[MN+5],X=1,Y;
map<ll,int> mp;
int main()
{
	int n,i;long long ans=0;
	scanf("%d",&n);
	scanf("%s",s+1);
	for(i=1;i<=n;++i)
	{
		f[i]=f[i-1];
		if(s[i]=='+')f[i]+=X;
		if(s[i]=='-')f[i]-=X;
		if(s[i]=='<')X*=x;
		if(s[i]=='>')X*=y;
		++mp[f[i]];
	}
	for(i=X=1;i<=n;++i)
	{
		ans+=mp[f[n]*X+Y];
		if(s[i]=='+')Y+=X;
		if(s[i]=='-')Y-=X;
		if(s[i]=='<')X*=x;
		if(s[i]=='>')X*=y;
		--mp[f[i]];
	}
	printf("%lld",ans);
}

Measured memory_bytes: 33664
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

template<class T>
class Graph {
public:
	class Edge {
	public:
		int to;
		T cost;

		Edge(int t, T c) : to(t), cost(c) {}
	};

	vector<vector<Edge>> G;
	int V;

	Graph(int n = 0) {
		resize(n);
	}

	void resize(int n) {
		V = n;
		G.resize(n);
	}

	void addEdge(int from, int to, T cost = 0) {
		int v = max(from, to);
		if (v >= V)
			resize(v + 1);
		G[from].push_back(Edge(to, cost));
	}

	void dfs(int s) {
		vector<int> visit(V);
		calcDfs(visit, s);
	}

	void calcDfs(vector<int>& visit, int s) {
		if (visit[s])
			return;

		visit[s] = 1;
		for (int i = 0; i < G[s].size(); ++i) {
			calcDfs(visit, G[s][i].to);
		}
	}

	vector<int> bfs(int s) {
		vector<int> dist(V);
		queue<int> que;

		fill(dist.begin(), dist.end(), -1);
		dist[s] = 0;
		que.push(s);
		while (!que.empty()) {
			int from = que.front();
			que.pop();
			for (int i = 0; i < G[from].size(); ++i) {
				int to = G[from][i].to;
				if (dist[to] != -1)
					continue;
				dist[to] = dist[from] + 1;
				que.push(to);
			}
		}

		return dist;
	}

	T prim() {
		int s = -1;
		for (int i = 0; i < V; ++i) {
			if (G[i].size() > 0) {
				s = i;
				break;
			}
		}

		T dst = 0;
		vector<int> visit(V);
		priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			auto from = que.top();
			que.pop();

			if (visit[from.second] != 2) {
				dst += from.first;
				visit[from.second] = 2;
			}

			for (int i = 0; i < G[from.second].size(); ++i) {
				auto tmp = G[from.second][i];
				if (visit[tmp.to] != 2) {
					visit[tmp.to] = 1;
					que.push(make_pair(tmp.cost, tmp.to));
				}
			}
		}

		return dst;
	}
};

int main() {
	int n, c;
	Graph<int> g;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			cin >> c;
			if (c == -1)
				continue;
			g.addEdge(i, j, c);
		}
	}

	cout << g.prim() << endl;

	return 0;
}

Measured memory_bytes: 3124
# import sys
# import math #sqrt
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    x = int(input())
    ans = x // 500 * 1000
    x %= 500
    ans += x // 5 * 5
    print(ans)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 3316
S = list(input())

SCheckA = []
SCheckB = []
for i in range(len(S)):
  if i % 2 == 0:
    SCheckA.append("1")
    SCheckB.append("0")
  else:
    SCheckA.append("0")
    SCheckB.append("1")
countA = 0
countB = 0
for j in range(len(S)):
  if SCheckA[j] != S[j]:
    countA += 1
  if SCheckB[j] != S[j]:
    countB += 1
    
if countA >= countB:
  print(countB)
else:
  print(countA)

Measured memory_bytes: 5512
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
template<class T> inline bool chmax(T& a, T b){if(a<b) {a=b; return 1;} return 0; }
template<class T> inline bool chmin(T& a, T b){if(a>b) {a=b; return 1;} return 0; }
const ll INF = 1LL << 60;
const ll mod = 1000000007;

//ll dp[3100][3100];// dp[i][j]=
int keta10(ll n){
	return log10(n)+1;
}
int main(){
	ll N; cin>>N;
	string S; cin>>S;
	
	ll ans=0;
	rep(i,1000){
		ll s[3]={i/100, (i/10)%10, i%10};
		ll k=0;
		rep(j,N){
			if(S[j]=='0'+s[k]) k++;
		}
		if(k>=3) ans++;
	}
	
	cout<<ans<<endl;
}

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

using namespace std;

void dfs(vector<long> &c, vector<vector<int>> &G, int cur, int prev, int d) {
    c[cur] += d;
    for(auto v: G[cur]) {
        if(v==prev) continue;
        dfs(c, G, v, cur, c[cur]);
    }
    return;
}

int main(void) {
    long n, q;
    cin >> n >> q;

    vector<vector<int>> G(n);
    vector<long> c(n);

    for(int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i=0; i<q; i++) {
        int p, x;
        cin >> p >> x;
        p--;
        c[p] += x;
    }

    dfs(c, G, 0, -1, 0);

    for(auto x: c) cout << x << ' ';
    cout << endl;
}


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

int main() {
    int n, temp, minimum = INT_MAX, maximum = INT_MIN;
    cin >> n;
    rep(i, n) {
        cin >> temp;
        minimum = min(minimum, temp);
        maximum = max(maximum, temp);
    }
    int ans = maximum - minimum;
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
lake_sum = 0
stack1 = []
stack2 = []
for i in range(len(S)):
    if S[i] == '\\':
        stack1.append(i)
    elif S[i] == '/':
        if stack1 == []:
            continue
        j = stack1.pop()
        area = i - j
        lake_sum += area
        while True:
            if stack2 == []:
                break
            k, l = stack2.pop()
            if k < j:
                stack2.append((k, l))
                break
            area += l
        stack2.append((j, area))
print(lake_sum)
if stack2 == []:
    print(0)
else:
    lakes = []
    lakes.append(str(len(stack2)))
    for lake in stack2:
        lakes.append(str(lake[1]))
    print(' '.join(lakes))


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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n=100,m=0,k,i,j,a,b;
	cin >> k;
	while(n<k)
	{
		m++;
		n+=(n/100);
	}
	cout << m << "\n";
	return 0;
}

Measured memory_bytes: 3624
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>
// #include "atcoder/all"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

// doc: https://shibh308.github.io/library/library/lib/classes/binarylifting.cpp.html
struct BinaryLifting{
    int n;
    vector<vector<int>> next;
    vector<int> par;
    vector<vector<int>> childs;
    vector<int> depth;

    BinaryLifting(vector<int> v) : n(v.size()){

        next.push_back(par);
        for(int k = 0;; ++k){
            bool fl = false;
            next.emplace_back(n, -1);
            for(int i = 0; i < n; ++i){
                next[k + 1][i] = (next[k][i] == -1 ? -1 : next[k][next[k][i]]);
                if(next[k + 1][i] != -1)
                    fl = true;
            }
            if(!fl)
                break;
        }
    }
    // kth_next(x, 0) => x
    int kth_next(int x, int k){
        for(int i = 0; i < next.size() && k; ++i){
            if(k & (1 << i)){
                x = next[i][x];
                if(x == -1)
                    break;
            }
        }
        return x;
    }
};

void solve(long long n, long long x, long long m){

    vector<vector<i64>> nex(1, vector<i64>(m));
    for(int i = 0; i < m; ++i)
        nex[0][i] = (1LL * i * i) % m;
    vector<vector<i64>> cost(1, vector<i64>(m));
    for(int i = 0; i < m; ++i)
        cost[0][i] = i;
    for(int i = 0; (1LL << i) <= n; ++i){
        nex.emplace_back(m, 0);
        cost.emplace_back(m, 0);
        for(int j = 0; j < m; ++j){
            nex[i + 1][j] = nex[i][nex[i][j]];
            cost[i + 1][j] = cost[i][j] + cost[i][nex[i][j]];
        }
    }
    i64 ans = 0;
    i64 now = x;
    for(int i = 0; i <= 60; ++i){
        if((1LL << i) & n){
            ans += cost[i][now];
            now = nex[i][now];
        }
    }
    cout << ans << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long M;
    scanf("%lld",&M);
    solve(N, X, M);
    return 0;
}


Measured memory_bytes: 58740
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   var m=Arr.shift()-0;
   if(n==0 && m==0)break;
   var ansA={1:true};
   var ansB={1:true};
   var arr=[];
   for(var i=0;i<m;i++){
      var ab=(Arr.shift()).split(" ");
      arr.push(ab);
   }
   for(var i=0;i<m;i++){
      if(arr[i][0]=="1")ansA[arr[i][1]]=true;
   }
   for(var i=0;i<m;i++){
      if(ansA.hasOwnProperty(arr[i][0]) && ansA.hasOwnProperty(arr[i][1])==false)ansB[arr[i][1]]=true;
      if(ansA.hasOwnProperty(arr[i][1]) && ansA.hasOwnProperty(arr[i][0])==false)ansB[arr[i][0]]=true;
   }
   console.log(Object.keys(ansA).length+Object.keys(ansB).length-2);
}

Measured memory_bytes: 11808
/*May The Force Be With Me*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define MOD 1000000007
#define endl "\n"
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define pb push_back
#define f first
#define s second
#define inf INT_MAX
#define size_1d 10000000
#define size_2d 1000
#define rep(i,v,n) for(ll i = v; i < n; i++)
//Snippets: delta, sieve, fastexp, dfs, bfs, dijkstra, floodfill

using namespace std;

ll n;

void Input() {
	cin >> n;
}

void Solve() {
	ll a[n][3];
	for (ll i = 0; i < n; i++)for (ll j = 0; j < 3; j++)cin >> a[i][j];
	ll b[n][3];
	memset(b, 0, sizeof b);
	for (ll j = 0; j < 3; j++)b[0][j] = a[0][j];
	for (ll i = 1; i < n; i++)for (ll j = 0; j < 3; j++) {
			for (ll k = 0; k < 3; k++) {
				if (k != j) b[i][j] = max(b[i][j], b[i - 1][k] + a[i][j]);
			}
		}
	ll ans = 0;
	for (ll i = 0; i < 3; i++)ans = max(ans, b[n - 1][i]);
	cout << ans;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll T = 1;
	//cin >> T;
	//ll t = 1;
	while (T--) {
		Input();
		//cout << "Case " << t << ": ";
		Solve();
		//t++;
	}
	return 0;
}

Measured memory_bytes: 8268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
ll x[1010], y[1010], z[1010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }  
  ll ans = 0;
  for (int i = 0; i < 1 << 3; i++) {
    vector<ll> v;
    for (int j = 0; j < N; j++) {
      ll sum = 0;
      sum += (i >> 0 & 1 ? -1 : 1) * x[j];
      sum += (i >> 1 & 1 ? -1 : 1) * y[j];
      sum += (i >> 2 & 1 ? -1 : 1) * z[j];
      v.emplace_back(sum);
    }
    sort(v.rbegin(), v.rend());
    ans = max(ans, accumulate(v.begin(), v.begin() + M, 0LL));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

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

	ll n;

	scanf("%lld", &n);
	printf("%lld\n", 1000LL * (n / 500) + 5LL * ((n % 500) / 5));

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli a, b, k;
int main() {
  cin >> a >> b >> k;
  lli i;
  for (i=a; i<min(b, a+k); ++i) cout << i << '\n';
  for (i=max(i, b-k+1); i<=b; ++i) cout << i << '\n';
  return 0;
}



Measured memory_bytes: 256