akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

char A,B;

signed main(){

    in(A,B);
    if(A=='H'){
        out(B);
    }else{
        out(B=='H'?'D':'H');
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,r=0,g=0,b=0,ans=0,x,i,j;
    string s;
    cin>>n;
    cin>>s;
    for(i=0; i<s.length(); i++)
    {
        if(s[i]=='R')
        {
            r++;
        }
        else if(s[i]=='G')
        {
            g++;
        }
        else if(s[i]=='B')
        {
            b++;
        }
    }
    ans=r*g*b;

    for (i=0; i<n-1; i++)
    {
        for(j=i+1; j<n; j++)
        {
            if(2*j-i<n)
            {
                if(s[2*j-i]!=s[i]&&s[i]!=s[j]&&s[2*j-i]!=s[j])
                {
                    ans--;
                }
            }
        }

    }

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


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

int sum(int *arr,int n)
{
	int s = 0;
	for(int *p = arr;p < arr + n;p++)
		s += *p;
	return s;
	
}

int max(int *arr,int n)
{
	int max = 0;
	for(int *p = arr;p < arr + n;p++)
	{
		if(max < *p)
			max = *p;
	}
	return max;
}

int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0;i < n;i++)
		cin >> a[i];
	int s = sum(a,n);
	int m = s - max(a,n);
	cout << ((max(a,n) < m) ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 384
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    vector<ll> Ac(N);
    Ac[0] = A[0];
    FOR(i, 1, N){
        Ac[i] = Ac[i-1] + A[i];
    }

    ll x = 0;
    for(ll b=45; b>=0; b--){
        ll count = 0;
        ll binary = 1LL<<b;

        FOR(l, 0, N){
            FOR(r, l, N){
                ll Ai;
                // pn(b);
                // pn(binary);
                // pn(1<<2);
                // pn(1<<10);
                // return 0;
                if(l==0){
                    Ai = Ac[r];
                }else{
                    Ai = Ac[r] - Ac[l-1];
                }
                // cout << l << " " << r << " " << Ai << " " << binary << " " << x+Ai << endl;
                ll xb = x+binary;
                if((xb&Ai) == xb){
                    count++;
                }
            }
        }
        if(count>=K){
            x += binary;
        }
    }

    p(x);
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = [0]*10**7

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            A[x**2+y**2+z**2+x*y+y*z+z*x] += 1
                
print(*A[1:n+1],sep='\n')

Measured memory_bytes: 146304
n = int(input())
hs = list(map(int, input().split()))

res = 0
left = 0
while left < n:
    if hs[left] == 0:
        left += 1
        continue
    right = left + 1
    while right <= n:
        if right < n and hs[right] > 0:
            right += 1
        else:
            a = min(hs[left:right])
            res += a
            for i in range(left, right):
                hs[i] -= a
            break
print(res)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long int Int;
int main() {
	Int N,M,ans=0;
	scanf("%lld %lld",&N,&M);
	ans+=min(N,M/2);
	M-=ans*2;
	ans+=M/4;
	printf("%lld\n",ans);
}

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

int main(){
  int h,w;
  long long l;
  int x,y,d;
  string g[100];

  int vis[100][100][4];
  char dir[] = {'N','E','S','W'};
  int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

  int px[40100],py[40100],pd[40100];

  while(cin >> h >> w >> l,h){
    for(int i=0;i<h;i++)cin >> g[i];

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int k=0;k<4;k++){
	  if(g[i][j] == dir[k]){
	    y = i; x = j; d = k;
	  }
	  vis[i][j][k] = -1;
	}
      }
    }

    int step = 0;
    for(;;){
      if(vis[y][x][d]>=0)break;
      vis[y][x][d] = step;
      
      py[step] = y; px[step] = x; pd[step] = d;
      step++;

      for(int i=0;i<4;i++){
	int nd = (d+i)%4;
	int ny = y+dy[nd], nx = x+dx[nd];
	if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
	if(g[ny][nx] == '#')continue;
	y = ny; x = nx; d = nd;
	break;
      }
    }

    long long head = vis[y][x][d], now = l;
    if(step<l){
      now -= head;
      now %= step-head;
      now += head;
    }
    cout << py[now]+1 << " " << px[now]+1 << " " << dir[pd[now]] << endl;
  }
}

Measured memory_bytes: 1464
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
using namespace std;

int main() {
	int N,p=0,w=0,g=0,y=0;
	char a;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		if (a == 'P') {
			p=1;
		}
		else if (a == 'W') {
			w=1;
		}
		else if (a == 'G') {
			g=1;
		}
		else if (a == 'Y') {
			y=1;
		}
	}
	if (p + w + g + y == 3) {
		cout << "Three" << endl;
	}
	else {
		cout << "Four" << endl;
	}
}

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

using namespace std;

#define ll long long

signed main() {
	int k; cin >> k;
	vector<int> a(k);
	for (int i = 0; i < k; ++i)
		cin >> a[i];

	if (a[k - 1] != 2) {
		cout << -1 << endl;
		exit(0);
	}

	ll s = 2, m = 2;
	for (int i = k - 1; i >= 0; --i) {
		int ai = a[i];
		// nx_s := s以上の最小のaiの倍数
		ll nx_s = ((s - 1) / ai + 1) * ai;
		// nx_m := m以下の最大のaiの倍数 + (ai - 1)
		ll nx_m = (m / ai * ai) + ai - 1;
		if (nx_m < nx_s) {
			cout << -1 << endl;
			exit(0);
		}
		s = nx_s; m = nx_m;
	}

	cout << s << " " << m << endl;

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define M0D 998244353;

int main(){
  const double pi = 3.141592653589793;
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  double ans=0,cosX,num;
  num = abs(360*M/60 - 360*(H+M/60)/12);
  cosX = min(360.-num,num);
  ans = sqrt(A*A + B*B - 2*A*B*cos(pi/(180./num)));
  cout << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 4192
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
	string s; cin >> s; int n = s.length(); bool x = true;
	for (int i = 97; i <=122; i++)
	{
		 x = true;
		for (int j = 0; j < n; j++)
		{

			if (char(i) == s[j])
			{
				x = false;
				continue;

			}

		}
	
		if (x== true)
		{
			cout<<char(i)<<endl;
			return 0;
		}
	}
	if (x == false) {
		cout << "None" << endl;
		return 0;
	}
}


Measured memory_bytes: 3768
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int n,fi,fi1;
    string str;
    cin>>n;
    for(int i=0;i<n;i++){
        if(i==0){
        getline(cin,str);
        }
        getline(cin,str);
        while(1){
        fi=str.find("Hoshino");
            if(fi==-1){
                break;
            }
        str.replace(fi,7,"Hoshina");
        }
        cout<<str<<endl;
    }
    return 0;
}

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

ll gcd(ll a, ll b) {
  return b != 0 ? gcd(b, a % b) : a;
}

int main(){
  int K;
  ll sums = 0;
  cin >> K;
  rep(i, K){
    rep(j, K){
      rep(k, K){
        sums += gcd(gcd((i+1), (j+1)), (k+1));
      }
    }
  }
  cout << sums << endl;
}


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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int n, m;
  cin >> n >> m;
  int best = -1;
  auto modify = [&](auto g) {
    if (m / g >= n) {
      best = max(best, g);
    }
  };
  for (int f = 1; f * f <= m; ++f) {
    if (m % f == 0) {
      modify(f);
      modify(m / f);
    }
  }
  cout << best << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
use itertools::iproduct;
use num::integer::gcd;
use proconio::input;

#[rustfmt::skip]
fn main() { std::thread::Builder::new().stack_size(128 * 1024 * 1024).spawn(solve).unwrap().join().unwrap(); }

#[proconio::fastout]
fn solve() {
    input! {
        K: i64
    }

    println!(
        "{}",
        iproduct!(1..=K, 1..=K, 1..=K)
            .map(|(a, b, c)| gcd(a, gcd(b, c)))
            .sum::<i64>()
    );
}


Measured memory_bytes: 2260
// dp[i][K] denote the number of ways to distribute all K candies among first i people
// dp[i][K] = dp[i-1][K] + dp[i-1][K-1] + dp[i-1][K-2]....dp[i-1][K-A[i]]

// dp[0][0] = 1; dp[0][X] = 0;

// prefixSum of dp[i-1]

// dp[i][K] denote number of ways to distribute atmost K candies to first i students! 
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
ll a[101];
ll dp[101][100001];
ll prefix[101][100001];
ll mod = 1000000007LL;
int main() {
	ll n, K;
	cin>>n>>K;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
	}
	dp[0][0] = 1;
	prefix[0][0] = 1;
	for(int j=1;j<=K;j++) {
		prefix[0][j] = prefix[0][j-1];
	}
	for(int i=1;i<=n;i++) {
		for(int j=0; j<=K;j++) {
			dp[i][j] = prefix[i-1][j] - 
				(j - a[i] -1 >=0 ? prefix[i-1][j-a[i] -1]:0LL);
			dp[i][j] %= mod;
		}
		prefix[i][0] = dp[i][0];
		for(int j=1; j<=K;j++) {
			prefix[i][j] = prefix[i][j-1] + dp[i][j];
			prefix[i][j] %= mod;
		}
	}
	if(dp[n][K] < 0) dp[n][K] += mod;
	cout<< dp[n][K] <<endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 25;

vector <ll> b(L);
ll a[L][L];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N, M, C;
    cin >> N >> M >> C;

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

    ll ans = 0;

    for(ll i=0; i<N; i++)
    {
        for(ll j=0; j<M; j++)
        {
            cin >> a[i][j];
        }

        ll cur = C;
        for(ll j=0; j<M; j++)
        {
            cur+=a[i][j]*b[j];
        }

        if(cur > 0)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#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>
#include "limits.h"
 
#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 (int 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>;

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

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

  std::reverse(all(s));

  ll n=s.size();

  ll dp[2]={0};

  dp[1]=MOD;

  rep(i,0,n){
    ll num=s[i]-'0';
    ll temp[2]={MOD};
    temp[0]=MOD;
    temp[1]=MOD;
    if(num==9){
      chmin(temp[1],dp[1]);
    }else{
      chmin(temp[1],dp[1]+9-num);
      chmin(temp[0],dp[1]+num+1);
    }
    if(num==0){
      chmin(temp[0],dp[0]);
    }else{
      chmin(temp[1],dp[0]+10-num);
      chmin(temp[0],dp[0]+num);
    }
    dp[0]=temp[0];
    dp[1]=temp[1];
  }

  std::cout<<std::min(dp[0],dp[1]+1)<<"\n";

  return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1010;

int n, m;
char g[N][N];

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++) scanf("%s", g[i]);

    for(int i = 0; i < n; i++) printf("%s\n%s\n", g[i], g[i]);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;
#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif


namespace Solver{
using namespace std;

struct Problem{
    int n,k;
    Problem(LL n):n(n){};

    void solve(){
        string s,s_pre;
        k=1;
        while(k<n)k<<=1;
        k>>=1;
        DBG(k)
        cout << 0 <<endl;
        fflush(stdout);
        cin >> s_pre;
        if(s_pre=="Vacant")return;
        int now = k,prev=0;
        while(k>1){
            cout << now <<endl;
            fflush(stdout);
            cin >> s;
            k>>=1;
            if(s=="Vacant"){
                return;
            }else if(s!=s_pre){
                int tmp = now;
                now = (now+prev)/2;
                prev=tmp;
            }else{
                int tmp = now;
                if(prev<now){
                    while(now+k>=n)k>>=1;
                    now+=k;
                }else{
                    now-=k;
                }
                prev = tmp;
            }
            s_pre=s;
        }
        cout << now <<endl;
        fflush(stdout);
        cin >> s;
        assert(s=="Vacant");
    }
};
}

int main(){
    long long n=0;
    std::cin >> n;
    Solver::Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 852
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include<string>
#include <bitset>

#define SIZE 1001
typedef long long ll;
using namespace std;

int main(){

    string S,T;
    cin >> S;
    cin >> T;
    int c = T.size();
    for(int i = 0 ; i < S.size() - T.size() + 1 ; i++){
        int count = 0;
        for(int j = 0 ; j < T.size() ; j++){
            if(S[j+i] != T[j]){
                count++;
            }
        }
        if(count < c){
            c = count;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3600
/* Name        : a
 * Creat       : Fri Jul 12 22:17:16 CST 2019
 * Accept      : Fri Jul 12 22:17:54 CST 2019
 * Author      : landcold7
 * Action speaks louder more than words
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int x, a;
  cin >> x >> a;
  if (x < a) {
    cout << 0 << "\n";
  }
  else {
    cout << 10 << "\n";
  }
}

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


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    int k, t;
    int gokei = 0;
    cin >> k >> t;
    vector<int> a(t);
    REP(i, t) {
        cin >> a[i];
        gokei += a[i];
    }
    sort(ALL(a));
    gokei -= a[t-1];

    if(a[t-1] <= gokei + 1) {
        cout << "0" << endl;
    } else {
        cout << a[t-1] - gokei - 1 << endl;
    }

    return 0;
}

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

struct Dice{
	int top;
	int front;
	int right;
	int left;
	int back;
	int bottom;
};
void roll_n(Dice &dice)
{
	int a = dice.top;
	dice.top = dice.front;
	dice.front = dice.bottom;
	dice.bottom = dice.back;
	dice.back = a;
}
void roll_e(Dice &dice)
{
	int a = dice.top;
	dice.top = dice.left;
	dice.left = dice.bottom;
	dice.bottom = dice.right;
	dice.right = a;
}
void roll_w(Dice &dice)
{
	int a = dice.top;
	dice.top = dice.right;
	dice.right = dice.bottom;
	dice.bottom = dice.left;
	dice.left = a;
}
void roll_s(Dice &dice)
{
	int a = dice.top;
	dice.top = dice.back;
	dice.back = dice.bottom;
	dice.bottom = dice.front;
	dice.front = a;
}
void roll_top(Dice &dice, int top)
{
	if(top == dice.top){
	
	}
	else if(top == dice.front){
		roll_n(dice);
	}
	else if(top == dice.right){
		roll_w(dice);
	}
	else if(top == dice.left){
		roll_e(dice);
	}
	else if(top == dice.back){
		roll_s(dice);
	}
	else{
		roll_e(dice);
		roll_e(dice);
	}
}
void roll_front(Dice &dice, int front)
{
	if(front == dice.front){
	
	}
	else if(front == dice.right){
		roll_top(dice, front);
		roll_s(dice);
	}
	else if(front == dice.left){
		roll_top(dice, front);
		roll_s(dice);
	}
	else{
		roll_top(dice, front);
		roll_s(dice);
	}
}
int main(void)
{	
	Dice dice;
	
	cin >> dice.top >> dice.front >> dice.right >> dice.left >> dice.back >> dice.bottom;
	
	int q;
	cin >> q;
	
	for(int i = 0; i < q; i++){
		int top;
		int front;
		cin >> top >> front;
		
		roll_front(dice, front);
		roll_top(dice, top);
		
		cout << dice.right << endl;
	}

	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
  long n;
  std::cin >> n;
  std::vector<long> a(n);
  rep(i,n)std::cin >> a[i];
  sort(all(a));
  int counter=n,cc=1;
  rep(i,n-1){
    
    if(a[i]==a[i+1]){
      counter--;
      cc++;
    }else{
      if(cc%2==0)counter--;
      cc=1;
    }
    
  }
  if(cc%2==0)counter--;
  std::cout << counter << std::endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int a,b;
  cin>>a>>b;
  cout<<max(2*a-1,max(a+b,2*b-1))<<endl;
}

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

using namespace std;

int main()
{
    int N,D;
    cin >> N >> D;
    vector<vector<int>> X(N);
    for(int i = 0;i < N;i++){
        vector<int> q(D);
        X[i] = q;
        for (int j = 0;j < D;j++) {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for(int i = 0;i < N-1;i++) {
        for(int j = i + 1;j < N;j++){
            //(i, j)
            int t = 0;
            for (int k = 0;k < D;k++) {
                t+=pow(X[i][k] - X[j][k] ,2);
            }
           bool f = false;
           for (int k = 1;k < t+1;k++) {
               if(k*k == t){
                   f = true;
               }
           }

           if(f == true){
               ans++;
           }
        }
    }
    cout<<ans<<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;
typedef long long ll;
const int INF = 1e9;

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

  if (n < 100) {
    cout << 0 << endl;
    return 0;

  } else {
    if (n / 100 * 105 >= n) {
      cout << 1 << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        const bool IsTest = false;

        const string t1 = "111";
        const string t2 = "112";
        public static void Main(string[] args)
        {
            if (!IsTest) {
                new Program().Solve(new ConsoleInput(Console.In));
            } else {
                new Program().Solve(new ConsoleInput(new StringReader(t1)));
                new Program().Solve(new ConsoleInput(new StringReader(t2)));
            }
        }

        public void Solve(ConsoleInput cin)
        {
            cin.ReadLine();
            var N = cin.Read<int>();
            Console.WriteLine(((N + 110) / 111) * 111);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private readonly char _separator = ' ';
        private string _curLine;
        private string[] _curLineSplitted;
        private int _curItemIndex;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
        }
        public T Read<T>()
        {
            var converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(T));
            if (converter == null) {
                throw new Exception(string.Format("TypeDescriptor.GetConverter {0}", typeof(T).Name));
            }
            return (T)converter.ConvertFromString(ReadString());
        }
        public T[] ReadArray<T>(long N)
        {
            var ret = new T[N];
            for (long i = 0; i < N; i++) {
                ret[i] = Read<T>();
            }
            return ret;
        }
        public Tuple<T> ReadLineAs<T>()
        {
            ReadLine();
            return new Tuple<T>(Read<T>());
        }
        public Tuple<T, S> ReadLineAs<T, S>()
        {
            ReadLine();
            return new Tuple<T, S>(Read<T>(), Read<S>());
        }
        public Tuple<T, S, U> ReadLineAs<T, S, U>()
        {
            ReadLine();
            return new Tuple<T, S, U>(Read<T>(), Read<S>(), Read<U>());
        }
        public Tuple<T, S, U, V> ReadLineAs<T, S, U, V>()
        {
            ReadLine();
            return new Tuple<T, S, U, V>(Read<T>(), Read<S>(), Read<U>(), Read<V>());
        }
        public Tuple<T, S, U, V, R> ReadLineAs<T, S, U, V, R>()
        {
            ReadLine();
            return new Tuple<T, S, U, V, R>(Read<T>(), Read<S>(), Read<U>(), Read<V>(), Read<R>());
        }

        public string ReadString()
        {
            return _curLineSplitted[_curItemIndex++];
        }
        public void ReadLine()
        {
            _curLine = _stream.ReadLine();
            if (_curLine == null) {
                throw new System.Exception("No more lines");
            }
            _curLineSplitted = _curLine.Split(_separator);
            _curItemIndex = 0;
        }
    }
}



Measured memory_bytes: 14420
N = int(input())
lst = [0]*(N+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            p = (x+y)*(x+z)+y**2+z**2
            if p > N:
                break
            else:
                lst[p] += 1
for i in range(1,N+1):
    print(lst[i])

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

using namespace std;

typedef long long ll;

const int N = 1e5+5;

const int mod = 1e9+7;

int n;
int a , b;
int x[N];

int main() {
    scanf("%d%d%d" , &n , &a , &b);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &x[i]);
    }
    if(b <= a){
        printf("%lld\n" , (n - 1LL) * b);
        return 0;
    }
    long long ans = 0;
    for(int i = 2; i <= n; i++){
        ans += min(b*1LL , (x[i] - x[i-1] - 0LL) * a);
    }
    printf("%lld\n" , ans);
    return 0;
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main(){
    ll N; cin >> N;
    ll ans = 0;
    rep(i,N){
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
(defparameter *dp* (make-array 100010 :initial-element 0))
(defun StrangeBank (n)
  (dotimes (i n)
    (let ((ii (1+ i)))
      (setf (aref *dp* ii) 
            (1+ (aref *dp* (1- ii))))
      (do ((tmp 6 (* tmp 6)))
          ((> tmp ii))
        (setf (aref *dp* ii) (min (aref *dp* ii)
                                    (1+ (aref *dp* (- ii tmp))))))
      (do ((tmp 9 (* tmp 9)))
          ((> tmp ii))
        (setf (aref *dp* ii) (min (aref *dp* ii)
                                  (1+ (aref *dp* (- ii tmp))))))))
  (format t "~A~%" (aref *dp* n)))
 
(StrangeBank (read))

Measured memory_bytes: 18276
n = int(input())
B = list(map(int, input().split()))
A = []
for b in B:
    A.insert(b-1, b)
if all(A[i] <= i+1 for i in range(n)):
    C = []
    for a in A:
        C.insert(a-1, a)
    if B == C:
        print(*A, sep='\n')
    else:
        print(-1)
else:
    print(-1)

Measured memory_bytes: 3060
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

newtype Vector a =
    Vector (a, a)
    deriving (Eq, Show)

vector :: a -> a -> Vector a
vector x y = Vector (x, y)

isOrthogonal :: (Num a, Eq a) => Vector a -> Vector a -> Bool
isOrthogonal (Vector (x1, y1)) (Vector (x2, y2))
    = (x1 * x2 + y1 * y2) == 0

isParallel :: (Num a, Ord a) => Vector a -> Vector a -> Bool
isParallel (Vector (x1, y1)) (Vector (x2, y2))
    = if x1 < x2
      then (x1 * y2 - x2 * y1) == 0
      else (x2 * y1 - x1 * y2) == 0

solve :: [[Int]] -> IO ()
solve [] = return ()
solve ([x0, y0, x1, y1, x2, y2, x3, y3]:ps) = do
    let v1 = vector (x1 - x0) (y1 - y0)
    let v2 = vector (x3 - x2) (y3 - y2)
    case () of
        _ | isParallel v1 v2   -> putStrLn "2"
          | isOrthogonal v1 v2 -> putStrLn "1"
          | otherwise          -> putStrLn "0"
    solve ps

main :: IO ()
main = do
    q <- readLn
    qs <- fmap (fmap readi . B.words) <$> replicateM q B.getLine
    solve qs



Measured memory_bytes: 4340
import math
X=int(input())
if X==2:
  print('2')
  exit()
else:
  l=list()
  x=math.sqrt(X)
  key=math.floor(x)
  for i in range(X,(key+1)**2):
    l.append(i)
    
for n in range(2,key+1):
  for x in l:
    if x%n==0:
      l.remove(x)
print(l[0])

Measured memory_bytes: 3060
'use strict'
function Main(input) {
  input = input.split('\n')[0].split('');
  let output = '';
  for (let i = 0; i < input.length; i++) {
    if (input[i] == '0') {
      output += '0';
    } else if (input[i] == '1') {
      output += '1';
    } else {
      output = output.slice(0, -1);
    }
  }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long long a, long long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long long a, long long b){
	return a / gcd(a,b) * b;
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int n, p;
int mini = 1123456;
int cnt = 0;

int main(){
	cin >> n;
	REP(i,n){
		cin >> p;
		if (mini >= p){
			cnt++;
			mini = p;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int k,s;
	int ans=0;
	scanf("%d %d", &k, &s);
	for(int i=0; i<=k; i++){
		for(int j=0; j<=k; j++){
			if (s-i-j<=k && s-i-j>=0) ans++;
		}
	}
	printf("%d", ans);
	return 0;
}

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

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

  ll ans = 0;
  if (a >= k) {
    cout << k << endl;
    return 0;
  } else {
    ans += a;
    k -= a;
  }

  if (b >= k) {
    cout << ans << endl;
    return 0;
  } else {
    k -= b;
  }

  ans -= k;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

ll INF = (ll) 1e20;
int iINF = (int) 1e20;
ll mod = (ll) 1e9 + 7;
ll mod2 = (ll) 1e9 + 9;

void dfs(ll v, vector<vector<ll>> &nodes, vector<ll> &num, ll p, vector<ll> &ans, ll sum) {
    sum += num[v];
    ans[v] = sum;
    for (auto i : nodes[v]) {
        if (i != p)
            dfs(i, nodes, num, v, ans, sum);
    }
}

signed main() {
    ll n, q;
    cin >> n >> q;
    vector<vector<ll>> nodes(n);
    for (int i = 0; i < n - 1; ++i) {
        ll a, b;
        cin >> a >> b;
        nodes[a - 1].push_back(b - 1);
        nodes[b - 1].push_back(a - 1);
    }
    vector<ll> num(n, 0);
    while (q--) {
        ll id, x;
        cin >> id >> x;
        num[id - 1] += x;
    }
    vector<ll> ans(n);
    dfs(0, nodes, num, 0, ans, 0);
    for(auto i : ans)
        cout << i << ' ';
}



Measured memory_bytes: 24212
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	long long int n, fiv=10, ans=0;

	cin>> n;

	if (n % 2 == 1) {
		cout << "0" << endl;
		return 0;
	}

	while (fiv <= 1000000000000000000) {
		//cout << fiv << endl;
		ans += n / fiv;
		fiv *= 5;
	}

	cout<< ans << endl;


}


Measured memory_bytes: 256
import heapq
from collections import deque

N = int(input())
A = [[int(a) for a in input().split()] for _ in range(N)]

def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**9+1] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


Road = [[] for _ in range(N)]
h = []
for i in range(N):
    for j in range(i+1, N):
        heapq.heappush(h, (A[i][j], i, j))
        
m = h[0][0]
D = [[10**9+1]*N for _ in range(N)]
ans = 0
while h:
    t = heapq.heappop(h)
    cost = t[0]
    i = t[1]
    j = t[2]
    if cost < 2*m:
        Road[i].append((cost, j))
        Road[j].append((cost, i))
        D[i][j] = cost
        D[j][i] = cost
    elif D[i][j] > cost:
        D[i] = dijkstra_heap(i, Road, N)
        if D[i][j] > cost:
            Road[i].append((cost, j))
            Road[j].append((cost, i))
            D[i][j] = cost
            D[j][i] = cost
    if D[i][j] < cost:
        ans = -1
        break
            
if ans == 0:
    for i in range(N):
        for t in Road[i]:
            ans += t[0]
            
    ans //= 2
        
print(ans)

Measured memory_bytes: 78684
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        n: u32,
        a: [u32; n],
    };
    let mut b = a.clone();
    let mut ans: i32 = 0;
    b.sort_by(|a, b| b.cmp(a));
    for (i, &v) in b.iter().enumerate(){
        ans += if i % 2 == 0 {v as i32} else{-1 * v as i32};
    }
    println!("{}", ans);
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll x,n;
  cin>>x>>n;
  vll q(101);
  REP(i,n){
    ll p;
    cin>>p;
    q[p]=1;
  }

  ll pmin=102;
  ll pdiff=1000;
  for(ll p=100; p>=1; p--){
    if(q[p]==1)
      continue;
    if(abs(x-p)<=pdiff){
      pmin=p;
      pdiff=abs(x-p);
    }
  }
  ll r=101;
  if(abs(x-r)<=pdiff){
    if(abs(x-r)==pdiff)
      pmin=min(pmin,r);
    else
      pmin=r;

    pdiff=abs(x-r);
  }
  ll l=0;
  if(abs(x-l)<=pdiff){
    if(abs(x-l)==pdiff)
      pmin=min(pmin,l);
    else
      pmin=l;
    pdiff=abs(x-l);
  }


  cout<<pmin<<endl;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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 int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

/*------------------------------------*/

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

    int N;
    cin>>N;
    vector<vector<ll>> cnt(10,vector<ll>(10,0));
    rep1(i,N+1){
        string S = to_string(i);
        int top = S[0] - '0';
        int back = S[S.size() - 1] - '0';
        //cerr<<i<<" "<<top<<" "<<back<<endl;
        cnt[top][back]++;
    }
    ll ans = 0;
    rep1(i,10)rep1(j,10){
        ans += cnt[i][j] * cnt[j][i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var pi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var count = 0;
            var min = n;
            for (var i = 0; i < n; i++)
            {
                var val = pi[i];
                if (val <= min)
                {
                    count++;
                    min = val;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 34012
N = int(input())
A = list(map(int, input().split()))
A_1 = sum(A)//2
A_tmp = 0
for i in range(N):
    A_tmp += A[i]
    if A_tmp < A_1:
        pass
    elif A_tmp == A_1:
        print(0)
        exit()
    else:
        A_tmp2 = A_tmp-A[i]
        ans1 = abs(A_tmp - (sum(A) - A_tmp))
        ans2 = abs(A_tmp2 - (sum(A) - A_tmp2))
        print(min(ans1,ans2))
        exit()

Measured memory_bytes: 87760
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

typedef pair < ll, ll> P;

const ll LLINF = pow(2, 61) - 1;
ll N, M;
struct edge {
	ll to, cost;
	
};

ll d[10000000];

vector<edge>G[100000];
void dijkstra(ll s) {
	priority_queue<P, vector<P>, greater<P>> q;
	fill_n(d, N, LLINF); d[s] = 0; q.push(P(0, s));
	while (!q.empty()) {
		P p = q.top(); q.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (auto e : G[v]) {
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	cin >> N >> M;
	rep(i, M) {
		int L, R, C; cin >> L >> R >> C; L--; R--;
		edge tmp = { R, C };
		G[L].push_back(tmp);
	}
	rep(i, N - 1) G[i + 1].push_back((edge){i, 0});
	dijkstra(0);
	ll result = (d[N - 1] != LLINF) ? d[N - 1] : -1;
	// rep(i,N) cout << d[i] << " "; cout << endl;
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 10364
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			if (a == 0)
				break;
			double sum = 0;
			int[] b = new int[a];
			for (int i = 0; i < a; i++) {
				b[i] = scanner.nextInt();
				sum += b[i];
			}
			double m = sum / a;
			double aa = 0;
			for (int i = 0; i < a; i++) {
				aa += Math.pow(b[i] - m, 2) / a;
			}
			System.out.println(Math.sqrt(aa));

		}

	}
}


Measured memory_bytes: 31384
def s():
 n=int(input())+1
 e=[input().split()for _  in[0]*~-n]
 p=[int(e[0][0])]+list(int(x[1])for x in e)
 m=[[0]*n for _ in[0]*n]
 for i in range(n):
  for r in range(n-i-1):
   c=r+i+1
   for j in range(r+1,c):
    x=m[r][j]+m[j][c]+p[r]*p[j]*p[c]
    if not 0<m[r][c]<=x:m[r][c]=x
 print(m[r][c])
if'__main__'==__name__:s()



Measured memory_bytes: 5716
def eratosthenes_sieve(n):
    if n < 2:
        return []

    is_primes = [True] * (n + 1)
    for x in range(2, int(n ** 0.5 + 1) + 1):
        if is_primes[x]:
            for mx in range(2 * x, n + 1, x):
                is_primes[mx] = False

    return [i for i in range(2, n + 1) if is_primes[i]]


X = int(input())
Primes = eratosthenes_sieve(10 ** 6)
for p in Primes:
    if p >= X:
        print(p)
        exit()


Measured memory_bytes: 13960
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define REP(i,m) for(int i = 0; i < m; ++i)
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

string str = "ENWS";
void solve()
{
	int w, h;
	while(cin >> w >> h, w || h) 
	{
		vector< vector<char> > ba(w, vector<char>(h));
		REP(y,h) REP(x,w) cin >> ba[x][y];
		int res = -1;
		REP(time, 180) 
		{
			int man = 0;
			REP(y,h) 
			{
				REP(x,w) 
				{
					REP(i,4) 
					{
						if (ba[x][y] == str[i]) 
						{
							man++;
							REP(k,4) 
							{
								int d = (i+3+k)%4;
								int xx = x+dx[d];
								int yy = y+dy[d];
								if (ba[xx][yy]=='X'||ba[xx][yy]=='.') 
								{
									ba[x][y] = str[d];
									goto OUT;
								}
							}
						}
					}
					OUT:;
				}
			}
			vector< vector<char> > next(w, vector<char>(h));
			next = ba;
			REP(x,w) 
			{
				REP(y,h) 
				{
					if (ba[x][y] != '.' && ba[x][y] != 'X') continue;
					REP(k,4) 
					{
						int xx = x+dx[k];
						int yy = y+dy[k];
						if (xx<0||xx>=w||yy<0||yy>=h) continue;

						if (ba[xx][yy] == str[(k+2)%4]) 
						{
							if (ba[x][y] == '.')
							next[x][y] = ba[xx][yy];
							else
							man--;
							next[xx][yy] = '.';
							break;
						}
					}
				}
			}
			if (man==0) 
			{
				res = time + 1;
				break;
			}
			ba = next;
		}
		if (res>=0)
		{
		  cout << res << endl;
		}
		else
		{
		  cout << "NA" << endl;
		}
	}
}

int main() 
{
  solve();
  return(0);
}

Measured memory_bytes: 0