akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
from collections import Counter
def print_ans(N, sr):
    """Test Case
    >>> print_ans(3, ["acornistnt", "peanutbomb", "constraint"])
    1
    >>> print_ans(2, ["oneplustwo", "ninemodsix"])
    0
    >>> print_ans(5,["abaaaaaaaa","oneplustwo","aaaaaaaaba","twoplusone","aaaabaaaaa"]) 
    4
    """
    for i in range(N):
        sr[i] = "".join(sorted(sr[i]))
    C = Counter(sr)
    ans = 0
    for v in C.values():
        ans += v * (v - 1) // 2
    print(ans)

    # for i in range(N):
    #     tmp = sr[i]
    #     for k in range(i + 1, N):
    #         if tmp == sr[k]:
    #             count +=1
    # print(count)


if __name__ == '__main__':
    N = int(input().rstrip())
    sr = [ input().rstrip() for _ in range(N)]
    print_ans(N, sr)


Measured memory_bytes: 19820
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  
  S[K-1] = S[K-1] + 0x20;
  
  cout << S << endl;
  
  return 0;
}



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

int main(){
    string S; cin >> S;
    int N = S.size();
    int cnt =0;
    for(int i=0; i<S.size(); i++){
        if(S.at(i)=='o'){
            cnt++;
        }
    }
    if( cnt+15-S.size() >=8 ){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

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

int main()
{
	long long q;
	cin>>q;
	while(q--){
		long long x,y;
		cin>>x>>y;
		long long sqr=(long long)sqrt(x*y);
		if(x==y){
		    cout<<2*sqr-2<<endl;
		    continue;
	    }
		long long ans=2*sqr-1;
		if(sqr*(sqr+1)>=x*y) ans--;
		if(sqr*sqr==x*y) ans--;
		cout<<ans<<endl;
	}
	return 0;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 507;
vector<int> vec[N];
int main()
{
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    while(m--)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        vec[l].push_back(r);
    }
    for(int i = 1; i <= n; i++)
    {
        sort(vec[i].begin(), vec[i].end());
    }
    while(q--)
    {
        int l, r, ans = 0;
        scanf("%d%d", &l, &r);
        for(int i = l; i <= r; i++)
        {
            ans += upper_bound(vec[i].begin(), vec[i].end(), r)-vec[i].begin();
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF ULLONG_MAX

ull N;
int main(){
    cin >> N;
    ull temp;
    ull min_tra = INF;
    for (int i = 0; i < 5; ++i){
        cin >> temp;
        min_tra = min(temp, min_tra);
    }
    if (N % min_tra == 0){
        cout << (N / min_tra) + 4 << endl;
    }else{
        cout << ((N / min_tra) + 5) << endl;
    }
}

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

void printVector(vector<int> A) {
  // 配列の中身を出力
  for (int i = 0; i < A.size(); i++) {
    cout << A.at(i);
    if (i < A.size() - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  return;
}

void insertionSort(vector<int> &A) {
  int i, j, v;
  for (i = 1; i < A.size(); i++) {
    v = A.at(i);
    j = i - 1;
    while (j >= 0 && A.at(j) > v) {
      A.at(j + 1) = A.at(j);
      j--;
    }
    A.at(j + 1) = v;
    printVector(A);
  }
  return;
}

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

  vector<int> A(N);
  for (int i = 0; i < A.size(); i++) {
    cin >> A.at(i);
  }

  printVector(A);
  insertionSort(A);

  return 0;
}


Measured memory_bytes: 3120
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#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 CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;
 
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {1, 0, -1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};

void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}
 
ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 2e5 + 15;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
/*************************************************************************/

ll n;
void solve() {
    cin>>n;
    ll cnt = 0;
    if(n%2==0)n/=2;
    else {
        cout<<0<<endl;
        return;
    }
    for(ll i = 5; i<=n;i*=5) {
        cnt += n/i;
    }
    cout<<cnt<<endl;
}
  
int main()
{   
    //freopen("i.txt", "r", stdin);
    // freopen("o.txt", "w", stdout);
    solve();
    return 0;
 
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << '\n'
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, m, d;
    cin >> n >> m >> d;
    double ans = 0.0;
    double res = min(d*2, n)*1.0/static_cast<double>(n) + (n-min(d*2, n))*2.0/static_cast<double>(n);
    if (d==0) {
        res = 1.0;
    }
    //res /= n;
    debug(res);
    
    res *= static_cast<double>(m-1)/static_cast<double>(n);

    ans = res;
    
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 3812
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  string S;
  cin>>S;
  int L=S.size(),cnt=0;
  for(int i=0;i<L-1;i++){
    if(S[i]!=S[i+1]){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    for(int i=0;i<=N/7;i++){
        if((N-i*7)%4==0){
            cout<<"Yes"<<endl;return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3616
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

const int MAX_N = 2E+05;

int N;
string s;

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

    cin >> N;
    cin >> s;

    int count = 0;
    int lp = 0;
    int rp = s.size() - 1;
    while (true) {
        int i = 0;
        while (s[lp + i] == 'R') {
            i++;
        }
        lp += i;

        int j = 0;
        while (s[rp - j] == 'W') {
            j++;
        }
        rp -= j;

        if (lp > rp)
            break;

        swap(s[lp], s[rp]);

        count++;
    }

    cout << count << "\n";

    return 0;
}

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

using Field=array<int,16>;
using Event=vector<Field>;
struct State{
    int day;
    int pos;
    array<int,4> f;
};
bool operator<(State lhs,State rhs){
    return make_tuple(lhs.day,lhs.pos,lhs.f[0],lhs.f[1],lhs.f[2],lhs.f[3])<make_tuple(rhs.day,rhs.pos,rhs.f[0],rhs.f[1],rhs.f[2],rhs.f[3]);
}
set<State> s;
int n;
int dfs(State st,const Event &e);
vector<vector<int>> nei=
{
    {0,1,2,4,8},
    {0,1,2,5,9},
    {0,1,2,6,10},
    {},
    {0,4,8,5,6},
    {1,4,9,5,6},
    {2,4,10,5,6},
    {},
    {0,4,8,9,10},
    {1,5,8,9,10},
    {2,6,8,9,10},
    {}
};
int dfs(State st,const Event &e){
    if(st.day==n) return true;
    if(s.count(st)) return false;
    s.insert(st);
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            if(e[st.day][st.pos+i*4+j]){
                return false;
            }
            int x=st.pos+i*4+j;
            if(x==0) st.f[0]=-1;
            if(x==3) st.f[1]=-1;
            if(x==12) st.f[2]=-1;
            if(x==15) st.f[3]=-1;
        }
    }
    for(int i=0;i<4;i++){
        if(++st.f[i]>=7) return false;
    }
    st.day++;
    int prep=st.pos;
    for(int i=0;i<nei[prep].size();i++){
        st.pos=nei[prep][i];
        if(dfs(st,e)) return true;
    }
    
    return false;
}
int solve(Event e){
    State ini;
    ini.day=0;
    ini.pos=5;
    fill(ini.f.begin(),ini.f.end(),0);
    return dfs(ini,e);
}
int main(){
    while(cin>>n,n){
        s.clear();
        Event event(n);
        for(int i=0;i<n;i++){
            for(int j=0;j<16;j++) cin>>event[i][j];
        }        
        cout<<solve(event)<<endl;
    }
    return 0;
}


Measured memory_bytes: 13904
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
  n, m = LI()
  a = LI()
  for i in range(n-1):
    a[i + 1] += a[i]
  a = [i % m for i in a]
  d = defaultdict(int)
  for i in range(n):
    d[a[i]] += 1
  ans = d[0]
  for i in d.values():
    ans += i * (i-1) // 2
  print(ans)

  return

#B
def B():
  return

#C
def C():
  return

#D
def D():
  return

#E
def E():
  return

#F
def F():
  return

#G
def G():
  return

#H
def H():
  return

#Solve
if __name__ == '__main__':
  A()

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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
#define pb push_back
#define INF 1000000005
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define mod 998244353

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

ll power(ll x, ll y, ll p = MOD){  
  ll res = 1LL; 
  x = x % p;
  if (x == 0) return 0;
  while (y > 0){
    if (y & 1LL)  
      res = (res*x) % p;
    y = y>>1LL; 
    x = (x*x) % p;  
  }  
  return res;  
}  

int main(){
	// IO
	ll n, m, x;
	cin >> n >> x >> m;

	ll count[m + 1] = {0};
	count[x%m] = 1;
	ll prev = x, curr;

	vector<ll> cycle;
	ll sum = x;
	cycle.push_back(x);
	int cycle_point = -1, iter = 1;
	while(iter < n) {
		curr = power(prev, 2, m);
		if(count[curr]) {
			cycle_point = curr;
			break;
		}
		++count[curr];
		cycle.push_back(curr);
		sum+=curr;

		prev = curr;
		++iter;
	}
	if(iter == n || cycle_point == 0) {
		cout << sum << endl;
	}
	else {
		// cout << "NAH\n";
		ll len = (ll)cycle.size(), cl = 0;
		int i;
		for(i = 0; i < len; ++i) {
			if(cycle[i] == cycle_point) {
				break;
			}
		}
		ll add = 0LL;
		for(int j = i; j < len; ++j) {
			++cl;
			add+=cycle[j];
		}

		sum = sum + ((n - len)/cl)*add;
		int left = (n - len)%cl;
		for(int j = i; left; ++j) {
			sum+=cycle[j];
			--left;
		}

		cout << sum << endl;
	}
	


	return 0;
}

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

int main(){
  int d,n,x=1; cin>>d>>n;
  if(n!=100){
  if(d!=0){
    while(d>0){
    x=x*100;
    d--;
     }
  }
  else if(d==0){
    x=1;
  }
  cout<<x*n<<endl;
  }
  if(n==100){
    if(d!=0){
    while(d>0){
    x=x*100;
    d--;
     }
  }
  else if(d==0){
    x=1;
  }
    cout<<x*101<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(100).
       01 A PIC 9999999999.
       01 B PIC 9999999999.
       01 C PIC X(100).
       01 REN PIC 9999999.
       01 RE PIC ZZZZZZZZ9.
       01 temp1 PIC 9999.
       01 temp2 PIC 9999.
       01 N PIC 9999.
       PROCEDURE DIVISION.
       MAIN.
       	ACCEPT INP.
      	PERFORM VARYING temp1 FROM 1 BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	SUBTRACT 1 FROM temp1.
      	MOVE INP(1:temp1) TO A.
      	ADD 2 TO temp1.
      	PERFORM VARYING temp2 FROM temp1 BY 1 UNTIL INP(temp2:1)=SPACE
      	END-PERFORM.
      	COMPUTE N=temp2 - temp1.
      	MOVE INP(temp1:N) TO B.
      	IF A >= B THEN
      		SUBTRACT B FROM A
      	ELSE
      		MOVE 0 TO A
      	END-IF.
      	MOVE A TO RE.
      	DISPLAY RE.
        STOP RUN.



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<30);

using namespace std;

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll a, b; cin >> a >> b;
    cout << max(0ll, a - 2*b) << 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() {
  ll n, ans = INF, cnt = 0;
  string s;
  cin >> n >> s;
  vector<ll> w(n + 3, 0), b(n + 3, 0);
  for (int i = 0; i < n; ++i) {
    if (s[i] == '.') {
      w[i + 1] = w[i] + 1;
      b[i + 1] = b[i];
    } else {
      w[i + 1] = w[i];
      b[i + 1] = b[i] + 1;
    }
  }

  for (int i = 0; i <= n; ++i) 
    ans = min(ans, b[i] + w[n] - w[i]);
  

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


Measured memory_bytes: 3716
#include <stdio.h>

int main() {
	long int h,w;
	scanf("%ld%ld", &h,&w);
	if(h==1){
		printf("1\n");
	}else if(w==1){
		printf("1\n");
	}else if((h%2==1)&&(w%2==1)){
		printf("%ld\n", ((h-1)*w/2)+(w/2+1));
	}else{
		printf("%ld\n", h*w/2);
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001

// vector<int> a(5);
map<int,int> counter;
int n,k;
int a[200000];

int main(void){
    cin >> n >> k;
    REP(i,0,n) {
        cin >> a[i];
    }
    
    REP(i,0,n) {
        counter[a[i]]++;
    }
    
    int kinds = counter.size();
    
    // cout << counter.size() << endl;
    
    priority_queue<pair<int,int>> q;
    for(auto u: counter) {
        q.push({-u.second,u.first});
    }
    
    int ans = 0;
    if (kinds > k) {
        // cout << q.top().second << endl;
        while(!q.empty() && kinds > k) {
            int a = abs(q.top().first);
            q.pop();
            ans += a;
            kinds -= 1;
        }
        
    }

    cout << ans << endl;
    
    
    // long long ans = 0;
    // REP(i,0,5) {
    //     REP(j,0,5) {
    //         if (i == j) continue;
    //         long long temp = 1;
    //         for (auto u : counter) {
    //             // cout << u.first << u.second << endl;
    //             if (u.first == s[i] || u.first == s[j]) continue;
    //                 temp *= u.second;
    //         }
    //         ans += temp;
    //         cout << ans << endl;
    //         // cout << ans << endl;
    //     }
    // }
    
    // cout << ans << end;
    // int ans = 1;
    // for (auto u : counter) {
    //     // cout << u.first << u.second << endl;
    //     ans *= u.second;
    // }
    // cout << ans << endl;

}

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

int main(){
    std::string s;
    std::cin >> s;
    for(uint32_t i = 0; i < s.size(); i++){
        if(i % 2 == 1){
            if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D'){
                std::cout << "No";
                return 0;
            }
        }
        else{
            if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
                std::cout << "No";
                return 0;
            }
        }
    }
    std::cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    vector<int> vec;
    int x;
    rep(i,6){
        cin>>x;
        vec.push_back(x);
    }
    int maxv=count(vec.begin(),vec.end(),1);
    maxv=max(maxv,(int)count(vec.begin(),vec.end(),2));
    maxv=max(maxv,(int)count(vec.begin(),vec.end(),3));
    maxv=max(maxv,(int)count(vec.begin(),vec.end(),4));
    cout<<(maxv>=3?"NO":"YES")<<endl;
}

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

using ll=long long;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

int n, d;
vector<int> D;

int bin_search(int key, int left, int right){
    if(key > D[n-1]) return min(d-key, key-D[n-1]);
    while(right-left > 1){
        int mid=left+(right-left)/2;
        if(D[mid] >= key) right=mid;
        else left=mid;
    }
    return min(D[right]-key, key-D[left]);
}

int main(){
    while(1){
        cin >> d;
        if(d == 0) break;
        int m; cin >> n >> m;
        D.resize(n);
        D[0]=0;
        for(int i=1; i<n; i++) cin >> D[i];
        sort(D.begin(), D.end());
        vector<int> k(m);
        for(int i=0; i<m; i++) cin >> k[i];
        int res=0;
        for(int i=0; i<m; i++){
            res+=bin_search(k[i], 0, n-1);
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,a,b;
ll mon[100001];
bool check(ll mid){
    ll nowans=0;
    for(int i=0;i<n;i++)
        nowans+=max(0ll,(mon[i]-b*mid+a-1)/a);
    if(nowans<=mid) return 1;
    return 0;
}
main(){
    cin>>n>>a>>b;
    a-=b;
    for(int i=0;i<n;i++)
        scanf("%d",&mon[i]);
    ll lb=-1,ub=1.5e9;
    while(lb<=ub){
        ll mid=(lb+ub)/2;
        if(check(mid))
            ub=mid-1;
        else
            lb=mid+1;
    }
    cout<<lb<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int a,b,c,d,e,A,B,C,D,E,minn;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	A=a%10;
	a= A!=0 ? a-A+10 : a;
	B=b%10;
	b= B!=0 ? b-B+10 : b;
	C=c%10;
	c= C!=0 ? c-C+10 : c;
	D=d%10;
	d= D!=0 ? d-D+10 : d;
	E=e%10;
	e= E!=0 ? e-E+10 : e;
	if (A==0 && B==0 && C==0 && D==0 && E==0){
		printf("%d",a+b+c+d+e);
	}else{
		minn=999999;
		if (A!=0 && A < minn) minn = A;
		if (B!=0 && B < minn) minn = B;
		if (C!=0 && C < minn) minn = C;
		if (D!=0 && D < minn) minn = D;
		if (E!=0 && E < minn) minn = E;
		printf("%d",a+b+c+d+e+minn-10);
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (2000 + 2)

void exec(){
  vector<string> s;
  bool isMatch[3][3][MAX_N];
  for (int i = 0; i < 3; i++) {
    string tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  sort(s.begin(), s.end());
  int ans = s[0].length() + s[1].length() + s[2].length();

  do{
    // printf("NEXT_PERMUTATION s[0] = %s, s[1] = %s, s[2] = %s\n", s[0].c_str(), s[1].c_str(), s[2].c_str());
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (i >= j) {
          continue;
        }

        for (int k = 0; k <= s[i].length(); k++) {
          bool isOK = true;
          for (int l = 0; l <= s[i].length(); l++) {
            int index = k + l;
            if (index >= s[i].length() || l >= s[j].length()) {
              break;
            }

            // printf("s[%d][%d] = %c, s[%d][%d] = %c, k = %d, l = %d, result = %d\n", i, index, s[i][index], j, l, s[j][l], k, l, (int)(!(s[i][index] != s[j][l] && s[i][index] != '?' && s[j][l] != '?')));
            if (s[i][index] != s[j][l] && s[i][index] != '?' && s[j][l] != '?') {
              isOK = false;
              break;
            }
          }
          isMatch[i][j][k] = isOK;
          // if (isMatch[i][j][k]) {
            // printf("s[%d] = %s, s[%d] = %s, matched! = [%d][%d][%d]\n",i, s[i].c_str(), j, s[j].c_str(),i, j, k);

          // }
        }
      }
    }

    for (int i = 0; i <= s[0].length(); i++) {
      for (int j = 0; j <= s[0].length(); j++) {
        if (!isMatch[0][1][i]) {
          continue;
        }
        if (j <= s[1].length() && !isMatch[1][2][j]) {
          continue;
        }
        if (i+j <= s[0].length() && !isMatch[0][2][i+j]) {
          continue;
        }

        int tmp = s[0].length();
        tmp = max<int>(tmp, s[1].length() + i);
        tmp = max<int>(tmp, s[2].length() + i + j);
        // if (tmp < ans) {
          // printf(
              // "s[0] = %s, s[1] = %s, s[2] = %s, i = %d, j = %d, tmp = %d\n",
              // s[0].c_str(),
              // s[1].c_str(),
              // s[2].c_str(),
              // i,
              // j,
              // tmp
              // );
        // }
        ans = min(ans, tmp);
      }
    }
  } while(next_permutation(s.begin(), s.end()));

  cout << ans << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


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

int main() {

	int house, a, b;
	int difa, difb;
	cin >> house >> a >> b;

	house > a ? difa = house - a : difa = a - house;
	house > b ? difb = house - b : difb = b - house;

	if (difa < difb) {
		cout << "A";
	}
	else {
		cout << "B";
	}

	return 0;
}

//*/

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        k: i64,
        q: usize,
        a: [usize; q],
    }

    let mut par = vec![0; n+1];

    for i in &a {
        par[*i] = par[*i] + 1;
    }

    for p in par.iter().skip(1) {
        if *p > q as i64 - k {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 6780
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    q = int(input())
    b = 0
    hq_l, hq_r = [], []
    sum_l, sum_r = 0, 0

    for _ in range(q):
        a = list(map(int, input().split()))
        if a[0] == 1:
            b += a[2]
            if len(hq_l)==0 or a[1] <= -hq_l[0]:
                heappush(hq_l, -a[1])
                sum_l += a[1]
            else:
                heappush(hq_r, a[1])
                sum_r += a[1]
        else:
            while len(hq_l)-1 > len(hq_r):
                sum_l -= -hq_l[0]
                sum_r += -hq_l[0]
                m = -heappop(hq_l)
                heappush(hq_r, m)
            while len(hq_l) < len(hq_r):
                sum_l += hq_r[0]
                sum_r -= hq_r[0]
                m = -heappop(hq_r)
                heappush(hq_l, m)
            print(-hq_l[0],  (-hq_l[0]*len(hq_l)) - sum_l + sum_r - (-hq_l[0]*len(hq_r)) + b)

if __name__ == '__main__':
    main()

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

//W hidari E migi

int main(){
    int A;
    char c[400000];
    cin >> A;
    cin >> c;

    int e_count = 0;
    int w_count = 0;
    for(int i = 1; i < A; i ++){
        if(c[i] == 'W'){
            w_count ++;
        }
        if(c[i] == 'E'){
            e_count ++;
        }
    }
    int min = e_count;
    int current = e_count;
    // i ga wakeme
    for(int i = 1; i < A; i ++){
        if(c[i - 1] == 'W'){
            current ++;
        }
        if(c[i] == 'E'){
            current --;
        }
        if(current < min) {
            min = current;
        }
    }

    cout << min << endl;  
    return 0;
}

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

class UF {
  vector<int> p;
  vector<bool> namori;
public:
  UF(int n) : p(n), namori(n) {
    for (int i = 0; i < n; ++i) p[i] = i;
  }
  int root(int i) {
    if (p[i] == i) return i;
    return p[i] = root(p[i]);
  }
  bool same(int i, int j) {
    return root(i) == root(j);
  }
  void unite(int i, int j) {
    int ri = root(i);
    int rj = root(j);
    if (ri == rj) {
      namori[ri] = true;
      return; 
    }
    p[ri] = rj;
    if (namori[ri]) namori[rj] = true;
  }
  int is_namori(int i) {
    return namori[root(i)];
  }
};

using T = pair<int, pair<int, int>>;
int n, h, w;
int main() {
  cin >> n >> h >> w;
  priority_queue<T> Q;
  for (int k = 0; k < n; ++k) {
    int i, j, a;
    cin >> i >> j >> a;
    --i; --j;
    j += h;
    Q.push(T(a, make_pair(i, j)));
  }
  
  bool flg = false;
  UF uf(h + w);
  long sum = 0;
  while (!Q.empty()) {
    T t = Q.top(); Q.pop();
    int a = t.first;
    int i = t.second.first;
    int j = t.second.second;
    
    if (uf.is_namori(i) && uf.is_namori(j)) continue;
    uf.unite(i, j);
    sum += a;
  }
  cout << sum << endl;
}

Measured memory_bytes: 2292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
  int n,k;
  cin >> n >> k;
  VI l(n);
  rep(i,n) cin >> l[i];
  
  sort(l.begin(), l.end(), greater<int>());
  
  int ans=0;
  rep(i,k){
    ans += l[i];
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
int s1,e1,s2,e2;
int main()
{
    scanf("%d%d%d%d",&s1,&e1,&s2,&e2);
    for(reg int i=1;i<=(e2-e1);i++)printf("U");
    for(reg int i=1;i<=(s2-s1);i++)printf("R");
    for(reg int i=1;i<=(e2-e1);i++)printf("D");
    for(reg int i=1;i<=(s2-s1);i++)printf("L");
    printf("L");
    for(reg int i=1;i<=(e2-e1)+1;i++)printf("U");
    for(reg int i=1;i<=(s2-s1)+1;i++)printf("R");
    printf("D");
    printf("R");
    for(reg int i=1;i<=(e2-e1)+1;i++)printf("D");
    for(reg int i=1;i<=(s2-s1)+1;i++)printf("L");
    printf("U\n");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A_list = [int(elem) for elem in input().split(' ')]
assert N >= 4
assert len(A_list) == N

# cummulative sum
cuml_A_list = [0] * N
cuml_A_list[0] = A_list[0]
for i in range(1, N):
    cuml_A_list[i] = cuml_A_list[i-1] + A_list[i]

best_diff = max(cuml_A_list[0], cuml_A_list[1]-cuml_A_list[0], cuml_A_list[2]-cuml_A_list[1], cuml_A_list[-1]-cuml_A_list[2])\
        - min(cuml_A_list[0], cuml_A_list[1]-cuml_A_list[0], cuml_A_list[2]-cuml_A_list[1], cuml_A_list[-1]-cuml_A_list[2])

left_sep = 0
right_sep = 2

# time complexity: O(N)
for mid_sep in range(1, N - 2):
    left_sum = cuml_A_list[mid_sep - 1]
    right_sum = cuml_A_list[-1] - cuml_A_list[mid_sep - 1]

    while abs(cuml_A_list[mid_sep] - 2*cuml_A_list[left_sep]) > abs(cuml_A_list[mid_sep] - 2*cuml_A_list[left_sep + 1]):
        left_sep += 1
    while abs(cuml_A_list[-1] - 2*cuml_A_list[right_sep] + cuml_A_list[mid_sep]) > abs(cuml_A_list[-1] - 2*cuml_A_list[right_sep + 1] + cuml_A_list[mid_sep]):
        right_sep += 1
    diff = max(cuml_A_list[left_sep], cuml_A_list[mid_sep] - cuml_A_list[left_sep], cuml_A_list[right_sep] - cuml_A_list[mid_sep], cuml_A_list[-1] - cuml_A_list[right_sep])\
        - min(cuml_A_list[left_sep], cuml_A_list[mid_sep] - cuml_A_list[left_sep], cuml_A_list[right_sep] - cuml_A_list[mid_sep], cuml_A_list[-1] - cuml_A_list[right_sep])
    best_diff = min(best_diff, diff)
print(best_diff)


Measured memory_bytes: 25672
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool ihmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int x; read(x); if (x >= 30) write("Yes"); else write("No");
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n,k;cin>>n>>k;

if(k==1){
  cout<<0;
  return 0;
}
  cout<<n-k<<endl;

 

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int A,B;
  scanf("%d",&A);
  scanf("%d",&B);
  int wa,sa,seki;
  wa=A+B;
  sa=A-B;
  seki=A*B;

  if(wa>=sa&&wa>=seki)
    printf("%d",wa);
  else if(seki>=wa&&seki>=sa)
    printf("%d",seki);
  else
    printf("%d",sa);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int,int> P;
bool hangaku(int h,int m){
	if(h == 18){
		return true;
	}else if(h == 17){
		return m >= 30;
	}else if(h == 19){
		return m <= 30;
	}else{
		return false;
	}
}

int main(){
	int s,g;
	int kyori[8] = {0,0,6,13,18,23,43,58};
	map<P,int> price;
	price[P(1,2)] = 300;
	price[P(1,3)] = 500;
	price[P(1,4)] = 600;
	price[P(1,5)] = 700;
	price[P(1,6)] = 1350;
	price[P(1,7)] = 1650;
	price[P(2,3)] = 350;
	price[P(2,4)] = 450;
	price[P(2,5)] = 600;
	price[P(2,6)] = 1150;
	price[P(2,7)] = 1500;
	price[P(3,4)] = 250;
	price[P(3,5)] = 400;
	price[P(3,6)] = 1000;
	price[P(3,7)] = 1350;
	price[P(4,5)] = 250;
	price[P(4,6)] = 850;
	price[P(4,7)] = 1300;
	price[P(5,6)] = 600;
	price[P(5,7)] = 1150;
	price[P(6,7)] = 500;
	while(cin>>s,s){
		int h1,m1,h2,m2;
		cin>>h1>>m1>>g>>h2>>m2;
		if(s > g) swap(s,g);
		int ans = price[P(s,g)];
		if(hangaku(h1,m1) || hangaku(h2,m2)){
			if(kyori[g]-kyori[s] <= 40){
				if(ans % 100){
					ans = (ans+50)/2;
				}else{
					ans /= 2;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var lines = input.split('\n');

  var _splitNum = splitNum(lines[0]),
      _splitNum2 = _slicedToArray(_splitNum, 1),
      N = _splitNum2[0];

  var min = Infinity;

  for (var i = 0; i <= N; i++) {
    var current = i;
    var res = 0;
    var six = Math.pow(6, 7);

    while (six >= 1) {
      res += Math.floor(current / six);
      current = current % six;
      six /= 6;
    }

    current = N - i;
    var nine = Math.pow(9, 6);

    while (nine >= 1) {
      res += Math.floor(current / nine);
      current = current % nine;
      nine /= 9;
    }

    res += current;

    if (res < min) {
      min = res;
    }
  }

  console.log(min);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 7628
# include <bits/stdc++.h>
using namespace std;
# define MOD 1000000007
typedef long long ll;
class line{
public:
    ll m, c;
    line(ll m, ll c){
        this->m = m;
        this->c = c;
    }
    ll value(ll x){
        return x*m + c;
    }
};
ll intersection(line& l1, line& l2){
    return ceil(1.0*(l2.c - l1.c)/(l1.m - l2.m));
}
class CH{
    deque<pair<line, ll>> dq;
public:
    void insert(line l){
        if(dq.empty()){
            dq.push_back({l, 0});
        }else{
            while(!dq.empty()){
                ll x = intersection(l, dq.back().first);
                if(x <= dq.back().second){
                    dq.pop_back();
                }else break;
            }
            ll x = intersection(l, dq.back().first);
            dq.push_back({l, x});
        }
    }
    ll min_intercept(ll x){
        while(dq.size() > 1){
            if(dq[1].second <= x){
                dq.pop_front();
            }else break;
        }
        return dq[0].first.value(x);
    }
};
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n;
    ll C;
    cin>>n>>C;
    ll heights[n];
    for(int i=0;i<n;i++){
        cin>>heights[i];
    }
    ll dp[n];
    dp[0] = 0;
    CH lines;
    lines.insert(line(-2*heights[0], heights[0]*heights[0]));
    for(int i=1;i<n;i++){
        dp[i] = heights[i]*heights[i] + C + lines.min_intercept(heights[i]);
        lines.insert(line(-2*heights[i], dp[i] + heights[i]*heights[i]));
    }
    cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 6656
with open(0) as f:
    H, W, N, *a = map(int, f.read().split())

line = []
for i in range(N):
    line += [i+1] * a[i]
ans = [line[i*W:(i+1)*W] for i in range(H)]
for i, v in enumerate(ans):
    if i&1:
        v.reverse()
    print(*v)

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


int main(){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  cout << (s < t ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <cstring>

#define nl '\n'

using namespace std;

double h, a;

int main(){

    cin >> h >> a;

    cout << ceil(h/a);

}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

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

using namespace std;

int main(){
	string s;
	int K;
	list<string> matrix;
	for (int i = 0; i < 5; i++){
		matrix.push_front("{");
	}
	
	cin >> s >> K;
	int i;
	if (s.length() >= 5){ 
		for (i = 0; i < s.length() - 4; i++){
			for (int j = 1; j <= 5; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
						break;
					}
					else if (temp.compare(*itr) == 0){
						break;
					}
				}
			}
		}
		
		for (; i < s.length(); i++){
			for (int j = 1; j <= s.length() - i; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
						break;
					}
					else if (temp.compare(*itr) == 0){
						break;
					}
				}
			}
		}
	}else{
		for (i = 0; i < s.length(); i++){
			for (int j = 1; j <= s.length() - i; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
						break;
					}
					else if (temp.compare(*itr) == 0){
						break;
					}
				}
			}
		}
	}
	
	
	for (int i = 0; i < K - 1; i++){
		matrix.pop_front();
	}
	cout << matrix.front();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    ll x;
    cin >> x;

    ll n = 100;
    int ans = 0;
    while(n < x){
        n *= 1.01;
        ans += 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
from collections import defaultdict, Counter

def primes(x):
    d = {}
    i = 2
    while i <= x:
        count = 0
        while x % i == 0 and x > 0:
            count += 1
            x //= i
        if count > 0:
            d[i] = count
        i += 1
    return d


if __name__ == '__main__':
    n = int(input())
    d = {}
    for i in range(2, n + 1):
        d1 = primes(i)
        for j, v in d1.items():
            if j not in d:
                d[j] = v
            else:
                d[j] += v
    counter = Counter(d.values())
    d2 = {3: 0, 5: 0, 15: 0, 25: 0, 75: 0}
    for count, v in counter.items():
        if count >= 74:
            d2[75] += v
        if count >= 24:
            d2[25] += v
        if count >= 14:
            d2[15] += v
        if count >= 4:
            d2[5] += v
        if count >= 2:
            d2[3] += v
    ans = d2[75] + d2[25] * (d2[3] - 1) + d2[15] * (d2[5] - 1) + d2[5] * (d2[5] - 1) * (d2[3] - 2) // 2
    print(ans)



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

int main()
{
    int N, K;
    cin >> N >> K;
    int ans=0;
    for (int i = 0; i < N; ++i){
        if(i==0)
            ans = K;
        else
            ans *= (K - 1);
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;
    
    vector<vector<int> > E(N+1);
    for(int n=0; n<N-1; n++) {
        int a, b;
        cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    vector<int> ans(N+1, 0);
    for(int q=0; q<Q; q++) {
        int p, x;
        cin >> p >> x;
        ans[p]+=x;
    }
    
    vector<bool> seen(N+1, false);
    seen[1]=true;
    queue<int> que;
    que.push(1);
    while(!que.empty()) {
        int cur=que.front();
        que.pop();
        
        for(int i=0; i<E[cur].size(); i++) {
            if(seen[E[cur][i]]) continue;
            
            seen[E[cur][i]] = true;
            que.push(E[cur][i]);
            ans[E[cur][i]] += ans[cur];
        }
    }
    for(int i=1; i<ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
    
}

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

// flag を用いたバブルソート
int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    for (int i =0; flag; i++){
        flag = 0;
        for ( int j = N-1; j >= i+1; j--){
            if (A[j] <A[j-1]){
                //隣接要素を交換する
                swap(A[j], A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(){
    int A[100], N, sw;

    cin >> N;
    for ( int i = 0; i < N; i++ ) cin >> A[i];

    sw = bubbleSort(A, N);

    
    for ( int i = 0; i < N; i++ ){
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw <<endl;
    
    return 0;
}


Measured memory_bytes: 3080