akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n); for(ll i = 0; i < ll(n); i++)
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}



int main(){
  int n;
  cin>>n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  sort(l.begin(),l.end());
  int ans=0;
  rep(i,n-2){
    for(int j=i+1; j<n-1; j++){
      /*for(int k=j+1; k<n; k++){
        if(max(l[i]-l[j],l[j]-l[i])<l[k]&&l[k]<l[i]+l[j]) ans++;
      }*/

      
      int lf=j+1,r=n-1,m;
      if(l[j]-l[i]<l[r]&&l[r]<l[i]+l[j]){
        ans+=n-1-j;
      }
      else if(l[j]-l[i]>=l[lf]||l[lf]>=l[i]+l[j]){
      }else{      
      while(r-lf>1){
        m=(lf+r)/2;
        if(l[j]-l[i]<l[m]&&l[m]<l[i]+l[j]) lf=m;
        else r=m;
      }
      ans+=lf-j;
      }
    }
  }
  
  cout<< ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String a = sc.next();
      String b = sc.next();
      if(( a.equals("H")&&b.equals("H") )||( a.equals("D")&&b.equals("D")) ){
      	System.out.println("H");
      }
      else System.out.println("D");
    }
}

Measured memory_bytes: 21844
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#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++)
const long long INF =  999999999;

int main(){
  typedef pair<int,int> P;
  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  int h,w;
  REP(i,H){
    cin>>S[i];
    REP(j,W) if(S[i][j]=='.'){
      h=i,w=j;
    }
  }
  int ans=0;
  int dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};
  vector<vector<bool>> used(H,vector<bool>(W,false));
  REP(hoge,10){
    vector<vector<int>> d(H,vector<int> (W,-1));
    queue<P> que;
    que.push(P(h,w));
    d[h][w]=0;
    used[h][w]=true;
    while(!que.empty()){
      P p=que.front();que.pop();
      int x=p.first,y=p.second;
      REP(j,4){
        int nx=x+dx[j],ny=y+dy[j];
        if(0<=nx&&nx<H&&0<=ny&&ny<W&&S[nx][ny]=='.'&&d[nx][ny]==-1){
          que.push(P(nx,ny));d[nx][ny]=d[x][y]+1;
          ans=max(ans,d[nx][ny]);
          if(!used[nx][ny]){
            h=nx;w=ny;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, b;
    cin >> a >> b;
    rep(i, 1, 10000) {
        int x = i * 8 / 100;
        int y = i * 10 / 100;
        if (x == a && y == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(int i = (m); i <= (n); i++)
#define zep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll a, b, c;
    cin >> a >> b >> c;
    if((a < c && c < b) || (b < c && c < a )){
    	print("Yes")
    }else{
    	print("No")
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 100010;
static const ll mod = 1000000007;
static const ll max_value = 100000000000100;



void Main(){
    // bool is_ok = true;
    // printf("------------- V=%lld---------\n", V);
    ll N, a;
    map<ll, ll> data;
    sll(N);
    ll ans = 0;
    rep(i, N){
        sll(a);
        ll input = a + i + 1;
        ll query = i + 1 - a;
        data[input] ++;
        if(data.find(query) != data.end()){
            ans += data[query];
        }
    }

    printf("%lld\n", ans);


    // cout<<fixed<<setprecision(10)<<num<<endl;
    // cout << num << endl;

}

int main(){
    Main();

    return 0;

}

Measured memory_bytes: 15584
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(max(a, b), c) * 10 + a + b + c - max(max(a, b), c) << endl;
	return 0;
}

Measured memory_bytes: 256
t,T,a,A,b,B=map(int, open(0).read().split())
x,y=(b-a)*t,(A-B)*T
if y-x==0:
 r="infinity"
else:
 s,t=divmod(x,y-x)
 r=max(0,s*2+(1 if t else 0))
print(r)

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

std::vector<int> v;

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

    int n;
    std::cin >> n;
    for(int i=0; i<n; i++)
    {
        int a;
        std::cin >> a;
        v.push_back(a);
    }
    std::sort(v.begin(), v.end(), std::greater<int>());
    int a = -1, b = -1;
    auto it = v.begin();
    it++;
    for(;it!=v.end(); it++)
    {
        if(*(it-1) == *it)
        {
            if(a==-1)
            {
                a = *it;
                it++;
                continue;
            }
            b = *it;
            break;
        }
    }
    if(b==-1) std::cout << "0\n";
    else std::cout << ((long long)a)*((long long)b) << '\n';
}

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

int main(){
    string s;
    cin >> s;
    int Q;
    cin >> Q;
    vector<char> front,back;
    int now = 1;
    rep(i,Q){
        int T;
        cin >> T;
        if(T == 1) now *= -1;
        else{
            int F; char C;
            cin >> F >> C;
            if(F == 2) F = -1;
            F *= now;
            if(F == 1) front.push_back(C);
            else back.push_back(C);
        }
    }
    if(now == 1){
        for(int i = (int)front.size()-1; i >= 0 ; i--) cout << front[i];
        cout << s;
        rep(i, back.size()) cout << back[i];
    } else {
        for(int i = (int)back.size()-1; i >= 0 ; i--) cout << back[i];
        for(int i = (int)s.size()-1; i >= 0 ; i--) cout << s[i];
        rep(i, front.size()) cout << front[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

	vector<ll> num(K);

	for (int i = 1; i <= N; ++i) num[i % K]++;
	//for (int i = 0; i < K; ++i) cout << num[i] << endl;
	ll res = 0;

	for (int a = 0; a < K; a++)
	{
		int b = (K - a) % K;
		int c = (K - a) % K;
		if ((b + c) % K != 0) continue;

		//cout << a << " " << b << " " << c << endl;
 
		res += num[a] * num[b] * num[c];
	}
	cout << res << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
/*
Miku
*/
using namespace std;
typedef long long ll ;
const ll mk = 100005;
#define endl "\n"
const int mod = 1e9 + 7;
int n,k,a[2000],t,f[2000],i,j,l,ans;
inline int Mikuplaying(int x,int y){
    int ans=1;
	for(;y;y>>=1,x=1ll*x*x%mod) if(y&1)ans=1ll*ans*x%mod;return ans;
}
int main(){
	cin >> n >> k; 
	for(i=1;i*i<=n;++i)if(n%i==0){a[++t]=i;if(i*i !=n)a[++t]=n/i;}
	std::sort(a+1,a+t+1);
	for(j=1;j<=t; ans=(ans+1ll*f[j]*(a[j]&1?a[j]:a[j]/2))%mod,++j)
		for(f[j]=Mikuplaying(k,a[j]+1>>1),l=1;l<j;++l)if(a[j]%a[l]==0)f[j]=(f[j]+mod-f[l])%mod;
	cout << ans;
	return 0;
}

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

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

    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(n),b(n);
    REP(i,n) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(),b.end());

    int ans = inf;
    REP(i,n) {
        vector<int> v, vv;
        REP(j,n) {
            if (a[j] < b[i]) {
                if (sz(vv) >= k) {
                    sort(vv.begin(), vv.end());
                    REP(kk, sz(vv) - k + 1) {
                        v.pb(vv[kk]);
                    }
                }
                vv.clear();
            } else {
                vv.pb(a[j]);
            }
        }
        if (sz(vv) >= k) {
            sort(vv.begin(), vv.end());
            REP(kk, sz(vv) - k + 1) {
                v.pb(vv[kk]);
            }
        }

        if (sz(v) < q) break;
        sort(v.begin(), v.end());
        ans = min(ans, v[q-1] - v[0]);

    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll sum[N],X[N];
ll a[N];
int main() {
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	sum[1]=X[1]=a[1];
	for(int i=2; i<=n; i++) sum[i]=sum[i-1]+a[i],X[i]=X[i-1]^a[i];
	ll ans=0;
	int l=1;
	for(int r=1; r<=n; r++) {
		for(; sum[r]-sum[l-1]!=(X[r]^X[l-1]); l++);
		ans+=(r-l+1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const ll mod = 7 * 17 * (1 << 23) + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, jumpid[200200], st[200200];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	set<int> pos[200200];
	vi a;
	ll k = 0;
	cin >> n >> k;
	a.resize(n);
	for (int i = 0; i < n; i++)
		cin >> a[i], pos[a[i]].insert(i);
	int i = 0, j = 1;
	jumpid[0] = 1;
	st[1] = 0;
	int fcyc = -1, cl = 0, nw;
	while (true) {
		nw = 0;
		auto it = pos[a[i]].upper_bound(i);
		if (it != pos[a[i]].end())
			i = (1 + *it);
		else {
			i = (1 + *pos[a[i]].begin());
			st[++j] = i;
			nw = 1;
		}
		if (i == n)
			i = 0, st[++j] = 0, nw = 1;
		if (jumpid[i]) {
			fcyc = jumpid[i];
			cl = j - jumpid[i];
			break;
		}
		if (nw)
			jumpid[i] = j;
	}
	if (k < fcyc) {
		k = st[k];
	} else {
		k = st[fcyc + (k - fcyc) % cl];
	}
	set<int> z;
	vi ans;
		for (int i = k; i < n; i++) {
			if (z.count(a[i])) {
				while (z.count(a[i])) {
					z.erase(ans.back());
					ans.pop_back();
				}
			} else
				ans.pb(a[i]), z.insert(a[i]);
		}
		for (auto i : ans)
			cout << i << " ";
		cout << "\n";
	return 0;
}


Measured memory_bytes: 34288
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7

S = sys.stdin.read()
S = S.lower()
dic_alpha = {s: 0 for s in "abcdefghijklmnopqrstuvwxyz"}

for s in S:
    if s in dic_alpha:
        dic_alpha[s] += 1
[print(k, ":", v) for k, v in dic_alpha.items()]


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

using namespace std;

int cnt;

void insertionSort(int *A,int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j];
      j-=g;
      cnt++;
    }
    A[j+g]=v;
  }
}
void shellSort(int *A,int n){
  cnt=0;
  int r=1;
  vector<int> G;
  while(r<=n){
    G.push_back(r);
    r*=2;
  }
  int m=G.size();
  reverse(G.begin(),G.end());
  cout<<m<<endl;
  for(int i=0;i<m;i++) cout<<G[i]<<" \n"[i==m-1];
  for(int i=0;i<m;i++) insertionSort(A,n,G[i]);
  cout<<cnt<<endl;
}

int main()
{
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  shellSort(A,n);
  for(int k=0;k<n;k++) cout<<A[k]<<endl;
  return 0;
}



Measured memory_bytes: 7068
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;



int main() {
	string S;
	cin >> S;
	vector<int>pi;
	int N = S.size();
	vector<int>gr;
	char las = 'R';
	int cnt = 0;
	map<int, int>ans;
	for (int i = 1; i < N; ++i) {
		if (S[i - 1] == 'R' && S[i] == 'L') {
			pi.push_back(i);
		}
		
	}
	for(int i = 0;i < N;++i){
		if (las != S[i]) {
			gr.push_back(cnt);
			cnt = 1;
			las = S[i];
		}
		else {
			cnt++;
		}
	}
	gr.push_back(cnt);
	for (int j = 0; j < pi.size(); ++j) {
		int lef = gr[j * 2];
		int rht = gr[j * 2 + 1];
		int lan = lef - lef / 2 + rht / 2;
		int ran = rht - rht / 2 + lef / 2;
		ans[pi[j] - 1] = lan;
		ans[pi[j]] = ran;
	}
	for (int i = 0; i < N; ++i) {
		cout << ans[i] << " \n"[i == N - 1];
	}
	return 0;
}

Measured memory_bytes: 5816
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,M=get_i
s=array(M)
M.times do|i|
  s[i]=get_i
end
p=get_i
ans=0
(2**N).times do|bit|
    switch=array(N,0)
    N.times do|i|
        unless (bit&(2**i)).zero?
          switch[i]=1
        end
    end
    flag=true
    M.times do|i|
        cnt=0
        s[i][0].times do|j|
          cnt+=switch[s[i][j+1]-1]   
        end
        if cnt%2!=p[i]
            flag=false
            break
        end
    end
    ans+=1 if flag
end
puts ans

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define M 1000000007
#define N 100001
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

int t;
ll a, b, c, d, x, y;

int main() {
    //scanf("%d", &t);
    t = 1;
    while(t--) {
        scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

        ll ans = LONG_MIN;
        if(b > 0 && d > 0) ans = max(ans, b * d);    // both +ve
        if(a < 0 && c < 0) ans = max(ans, a * c);     // both -ve
        if(b < 0 && c > 0) ans = max(ans, b * c);
        if(d < 0 && a > 0) ans = max(ans, d * a);
        if((a <= 0 && 0 <= b) || (c <= 0 && 0 <= d)) ans = max(ans, 0LL);

        printf("%lld\n", ans);
    }
	return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;

struct UnionFind {
  vector<int> size, par;
  UnionFind(int n) {
    size.resize(n, 0);
    par.resize(n, 0);
    for(int i = 0; i < n; i++) {
      maketree(i);
    }
  }

  void maketree(int x) {
    par[x] = x;
    size[x] = 1;
  }

  int root(int x) {
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    if(size[rx] < size[ry]) par[rx] = ry;
    else {
      par[ry] = rx;
      if(size[rx] == size[ry]) size[rx]++;
    }
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int N, K, L;

int main() {
  cin >> N >> K >> L;
  UnionFind tree(N);
  UnionFind tree2(N);
  rep(i, K) {
    int x, y;
    cin >> x >> y;
    x--;y--;
    tree.unite(x, y);
  }
  rep(i, L) {
    int x, y;
    cin >> x >> y;
    x--;y--;
    tree2.unite(x, y);
  }
  vector<P> v;
  map<P, int> mp;
  rep(i, N) {
    mp[{tree.root(i), tree2.root(i)}]++;
  }
  rep(i, N) {
    cout << mp[{tree.root(i), tree2.root(i)}] << endl;
  }
  return 0;
}

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

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

    if(N%10 == 2) cout << "hon";
    if(N%10 == 4) cout << "hon";
    if(N%10 == 5) cout << "hon";
    if(N%10 == 7) cout << "hon";
    if(N%10 == 9) cout << "hon";
    if(N%10 == 0) cout << "pon";
    if(N%10 == 1) cout << "pon";
    if(N%10 == 6) cout << "pon";
    if(N%10 == 8) cout << "pon";
    if(N%10 == 3) cout << "bon";
}

Measured memory_bytes: 3632
#include <stdio.h>

int main() {

	int N;

	scanf("%d",&N);
	N%=10;
	switch(N%10) {
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			printf("hon\n");
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			printf("pon\n");
			break;
		default:
			printf("bon\n");
	}
	return 0;
}


Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;

int main()
{
  ll a,b;
  cin>>a>>b;
  a-=2*b;
  if(a<0)a=0;
  cout<<a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,ans=0;
int c[]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
vector<int>dp(1000010,1000000);
signed main(){
    cin>>n;
    reverse(c,c+12);
    dp[0]=0;
    for(int i=1;i<=n;i++){
        rep(j,12){
            if(i>=c[j])dp[i]=min(dp[i],dp[i-c[j]]+1);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}



Measured memory_bytes: 8064
#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from random import randint
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
import sys
import os
import re
sys.setrecursionlimit(9999)
inf = float('inf')
mod = int(1e9) + 7
mod_ = 998244353
N = 5001
 
'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''

def main():
	n = int(input())
	for i in range(1, int(n**.5)+1):
		if n%i == 0:
			if i <= 9 and n//i <= 9:
				print('Yes')
				return
	print('No')


BUFSIZE = 8192
class FastI(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = StringIO()
		self.newlines = 0
 
	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
		self.newlines = 0
		return self.buffer.read()
 
	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count("\n") + (not b)
			ptr = self._buffer.tell()
			self._buffer.seek(0, 2), self._buffer.write(
				b), self._buffer.seek(ptr)
		self.newlines -= 1
		return self._buffer.readline()
class FastO(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = __pypy__.builders.StringBuilder()
		self.write = lambda s: self._buffer.append(s)
 
	def flush(self):
		os.write(self._fd, self._buffer.build())
		self._buffer = __pypy__.builders.StringBuilder()
def print(*args, **kwargs):
	sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop("end", "\n"))
	if kwargs.pop("flush", False):
		file.flush()
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
	def bootstrap(cont):
		call, arg = cont.switch()
		while True:
			call, arg = cont.switch(to=continulet(
				lambda _, f, args: f(*args), call, arg))
	cont = continulet(bootstrap)
	cont.switch()
	main()

Measured memory_bytes: 31212
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  int n,m;
  cin >> n >>  m;
  int kake = n*m;
  int tasi = n+m;
  int hiki = n-m;
  cout << fmax(fmax(kake, tasi), hiki) << endl;
}


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

const static double	de_PI	= 3.14159265358979323846;
const static int	de_MOD	= 1000000007;
const static int	de_MAX	= 999999999;
const static int	de_MIN = -999999999;

struct VECTOR {
	double x;
	double y;
	double z;
};

inline VECTOR RelativePositionVector(const VECTOR A, const VECTOR B) {

	VECTOR v;
	v.x = B.x - A.x;
	v.y = B.y - A.y;
	v.z = B.z - A.z;

	return(v);

}

inline VECTOR CrossProduct(const VECTOR A,const VECTOR B) {

	VECTOR v;
	v.x = A.y*B.z - A.z*B.y;
	v.y = A.z*B.x - A.x*B.z;
	v.z = A.x*B.y - A.y*B.x;

	return(v);

}

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());

	VECTOR A, B, C, P;
	A.z = B.z = C.z = P.z = 0;
	std::vector<std::string> ans;

	while (std::cin >> A.x) {

		std::cin >> A.y >> B.x >> B.y >> C.x >> C.y >> P.x >> P.y;
		
		VECTOR AB = RelativePositionVector(A, B);
		VECTOR AP = RelativePositionVector(A, P);
		VECTOR BC = RelativePositionVector(B, C);
		VECTOR BP = RelativePositionVector(B, P);
		VECTOR CA = RelativePositionVector(C, A);
		VECTOR CP = RelativePositionVector(C, P);

		VECTOR ABxAP = CrossProduct(AB, AP);
		VECTOR BCxBP = CrossProduct(BC, BP);
		VECTOR CAxCP = CrossProduct(CA, CP);

		if (ABxAP.z > 0 && BCxBP.z > 0 && CAxCP.z > 0) {
			ans.push_back("YES");
		}
		else if (ABxAP.z < 0 && BCxBP.z < 0 && CAxCP.z < 0) {
			ans.push_back("YES");
		}
		else {
			ans.push_back("NO");
		}
	}

	for (unsigned int i = 0; i < ans.size(); i++) {
		std::cout << ans[i] << std::endl;
	}

}

Measured memory_bytes: 3164
#include <stdio.h>
int main(void){
        int i, j;
 
    int r, c;
    scanf("%d%d",&r,&c);
    int a[r+1][c+1];
    for(i=0;i<r+1;++i)
        for(j=0;j<c+1;++j)
            a[i][j] = 0;
    for(i=0;i<r;++i)
        for( j = 0; j < c; ++j )
            scanf("%d", &a[i][j]);
 
    int sum;
    for( i = 0; i < r; ++i ){
        sum = 0;
        for( j = 0; j < c; ++j ){
            sum += a[i][j];
        }
        a[i][j] = sum;
    }
    for( i = 0; i < c+1; ++i ){
        sum = 0;
        for( j = 0; j < r; ++j ){
            sum += a[j][i];
        }
        a[j][i] = sum;
    }
    for( i = 0; i < r+1; ++i ){
        for( j = 0; j < c+1; ++j ){
            printf("%d", a[i][j]);
            if( j != c ) printf(" ");
        }
        printf("\n");
    }
 
    return 0;
    
}



Measured memory_bytes: 2112
K,N=map(int,input().split())
A=list(map(int,input().split()))
ans=0
for i in range(N):
    if i==N-1:
        dis=K+A[0]-A[N-1]
    
    else:
        dis=A[i+1]-A[i]
    ans=max(dis,ans)
print(K-ans)

Measured memory_bytes: 25452
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
bool gray,brown,green,cyan,blue,yellow,orange,red;
int other;
int n;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		if(a<400) gray=1;
		else if(a<800) brown=1;
		else if(a<1200) green=1;
		else if(a<1600) cyan=1;
		else if(a<2000) blue=1;
		else if(a<2400) yellow=1;
		else if(a<2800) orange=1;
		else if(a<3200) red=1;
		else other++;
	}
	int ans=gray+brown+green+cyan+blue+yellow+orange+red;
	if(!ans) cout<<1<<' '<<other;
	else cout<<ans<<' '<<ans+other;
	re 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(void)

{

   int a,b,c;

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

   if(a<b)

   {

      if(b<c)

      {

         printf("Yes\n");

      }

      else

      {

         printf("No\n");

      }

   }

   else

   {

      printf("No\n");

   }

   return 0;

}

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

int main(){
    int N, numArray[100];
    // read input
    scanf("%d\n",&N);
    for ( int ixArray = 0 ; ixArray < N ; ixArray++ )
        scanf("%d",&numArray[ixArray]);
        
    int counter = 0;
    for ( int ixArray = 0 ; ixArray < N ; ixArray++ )
        for ( int jxArray = N-1 ; jxArray > ixArray ; jxArray-- )
            if ( numArray[jxArray] < numArray[jxArray-1] ){
                int temp = numArray[jxArray];
                numArray[jxArray] = numArray[jxArray-1];
                numArray[jxArray-1] = temp;
                counter++;
            }
    for ( int ixArray = 0 ; ixArray < N ; ixArray++ ){
            if ( ixArray == N-1 ) printf("%d\n",numArray[ixArray]);
            else printf("%d ",numArray[ixArray]);
        }
        printf("%d\n",counter);
    
    return 0;
}



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

struct vertex {
	std::set<int> edge;
	bool del;
	bool leaf;
	bool vis;
	int color;
	int deg;
	int val;
	int val1;
} v[100003];
int n;
int dia;
void dfs(int i)
{
	v[i].vis = true;
	int val1 = 0, val2 = 0;
	for(std::set<int>::iterator j = v[i].edge.begin();j != v[i].edge.end();++j) {
		if(v[*j].vis) continue;
		dfs(*j);
		if(v[*j].val1 > val1) {
			val2 = val1;
			val1 = v[*j].val1;
		} else if(v[*j].val1 > val2) {
			val2 = v[*j].val1;
		}
	}
	v[i].val1 = val1 + v[i].val;
	if(val1+val2+v[i].val > dia) dia = val1+val2+v[i].val;
}
int main()
{
	scanf("%d",&n);
	for(int i = 0;i < n - 1;++i) {
		int a,b;
		scanf("%d%d",&a,&b);--a,--b;
		v[a].edge.insert(b);
		v[b].edge.insert(a);
	}
	scanf(" ");
	for(int i = 0;i < n;++i) {
		char c = getchar();
		if(c == 'B') {
			v[i].color = 0;
		} else {
			v[i].color = 1;
		}
	}
	if(n == 1) {
		if(v[0].color == 0) {
			printf("0\n");
		} else {
			printf("1\n");
		}
		return 0;
	}
	std::queue<int> q;
	for(int i = 0;i < n;++i) {
		if(v[i].color == 0 && v[i].edge.size() <= 1) {
			v[i].leaf = true;
			q.push(i);
		}
	}
	while(!q.empty()) {
		int i = q.front();q.pop();
		//printf("del %d\n", i);
		v[i].del = true;
		for(std::set<int>::iterator j = v[i].edge.begin();j != v[i].edge.end();++j) {
			v[*j].edge.erase(i);
			if(v[*j].color == 0 && v[*j].edge.size() == 1) q.push(*j);
			if(v[*j].edge.size() == 0) {
				if(v[*j].color == 0) {
					printf("0\n");
				} else {
					printf("1\n");
				}
				return 0;
			}
		}
	}
	int root = -1;
	int ans = 0;
	for(int i = 0;i < n;++i) {
		if(v[i].del) continue;
		ans += 2;
		if(root == -1) root = i;
		v[i].color ^= v[i].edge.size()&1;
		if(v[i].color == 1) {
			//printf("init-white %d\n", i);
			if(v[i].leaf) v[i].val = 1; else v[i].val = 2;
			++ans;
		} else {
			v[i].val = 0;
		}
	}
	if(root == -1) {
		printf("0\n");
		return 0;
	}
	dia = 0;
	dfs(root);
	ans -= ((dia+1)/2)*2;
	printf("%d\n", ans-2);
}


Measured memory_bytes: 22144
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        double sum = 0;
        for (int i = 0; i < N; i++) {
            double x = scan.nextDouble();
            String y = scan.next();
            double t = "JPY".equals(y) ? 1 : 380000;
            sum += x * t;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 23380
using System;

namespace AtTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);

            string[] arrayInput = Console.ReadLine().Split(' ');
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = int.Parse(arrayInput[i]);
            }

            Array.Sort(array);
            int changeCount = 0;
            int index = 0;
            int firstVal = array[0];
            while (index < n)
            {
                if (array[index] == firstVal)
                {
                    index++;
                    //continue;
                }
                else
                {
                    index += k - 1;
                    changeCount++;
                }
            }

            Console.WriteLine(changeCount);
        }
    }
}


Measured memory_bytes: 16864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		while(true) {

			int N=sc.nextInt();

			if(N==0) break;

			int[] dp=new int[N+1];

			for(int i=0;i<N+1;i++) dp[i]=0;

			dp[0]=1;

			for(int i=0;i<N;i++) {
				for(int j=1;j<=3;j++) {
					if(i+j>N) break;
					dp[i+j]+=dp[i];
				}
			}

			int ans=(((dp[N]+9)/10)+364)/365;
			System.out.println(ans);
		}

		sc.close();

	}

}



Measured memory_bytes: 26088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

struct Segtree {
	ll a[N_SIZE];
	ll seg[N_SIZE * 2];
	ll lazy[N_SIZE * 2];
	ll gt;
	void init(int n) {
		gt = 1;
		while (n > gt)gt *= 2;
		REP(i, n)a[i] = 0;
		REP(i, N_SIZE) {
			seg[i] = 0;
			lazy[i] = 0;
		}
		REP(i, n)seg[i + gt - 1] = a[i];
	}

	void lazy_evaluate(int k, int l, int r) {
		seg[k] += lazy[k] * (r - l);
		if (gt > k) {
			lazy[2 * k + 1] += lazy[k];
			lazy[2 * k + 2] += lazy[k];
		}
		lazy[k] = 0;
	}

	//[a,b)
	void update(int a, int b, int x) { update(a, b, 0, 0, gt, x); }
	void update(int a, int b, int k, int l, int r, int x) {
		if (r <= a || b <= l) {
			return;
		}
		if (a <= l&&r <= b) {
			lazy[k] += x;
		}
		else {
			update(a, b, 2 * k + 1, l, (l + r) / 2, x);
			update(a, b, 2 * k + 2, (l + r) / 2, r, x);
			if (gt > k) {
				seg[k] = seg[2 * k + 1] + lazy[2 * k + 1] * (r - l) / 2
					+ seg[2 * k + 2] + lazy[2 * k + 2] * (r - l) / 2;
			}
		}
	}

	//[a,b???min
	ll query(int a, int b) { return query(a, b, 0, 0, gt); }
	ll query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return 0;
		if (a <= l&&r <= b) {
			ll add = (r - l)*lazy[k];
			//lazy_evaluate(k, l, r);
			return seg[k] + add;
		}
		else {
			lazy_evaluate(k, l, r);
			return query(a, b, 2 * k + 1, l, (l + r) / 2)
				+ query(a, b, 2 * k + 2, (l + r) / 2, r);
		}
	}

	void print() {
		REP(i, gt * 2)cout << "!" << i << " " << seg[i] << " " << lazy[i] << endl;
	}
};

int n, q;
Segtree tr;

int main() {
	cin >> n >> q;
	tr.init(n);
	REP(i, q) {
		bool f;
		int a, b, c;
		cin >> f;
		if (!f) {
			cin >> a >> b >> c;
			a--; b--;
			tr.update(a, b + 1, c);
		}
		else {
			cin >> a >> b;
			a--; b--;
			cout << tr.query(a, b + 1) << endl;
		}
		//tr.print();
	}
}

Measured memory_bytes: 20300
#include<stdio.h>

int search(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)i++;
  return i!=n;
}

int main(){
  int i,n,A[10000+1],q,key,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(search(A,n,key))sum++;
  }
  printf("%d\n",sum);
  return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

struct Key {
  int price;
  int bits;
};

const int INF = 1 << 30;

void setmin(int& a, int b) {
  if (a > b) a = b;
}

int main() {
  in(int, n, m);
  vector<Key> keys(m);
  rep(i, m) {
    in(int, a, b);
    keys[i].price = a;
    dbg(a, b);
    rep(j, b) {
      in(int, c);
      keys[i].bits |= 1 << (c - 1);
    }
    dbg(keys[i].price, keys[i].bits);
  }
  vector<int> dp(1 << n, INF);
  dp[0] = 0;
  rep(bits, (1 << n)) {
    rep(i, m) {
      setmin(dp[bits | keys[i].bits], dp[bits] + keys[i].price);
    }
  }
  int ans = dp[(1 << n) - 1];
  if (ans == INF) {
    out(-1);
  } else {
    out(ans);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;

const int mx = 1e5 + 5;
int vis[mx], val[mx];
int n, m;
vector<pii> G[mx];

bool dfs(int x){
    vis[x] = 1;
    for(pii u : G[x]){
        if(vis[u.first]){
            if(val[u.first] != val[x] + u.second) return false;
            else continue;
        }
        val[u.first] = val[x] + u.second;
        if(!dfs(u.first)) return false;
    }
    return true;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m;
    for(int i = 0, a, b, w; i < m; i++){
        cin >> a >> b >> w;
        G[a].emplace_back(b,w);
        G[b].emplace_back(a,-w);
    }
    for(int i = 1; i <= n; i++){
        if(!vis[i] && !dfs(i)){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,a=0,b=0,c=0;
  cin>>N>>M;
  c = c + (M%5000)/1000;
  M = M - M%5000;
  b = M/5000;
  while(1){
    if(a+b+c>N){
      b -= 2;
      a++;
    }
    if(a+b+c<N){
      b --;
      c += 5;
    }
    if(b<0){
      a = -1;
      b = -1;
      c = -1;
      break;
    }
    if(a+b+c == N){break;}
  }
      
  cout << a << " " << b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

h,w = lr()
s = [input() for i in range(h)]
dis = [[0 for i in range(w+1)]for j in range(h+1)] # 障害物に当たる最小数
for i in range(2,w+1):
    dis[0][i] = inf
for i in range(2,h+1):
    dis[i][0] = inf
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            dis[i+1][j+1] = min(dis[i][j+1], dis[i+1][j])
        else:
            if i>0 and j>0 and s[i-1][j]=='#' and s[i][j-1]=='#':
                dis[i+1][j+1] = min(dis[i][j+1], dis[i+1][j])
            elif i>0 and s[i-1][j]=='#':
                dis[i+1][j+1] = min(dis[i][j+1], dis[i+1][j]+1)
            elif j>0 and s[i][j-1]=='#':
                dis[i+1][j+1] = min(dis[i][j+1]+1, dis[i+1][j])
            else:
                dis[i+1][j+1] = min(dis[i][j+1]+1, dis[i+1][j]+1)
print(dis[h][w])

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

typedef long long LL;

int main(){
	LL n,k;
	cin >> n >> k;
	swap(n,k);
	LL ans = n;
	n--;
	for(int i=1;i<k;i++) ans*=n;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	stack<int>s1;
	stack<pair<int, int>>s2;
	int sum(0); char ch;
	for (int i(0); cin >> ch; i++) {
		if (ch == '\\')s1.push(i);
		else if (ch == '/' && !s1.empty()) {
			int j = s1.top(); s1.pop();
			sum += i - j;
			int a = i - j;
			while (!s2.empty() && j < s2.top().first) {
				a += s2.top().second; s2.pop();
			}
			s2.push(make_pair(j, a));
		}
	}
	vector<int>ans;
	while (!s2.empty()) {
		ans.emplace_back(s2.top().second);
		s2.pop();
	}
	reverse(all(ans));
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " " << ans[i];
	}
	cout << endl;
	return 0;
}

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

int main() {
    int a, b, c, d, e;
    std::string result;
    std::cin >> a;
    std::cin >> b;
    std::cin >> c;
    std::cin >> d;
    std::cin >> e;
    if(c < 0 || d < 0){
      result = "No";
    }else if((c+e) > a || (d+e) > b){
      result = "No";
    }else{
      result = "Yes";
    }
    std::cout << result << std::endl;
}


Measured memory_bytes: 3208
#include<iostream>
using namespace std;
int main () {
  long long H;
  cin >> H;
  long long ans = 0;
  const long long t = 2;
  long long k = 1;
  while(H) {
    H /= t;
    ans += k;
    k *= 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
s=list(input())
k=[0]*n
for i in range(1,n):
    if s[i-1]=='A' and s[i]=='C':
        k[i]=k[i-1]+1
    else:
        k[i]=k[i-1]
for i in range(q):
    a,b=map(int,input().split())
    print(k[b-1]-k[a-1])

Measured memory_bytes: 6872
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int y=sc.nextInt();
		if(y<n*1000||n*10000<y) {
			System.out.println(-1+" "+-1+" "+-1);
			return;
		}else{
			for(int man=0;man*10000<=y;man++) {
				for(int sen=0;sen<=n-man;sen++) {
					int gosen=n-man-sen;
					if(sen*1000+gosen*5000+man*10000==y) {
						System.out.println(man+" "+gosen+" "+sen);
						return;
					}
				}
			}
			System.out.println(-1+" "+-1+" "+-1);
		}

	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
int a[MAX_N];

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

  cin >> N;
  rep(i, N) cin >> a[i];
  
  int mi = INFINT;
  for (int i = 0; i < N; ++i) {
      mi = min(mi, a[i]);
  }

  int c1 = 0, c2 = 0;
  for (int i = 0; i < N; ++i) {
      if (a[i] == mi) ++c1;
      else if (a[i] == mi+1) ++c2;
      else {
          cout << "No" << endl;
          return 0;
      }
  }

  if (c2 == 0) {
      if (mi*2 <= N || mi == N-1) {
          cout << "Yes" << endl;
      } else {
          cout << "No" << endl;
      }
      return 0;
  }

  int lb = c1 + 1;
  int ub = c1 + (c2/2);

  if (lb <= mi+1 && mi+1 <= ub) {
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }

  return 0;
}


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

#include <atcoder/all>
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = ((ll)(n)-1); i >= 0; --i)
#define rreps(i, n) for (ll i = ((ll)(n)); i > 0; --i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repc2(i, s, n) for (ll i = (s); i <= (ll)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
using namespace atcoder;

int n, q;

int main() {
    scanf("%d%d", &n, &q);
    fenwick_tree<ll> bit(n);
    rep(i, n) {
        ll a;
        scanf("%lld", &a);
        bit.add(i, a);
    }
    rep(i, q) {
        int c, a, b;
        scanf("%d%d%d", &c, &a, &b);
        if (c == 0) {
            bit.add(a, b);
        } else {
            printf("%lld\n", bit.sum(a, b));
        }
    }
    return 0;
}

Measured memory_bytes: 8224
import sys
n,q=map(int,input().split())
s=list(input())
l=[list(input().split()) for i in range(q)]
L1=0;R1=n-1
while L1!=R1:
  x1=(L1+R1)//2
  p=x1
  for i in range(q):
    if l[i][0]==s[p]:
      if l[i][1]=='L':
        p-=1
      else:
        p+=1
    if p==-1 or p==n:
      break
  if p==-1:
    L1=x1+1
  else:
    R1=x1

if L1==0:
  p=0
  for i in range(q):
    if l[i][0]==s[p]:
      if l[i][1]=='L':
        p-=1
      else:
        p+=1
      if p==-1 or p==n:
        break
  if p==n:
    print(0)
    sys.exit()

L2=0;R2=n-1
while L2!=R2:
  x2=(L2+R2+1)//2
  p=x2
  for i in range(q):
    if l[i][0]==s[p]:
      if l[i][1]=='L':
        p-=1
      else:
        p+=1
    if p==-1 or p==n:
      break
  if p==n:
    R2=x2-1
  else:
    L2=x2

if L2==n-1:
  p=n-1
  for i in range(q):
    if l[i][0]==s[p]:
      if l[i][1]=='L':
        p-=1
      else:
        p+=1
      if p==-1 or p==n:
        break
  if p==-1:
    print(0)
    sys.exit()

print(L2-L1+1)

Measured memory_bytes: 97608
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  for(i<-1 to readInt) {
    val x = readLine.split(" ") map { _.toDouble }
    val p = (x(2)-x(0))*(x(7)-x(5)) - (x(6)-x(4))*(x(3)-x(1))
    if(p< 1e-10 && p > -(1e-10)) println("YES") else println("NO")
  }
}

Measured memory_bytes: 43988
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main(){
#define double long double
	int n;
	cin >> n;
	double t;
	cin >> t;
	double ans = 0;
	REP(i, n) {
		double a, b;
		cin >> a >> b;
		ans = max((t / a)*b,ans);
	}
	cout <<fixed << setprecision(20) <<  ans << endl;
	return 0;
}


Measured memory_bytes: 3304
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ac=0;
        int wa=0;
        int tle=0;
        int re=0;
        
        for(int i=0;i<n;i++){
            String str = sc.next();
            if(str.equals("AC")){
                ac++;
            }
            if(str.equals("WA")){
                wa++;
            }
            if(str.equals("TLE")){
                tle++;
            }
            if(str.equals("RE")){
                re++;
            }

        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }
}

Measured memory_bytes: 58852