akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
map<string, int>mp1, mp2 ;
int main(){
	int m, n ;
	cin>>m ;
	for(int i = 0; i < m; i++) {
		string s ;
		cin>>s ;
		mp1[s]++ ;
	}
	cin>>n ;
	for(int i = 0; i < n; i++){
		string s ;
		cin>>s ;
		mp2[s]++ ;
	}
	map<string, int> :: iterator it ;
	int mx = 0 ;
	for(it = mp1.begin(); it != mp1.end(); it++){
		mx = max(mx, mp1[it->first] - mp2[it->first]) ;
	}
	cout<<mx ;
	return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x=0,maxi=0,i;
	cin>>n;
	string str;
	cin>>str;
	for(i=0;i<n;i++)
	{
		if(str[i]=='I')
		x++;
		else if(str[i]=='D')
		x--;
		if(x>maxi)
		maxi=x;
		 
	}
	cout<<maxi;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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 main()
{
  INT(N);
  VEC(ll,A,N);
  ll ans = 0;
  REP(i,N-1){
    if(A[i]>A[i+1]){
      ans+=A[i]-A[i+1];
      A[i+1]=A[i];
    }
  }

  cout << ans << endl;
}

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

using namespace std;

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


  int A, B;
  cin >> A >> B;
  for (int i = 1; i < 1300; ++i) {
    if ((int)(i*0.08) == A && (int)(i*0.1) == B) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
	return 0;
}



Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)

#include <iostream>
#include <math.h>

using namespace std;

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

    cout << pow(N, 3) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <iomanip>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    if ((b - a) % 2 == 0) {
        cout << (b - a) / 2 << endl;
    } 
    else {
        cout << min(a + (b - a - 1) / 2, (n - b + 1) + (n - a - n + b) / 2) << endl;
    }

}

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

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

const int M = 181;
int tetra[M];
int memo1[1000010];
int memo2[1000010];

int dfs1(int n) {
  if (memo1[n] != -1) { return memo1[n]; }
  if (n == 0) { return memo1[n] = 0; }
  int ret = 1000000;
  for (int i = M-1; i >= 0; --i) {
    if (tetra[i] <= n) {
      ret = min(ret, dfs1(n-tetra[i])+1);
    }
  }
  return memo1[n] = ret;
}

int dfs2(int n) {
  if (memo2[n] != -1) { return memo2[n]; }
  if (n == 0) { return memo2[n] = 0; }
  int ret = 1000000;
  for (int i = M-1; i >= 0; --i) {
    if (tetra[i] <= n && tetra[i] % 2 == 1) {
      ret = min(ret, dfs2(n-tetra[i])+1);
    }
  }
  return memo2[n] = ret;
}

int main() {
  memset(memo1, -1, sizeof(memo1));
  memset(memo2, -1, sizeof(memo2));

  int sum = 1;
  tetra[0] = 1;
  FOR(i, 1, M) {
    sum += i+1;
    tetra[i] = tetra[i-1]+sum;
  }

  int n;
  while (scanf("%d", &n), n) {
    printf("%d %d\n", dfs1(n), dfs2(n));
  }
}

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

using s64 = long long;

int main() {
  int n;
  cin >> n;
  s64 answer = 0;
  s64 consecutive = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a > 0) {
      consecutive += a;
    } else {
      answer += consecutive / 2;
      consecutive = 0;
    }
  }
  cout << answer + consecutive / 2 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

string s3[3]={
    "aab",
    "d.b",
    "dcc"
};
string s4[4]={
    "aabc",
    "ddbc",
    "efgg",
    "efhh"
};
string s5[5]={
    "aabcc",
    "d.bee",
    "dffgg",
    "xyz..",
    "xyz.."
};
string s6[6]={
    "aabbcc",
    "ddeeff",
    "xyz...",
    "xyz...",
    "...opq",
    "...opq"
};
string s7[7]={
    "abbcc..",
    "a.dee..",
    "ffd..gg",
    "hi.jj..",
    "hi...kk",
    "..l..mn",
    "..l..mn"
};


int main(){fastio
    ll n;cin>>n;
    if(n==2){
        cout<<-1<<endl;return 0;
    }
    if(n==3){
        rep(i,0,2){
            rep(j,0,2){
                cout<<s3[i][j];
            }cout<<endl;
        }return 0;
    }
    string ans[n];
    rep(i,0,n-1){
        rep(j,0,n-1)ans[i]+='.';
    }
    ll ls=0;
    for(ll i=0;i<=n-8;i+=4){
        rep(x,i,i+3){
            rep(y,i,i+3){
                ans[x][y]=s4[x-i][y-i];
            }
        }
        ls=i+4;
    }
    if(n-ls==4){
        rep(x,ls,n-1){
            rep(y,ls,n-1){
                ans[x][y]=s4[x-ls][y-ls];
            }
        }
    }else if(n-ls==5){
        rep(x,ls,n-1){
            rep(y,ls,n-1){
                ans[x][y]=s5[x-ls][y-ls];
            }
        }
    }else if(n-ls==6){
        rep(x,ls,n-1){
            rep(y,ls,n-1){
                ans[x][y]=s6[x-ls][y-ls];
            }
        }
    }else if(n-ls==7){
        rep(x,ls,n-1){
            rep(y,ls,n-1){
                ans[x][y]=s7[x-ls][y-ls];
            }
        }
    }
    rep(i,0,n-1){
        rep(j,0,n-1){
            cout<<ans[i][j];
        }cout<<endl;
    }
    
    return 0;
}


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

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

	vector<double> x(n);
	vector<string> u(n);

	for (int i = 0; i < n; i++) cin >> x[i] >> u[i];

	double ans = 0;

	for (int i = 0; i < n; i++) {

		if (u[i] == "JPY") ans += x[i];
		else ans += x[i] * 380000;
	}

	cout << fixed << setprecision(11) << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){

  int n;
  int number;
  int max,min;
  long long int sum;
  
  cin >> n;

  cin >> number;

  max = min = sum = number;

  for (int i =0;i < (n-1); i++){

  cin >> number;
  if(number >= max)  max = number;
  else if (number <= min) min = number;
  sum += number;

}

  cout << min << " " << max <<" " << sum << endl;

}


Measured memory_bytes: 3100
<?php

fscanf(STDIN, "%d %d", $a, $b);

$acd = [];
for ($i = 1; $i <= sqrt($a); ++$i) {
    if ($a % $i === 0) {
        $acd[] = $i;
        $acd[] = $a / $i;
    }
}

$bcd = [];
for ($i = 1; $i <= sqrt($b); ++$i) {
    if ($b % $i === 0) {
        $bcd[] = $i;
        $bcd[] = $b / $i;
    }
}

$cd = array_unique(array_intersect($acd, $bcd));
sort($cd);

$cnt = 0;
foreach ($cd as $val) {
    $flg = true;
    for ($j = 2; $j <= sqrt($val); ++$j) {
        if ($val % $j === 0) {
            $flg = false;
            break;
        }
    }
    $cnt += $flg ? 1 : 0;
}

echo $cnt;


Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

auto solve(string S) {
    return S != "AAA" and S != "BBB";
}

// generated by online-judge-template-generator (https://github.com/kmyk/online-judge-template-generator)
int main() {
    string S;
    cin >> S;
    auto ans = solve(S);
    printf("%s\n", ans ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){

    long N,K;
    std::cin >> N >> K;
    std::vector<long> p;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        p.push_back(temp);
    }
    std::sort(p.begin(),p.end());
    long sum=0;
    for(long i=0; i<K; i++){
        sum+=p[i];
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
map<ll,ll> name;
int main()
{
   ll n,m,i,j,t,a,b,c,p,k,kk;
     ll s=0;
	 cin>>n; 
     for(i=0;i<n;i++)
     {
     	scanf("%lld",&d[i]);
     	s+=d[i];
     	name[d[i]]++;
	 }
//	 cout<<s<<endl;
	 cin>>m;
	 for(i=0;i<m;i++)
	 {
	 	scanf("%lld %lld",&a,&b);
	 	s=s-name[a]*a+name[a]*b;
	 	name[b]+=name[a];
	 	name[a]=0;
	 	cout<<s<<endl;
	 }
	 
} 

Measured memory_bytes: 10240
s1 = input()
s2 = input()
def distance(s1, s2):
    l1 = list(range(len(s2) + 1))
    for i, c1 in enumerate(s1):
        l2 = [i+1]
        for j, c2 in enumerate(s2):
            l2.append(min(l1[j +1] + 1, l2[j] + 1, l1[j] + (c1 != c2)))
        l1 = l2
    return l1[-1]
print(distance(s1, s2))



Measured memory_bytes: 5584
#include <iostream>
#include <queue>
#include <vector>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <set>
#include <string>
#include <utility>
#include <cmath>
#include <cstring>
#include <limits>
#include <iomanip>

typedef long long ll;
typedef unsigned long long ull;
#define sq(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
#define iter(i, j) for(auto i = j.begin(); i != j.end(); ++i)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end()  
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define IMAX std::numeric_limits<int>::max()
#define IMIN std::numeric_limits<int>::min()
using namespace std;
template <class T> T count_multiples_of(T x, T upper_bound, T lower_bound)
{
    T ans = upper_bound / x - lower_bound / x;
    if(lower_bound % x == 0) return ans + 1;
    else return ans;
}
ll C(ll n, ll k) 
{ 
    ll C[n + 1][k + 1]; 
    ll i, j; 
    for(i = 0; i <= n; i++) 
    { 
        for(j = 0; j <= min(i, k); j++) 
        { 
            if (j == 0 || j == i) 
                C[i][j] = 1; 
            else
                C[i][j] = C[i - 1][j - 1] + 
                          C[i - 1][j]; 
        } 
    } 
    return C[n][k]; 
}
template <class T> void display_1D_vector(vector<T> v)
{
    ll n = v.size();
    rep(i, n) cout << v[i] << " ";
    cout << endl;
}

template <class T> void display_2D_vector(vector< vector<T> > v)
{
    ll n = v.size(), m = v[0].size();
    rep(i, n)
    {   
        rep(j, m) cout << v[i][j] << " ";
        cout << endl;
    }
}
int fast_exp(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
    }
    return res;
}

int main()
{
    fast_io
    //file_io
    ll h; cin >> h;
    cout << (ll(1) << (1 + ll(floor(log2(h))))) - 1;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        int a = 0;
        int b = 0;
        int ab = 0;
        for (int i=0;i<n;i++){
            String s = sc.next();
            if (s.charAt(0)=='B'){
                if (s.charAt(s.length()-1)=='A')ab++;
                else b++;
            }else {
                if (s.charAt(s.length()-1)=='A')a++;
            }
            for (int j=0;j<s.length()-1;j++){
                if (s.charAt(j)=='A'&&s.charAt(j+1)=='B')ans++;
            }
        }
        if (ab!=0){
            ans+=ab-1;
            if (a!=0){
                ans++;
                a--;
            }
            if (b!=0){
                ans++;
                b--;
            }
        }
        ans+=Math.min(a,b);
        System.out.println(ans);
    }
}


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

typedef long long ll;
#define BR "\n"
#define SP " "

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

  vector<ll> c(M);
  for (int i = 0; i < M; i++) {
    cin >> c[i];
  }

  vector<ll> p(N + 1, 50000);
  p[0] = 0;
  for (int i = 0; i < M; i++) {
    for (int k = 0; k < 50001; k++) {
      ll temp = k + c[i];
      if ( temp <= N ) {
        p[temp] = min(p[temp], p[k] + 1);
      }
    }
  }

  cout << p[N] << "\n";
  return 0;
}


Measured memory_bytes: 3124
n,m,l = gets.split(" ").map(&:to_i)
b = readlines.map{|i| i.chomp.split.map(&:to_i)}
a = b.slice!(0,n)
c = Array.new(n).map{Array.new(l,0)}
n.times do |i|
  l.times do |j|
    m.times do |k|
      c[i][j] += a[i][k]*b[k][j]
    end
  end
  puts c[i].join(" ")
end

Measured memory_bytes: 9440
s=input()
key="keyence"
li=[]
for i in range(len(key)):
  li.append([key[:i],key[i:]])
  
for i in li:
  #print("{} {}".format(s[:len(i[0])],s[-len(i[1]):]))
  if s[:len(i[0])]==i[0] and s[-len(i[1]):]==i[1]:
    print("YES")
    break
else:
  print("NO")


Measured memory_bytes: 9092
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

int N;
int A[100010], B[100010];

int solve() {
  try {
    rep (i, N) {
      if ((A[i] == 0) != (i == 0)) throw 0;
      if ((B[i] == 0) != (i == 1)) throw 0;
    }

    int D = B[0];
    if (A[1] != D) throw 0;

    map<pair<int, int>, int> cnt;
    rep (i, N) cnt[mp(A[i], B[i])] += 1;

    map<int, map<int, int>> taba;
    rep (i, N) {
      taba[A[i] + B[i]][A[i]] += 1;
    }

    for (int d = 0; d < D; ++d) {
      if (taba.count(d)) throw 0;
    }

    int ans = N - 1;

    for (auto &i : taba) {
      int d = i.first;
      map<int, int> &m = i.second;

      int request = 0;  // request from left
      for (const auto &j : m) {
        int a = j.first, b = d - a, c = j.second;
        if (a > 0 && cnt[mp(a - 1, b - 1)] + cnt[mp(a - 1, b)] + cnt[mp(a - 1, b + 1)] == 0) {
          throw 0;
        }

        int hige;
        if (cnt[mp(a - 1, b - 1)]) hige = max(0, c - request);
        else hige = 0;
        c -= hige;

        ans += max(0, request - c);

        if (cnt[(mp(a + 1, b - 1))] > 0) {
          request = c;
        } else if (b > 0) {
          if (cnt[mp(a - 1, b - 1)] + cnt[mp(a, b - 1)] + cnt[mp(a + 1, b - 1)] == 0) {
            throw 0;
          }
          ans += c;
          request = 0;
        }
      }
    }
    return ans;
  } catch (...) {
    return -1;
  }
}

int main() {
  scanf("%d", &N);
  rep (i, N) {
    scanf("%d%d", &A[i], &B[i]);
  }

  int ans1 = solve();

  rep (i, N) swap(A[i], B[i]);
  swap(A[0], A[1]);
  swap(B[0], B[1]);
  int ans2 = solve();

  assert(ans1 == ans2);
  printf("%d\n", ans1);

  return 0;
}


Measured memory_bytes: 46336
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 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 kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int dp[405][405];
int n,a[405],sum[405];
int dfs(int l,int r){
	if(r-l==1)return 0;
	if(dp[l][r])return dp[l][r];
	int mi=inf;
	for(int i=l+1;i<r;i++){
		chmin(mi,dfs(l,i)+dfs(i,r));
	}
	return dp[l][r]=mi+sum[r]-sum[l];
}
signed main() {
	cin>>n;
	rep(i,n){
		cin>>a[i];
		sum[i+1]+=a[i];
		sum[i+1]+=sum[i];
	}
	cout<<dfs(0,n)<<endl;
}


Measured memory_bytes: 1536
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t  i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

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

  std::string s;
  std::cin>>s;

  if(s=="AAA"||s=="BBB")std::cout<<"No\n";
  else std::cout<<"Yes\n";

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int N=1e6+10;
int s[N],g[N];
map<pll,int> m1;
vector<int> q1,q2;
int main(){
    ios::sync_with_stdio(false);
    int n,m,q;
    cin>>n>>m>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        s[a]++,g[b]++;
        m1[{a,b}]++;
    }
    int mx=0;
    int mx2=0;
    int i;
    for(i=1;i<=n;i++){
        mx=max(mx,s[i]);
    }
    for(i=1;i<=n;i++){
        if(mx==s[i])
            q1.push_back(i);
    }
    mx=0;
    for(i=1;i<=m;i++){
        mx=max(mx,g[i]);
    }
    for(i=1;i<=m;i++){
        if(mx==g[i])
            q2.push_back(i);
    }
    int ans=0;
    int ok=0;
    for(auto x:q1){
        for(auto y:q2){
            ans=max(s[x]+g[y]-m1[{x,y}],ans);
            if(m1[{x,y}]==0){
                ok=1;
                break;
            }
        }
        if(ok)
            break;
    }
    cout<<ans<<endl;
}


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N){
        cin >> P[i];
        P[i]--;
    }
    rep(i, N){
        cin >> Q[i];
        Q[i]--;
    }

    vector<int> order(N);
    rep(i, N)
        order[i] = i;
    int a, b;
    int count = 1;
    do{
        bool check_p = true, check_q = true;
        rep(i, N){
            if(P[i] != order[i])
                check_p = false;
            if(Q[i] != order[i])
                check_q = false;
        }
        if(check_p)
            a = count;
        if(check_q)
            b = count;
        count++;
    }while(next_permutation(order.begin(), order.end()));

    cout << abs(a - b) << endl;
	
	return 0;
}

Measured memory_bytes: 256
//
// Created by botoc on 12/04/2020.
//
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b)
{
    int r = 1;
    while(b)
    {
        r = a %b;
        a = b;
        b = r;
    }

    return a;
}


int main()
{
    int k, l, i, j;
    long long sum = 0;
    cin>>k;
    for(i=1;i<=k;i++)
    {
      for(j=1;j<=k;j++)
      {
          int x = gcd(i, j);
          for(l = 1;l<=k;l++)
          {
               sum = sum + gcd(x, l);
          }
      }
    }
    cout<<sum<<"\n";

}


Measured memory_bytes: 3624
#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
#include<map>
using namespace std;
int main(){
	int n,ans=0;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(x%2==0){
			if((x%3)*(x%5))
			ans=1;
		}
	}
	if(ans==0)
	printf("APPROVED");
	else
	printf("DENIED");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[101];
    cin>>n;
    //n为数的个数，a数组用来储存这些数
    for (int i=1; i<=n; i++)
    {
        cin>>a[i]; //输入这些数
    }
    sort(a+1,a+n+1); //排序，这样第一项就是最小值，最后一项就是最大值
    cout<<a[n]-a[1]; //输出首项末项之差即可
    return 0;
}

Measured memory_bytes: 256
def resolve():
    x, y = map(int, input().split(' '))

    group_a = [1, 3, 5, 7, 8, 10, 12]
    group_b = [4, 6, 9, 11]
    group_c = [2]

    if (x in group_a) and (y in group_a):
        print('Yes')
        return

    elif (x in group_b) and (y in group_b):
        print('Yes')
        return

    elif (x in group_c) and (y in group_c):
        print('Yes')
        return

    print('No')

resolve()

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>

using ll = long long int;
using namespace std;

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> pluss;
    vector<ll> minuss;
    vector<ll> zeros;
    for(ll i=0; i<n; ++i){
        ll a; cin >> a;
        if(a < 0){ minuss.push_back(a); }
        else if(a == 0){ zeros.push_back(a); }
        else{ pluss.push_back(a); }
    }
    sort(pluss.begin(), pluss.end());
    sort(minuss.begin(), minuss.end());

    ll p_len = pluss.size();
    ll m_len = minuss.size();
    ll z_len = zeros.size();

    ll minus_num = p_len * m_len;
    ll zeros_num = z_len * (z_len - 1LL) / 2LL + z_len * (m_len + p_len);

    ll l = -(ll)1e18 - 10LL; ll r = (ll)1e18 + 10LL;
    while(r - l > 1){
        ll mid = (l + r) / 2;
        ll cnt = 0;
        if(mid > 0){
            ll ret = 0;
            for(ll i=0; i<(ll)pluss.size(); ++i){
                ret += upper_bound(pluss.begin(), pluss.end(), mid / pluss[i]) - pluss.begin(); 
                if(pluss[i] * pluss[i] <= mid){ ret -= 1; }
            }
            cnt += ret / 2;
            ret = 0;
            for(ll i=0; i<(ll)minuss.size(); ++i){
                ret += m_len - (ll)(lower_bound(minuss.begin(), minuss.end(), mid / minuss[i]) - minuss.begin()); 
                if(minuss[i] * minuss[i] <= mid){ ret -= 1; }
            }
            cnt += ret / 2;
            cnt += minus_num;
            cnt += zeros_num;
        }
        else if(mid == 0){
            cnt += minus_num;
            cnt += zeros_num;
        }
        else{
            for(ll i=0; i<(ll)pluss.size(); ++i){
                cnt += upper_bound(minuss.begin(), minuss.end(), (mid - pluss[i] + 1) / pluss[i]) - minuss.begin();
            }
        }
        if (cnt >= k){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 2548
import math  
n = int(input())
while n!= 0 :
    li = list(map(int,input().split()))
    m = sum(li)/n
    s = 0
    for i in li:
        s += (i-m)**2
        
    a = math.sqrt(s/n)
    print(a)
    n = int(input())


Measured memory_bytes: 5700
#include<stdio.h>

int main ()
{
 int n,x,i,j,k,s;

 while(1){

  s=0;

  scanf("%d %d",&n,&x);
  if (n==0 && x==0) break;

  for(i=1 ; i <= n-2 ; i++){

   for(j=i+1 ; j <= n-1 ; j++){
   

    for(k=j+1 ; k <= n ; k++){

     if (i+j+k == x) {

      s++;
     }
    }
   }
  }
  printf("%d\n",s);
 }
}

Measured memory_bytes: 1756
import java.io.*;

class Main {
	public static void main(String[] args) {
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));
		try {
		        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str = br.readLine();
			// n:???????????°???k:?????????????????°
			int n = Integer.parseInt(str.split(" ")[0]);
			int k = Integer.parseInt(str.split(" ")[1]);
			// ?????????????´?????????????
			int[] nimotu = new int[n];
			// ??¨????????????????????????????¨?????????????
			int totalWeight = 0;
			int maxweight = 0;
			// ??????????????????????´????????????????????????§??????????±???????
			for (int i = 0; i < n; i++) {
				nimotu[i] = Integer.parseInt(br.readLine());
				totalWeight += nimotu[i];
				if(nimotu[i] > maxweight){
					maxweight = nimotu[i];
				}
			}
			// ???????????????????±???????
			int aver = totalWeight / k;
			//?¨???????????±???????
			int settingVal= 0;
			// ??????????????????????????????????????????????????????????????????????????????????????????????????£??\
			if(maxweight < aver){
				settingVal = aver;
			}else{
				settingVal = maxweight;
			}
			int tracknum;
			while(settingVal <= totalWeight){
				int weight = 0;
				tracknum = 1;
				// ?¨????????????????????¶???????????????????????????????????????????
				for(int i = 0;i < n && tracknum <= k;) {
					// ????????????????????????????????°?????????
					if(weight + nimotu[i] <= settingVal){
						weight += nimotu[i];
						i++;
					//???????????????????????????????????????????????????????????????????????£?????????????????°?¬???????????????????
					} else {
						weight = 0;
						tracknum++;
					}
				}
				/* ???????????¶
				 * ?±???????????°??????????????????????aver?????????????????¨?????????????????????????????????aver????????????????????¨?????????????????°????¨??????????????¶???????????????????
				 * ??\????????????????????????????????????????????°????¶???????????????????????±???????????°????????????????????????§?????????
				 * 1.tracknum = k???????????????????????????????????°????¶???????????????¨
				 * 2.flg = true????????¨?????????????????????????????????????????¨
				*/
				if(tracknum <= k){
					System.out.println(settingVal);
					break;
				}
				// ?????????????????´?????????????????????????¬????
				settingVal++;
			}
		} catch (IOException e) {
			System.out.println("error");
		}
	}
}

Measured memory_bytes: 29456
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	int a,b=0;
	cin >> a;
	vector<int> x(3000);
	for (int i = 0; i < a; i++) {
		cin >> x[i];
		b += x[i] - 1;
	}
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main () {

    std::string n;
    std::cin >> n;

    switch (n.back()) {
        case '2':
        case '4':
        case '5':
        case '7':
        case '9':
            std::cout << "hon" << std::endl;
            break;
        case '0':
        case '1':
        case '6':
        case '8':
            std::cout << "pon" << std::endl;
            break;
        case '3':
            std::cout << "bon" << std::endl;
            break;
    }

    return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  
  if (s == "Sunny") {
    cout << "Cloudy";
  } else if (s == "Cloudy") {
    cout << "Rainy";
  } else {
    cout << "Sunny";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007

using namespace std;

const int mxN=1e3,mxX=1e5;

int main()
{
    int n;
    cin>>n;
    int a[n];
    int dp[n];
    for(int i = 0; i<n; i++)
        cin>>a[i];
    dp[0] = 0;
    for(int i = 1; i<n; i++)
    {
        if(i-1)
            dp[i] = min((dp[i-2]+abs(a[i-2]-a[i])),(dp[i-1]+abs(a[i-1]-a[i])));
        else
            dp[i] = abs(a[i]-a[i-1]); 
    }
    // for(int i = 0; i<n; i++)
    //     cout<<dp[i]<<" ";
    // cout<<endl;
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int board[10][5];

int main(){ _;
  int h;
  while(cin>>h,h!=0){
    REP(i,10)REP(j,5)board[i][j]=0;
    REP(i,h){
      REP(j,5){
	cin>>board[h-i-1][j];
      }
    }
    int sum=0;
    bool chain=false;
    do{
      chain=false;
      REP(i,h){
	REP(j,3){
	  if(board[i][j]==0)continue;
	  int k=j+1;
	  for(;k<5;k++){
	    if(board[i][j]!=board[i][k])break;
	  }
	  if(k-j>=3){
	    sum+=board[i][j]*(k-j);
	    for(;j<k;j++)
	      board[i][j]=0;
	    break;
	  }
	}
      }
      REP(j,5){
	REP(i,h-1){
	  if(board[i][j]==0){
	    int k=i+1;
	    for(;k<10;k++){
	      if(board[k][j]!=0){
		board[i][j]=board[k][j];
		board[k][j]=0;
		chain=true;
		break;
	      }
	    }
	  }
	}
      }
      // REP(i,10){
      // 	REP(j,5)
      // 	  cout<<board[i][j]<<" ";
      // 	cout<<endl;
      // }
      // cout<<endl;
    }while(chain);
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 1196
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 1000005;
using namespace std;
int n, e, ter[N], nxt[N], lnk[N], m, opt[N]; bool vis[N];
void add(int x, int y) {
	ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e;
}
int main() {
	scanf("%d%d", &n, &m); int x, y;
	rep(i, 1, m) scanf("%d%d", &x, &y),
		add(x, y), add(y, x);
	int he = n, ta = n;
	opt[n] = 1; vis[1] = true;
	for ( ; ; ) {
		int u = opt[he];
		bool flg = false;
		for (int i = lnk[u]; i; i = nxt[i]) if (!vis[ter[i]]) {
			vis[ter[i]] = true, opt[-- he] = ter[i];
			flg = true; break ;
		}
		if (flg) continue ;
		u = opt[ta];
		for (int i = lnk[u]; i; i = nxt[i]) if (!vis[ter[i]]) {
			vis[ter[i]] = true; opt[++ ta] = ter[i];
			flg = true; break ;
		}
		if (flg) continue ;
		break ;
	}
	printf("%d\n", ta - he + 1);
	rep(i, he, ta) printf("%d ", opt[i]);
	return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <algorithm>

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

using namespace std;

int main() {
	int N;
	vector<int> A;
	cin >> N;

	rep(i, N) {
		int a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());

	int max = A[N-1];
	vector<int> dp(max+1,false);

	rep(i, N) {
		if (dp[A[i]] == true)continue;
		if (i != 0 && A[i] == A[i - 1]) {
			dp[A[i]] = true;
			continue;
		}

		rep(j, max+1) {

			if (j == 0 || j == 1)continue;
			int tmp = A[i] * j;
			if (tmp > max)break;
			dp[tmp] = true;
		}
	}

	int ans = 0;
	rep(i, N) {
		if (dp[A[i]] == false)ans++;
	}


	cout << ans;
	//cin >> N;
	return 0;
}

Measured memory_bytes: 8012
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

ll a[100010], b[100010];
ll n;

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

  cin >> n;
  REP(i,n) cin >> a[i] >> b[i];
  
  ll ans = 0LL;
  ll sum = 0LL;
  ROF(i,n-1,0){
    a[i] += ans;
    if(a[i]%b[i] != 0){
      ans += b[i]-a[i]%b[i];
    }
  }

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


Measured memory_bytes: 1792
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
void solve(){
    int N;
    cin>>N;
    vector<int> numbers(N);
    vector<int> sieve(1000010,0);
   for(int i=0;i<N;i++){
       cin>>numbers[i];
       sieve[numbers[i]]++;
   }
   int sum = 0;
   for(int i = 1;i<=1000000;i++){
       if(sieve[i]){
           if(sieve[i]>1){
               sum+=sieve[i];
               
           }
           for(int j  = i+i;j<=1000000;j=j+i){
                sum+=sieve[j];
                sieve[j] = 0;
            }
       }
   }
   cout<<N-sum<<'\n';
   return;
   
}
int main()
{
    
    
    solve();
    return 0;
}


Measured memory_bytes: 7972
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )

typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    ll n, k;
    cin >> n >> k;
    ll MAX_digit = 50;
    vector<ll> a(n);
    ll dp[MAX_digit+1][2];
    REP(i,n) cin >> a[i];
    memset(dp, -1, sizeof(dp)); // DP 配列を -1 で初期化
    dp[0][0] = 0;
    REP(i,MAX_digit) {
        ll mask = 1LL << (MAX_digit-i-1);
        int num = 0;
        REP(j,n) if (a[j]&mask) ++num;
        ll cost0 = mask*num;
        ll cost1 = mask*(n-num);
        if (dp[i][1] != -1) dp[i+1][1] = max(dp[i+1][1] ,dp[i][1]+max(cost0, cost1));
        if (dp[i][0] != -1) if (k&mask) dp[i+1][1] = max(dp[i+1][1] ,dp[i][0]+cost0);
        if (dp[i][0] != -1) {
            if (k&mask) dp[i+1][0] = max(dp[i+1][0] ,dp[i][0]+cost1);
            else dp[i+1][0] = max(dp[i+1][0] ,dp[i][0]+cost0);
        }
    }
    cout << max(dp[MAX_digit][0], dp[MAX_digit][1]) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>

using namespace std;

int main()
{
  int N, X;
  cin >> N >> X;

  int count = 1, D = 0;
  for (int i = 0; i < N; ++i)
  {
    int L;
    cin >> L;
    D += L;

    if (D <= X)++count;
    else break;
  }
  cout << count << endl;
}

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int r,g,b,n;
    cin >> r >> g >> b >> n;

    int nown=0;
    ll ans=0;
    for(int i=0;i<n/r+1;i++){
        nown=n-r*i;
        for(int j=0;j<nown/g+1;j++){
            if((nown-g*j)%b==0)ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
x, n = map(int, input().split())
p = map(int, input().split())

d = 100
pa = 0
px = range(102)
py = list(set(px) - set(p))

for i in py:

    if d > abs(i - x):
        pa = i
        d = abs(i - x)
    elif d == abs(i - x):
        if i < pa:
            pa = i

print(pa)

Measured memory_bytes: 61896
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll po(int a, int n) {
	ll ret = 1;
	for (int i = 0; i < n; i++)ret *= a;
	return ret;
}


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

	int N;
	cin >> N;

	ll ans = 0;
	for (int a = 1; a <= N; a++) {
		if (a % 10 == 0)continue;
		ll tmp = a;
		ll matsubi = tmp % 10;
		ll sentou;
		while (tmp > 0) {
			if (tmp <= 9) {
				sentou = tmp;
				break;
			}
			else tmp /= 10;
		}

		if (matsubi == sentou)ans += N >= sentou;
		int cnt = 0;
		ll cur;
		while (1) {
			cur = matsubi * po(10, cnt + 1) + sentou;
			if (cur > N)break;
			cur += 10 * (po(10, cnt) - 1);
			if (cur > N) {
				cur -= 10 * (po(10,cnt) - 1);
				ans += (N - cur) / 10 + 1;
				break;
			}
			else ans += po(10,cnt);
			cnt++;
		}
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

const int N=1e5+10;
int a[N];
main(){
    ios
    int n;cin>>n;
    rep(i,n){
        int x;cin>>x;
        a[x]++;
    }
    int sum=0;
    int ans=0;
    n/=2;
    rep2(i,1,100000){
        sum+=a[i];
        if(sum>n){
            cout<<ans;return 0;
        }
        if(sum==n)ans++;
    }
}



Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <sstream>
#include <stdio.h>
#include<math.h>
using namespace std;

int main(){

    int N,A,B,C,D;
    string S;

    cin >> N >> A >> B >> C >> D >> S;

    A = A - 1;
    B = B - 1;
    C = C - 1;
    D = D - 1;

    S[A] = 'A';
    S[B] = 'B';

    if(C<D){
        while(1){
            if(B==D){
                break;
            }
            if(S[B+2]!='#' && B+2<=D){
                S[B+2] = 'B';
                S[B] = '.';
                B = B + 2;
            }
            else if(S[B+1]!='#' && B+1<=D){
                S[B+1] = 'B';
                S[B] = '.';
                B = B + 1;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }
        while(1){
            if(A==C){
                break;
            }
            if(S[A+2]!='#' && A+2<=C){
                S[A+2] = 'A';
                S[A] = '.';
                A = A + 2;
            }
            else if(S[A+1]!='#' && A+1<=C){
                S[A+1] = 'A';
                S[A] = '.';
                A = A + 1;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else{
        while(1){
            if(S[A+2]!='#' && A+2<=C && S[A+2]!='B'){
                S[A+2] = 'A';
                S[A] = '.';
                A = A + 2;
            }
            else if(S[A+1]!='#' && A+1<=C && S[A+1]!='B'){
                S[A+1] = 'A';
                S[A] = '.';
                A = A + 1;
            }
            else if(S[B+1]!='#' && B+1<=D){
                S[B+1] = 'B';
                S[B] = '.';
                B = B + 1;
            }
            else if(S[B+2]!='#' && B+2<=D){
                S[B+2] = 'B';
                S[B] = '.';
                B = B + 2;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
            if(A>B){
                break;
            }
        }
        while(1){
            if(A==C){
                break;
            }
            if(S[A+2]!='#' && A+2<=C){
                S[A+2] = 'A';
                S[A] = '.';
                A = A + 2;
            }
            else if(S[A+1]!='#' && A+1<=C){
                S[A+1] = 'A';
                S[A] = '.';
                A = A + 1;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }
        while(1){
            if(B==D){
                break;
            }
            if(S[B+2]!='#' && B+2<=D){
                S[B+2] = 'B';
                S[B] = '.';
                B = B + 2;
            }
            else if(S[B+1]!='#' && B+1<=D){
                S[B+1] = 'B';
                S[B] = '.';
                B = B + 1;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 640
n = int(input())
for _ in range(n):
    balls = list(map(int, input().split()))
    b = 0
    c = 0
    flag = True
    for itm in balls:
        if b>c: b,c = c,b
        if c<itm: c=itm; continue
        elif b<itm: b=itm; continue
        else: flag = False; break
    if flag: print("YES")
    else: print("NO")

Measured memory_bytes: 7532
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

ll dp[51][51][5000];
int main(){
    int N;
    int A;
    cin >> N >> A;
    int x[N];
    rep(i, N){
        cin >> x[i];
    }

    dp[0][0][0] = 1;
    rep(i, N){
        rep(j, N){
            rep(k, 5000){
                if (k + x[i] < 5000) {
                    dp[i+1][j+1][k+x[i]] += dp[i][j][k];
                }
                dp[i+1][j][k] += dp[i][j][k];
            }
        }
    }
    ll ans = 0;
    REP(j,1, N+1) {
        REP(k, 1, 5000) {
            if (k == A * j) {
                ans += dp[N][j][k];
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 99840
import sys
sys.setrecursionlimit(10 ** 9)

from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))

G = [[] for _ in range(N)]

for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)


root = 0

ans = [0] * N
check = [False] * N
check[root] = True

memo = [None] * N

INF = 10 ** 10
dp = [INF] * N

def dfs(x):
    tmp = bisect_left(dp, A[x])
    memo[x] = (tmp, dp[tmp])
    dp[tmp] = A[x]
    ans[x] = bisect_left(dp, INF)
    for next_ in G[x]:
        if check[next_]:
            continue
        check[next_] = True
        dfs(next_)
    j, a = memo[x]
    dp[j] = a

dfs(root)

print (*ans, sep = '\n')



Measured memory_bytes: 242792