akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[])
{
    string shape;
    set<pair<string, int>> completeset;

    int totalnumber, number;
    set<pair<string, int>> trumpset;
    array<string, 4> totalshape = {"S", "H", "C", "D"};

    for (auto var : totalshape)
    {
        for (int i = 1; i < 14; i++)
        {
            completeset.insert(make_pair(var, i));
        }
    }

    cin >> totalnumber;
    for (int i = 0; i < totalnumber; i++)
    {
        cin >> shape >> number;
        trumpset.insert(make_pair(shape, number));
    }

    for (auto var : trumpset)
    {
        completeset.erase(var);
    }


    for (auto var1 : totalshape)
    {
        for (auto var : completeset)
        {
            if(var1==var.first) cout << var.first << " " << var.second << endl;
        }
    }


    return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define int long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vpll       vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(container) int((container).size())
#define rep(i,a,b) for(i=a;i<b;i++)
#define tr(container,it)   for(auto it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mod 998244353
#define fs first
#define sc second
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
void solve()
{
  int n,W,i,j,sum=0,mx=0;
  cin>>n>>W;
  int wgt[n],val[n];
  rep(i,0,n){
    cin>>wgt[i]>>val[i];
    sum+=val[i];
  }
  vector<vector<int>>dp(n+1,vector<int>(sum+1,1e18));
  for(i=0;i<=n;i++)
    dp[i][0]=0;
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=sum;j++)
    {
      dp[i][j]=dp[i-1][j];
      if(j-val[i-1]>=0)
        dp[i][j]=min(dp[i][j],dp[i-1][j-val[i-1]]+wgt[i-1]);
    }
  }
  for(i=1;i<=n;i++)
  {
    for(j=0;j<=sum;j++)
    {
      if(dp[i][j]<=W)
        mx=max(mx,j);
    }
  }
  cout<<mx;
}
signed main()
{
  fastio
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int t;
  t=1;
  //cin>>t;
  while(t--)
  solve();
  TIME
  return 0;
}

Measured memory_bytes: 80256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
#define mt make_tuple
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;



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

  li N,K;
  cin >>N>>K;

  if(!N){cout<<1;return 0;}

  li ans =0;
  while(N>0){
  	N/=K;
  	ans++;
  }

  cout<<ans;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt();
		int x = A * B;
		if(x%2 != 0)System.out.println("Yes");
		else if((x*3)%2 != 0)System.out.println("Yes");
		else System.out.println("No");
	}

}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  sort(ALL(a));
  rep(i,0,n)rep(j,i+1,n-1){
    ll x=lower_bound(ALL(a),a[i]+a[j])-a.begin();
    //cout<<i spa j spa x<<endl;
    res+=x-j-1;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n, m = rli()
    edges = []
    for _ in range(m):
        a, b = rli()
        edges.append((a, b))
    edges.sort(key=lambda x:x[1])
    ans = 0
    left = 0
    for e in edges:
        if e[0] <= left:
            continue
        ans += 1
        left = e[1]-1
    #     print(ans, e[0], left)
    # print(edges)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18308
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        ll N;
        cin >> N;
        vll A(N);
        rep(i, 0, N) cin >> A[i];

        vll acc(N+1);
        rep(i, 1, N+1) acc[i] = acc[i-1] + A[i-1];

        sort(all(acc));
        acc.push_back(inf);

        ll ans = 0;
        ll now = acc[0];
        
        ll cnt= 0;
        //print1d(acc);
        rep(i, 0, N+2) {
                if (acc[i] != now) {
                        ans += cnt*(cnt-1) / 2;
                        now = acc[i];
                        cnt = 1;
                } else {
                        ++cnt;
                }
        }

        cout << ans << endl;
}


Measured memory_bytes: 7884
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;


void weather_predicition()
{
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy\n";
  else if (s == "Cloudy") cout << "Rainy\n";
  else if (s == "Rainy") cout << "Sunny\n";
}


void odds_of_oddness()
{
  int n;
  cin >> n;

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (i % 2 != 0) ++cnt;
  }

  cout << (float)cnt / (float)n << "\n";
}


void curtain()
{
  int a, b;
  cin >> a >> b;

  if (a - 2 * b > 0) cout << a - 2 * b << "\n";
  else cout << 0 << "\n";
}


void cant_wait_for_holiday()
{
  string s;
  cin >> s;

  vector<string> S{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

  int cnt = 7;
  for (int i = 0; i < 7; ++i)
  {
    if (s == S[i]) cout << cnt << "\n"; 
    --cnt;
  }

}


void blackjack()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  if (accumulate(a.begin(), a.end(), 0) >= 22) cout << "bust\n";
  else cout << "win\n";
}


void round_one()
{
  int a, b;
  cin >> a >> b;

  cout << 6 - a - b;
}


void strings()
{
  string s, t;
  cin >> s >> t;

  cout << t + s << "\n";
}


void yen_conins()
{
  int k, x;
  cin >> k >> x;

  if (k * 500 - x >= 0) cout << "Yes\n";
  else cout << "No\n";
}


void tap_dance() 
{
  string s;
  cin >> s;

  int flag = 1;
  for (int i = 1; i <= s.size(); ++i)
  {
    if (i % 2 == 0)
    {
      if (s[i] == 'L') flag = 0;
    }
    else
    {
      if (s[i] == 'R' ) flag = 0;
    }
  }
  if (flag) cout << "Yes\n";
  else cout << "No\n";
}


void roller_coaster()
{
  int n, k;
  cin >> n >> k;

  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    int h;
    cin >> h;
    if (h >= k) ++cnt;
  }
  cout << cnt << "\n";
}



int main()
{
  //weather_predicition();
  //odds_of_oddness();
  //curtain();
  //cant_wait_for_holiday();
  //blackjack();
  //round_one();
  //strings();
  //yen_conins();

  //tap_dance();
  roller_coaster();
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    string s, ss;
    cin >> s >> ss;
    int N = int(s.size()) + int(ss.size());
    rep(i, N) {
        if (i % 2) {
            cout << ss[i/2];
        } else {
            cout << s[i/2];
        }
    }
    cout << endl;
    return 0;
}

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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            int a = ab[0], b = ab[1];
            if (a == b) Console.WriteLine(0);
            else
            {
                if ((a + b) % 2 == 0) Console.WriteLine((a + b) / 2);
                else Console.WriteLine("IMPOSSIBLE");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
int vals[100001] = {0};
vector<int> graph[100001];
vector<int> opp[100001];
void dfs(int node){
    vector<int> v;
      for (int i : graph[node]){
          dfs(i);
          v.push_back(vals[i]);
      }
      sort(v.rbegin(), v.rend());
      int cnt = 0;
      for (int p : v){
          cnt++;
          vals[node] = max(vals[node], p+cnt);
      }
}
int main ()
{
  prep();
  int n;
  cin >> n;
  
  for (int i=2; i<=n; i++){
      int a;
      cin >>a;
      graph[a].push_back(i);
      opp[i].push_back(a);
  }
  
  int maxx = 0;
  
  dfs(1);
  for (int i=1; i<=n; i++){
      maxx = max(vals[i], maxx);
      //cout << vals[i] << " ";
  }
  cout << maxx;
  return 0; 
}

Measured memory_bytes: 22528
from collections import defaultdict
n, p = map(int, input().split())
cnt = defaultdict(int)
if n == 1:
    print(p)
    exit()
for i in range(2, int(p ** 0.5) + 1):
    flag = False
    while p % i == 0:
        p //= i
        cnt[i] += 1
ans = 1
for k, v in cnt.items():
    ans *= k ** (v // n)

print(ans)

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h[256];
    int n;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>h[i];
    for(int i=1; i<=n; i++) {
        cout<<"node "<<i<<": key = "<<h[i];
        if(i>1) cout<<", parent key = "<<h[i/2];
        if(2*i<=n)cout<<", left key = "<<h[2*i];
        if(2*i<n)cout<<", right key = "<<h[2*i+1];
        cout<<", \n";
    }
    
    return 0;
}

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

using namespace std;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int maxn = 30003;

int n, b[maxn], c[maxn];
long long ans;
char s[maxn];

map <int, int> m[maxn], a[maxn], p;

int main()
{
	n = gi();
	scanf("%s", s + 1);
	for (int i = 2; i <= n; i+=1)
	{
		for (int j = 0; j <= 9; j+=1) if (m[i - 1][j] == 1) m[i][j] = 1;
		m[i][s[i - 1] - '0'] = 1; 
	}
	for (int i = n - 1; i > 1; i-=1)
	{
		for (int j = 0; j <= 9; j+=1) if (a[i + 1][j] == 1) a[i][j] = 1;
		a[i][s[i + 1] - '0'] = 1; 
	}
	/*
	for (int i = 1; i <= n; i+=1)
		for (int j = 0; j <= n; j+=1) 
			if (m[i][j]) cout << i << ' ' << j << endl;
	for (int i = 1; i <= n; i+=1)
		for (int j = 0; j <= n; j+=1) 
			if (a[i][j]) cout << i << ' ' << j << endl;
	*/
	for (int i = 1; i <= n; i+=1)
	{
		for (int j = 0; j <= 9; j+=1)
		{
			if (m[i][j])
			{
				for (int k = 0; k <= 9; k+=1)
				{
					if (a[i][k])
					{
//						cout << j * 100 + (s[i] - '0') * 10 + k << endl;
						p[j * 100 + (s[i] - '0') * 10 + k] = 1;
					}
				}
			}
		}
	}
	for (int i = 0; i <= 999; i+=1) if (p[i]) ++ans;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 31232
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

class UF{
public:
  vector<int> u;
  vector<int> r;

  void init(int n){
    u.resize(n, 0);
    r.resize(n, 0);
    for(int i=0; i<n; i++) u[i] = i;
  }
  int root(int x){
    // if( u[x] == x ) return x;
    // else return root(u[x]);
    return u[x] == x ? x : u[x] = root(u[x]);
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if( x == y ) return;

    if( r[x] < r[y] ){
      u[x] = y;
    }else{
      u[y] = x;
      if( r[x] == r[y] ) r[x]++;
    }
  }
};
class Graph{
public:
  int from, to, cost;
  bool operator<(const Graph &g1)const{
    return g1.cost < cost;
  };
};

int main(void) {

  int n;
  cin >> n;
  UF uf;
  uf.init(n);
  priority_queue<Graph> g;

  vector< vector<int> > d(n, vector<int> (n, inf));

  for(int i=0; i<n; i++){
    d[i][i] = 0;
    int u, k;
    cin >> u >> k;
    for(int j=0; j<k; j++){
      int c, v;
      cin >> v >> c;
      d[u][v] = min(c, d[u][v]);
      // Graph tg;
      // tg.to = v;
      // tg.from = u;
      // tg.cost = c;
      // g.push(tg);
    }
  }
  while( !g.empty() ){
    cerr << g.top().from << " " << g.top().to << " " << g.top().cost << endl;
    g.pop();
  }

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      for(int k=0; k<n; k++){
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }

  for(int i=0; i<n; i++){
    cout << i << " " << d[0][i] << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 3140
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int h = sc.nextInt();
			if (min > h) {
				min = h;
			}
			list.add(h);
		}
		System.out.println(count(list, min) + min);
	}
	
	static int count(ArrayList<Integer> list, int min) {
		ArrayList<Integer> nlist = new ArrayList<>();
		int nmin = Integer.MAX_VALUE;
		int total = 0;
		for (int i = 0; i < list.size(); i++) {
			int x = list.get(i);
			if (x == min) {
				if (nlist.size() != 0) {
					total += count(nlist, nmin) + nmin - min;
					nlist = new ArrayList<>();
					nmin = Integer.MAX_VALUE;
				}
			} else {
				nlist.add(x);
				if (nmin > x) {
					nmin = x;
				}
				if (i == list.size() - 1) {
					total += count(nlist, nmin) + nmin - min;
				}
			}
		}
		return total;
	}
}


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

void main_()
{
    string S;
    cin >> S;
    auto start_pos = S.find('A');
    auto end_pos = S.rfind('Z');
    cout << end_pos - start_pos + 1 << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 720
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 100050
int n,i,a[N];
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);int a1,a2;
	for (i=n;i>=1;i--) if (a[i]==a[i-1]) break;
	a1=a[i];
	if (a1==0){
		puts("0");return 0;
	}
	for (i-=2;i>=1;i--) if (a[i]==a[i-1]) break;
	a2=a[i];
	printf("%lld\n",1LL*a1*a2);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=pow(10,9)+7;
//int dp[22][(1<<22)+9];
vector<vector<ll>>adj;
pair<ll,ll> solve(int idx,int par){
  if(adj[idx].size()==1 && adj[idx][0]==par){
    pair<ll,ll>p={1,1};
    return p;
  }
  ll white_col=1;
  ll black_col=1;
  for(ll i=0;i<(ll)adj[idx].size();i++){
    if(adj[idx][i]==par)continue;
    pair<ll,ll>p=solve(adj[idx][i],idx);
    white_col=((white_col %mod)*((p.first+p.second)%mod))%mod;
    black_col=((black_col%mod)*(p.first%mod))%mod;
  }
  pair<ll,ll>p={white_col,black_col};
  return p;
}
int main(){
  ll n;
  cin>>n;
  ll x,y;
  adj.resize(n+1);
  for(ll i=0;i<n-1;i++){
    cin>>x>>y;
    adj[x-1].push_back(y-1);
    adj[y-1].push_back(x-1);
  }
  ll idx=0;
  ll par=-1;
  pair<ll,ll>ans=solve(idx,par);
  ll val=((ans.first%mod)+(ans.second%mod))%mod;
  cout<<val<<endl;
}

Measured memory_bytes: 15488
import math
A, B, H, M = map(int, input().split())

hDegree = H * 30 + M / 2
mDegree = M * 6
bDegree = abs(hDegree - mDegree)

print(math.sqrt(A**2+B**2-2 *A*B*math.cos(math.radians(bDegree))))

Measured memory_bytes: 62320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc137_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<string> s(N);
  rep(i, N) {
    string _s;
    cin >> _s;
    sort(_s.begin(), _s.end());
    s[i] = _s;
  }
  sort(s.begin(), s.end());

  ll tmp = 0;
  ll ans = 0;
  repi(i, 1, N) {
    if (s[i - 1] == s[i])
      tmp++;
    else {
      if (tmp != 0) {
        tmp++;
        ans += tmp * (tmp - 1) / 2;
        tmp = 0;
      }
    }
  }
  if (tmp != 0) {
    tmp++;
    ans += tmp * (tmp - 1) / 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 6372
import numpy as np
import sys,collections as cl
def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

n = int(input())

a = seachPrimeNum(55555)
aa = []
for i in range(len(a)):
	if a[i] % 5 == 1:
		aa.append(a[i])

print(" ".join(map(str,aa[:n])))


Measured memory_bytes: 20396
#include <stdio.h>
#include <stdlib.h>

/* 数列Aの長さ */
static int n;
/* 数列Aへのポインタ */
static int *A;

/* 入力値の M から選んだ要素を引いていく再帰関数 */
/* 再帰呼出されると i をカウントアップする */
int solve(int i, int m)
{
    if (m == 0)
        return (1); /* 0 の場合は"yes"を返すことにする */
    if (i >= n)
        return (0);

    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return (res);
}

int main()
{
    int q, M, i;

    /* 組み合わせに使用できる数値を入力 */
    scanf("%d", &n);
    A = (int *)calloc(n, sizeof(int));
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    /* 質問 */
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &M);
        if (solve(0, M)) {
            puts("yes");
        }
        else {
            puts("no");
        }
    }
    return (0);
}


Measured memory_bytes: 2076
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n=int(input())\n"
"a=list(map(int,input().split()))\n"
"i=0\n"
"l=0\n"
"while True:\n"
"    if i>n-1:break\n"
"    j=i\n"
"    while j<n-1 and a[j+1]==a[j]:\n"
"        j+=1\n"
"    l+=(j-i+1)//2\n"
"    i=j+1\n"
"print(l)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int main() {
	int A, B, X; cin >> A >> B >> X;
	if (A <= X && A + B >= X) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc100/abc100_c.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;
  
  vector<ll> c(N);
  rep(i, N) { cin >> c[i]; }

  ll cnt = 0;
  rep(i, N) {
    while(c[i] != 0 && c[i] % 2 == 0) {
      c[i] /= 2;
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 384
#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;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

class union_find {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
public:
    union_find(ll n);
    ll find(ll x);
    void unite(ll x, ll y);
    bool same(ll x, ll y);
    ll size(ll x);
};

union_find::union_find(ll n){
    par.resize(n);
    ran.resize(n, 0);
    m_size.resize(n, 1);
    rep(i,n) par[i] = i;
};

ll union_find::find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll t = size(x)+size(y);
    m_size[x] = m_size[y] = t;
    if (ran[x] < ran[y]) {
        par[x] = y;
        //size[y] += size[x];
    } else {
        par[y] = x;
        //ize[x] += size[y];
        if (ran[x]==ran[y]) ran[x]++;
    }
};

ll union_find::size(ll x) {
    if (par[x] == x) return m_size[x];
    return size(par[x] = find(par[x]));
}

bool union_find::same(ll x, ll y) {
    return (find(x) == find(y));
};

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<int> x(m), y(m), z(m);
    rep(i,m) {
        cin>>x[i]>>y[i]>>z[i];
        x[i]--; y[i]--;
    }

    union_find uf(n);
    rep(i,m) uf.unite(x[i], y[i]);
    set<int> ans;

    rep(i,n) ans.insert(uf.find(i));
    
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define mod 924844033
#define maxn 2010
using namespace std;
int ans,dp[2][maxn][4],p=0,np=1,fac[maxn]={1},n,k;
void upd(int& x,int y){if((x+=y)>=mod)x-=mod;}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
		fac[i]=1ll*fac[i-1]*i%mod;
	dp[np][0][0]=1;
	for(int i=1;i<=k;++i){
		for(int j=i;j<=n;j+=k,swap(p,np))
			for(int l=0;l<=n;++l)
				for(int x=0;x<4;++x)if(dp[np][l][x]){
					int s=dp[np][l][x];
					upd(dp[p][l][x>>1],s);
					if(l+1<=n){
						if((~x&1)&&j>i)upd(dp[p][l+1][x>>1],s);
						upd(dp[p][l+1][x>>1|2],s);
					}
					dp[np][l][x]=0;
				}
		for(int l=0;l<=n;++l){
			upd(dp[np][l][0],dp[np][l][1]);
			for(int x=1;x<4;++x)dp[np][l][x]=0;
		}
	}
	for(int i=0,j=1;i<=n;++i,j=-j)
		ans=(ans+1ll*j*fac[n-i]*dp[np][i][0])%mod;//,printf("{%d}",dp[np][i][0]);
	ans=(ans+mod)%mod;
	printf("%d",ans);
}

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

using namespace std;

#define PB push_back
#define SZ(a) (int)a.size()
#define MP make_pair

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;

int main() {

	int a,b;
	scanf("%d %d", &a, &b);

	printf("%d\n", a*b);

	return 0;
}


Measured memory_bytes: 3832
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_N 100'000

using namespace std;

int T[MAX_N];

int main() {
  int N, C, K;
  cin >> N >> C >> K;
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
  }
  sort(T, T + N);
  int i = 0;
  int res = 0;
  while (i < N) {
    int j = 0;
    while (i < N && j < C && T[i] - T[i - j] <= K) {
      ++i;
      ++j;
    }
    ++res;
  }
  printf("%d\n", res);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
char a[20],b[20],c[20];
int main()
{
    int i,j,k,m,n;
    int a,b,c;
    cin>>a>>b>>c;
    for(i=a;i<=10000;i+=a)
    {
        if(i%b==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

ll TotSum = 0;

void solve(string s, ll tot) {
	if (s.empty()) {
		TotSum += tot;
		return;
	}

	for (ll i = 1; i <= s.size(); i++) {
		solve(s.substr(i), tot + stoll(s.substr(0, i)));
	}
}

int main() {
	faster;

	string s;
	cin >> s;

	solve(s, 0);

	cout << TotSum << endl;

	return 0;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a,b;
	multiset<pair<long long,long long>> memo;
	for (int i = 0; i < n; ++i)
	{
		cin>>a>>b;
		memo.insert(make_pair(b,a));
	}
	long long t=0LL;
	for (auto i = memo.begin(); i != memo.end(); ++i)
	{
		auto p=*i;
		t+=p.second;
		if (t>p.first)
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	std::string C;
	std::cin >> C;

	cout << static_cast<char>(C[0] + 1) << endl;

	return 0;
}


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

int main() {
  
  string s, p; cin >> s >> p; s += s;
  
  for (int i = 0; i < s.size() / 2; i++) {
    
    string tmp = s.substr(i, p.size());
    
    if (tmp == p) {
      cout << "Yes" << endl;
      return 0;
    }
    
  }
    
    cout << "No" << endl;
  
}


Measured memory_bytes: 3184
#include <iostream>
#include <string>
using namespace std;
int main(){
    int D;
    cin >> D;
    if(D==25)cout << "Christmas" << endl;
    else if(D==24)cout << "Christmas Eve" << endl;
    else if(D==23)cout << "Christmas Eve Eve" << endl;
    else if(D==22)cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

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

using namespace std;

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

    long long res = 0;
    unordered_map<string, int> mp;
    string tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        sort(&tmp[0], &tmp[tmp.length()]);

        auto itr = mp.find(tmp);
        if (itr == mp.end()) {
            mp[tmp] = 1;
        } else {
            res += mp[tmp];
            mp[tmp]++;
        }
    }

    cout << res << "\n";
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<vector<int>> G(N, vector<int>(N));
  auto dfs = [&](auto dfs, vector<int> a, int k) -> void {
    if (a.size() <= 1) return;
    vector<int> a0, a1;
    rep(i, a.size()) if (i % 2 == 0) a0.push_back(a[i]); else a1.push_back(a[i]);
    for (int x : a0) for (int y : a1) G[x][y] = G[y][x] = k;
    dfs(dfs, a0, k+1);
    dfs(dfs, a1, k+1);
  };
  vector<int> a(N); rep(i, N) a[i] = i;
  dfs(dfs, a, 1);
  for (int i=0; i<N-1; i++) for (int j=i+1; j<N; j++) cout << G[i][j] << " \n"[j==N-1];
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > SIZE(IsPrime)){
        IsPrime.resize(max+1, true);
    }
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i = 2; i <= sqrt(max); i++){
        if(IsPrime[i]){
            for(size_t j = 2; i*j <= max; j++){
                IsPrime[i*j] = false;
            }
        }
    }
}

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

    sieve(1e+5+10);

    int i = X;
    while(1){
        if (IsPrime[i]) break;
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 3664
### constant

DELTA = 1e-5

### subroutines

def aleq(a, b)
  (a - b).abs < DELTA
end

### main

n = gets.to_i

n.times do
  qr, rp, pq = gets.split.map(&:to_f)
  #p [qr, rp, pq]
    
  pn = gets.to_i
  pts = pn.times.map{gets.split.map(&:to_f)}
  #p pts

  qr_pq2 = (qr * qr) / (pq * pq)
  rp_pq2 = (rp * rp) / (pq * pq)
  #p [qr_pq2, rp_pq2]

  dists2 = pn.times.map{pn.times.map{nil}}
  for i in (0...pn)
    pxi, pyi, pzi = pts[i]
    for j in ((i + 1)...pn)
      pxj, pyj, pzj = pts[j]
      dists2[i][j] = (pxj - pxi) ** 2 + (pyj - pyi) ** 2 + (pzj - pzi) ** 2
    end
  end
  #p dists2

  ans = nil
  
  for i in (0...pn)
    for j in ((i + 1)...pn)
      dij = dists2[i][j]
      for k in ((j + 1)...pn)
        dik = dists2[i][k]
        djk = dists2[j][k]

        fik_ij = dik / dij
        fjk_ij = djk / dij
        if aleq(fik_ij, qr_pq2) && aleq(fjk_ij, rp_pq2)
          ans = [j, i, k]
          break
        end
        if aleq(fjk_ij, qr_pq2) && aleq(fik_ij, rp_pq2)
          ans = [i, j, k]
          break
        end

        fij_jk = dij / djk
        fik_jk = dik / djk
        if aleq(fij_jk, qr_pq2) && aleq(fik_jk, rp_pq2)
          ans = [k, j, i]
          break
        end
        if aleq(fik_jk, qr_pq2) && aleq(fij_jk, rp_pq2)
          ans = [j, k, i]
          break
        end

        fij_ik = dij / dik
        fjk_ik = djk / dik
        if aleq(fij_ik, qr_pq2) && aleq(fjk_ik, rp_pq2)
          ans = [k, i, j]
          break
        end
        if aleq(fjk_ik, qr_pq2) && aleq(fij_ik, rp_pq2)
          ans = [i, k, j]
          break
        end
      end
    end
    break if ans
  end

  puts ans.map{|i| i + 1}.join(' ')
end

Measured memory_bytes: 6180
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
#define int long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int s, w; cin >> s >> w;
	if (w >= s) cout << "unsafe\n";
	else cout << "safe\n";
}

Measured memory_bytes: 3656
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var ans = m1(0, n);
        Console.WriteLine(ans);
    }

    static int[] d = new[] { 7, 5, 3 };
    static int m1(int x, int max)
    {
        var sum = m2(x) ? 1 : 0;
        for (int i = 0; i < 3; i++)
        {
            var n = 10 * x + d[i];
            if (0 < n && n <= max)
            {
                sum += m1(n, max);
            }
        }
        return sum;
    }

    static bool m2(int x)
    {
        var s = x.ToString();
        return s.Contains('7') && s.Contains('5') && s.Contains('3');
    }
}

Measured memory_bytes: 13268
#include <float.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

inline int max2(const int a, const int b){return a>b?a:b;}
inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

#define nextInt nextpint

int main(void){
	int N = nextInt();
	int *a = calloc(N, sizeof(N));
	int b = 0;
	for(int i=0; i<N; i++){
		b += (a[i] = nextInt());
	}
	int *c = calloc(N, sizeof(N));
	int min = 0;
	for(int i=0; i<N; i++){
		c[i] = dif2(a[i]*N, b);
		if(c[i] < c[min]){
			min = i;
		}
	}
	printf("%d\n", min);
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
ll a[N];
ll ans=1e9,n;
ll fei(ll x){
    ll su=0;
    for(int i=1;i<=n;i++){
        su+=(a[i]-x)*(a[i]-x);
    }
    return su;
}
int main(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(int i=1;i<=1000;i++){
        ans=min(ans,fei(i));
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;


int main()
{
   int r[5];
    int acc = 0, count=0;
    
    map<int, int> mp;
    for (int i = 0; i < 5; i++) {
        cin >> r[i];
    }
    
    for (int i = 0; i < 5; i++) {
        if (r[i] % 10 != 0) {
            mp[r[i] % 10] = r[i];
        } else {
            count++;
        }
    }
    if (count == 5) {
        cout <<  r[0] + r[1] + r[2] + r[3] + r[4] << endl;
        return 0;
    }
                
    for (int i = 0; i < 5; i++) {
        if ((r[i]%10) != 0) {
        acc += r[i] - (r[i]%10) + 10;
        } else {
            acc += r[i];
        }
    }
   
    acc = acc - (10 - mp.begin()->first);
        
    cout << acc << endl;
    
    return 0;   
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize,
        a: [usize; n]
    }

    let mut money = 1000;
    let mut stock = 0;

    for i in 0..n {
        // println!("money: {}, stock: {}", money, stock);
        if i == n-1 {
            money += stock * a[i]
        } else {
            if a[i] < a[i+1] {
                // 買えるだけ買う
                let stock_buy = money / a[i];
                stock += stock_buy;
                money -= stock_buy * a[i];
            } else if a[i] == a[i+1] {
                continue;
            } else {
                money += stock * a[i];
                stock = 0;
            }
        }
    }

    println!("{}", money);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2172
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>

using namespace std;

struct Node
{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k)
{
  while ( u != NIL && k != u->key )
  {
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }

  return u;
}

void insert(int k)
{
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while ( x != NIL )
  {
    y=x;
    if ( z->key < x->key ) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if (y == NIL) root = z;
  else
  {
    if ( z->key < y->key )
    {
      y->left = z;
    }
    else
    {
      y->right = z;
    }
  }
}

void inorder (Node *u)
{
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder (Node *u)
{
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main()
{
  int n, i, x;
  string com;

  scanf("%d", &n);
  for (i = 0; i < n; i++ )
  {
    cin >> com;
    if ( com[0] == 'f')
    {
      scanf("%d", &x);
      Node *t = find(root, x);
      if (t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com == "insert" )
    {
      scanf("%d", &x);
      insert(x);
    }
    else if ( com == "print" )
    {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



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

int main() {
	int H, W, N; cin >> H >> W >> N;
	int sr, sc; cin >> sr >> sc;
	sr--; sc--;
	string S, T; cin >> S >> T;
	
	int hmin, hmax, wmin, wmax;
	hmin = 0; hmax = H;
	wmin = 0; wmax = W;

	bool check = true;
	for (int i = N - 1; i >= 0; i--) {
		if (T[i] == 'R' and wmin != 0) wmin--;
		if (T[i] == 'L' and wmax != W) wmax++;
		if (T[i] == 'D' and hmin != 0) hmin--;
		if (T[i] == 'U' and hmax != H) hmax++;

		if (S[i] == 'R') wmax--;
		if (S[i] == 'L') wmin++;
		if (S[i] == 'D') hmax--;
		if (S[i] == 'U') hmin++;
		if (wmax == wmin or hmax == hmin) {
			check = false;
			break;
		}
	}

	if (check and hmin <= sr and sr < hmax and wmin <= sc and sc < wmax) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 776
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    L = len(s)
    tmp = []
    tt = ''
    for i, ss in enumerate( s ):
        tmp += [ s[L-i-1] ]
        if s[L-i-1] > s[L-i-2]:
            ans = s[:L-i-2]
            tt = s[L-i-2] 
            break
    tmp.sort()
    for i in tmp:
        if i > tt:
            print (ans + i)
            break
main()



Measured memory_bytes: 3832
#include <iostream>
#include <bits/stdc++.h>
#define read(a) scanf("%d", &a)
#define read2(a,b) scanf("%d%d", &a, &b)
#define f(i,a,b) for (int i=a; i<b; i++)
#define F(i,a,b) for (int i=a; i<=b; i++)
#define fod(i,a,b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define MOD 998244353
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef map<int,int> mii;

const int maxn=1e5+5;
int A[maxn];
int B[maxn];
int main()
{
    int n;
    cin>>n;
    F(i,1,n) cin>>A[i];
    B[2]=abs(A[2]-A[1]);
    F(i,3,n) B[i]=min(B[i-1]+abs(A[i]-A[i-1]), B[i-2]+abs(A[i]-A[i-2]));
    cout<<B[n];
    return 0;
}


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

/*
  ll n , m ;
  cin >> n >> m ;
  ll a , b , c ;
  cin >> a >> b >> c ;
  vector<ll> A(n) ;
  cout << "Yes" << endl ;
  cout << "No"  << endl ;
*/

int main(){
  ll k ;
  cin >> k ;
  ll mod = k ;
  ll now = 7 % mod ;
  ll p = 1 ;
  ll count = 1 ;
  map<ll,ll> mp ;
  mp[now]++ ;
  while( mp[now]<=1 ){
    if( now == 0 ){
      cout << count << endl ;
      return 0 ;
    }
    p *= 10  ;
    p %= mod ;
    now = now + p * 7 ;
    now %= mod ;
    mp[now]++ ;
    count++ ; 
  }
  cout << -1 << endl ;
  return 0 ;
}


Measured memory_bytes: 66084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main (String[] args ) throws IOException{
        BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
        
        String line = reader.readLine();
        String[] columns = new String[1000];
        columns = line.split(" ");
        int n = Integer.parseInt(columns[0]); // 3
        int m = Integer.parseInt(columns[1]); // 4
        int[][] matrix = new int[n][m];
        int[] vector = new int[m];   // 4
        int [] sum =new int[n]; // 3
        
        for (int y = 0; y < n; y++) {
            line = reader.readLine();
            columns = line.split(" ");
            for ( int x = 0 ; x < m; x++ ) {
                matrix[y][x] = Integer.parseInt(columns[x]);
            }
        }
        for (int x = 0; x < m; x++) {
            line = reader.readLine();
            vector[x] = Integer.parseInt(line);
        }
        for (int y = 0; y < n ; y++) {
            sum[y] = 0;
            for (int x = 0; x < m ; x++ ) {
                sum[y] += (vector[x] * matrix[y][x]);
            }
            System.out.println(sum[y]);
        }
    }
}

Measured memory_bytes: 27620
main = do
    n <- read <$> getLine :: IO Int
    hs <- map read . words <$> getLine :: IO [Int]
    print $ solve 0 (-1) hs

solve :: Int -> Int -> [Int] -> Int
solve x t [] = x 
solve x t (h:hs) = if h >= t then solve (x+1) h hs else solve x t hs

Measured memory_bytes: 508