akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

struct Vec2d{
  double x,y;
};

double cross(Vec2d &A, Vec2d &B){
  return A.x*B.y - A.y*B.x;
}

int main(void){
  double x[4],y[4];
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=EOF){
    bool f=true;
    for(int i=0;i<4;++i){
      double xx[3],yy[3];
      double xp = x[i], yp = y[i];
      int cnt=0;
      for(int j=0;j<4;++j){
        if(i==j) continue;
        xx[cnt] = x[j];
        yy[cnt] = y[j];
        ++cnt;
      }
      Vec2d AB,AP,BC,BP,CA,CP;
      AB.x = xx[1]-xx[0]; AB.y = yy[1]-yy[0];
      BC.x = xx[2]-xx[1]; BC.y = yy[2]-yy[1];
      CA.x = xx[0]-xx[2]; CA.y = yy[0]-yy[2];
      AP.x = xp-xx[0]; AP.y = yp-yy[0];
      BP.x = xp-xx[1]; BP.y = yp-yy[1];
      CP.x = xp-xx[2]; CP.y = yp-yy[2];
      if(cross(AB,AP)>0.0 && cross(BC,BP)>0.0 && cross(CA,CP)>0.0)
        f=false;
      else if(cross(AB,AP)<0.0 && cross(BC,BP)<0.0 && cross(CA,CP)<0.0)
        f=false;
      else ;
    }
    cout<<((f)?"YES":"NO")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

int N;
string S;
int K;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> S >> K;

  char c = S[K - 1];
  for (int i = 0; i < N; i++) {
    if (c == S[i]) {
      cout << c;
    } else {
      cout << '*';
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
local function no()
    print("No")
    os.exit()
end

local s = ""..io.read("*l")
if s ~= s:reverse() then
    no()
end
local front_s = s:sub(1, (s:len() - 1) / 2)
if front_s ~= front_s:reverse() then
    no()
end
local back_s = s:sub((s:len() + 3) / 2, s:len())
if back_s ~= back_s:reverse() then
    no()
end

print("Yes")

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

int main(){
  int N,K,a=1;
  cin>>N>>K;
  for (int i=0;i<N;i++){
    if (a<K){
      a*=2;
    }
    else {
      a+=K;
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())
X = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    a, b = a-1, b-1
    X.append((a, b, c, d))

import itertools
ans = -1
for p in itertools.combinations_with_replacement(range(m), n):
    temp = 0
    for i in range(q):
        a, b, c, d = X[i]
        if p[b]-p[a] == c:
            temp += d
    ans = max(ans, temp)

print(ans)


Measured memory_bytes: 68208
#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
#define pis pair<int,string>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N=2e5+5;
int n,mx;
map<string,int>s;
string x[N];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i],s[x[i]]++,mx=max(mx,s[x[i]]);
	for(map<string,int>::iterator it=s.begin();it!=s.end();it++)
	{
		if(it->second==mx)
		{
			cout<<it->first<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 26752
n = gets.to_i
p_a = gets.split.map(&:to_i)
n_a = (1..n).to_a
count = 0
0.upto(n) do |i|
  count += 1 if p_a[i] != n_a[i]
end
puts count > 2 ? "NO" : "YES"

Measured memory_bytes: 1788
N, M = map(int, input().split())
cakes = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for x in (1, -1):
  for y in (1, -1):
    for z in (1,-1):
      ans = max(ans, sum(sorted([c[0]*x+c[1]*y+c[2]*z for c in cakes],reverse=True)[0:M]))
print(ans)
      



Measured memory_bytes: 3700
import math
A,B = map(int,input().split())
c = 0
for i in range(math.ceil(A/0.08),math.floor((A+0.99)/0.08)+1):
    if c == 1:
        break
    for j in range(math.ceil(B/0.1),math.floor((B+0.99)/0.1)+1):
        if i == j:
            print(i)
            c = 1
            break
if c == 0:
    print(-1)

Measured memory_bytes: 3060
n,k = map(int, input().split())
t = [[0]*20 for i in range(n)]
count = 0
A = [0 for i in range(n)]
for i in range(n):
    t[i][0] = i+1

for i in range(n):
    for j in range(19):
        t[i][j+1] =t[i][j]*2 
        if t[i][j+1]>=k and t[i][j]<k:
            A[i] = j+1

for i in range(n):
    count = count + (0.5)**A[i]/n

print(count)

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

const int mod = 1000*1000*1000+7;

int N;
vector<int> T;
vector<int> A;
vector<int> H;
vector<int> X;

int main() {
    scanf("%d", &N);
    T.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &T[i]);
    }
    A.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    H = vector<int>(N, -1);

    for(int i = 0; i < N; i++) {
        if(i == 0 || T[i - 1] != T[i]) H[i] = T[i];
    }
    for(int i = N - 1; i >= 0; i--) {
        if(i == N - 1 || A[i + 1] != A[i]) {
            if(H[i] != -1 && H[i] != A[i]) {
                printf("0");
                return 0;
            }
            H[i] = A[i];
        }
    }
    X = vector<int>(N, -1);
    int mx = -1;
    for(int i = 0; i < N; i++) {
        mx = max(mx, H[i]);
        if(mx != T[i]) {
            printf("0");
            return 0;
        }
        X[i] = mx;
    }
    mx = -1;
    for(int i = N - 1; i >= 0; i--) {
        mx = max(mx, H[i]);
        if(mx != A[i]) {
            printf("0");
            return 0;
        }
        X[i] = min(X[i], mx);
    }

    int ans = 1;
    for(int i = 0; i < N; i++) if(H[i] == -1) {
        ans = 1LL * ans * X[i] % mod;
    }
    cout << ans;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int N;
int D[100];

int dp[100][30][30][30];
int solve(int i, int l, int r, int mn) {
  int &res = dp[i][l][r][mn];
  if (res != -1) {
    return res;
  }
  if (i >= N) {
    return res = mn;
  }
  // left
  res = max(res, solve(i + 1, D[i], r, min({mn, D[i] - l, r - D[i]})));
  // right
  res = max(res, solve(i + 1, l, 24 - D[i],
                       min({mn, r - (24 - D[i]), (24 - D[i]) - l})));
  return res;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    D[i] = min(D[i], 24 - D[i]);
  }
  sort(D, D + N);
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, 24, 24) << endl;
  return 0;
}


Measured memory_bytes: 10752
n, m = map(int, input().split())
if n < m:
  n, m = m, n

if m >= 2:
  n9 = (n-2) * (m-2)
  n4 = 4
  n6 = n * m - n9 - n4
  print(n9)
elif m == 1 and n >= 2:
  n2 = 2
  n3 = n * m - 2
  print(n3)
elif m == 1 and n == 1:
  print(1)
  

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

int n, k, ans, d, t;
bool vis[105];

int main() {
	cin >> n >> k;
	for (int i = 1; i <= k; ++i) {
		cin >> d;
		for (int j = 1; j <= d; ++j) {
			cin >> t;
			vis[t] = 1;
		}
	}
	for (int i = 1; i <= n; ++i)
		if (!vis[i])
			ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3512
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
  int meals_count;
  vector<int> eaten_numbers;
  vector<int> meal_satisfactions;
  vector<int> successive_bonuses;
  
  cin >> meals_count;
  
  for(int i = 0; i < meals_count; i++){
    int en;
    cin >> en;
    eaten_numbers.push_back(en - 1);
  }
  for(int i = 0; i < meals_count; i++){
    int ms;
    cin >> ms;
    meal_satisfactions.push_back(ms);
  }
  for(int i = 0; i < meals_count; i++){
    int sb;
    cin >> sb;
    successive_bonuses.push_back(sb);
  }
  
  int total_satisfaction = meal_satisfactions[eaten_numbers[0]];
  for(int i = 1; i < meals_count; i++){
    if(eaten_numbers[i] == eaten_numbers[i - 1] + 1){
      total_satisfaction += successive_bonuses[eaten_numbers[i - 1]];
    }
    total_satisfaction += meal_satisfactions[eaten_numbers[i]];
  }
  
  cout << total_satisfaction << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

int main(void){
    ll n;
    cin>>n;
    vector<ll> v(n);
    rep(i, n) cin>>v[i];
    int flag=0;
    rep(i, n) {
        if(v[i]!=v[0]){
            flag=1;
            break;
        }
    }
    if(flag==0) {
        cout<<n/2<<endl;
        return 0;
    }
    map<ll, ll> mp1;
    priority_queue<pair<ll, ll> > que1;
    for(ll i=0;i<n-1;i+=2) mp1[v[i]]++;
    for(auto itr = mp1.begin(); itr != mp1.end(); ++itr) {
        que1.push(make_pair(itr->second, itr->first));
    }
    map<ll, ll> mp2;
    priority_queue<pair<ll, ll> > que2;
    for(ll i=1;i<n;i+=2) mp2[v[i]]++;
    for(auto itr = mp2.begin(); itr != mp2.end(); ++itr) {
        que2.push(make_pair(itr->second, itr->first));
    }
    
    ll ans=0;
    if(que1.top().second==que2.top().second){
        ll max1=que1.top().first;
        ll max2=que2.top().first;
        que1.pop();
        que2.pop();
        ll max3=que1.top().first;
        ll max4=que2.top().first;
        ans=n-max(max1+max4, max2+max3);
    }
    else {
        ll max1=que1.top().first;
        ll max2=que2.top().first;
        ans=n-(max1+max2);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9588
#include <stdio.h>

char s[10001];

int main(void) {
	int n;
	scanf("%d%s", &n, s);

	char *p = s;
	while (*p != '\0') {
		char c = ((int)*p-'A'+n)%26 + 'A';
		*p++ = c;
	}
	puts(s);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new  Scanner(System.in);
    String s = sc.next();
    int num = 0;
    for(int i=0; i<3; i++){
      if(s.charAt(i) == 'o')num++;
    }
    System.out.println(700 + 100*num);
  }
}
      

Measured memory_bytes: 21844
N, M = map(int, input().split())

N += 1
n_patterns = 0
remain_min = 0
remain_max = 0

for i in range(M-1):
    remain_min += i
    remain_max += N - 1 - i

for i in range(M-1, N):
    remain_min += i
    remain_max += N - 1 - i
    n_remain = remain_max - remain_min + 1
    n_patterns += n_remain


print(n_patterns % (10**9 + 7))


Measured memory_bytes: 9196
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

int main(void) {
	ll n;
	cin >> n;
	ll count = 0;
	for (int i = 1; i <= n; i++) {
		count += ((n / i) * (n / i + 1)) / 2*i;
	}
	cout << count << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  sort(all(A), greater<int>());
  ll ans = 0;
  if(N % 2 == 0) {
    for(int i = 0; i < N / 2 - 1; ++i) ans += A[i] * 2;
    ans += A[N / 2 - 1];
    ans -= A[N / 2];
    for(int i = N / 2 + 1; i < N; ++i) ans -= A[i] * 2;
  } else {
    ll res = 0; ll res2 = 0;
    for(int i = 0; i < N / 2 - 1; ++i) res += A[i] * 2;
    res += A[N / 2 - 1];
    res += A[N / 2];
    for(int i = N / 2 + 1; i < N; ++i) res -= A[i] * 2;

    for(int i = 0; i < N / 2; ++i) res2 += A[i] * 2;
    res2 -= A[N / 2];
    res2 -= A[N / 2 + 1];
    for(int i = N / 2 + 2; i < N; ++i) res2 -= A[i] * 2;
    ans = max(res, res2);
  }
  cout << ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

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

    map<string, int> mp;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        mp[s]++;
    }

    int maxi = 0;
    for (auto it: mp) {
        if (it.second > maxi) {
            maxi = it.second;
        }
    }

    vector<string> v;
    for (auto it: mp) {
        if (it.second == maxi) {
            v.push_back(it.first);
        }
    }

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

    for (auto x: v) cout << x << "\n";







    return 0;
}


Measured memory_bytes: 25584
n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    ipt = list(map(int, input().split()))
    k.append(ipt[0])
    s.append(ipt[1:])
p = list(map(int, input().split()))
cnt = 0
for sw in (list(format(i, '0{}b'.format(n))) for i in range(2 ** n)):
    for i in range(m):
        if sum([int(sw[j - 1]) for j in s[i]]) % 2 != p[i]:
            break
    else:
        cnt += 1
print(cnt)

Measured memory_bytes: 42092
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,a[N];long long ans;
int main(){
	scanf("%d",&n);
	a[0]=-1;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i]>a[i-1]+1) return puts("-1"),0;
	}a[n+1]=-1;
	for (int i=n;i;i--){
		ans+=1ll*(a[i]>=a[i+1]?a[i]:0);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        A: usize,
        B: usize,
        C: usize,
        X: usize,
        Y: usize,
    }

    if 2*C > A+B {
        println!("{}", A*X + B*Y);
    } else {
        if X > Y {
            if A > 2*C {
                println!("{}", 2*C*X);
            } else {
                println!("{}", 2*C*Y + A*(X-Y));
            }
        } else {
            if B > 2*C {
                println!("{}", 2*C*Y);
            } else {
                println!("{}", 2*C*X + B*(Y-X));
            }
        }
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n;string s;
  cin>>n>>s;
  int c=0;
  rep(i,n-2){
    reps(j,i+1,n-1){
      reps(k,j+1,n){
        if(s[i]=='A'&&s[j]=='B'&&s[k]=='C'&&i+1==j&&j+1==k)c++;
      }
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

vector<pair<pii,pii>> v;

int n,m,q;

int rec(int ind,vi tmp,int prv)
{
    if(ind==n)
    {
        int res=0;
        for(auto& c:v)
        {
            if(tmp[c.F.S]-tmp[c.F.F]==c.S.F)
                res+=c.S.S;

        }

        return res;
    }

    int res=0;
    for(int i=prv;i<=m;++i)
    {
        tmp.pb(i);
        res=max(res,rec(ind+1,tmp,i));
        tmp.pob();
    }

    return res;
}

void solve()
{
    cin>>n>>m>>q;

    v.rz(q);
    for(int i=0;i<q;++i)
    {
        cin>>v[i].F.F>>v[i].F.S>>v[i].S.F>>v[i].S.S;
        --v[i].F.F;
        --v[i].F.S;
    }

    vi tmp;
    int ans=rec(0,tmp,1);
    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) if (debug) cout << #x << " = " << (x) << endl;

const int debug = 0;
const long long inf = 1LL << 40;

int main() { IO;
  int a, b, q;
  cin >> a >> b >> q;

  vector<long long> A(a + 2), B(b + 2);
  for (int i = 1; i <= a; ++i) {
    cin >> A[i];
  }

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

  A[0] = B[0] = -inf;
  A[a + 1] = B[b + 1] = inf;

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  if (debug) { cout << "A:"; for (auto &x : A) cout << " " << x; cout << endl; }
  if (debug) { cout << "B:"; for (auto &x : B) cout << " " << x; cout << endl; }

  while (q--) {
    long long initial;
    cin >> initial;

    vector<long long> shrine(2), temple(2);
    auto it = lower_bound(A.begin(), A.end(), initial);
    shrine[0] = *it;
    D(*it);
    it--;
    shrine[1] = *it;
    D(*it);

    it = lower_bound(B.begin(), B.end(), initial);
    temple[0] = *it;
    D(*it);
    it--;
    temple[1] = *it;
    D(*it);

    if (debug) { cout << "shrine:"; for (auto &x : shrine) cout << " " << x; cout << endl; }
    if (debug) { cout << "temple:"; for (auto &x : temple) cout << " " << x; cout << endl; }

    long long ans = numeric_limits<long long>::max();
    for (auto x : shrine) {
      for (auto y : temple) {
        long long cost0 = abs(initial - x) + abs(x - y);
        long long cost1 = abs(initial - y) + abs(x - y);

        ans = min(ans, cost0);
        ans = min(ans, cost1);
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
ll a[N], dp[N][2];
int main(void){
    IOS;
    int n; cin >> n; 
    for (int i = 1; i <= n; ++i) cin >> a[i];
    dp[2][0] = a[1], dp[2][1] = a[2];
    for (int i = 3; i <= n; ++i){
        if (i%2 == 1){
            dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
            dp[i][1] = a[i]+max(max(dp[i-2][1], dp[i-2][0]), max(dp[i-3][1], dp[i-3][0]));
        }else{
            dp[i][0] = a[i-1]+dp[i-2][0];
            dp[i][1] = a[i]+max(dp[i-1][0], max(dp[i-2][0], dp[i-2][1]));
        }
    }
    cout << max(dp[n][0], dp[n][1]) << endl;
    return 0;
}

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

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 0x7fffffffffffffff

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int h, w, m; cin >> h >> w >> m;
    int row[h], col[w];
    memset(row, 0, sizeof row);
    memset(col, 0, sizeof col);
    set<ii> yo;
    for (int i = 0; i < m; ++i){
        int x, y; cin >> x >> y;
        x--;
        y--;
        yo.insert({x, y});
        row[x]++;
        col[y]++;
    }
    int ma = 0, ans = 0;
    vi px, py;
    for (int i = 0; i < h; ++i){
        ma = max(row[i], ma);
    }
    for (int i = 0; i < h; ++i){
        if(row[i] == ma){
            px.pb(i);
        }
    }
    ans = ma;
    ma = 0;
    for (int i = 0; i < w; ++i){
        ma = max(col[i], ma);
    }
    for (int i = 0; i < w; ++i){
        if(col[i] == ma){
            for(auto l : px){
                if(yo.find({l, i}) == yo.end()) {
                    cout << ans+ma << "\n";
                    return 0;
                }
            }
        }
    }
    ans+=ma;

    cout << ans-1 << "\n";

    return 0;
}

Measured memory_bytes: 26408
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pi M_PI
#define inf 1<<30
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (!equals(x,p.x) ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};
typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}

// base????????????a???r?????????counter_clock_wise????????¢
Point rotate(Point base,Point a,double r){
  Point b=a-base;
  a.x=b.x*cos((r/180)*M_PI)-b.y*sin((r/180)*M_PI);
  a.y=b.x*sin((r/180)*M_PI)+b.y*cos((r/180)*M_PI);
  a=a+base;
  return a;
}

// ??¢???????????? return 4
// ?????\?????? return 3
// ????????? return 2
// ?????\?????? return 1
// ?????? return 0
int intersect(Circle a,Circle b){
  double dis=abs(a.c-b.c),sumr=a.r+b.r,minr=min(a.r,b.r),maxr=max(a.r,b.r);
  if((sumr-dis)<-eps)return 4;
  if(equals(sumr,dis))return 3;
  if((maxr-(dis+minr))<-eps)return 2;
  if(equals(dis+minr,maxr))return 1;
  return 0;
}

vector<Point> getCommonTangent(Circle a,Circle b){
  vector<Point> vp;
  int intersection=intersect(a,b);
  if(intersection==0)return vp;
  if(intersection==1){
    Vector v=b.c-a.c;
    if(b.r<a.r)v=(v*a.r)/abs(v);
    else v=(v*a.r*(-1))/abs(v);
    vp.push_back(a.c+v);
    return vp;
  }
  if(intersection==3){
    Vector v=b.c-a.c;
    v=v*a.r/abs(v);
    vp.push_back(a.c+v);
  }
  double d=abs(b.c-a.c),c,s;
  Vector v=(b.c-a.c)/d,v1=v*a.r,v2=v*b.r;
  Point p1,p2;

  c=sqrt(d*d-(a.r-b.r)*(a.r-b.r));
  s=(180*asin(c/d))/pi;

  if(a.r<b.r)s=180-s;
  vp.push_back(rotate(a.c,a.c+v1,s));
  vp.push_back(rotate(a.c,a.c+v1,360-s));

  if(intersection==2 || intersection==3)return vp;

  c=sqrt(d*d-(a.r+b.r)*(a.r+b.r));
  s=(180*asin(c/d))/pi;

  vp.push_back(rotate(a.c,a.c+v1,s));
  vp.push_back(rotate(a.c,a.c+v1,360-s));

  return vp;
}

int main()
{
  Circle c1,c2;

  cin>>c1.c.x>>c1.c.y>>c1.r;
  cin>>c2.c.x>>c2.c.y>>c2.r;

  vector<Point> v=getCommonTangent(c1,c2);
  sort(v.begin(),v.end());
  for(int i=0;i<v.size();i++)printf("%.10f %.10f\n",v[i].x,v[i].y);
  return 0;
}

Measured memory_bytes: 1284
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int sum = 0;
	vector<int> d(n);
	rep(i,n){
		cin >> d[i];
	}
	rep(i,n){
		for(int j = i+1;j < n;++j){
			if(i == j) continue;
			sum += d[i] * d[j];
		}
	}
	cout << sum << '\n';
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	char s[110], d[110], f[110];


	for(int i=0; i<7; i++){
		scanf("%c", &s[i]);
	}

	scanf(" ");

	scanf("%s", d);

	scanf(" ");



	for(int i=0; i<7; i++){
		scanf("%c", &f[i]);
	}



	printf("A%cC\n",d[0]);

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstring>
using namespace std;
int main() {
	int n, m;
	int n2[1001], m2[1001];
	while (1) {
		memset(n2, 0, sizeof(n2));
		memset(m2, 0, sizeof(m2));
		cin >> n >> m;
		if (n == 0 && m == 0)return 0;
		for (int i = 1; i <= n; i++) {
			cin >> n2[i];
		}
		for (int i = 1; i <= m; i++) {
			cin >> m2[i];
		}
		int cnt = 1;
		int j = 0;
		int temp = 0;
		j++;
		while (cnt < n) {
			cnt += m2[j];
			if (n2[cnt] != 0) {
				cnt += n2[cnt];
			}
			temp++;
			j++;
			if (cnt < 0) {
				cnt = 0;
			}
		}
		cout << temp << endl;
		temp = 0;
	}
}

Measured memory_bytes: 3100
n = int(input())
cnt = 0

def out(s):
    
    i_s = int(s)
    if i_s <= n:
        #7, 5, 3が1以上出現する
        if all([True if str(i_s).count(s) > 0 else False for s in '753']):
            global cnt
            #print(i_s)
            cnt +=1 
            #7, 5, 3を引っ付ける
            
        [out(str(i_s) + s) for s in '753']

out('0')
print(cnt)

Measured memory_bytes: 3060
using System;

namespace AtCoderWorkspace
{
    public class Class142_1
    {
        public static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ');
            int n = 0;
            int.TryParse(inputs[0],out n);

            bool isGusu = n % 2 == 0;
            int split = n / 2;
            if (!isGusu)
            {
                split++;
            }
            float result = (float)split / n;
            Console.WriteLine(result.ToString());
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<sstream>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int L = 0, R = 999999;
	for (int i = 0; i < m; i++)
	{
		int r, l;
		cin >> l >> r;
		if (L <= l)
		{
			L = l;
		}
		if (R >= r)
		{
			R = r;
		}
	}
	int ans = 0;
	for (int i = L; i <= R; i++)
	{
		if (i <= n)
		{
			ans++;
		}
	}
	cout << ans << endl;
}

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

vector<vector<int>> graph;
vector<int> d;
vector<bool> visited;

void DFS(int v, int dist){
    if(visited[v] == true) return ;
    visited[v] = true;
    d[v] = min(d[v], dist);

    for(int adjacent : graph[v]){
        if(visited[adjacent] == true) continue;

        DFS(adjacent, dist+1);
    }
}

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

    vector<pair<int,int>> edge(n-1);
    graph.resize(n);
    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;

        graph[a].push_back(b);
        graph[b].push_back(a);
        edge[i] = {a,b};
    }

    int ans = n;
    if(k % 2 == 0){
        for(int i=0; i<n; i++){
            d.assign(n,n+1);// n+1 = INF
            visited.assign(n,false);
            DFS(i,0);

            int count = 0;
            for(int j=0; j<n; j++){
                //cout << d[j] << " ";
                if(d[j] > k/2) count += 1;
            }
            //cout << endl;
            ans = min(ans, count);
        }
    }
    if(k % 2 == 1){
        for(int i=0; i<n-1; i++){
            d.assign(n,n+1);// n+1 = INF
            visited.assign(n,false);
            DFS(edge[i].first,0);
            visited.assign(n,false);
            DFS(edge[i].second,0);

            int count = 0;
            for(int j=0; j<n; j++){
                //cout << d[j] << " ";
                if(d[j] > k/2) count += 1;
            }
            //cout << endl;
            ans = min(ans, count);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int A, B, M, la = INT_MAX, lb = INT_MAX;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  for (int i = 0; i < A; i++) {
    cin >> a[i];
    la = min(la, a[i]);
  }
  for (int i = 0; i < B; i++) {
    cin >> b[i];
    lb = min(lb, b[i]);
  }
  int ans = la + lb;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    ans = min(ans, a[x - 1] + b[y - 1] - c);
  }
  cout << ans << endl;
}


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

int main(void){
    string year;
    cin >> year;

    if(year[5] == '0' && (year[6] == '4' ||year[6] == '3' ||year[6] == '2' || year[6] == '1')){
        puts("Heisei");
        return 0;
    }

    puts("TBD");
    return 0;
}


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

int main()
{
    int N;
    int t;
    vector<int> A;
    bool res = true;

    cin >> N;
    rep(i, N)
    {
        cin >> t;
        A.push_back(t);
    }

    for (int j : A)
    {
        if (j % 2 == 0)
        {
            if ((j % 3 == 0)||(j % 5 == 0))
            {
                res = true;
            }else{
                res = false;
                break;
            }
        }
    }

    cout << ((res) ? "APPROVED" : "DENIED");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t="";
  cin >> s;
  vector<long long> cntx;
  long long cnt=0,ans=0;
  for(size_t i=0;i<s.size();i++){
    if(s[i]!='x'){
      t+=s[i];
      cntx.push_back(cnt);
      cnt=0;
    }else{
      cnt++;
    }
  }
  cntx.push_back(cnt);
  for(size_t i=0;i<t.size();i++){
    if(t[i]!=t[t.size()-1-i]){
      cout << -1 << endl;
      return 0;
    }
  }
  for(size_t i=0;i<cntx.size();i++){
    ans+=abs(cntx[i]-cntx[cntx.size()-1-i]);
    if(cntx.size()-1-i-i<=1) break;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const int maxn = 110;
const int maxw = 100010;

long long int n, w;
vector<pair<long long int,long long int>> obj;
long long int dp[maxw][maxn];

int main(){
	cin >> n >> w;
	obj.push_back(make_pair(0,0));
	for (int i = 0; i < n; i++){
		int tw, v;
		cin >> tw >> v;
		obj.push_back(make_pair(tw, v));
	}
	
	for (int i = 0; i <= n; i++){
		dp[0][i] = 0;
	}
	for (int i = 0; i <= w; i++){
		dp[i][0] = 0;
	}
	
	for (int i = 1; i <= w; i++){
		for (int j = 1; j <= n; j++){
			if (obj.at(j).first <= i){
				dp[i][j] = max(dp[i-obj.at(j).first][j-1] + obj.at(j).second, dp[i][j-1]);
			}
			else {
				dp[i][j] = dp[i][j-1];
			}
		}
	}


	cout << dp[w][n] << endl;
	return 0;
}


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

int main() {
    string s,t;
    cin>>s>>t;
    ll ans=1e9;
    REP(i,s.size()){
        if(i+t.size()>s.size()) break;
        ll cnt=0;
        REP(j,t.size()){
            if(s[i+j]!=t[j]){
                cnt++;
            }
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;

      return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
using namespace std;
 
const int N = 2e6 + 5;
const int mod = 1e9 + 7;

int a[N];
int occ[N];

int32_t main() {
	fast;
	int n;
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	bool ok = true;
	for(int i=0; i<n; i++){
		int x = a[i];
		for(int i=2; i*i <=x; i++){
			if(x%i == 0){
				occ[i]++;
				if(occ[i]>1) ok = false;
				while(x%i == 0 ) x/= i;
			}
		}
		if(x!=1) occ[x]++;
		if(occ[x] > 1) ok = false;
	}
	if(ok){
		cout<<"pairwise coprime" <<endl;
		return 0;
	}
	for(int i=1; i<= 1000000; i++){
		if(occ[i] == n){
			cout<<"not coprime" <<endl;
			return 0;
		}
	}
	cout<<"setwise coprime"<<endl;
}





Measured memory_bytes: 19116
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
#define MAXM 2510
#define LL long long
#define MO 998244353
#define PII pair<int,int>
LL a[2][3];
LL ans,n;
bool LargerLine(int i,int j)
{
	for(int k=0;k<3;k++)
		if(a[i][k]<a[j][k]) return 0;
	return 1;
}
int main()
{
	scanf("%lld",&n);
	for(int i=0;i<2;i++)
		for(int j=0;j<3;j++)
			scanf("%lld",&a[i][j]);
	int k,t;
	if((k=LargerLine(0,1))||(t=LargerLine(1,0)))
	{
		if(t) swap(a[0],a[1]);
		for(LL i=0,edi=n/a[1][0];i<=edi;i++)
			for(LL j=0,edj=(n-i*a[1][0])/a[1][1];j<=edj;j++)
				ans=max(ans,n+i*(a[0][0]-a[1][0])+j*(a[0][1]-a[1][1])+((n-i*a[1][0]-j*a[1][1])/a[1][2])*(a[0][2]-a[1][2]));
	}
	else
	{
		int cnt=0;
		for(int i=0;i<3;i++)
			if(a[0][i]>=a[1][i]) swap(a[0][i],a[0][cnt]),swap(a[1][i],a[1][cnt]),cnt++;
		if(cnt==2)
		{
			n+=(a[1][2]-a[0][2])*(n/a[0][2]);
			for(LL i=0,edi=n/a[1][0];i<=edi;i++)
				ans=max(ans,n+i*(a[0][0]-a[1][0])+((n-i*a[1][0])/a[1][1])*(a[0][1]-a[1][1]));
		}
		else
		{
			for(LL i=0,edi=n/a[0][1];i<=edi;i++)
			{
				LL N=n+i*(a[1][1]-a[0][1])+((n-i*a[0][1])/a[0][2])*(a[1][2]-a[0][2]);
				ans=max(ans,(N/a[1][0])*(a[0][0]-a[1][0])+N);
			}
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (self.n + 1)
    def add(self, i, x):
        while i <= self.n:
            self.BIT[i] += x
            i += i & -i
    def query(self, i):
        res = 0
        while i > 0:
            res += self.BIT[i]
            i -= i & -i
        return res
n, q = map(int, input().split())
BIT = BinaryIndexedTree(n)
a = list(map(int, input().split()))
for i in range(n):
    BIT.add(i + 1, a[i])
for i in range(q):
    x, y, z = map(int, input().split())
    if x == 0:
        BIT.add(y + 1, z)
    else:
        print(BIT.query(z) - BIT.query(y))

Measured memory_bytes: 132332
#include<bits/stdc++.h>
using namespace std;
template<typename tn> void read(tn &a){
    tn x=0,f=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
    a=x*f;
}
#define int long long
const int L=2e3+5;
const int N=2e3+5;
int n,ans;
int b[N][L],l[N];
signed main(){
	read(n);
	for(int i=1;i<=n;i++)
		read(l[i]);
	sort(l+1,l+n+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=i;j++)
			b[i][l[j]]++;
	for(int i=1;i<=n;i++)
		for(int j=1;j<L;j++)
			b[i][j]+=b[i][j-1];
	for(int i=1;i<=n;i++)
	    for(int j=i+1;j<=n;j++)
	    	ans+=b[i-1][l[i]+l[j]-1]-b[i-1][l[j]-l[i]];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y;

vector< pair<int, int> > links;

int dfs(int current, vector<int> visited)
{
    vector<int> next;
    for (auto l : links) {
        int cand;
        if (l.first == current)
            cand = l.second;
        else if (l.second == current)
            cand = l.first;
        else
            continue;
        bool never = true;
        for (auto v : visited)
            if (v == cand) {
                never = false;
                break;
            }
        if (never)
            next.push_back(cand);
    }
    
    if (next.empty())
        if (visited.size() == N)
            return 1;
        else
            return 0;
    else {
        int sum = 0;
        for (auto n : next) {
            vector<int> newVisited;
            for (auto v : visited)
                newVisited.push_back(v);
            newVisited.push_back(n);
            sum += dfs(n, newVisited);
        }
        return sum;
    }
}

int main()
{
    cin >> N >> M;
    links = vector< pair<int, int> >(M);
    for (auto& l : links) {
        cin >> l.first >> l.second;
    }

    cout << dfs(1, {1}) << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
c=np.array([[int(i) for i in input().split()] for _ in range(3)])

b123=c[0]
a123=np.array([
    0,
    c[1][1]-b123[1],
    c[2][2]-b123[2],
])

isOk=True
for i in range(3):
    for j in range(3):
        if c[i][j]!=a123[i]+b123[j]:
            isOk=False

ans="Yes" if isOk else "No"
print(ans)


Measured memory_bytes: 12508
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 30010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[4];
string s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> s;
    s = " " + s;
    int res = 0;
    FOR(i,0,999) {
        a[2] = i % 10;
        a[1] = i / 10 % 10;
        a[0] = i / 100;
        int now = 0;
        FOR(j,1,n)
            if (s[j] - '0' == a[now]) {
                now++;
                if (now > 2) break;
            }
        if (now > 2) res++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
template<typename T>
T argument(const pair<T, T> &a, const pair<T, T> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

int const MAX = 2000000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

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

    COMinit();
    int n, k; std::cin >> n >> k;
    std::cout << (n>k? 0:1) << std::endl;
    
    return 0;
}


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

#define println(msg) cout << msg << endl
#define yes_or_no(flag) if (flag) { println("Yes"); } else { println("No"); }
#define sort_vec(vec) sort(vec.begin(), vec.end())
#define rsort_vec(vec) sort(vec.rbegin(), vec.rend()) // greater<int>()
int sum_of_digits(int n) {
  int sum = 0;
  for (; n > 0; n /= 10) { sum += (n % 10); }
  return sum;
}

int main() {
  // 入力
  int N, K;
  cin >> N >> K;

  vector<int> l(N);
  for (int i = 0; i < N; i++) {
    cin >> l.at(i);
  }
  
  // 計算
  rsort_vec(l);
  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += l.at(i);
  }
  
  // 出力
  println(sum);
}


Measured memory_bytes: 3532
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const long MOD = 1e9 + 7;
const long dx[] = {1, -1, 0, 0};
const long dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
long A[500010];
long n;
void max_heapify(long i)
{
	long largest;
	long l = i * 2;
	long r = i * 2 + 1;
	if(l <= n && A[l] > A[i])
		largest = l;
	else
		largest = i;
	if(r <= n && A[r] > A[largest])
		largest = r;
	if(largest != i)
	{
		swap(A[i], A[largest]);
		max_heapify(largest);
	}
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for(long i = 1; i <= n; i++)
		cin >> A[i];
	for(long i = n / 2; i >= 1; i--)
		max_heapify(i);
	for(long i = 1; i <= n; i++)
		cout << " " << A[i];
	cout << endl;
	return 0;
}




Measured memory_bytes: 7028
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7;
ll OO=1e15;
const int N=1e5 + 5,M=1e5 + 3;
ll arr[N];
ll pre[N];
int dp[N];

vector<int> adj[N];

ll n,m,k,cnt,SU,idx,len,MN,MX,T;
ll l,r,mid;
ll a,b,c,d;
vector<pair<int,pair<int,char>>> vec;
string str,t,ans;
bool flage;

int DFS(int u){
	
	int &ret = dp[u];
	if(~ret)
		return ret;
	
	ret = 0;
	
	for(int i:adj[u])
		ret = max(ret,1+DFS(i));
	

	return ret;
	
	
}


int main(){
	
	memset(dp,-1,sizeof dp);
	
	cin>>n>>m;
	for(int i=0;i<m;++i){
		cin>>a>>b;
		adj[a].push_back(b);
	}
	
	int MX=0;
	
	for(int i=1;i<=n;++i)
		MX=max(MX,DFS(i));


	cout<<MX<<endl;
	
	


}






Measured memory_bytes: 8832
#include <string>
#include <cmath>
#include <iostream>
using namespace std;

int main(){
	int n;
	double s[1000];
	double m;
	double a;
	double b;
	while(true) {
		cin >> n;
		if ( n == 0 ) break;
		m=0;
		for (int i = 0 ;i<n ;i++ ) {
			cin >> s[i];
			m+=s[i];
		}
		m = m / n;
		a=0;
		for (int i = 0 ;i<n ;i++ ) {
			b = s[i] - m;
			a += b*b;
		}
		cout << fixed << sqrt( a/n ) << endl;
	}
	return 0;
}

Measured memory_bytes: 1292
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int count = 0;
		
		for (int i = 1; i <= N; i++) {
			String str = String.valueOf(i);
			int length = str.length();
			
			if (length % 2 == 1) {
				count++;
			}
		}

		System.out.println(count);
	}
}

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

ll mod=1e9+7;
vector<ll> d(2e5+1,-1);
vector<set<ll>> a(2e5+1);

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

ll dfs(ll f) {
  d[f]=0;
  ll res=1;
  for(auto t:a[f]) {
    if(d[t]<0) {
      res+=dfs(t);
    }
  }
  return d[f]=res;
}

int main() {
  ll n;
  cin >> n;
  vector<pll> v(n-1);
  for(ll i=0;i<n-1;i++) {
    ll f,t;
    cin >> f >> t;
    f--;
    t--;
    v[i]=pll(f,t);
    a[f].insert(t);
    a[t].insert(f);
  }
  dfs(0);
  ll ans=(1-mpow(mpow(2,mod-2),n)+mod)%mod;
  for(ll i=0;i<n-1;i++) {
    ll e=min(d[v[i].first],d[v[i].second]);
    ll temp1=(1-mpow(mpow(2,mod-2),e)+mod)%mod;
    ll temp2=(1-mpow(mpow(2,mod-2),n-e)+mod)%mod;
    ans=(ans+temp1*temp2%mod)%mod;
  }
  ans=(ans+n*(-mpow(2,mod-2)+mod)%mod)%mod;
  cout << ans << endl;
}

Measured memory_bytes: 39680
from itertools import accumulate

n,c = map(int, input().split())
stc = sorted([list(map(int, input().split())) for i in range(n)])
finish = [1] * (c+1)
record = [0] * (10 ** 5 + 2) 
ans = 1
for s,t,c in stc:
  if finish[c] != s:
    s -= 1
  finish[c] = t
  record[s] += 1
  record[t] -= 1
ans = max(list(accumulate(record)))
assert ans >= 1
assert ans <= n
print(ans)

Measured memory_bytes: 68952
#include<bits/stdc++.h>
using namespace std;
string s;
int n,m;
int main()
{
	int i; 
    cin>>s;
    for(i=0;i<=s.size()-1;i++)
    if(s[i]=='A')
    {
    	n=i;
    	break;
    }
    for(i=s.size()-1;i>=0;i--)
    if(s[i]=='Z')
    {
    	m=i;
    	break;
    }
    cout<<m-n+1;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+5;
const LL Mod = 1000000007;
LL a[N], b[N];
int main() {
  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  LL n, ans = 1; cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
    if(a[i] == 0) {
      ans = (3 - b[0]) * ans % Mod;
      b[0]++;
    }
    else {
      LL k = b[a[i] - 1];
      ans = ans * (k - b[a[i]]) % Mod;
      b[a[i]]++;
    }
  } 
  cout << ans << endl;
} 

Measured memory_bytes: 1792