akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
 
#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;
 
const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);
 
 
//変数
int N, K, Q;
vector<int>A;
 
 
 
 
 
//サブ関数
//入力
void input()
{
	cin >> N >> K >> Q;
	A.resize(N);
	REP(i, N)cin >> A[i];
}
 
vector<vector<int>> slash(vector<int> A, int base)
{
	vector<vector<int>> res;
	vector<int> mid;
	REP(i, N) {
		if (A[i] >= base)mid.push_back(A[i]);
		else {
			res.push_back(mid);
			mid.clear();
		}
	}
	if (!mid.empty())res.push_back(mid);
 
	return res;
}
 
int X_Y(const vector<vector<int>> vv, int K,int Q) {
	vector<int> minimum;
	for (auto v : vv) {
		sort(v.begin(), v.end(),greater<int>());
		while (v.size() >= K) {
			minimum.push_back(v.back());
			v.pop_back();
		}
	}
	if (minimum.size() < Q)return INF;
 
	sort(minimum.begin(), minimum.end());
	return minimum[Q - 1] - minimum[0];
}
 
//計算
void calc()
{
	priority_queue<int,vector<int>,greater<int>> pq;
	for (auto num : A)pq.push(num);
 
	int ans = INF;
	while (!pq.empty()) {
		int base = pq.top(); pq.pop();
		auto vv = slash(A, base);
		int tmp = X_Y(vv, K, Q);
		if (tmp == INF)break;
		ans = min(ans,tmp);
	}
	cout << ans << endl;
}
 
 
//出力
void output()
{
 
}
 
 
//デバッグ
void debug()
{
	int N;
	cin>>N;
}
 
 
//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}

Measured memory_bytes: 384
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
ans = []
ans.append(min(X//500,A))
ans.append(min(X//100,B))
ans.append(min(X//50,C))
for i in range(ans[0]+1):
    for j in range(ans[1]+1):
        for k in range(ans[2]+1):
            p = i * 500 + j * 100 + k * 50
            if p == X:
                count += 1
print(count)

Measured memory_bytes: 40048
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
int main() {
    cin>>s;

    int cnt=0;
    REP(i, 0, s.size()/2){
        if(s[i]!=s[s.size()-i-1]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 102;
int N, M, F[MAXN], sum, tmp, cnt;
bool check;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N >> M;
	for(int i = 1;i<=N;i++){cin >> F[i]; sum+=F[i];}
	tmp = sum/(4*M);
	check = sum%(4*M)==0;
	for(int i = 1;i<=N;i++){
		if(check&&F[i]>=tmp)cnt++;
		else if(!check&&F[i]>tmp)cnt++;
	}
	if(cnt>=M){cout << "Yes" << nl;}
	else cout << "No" << nl;
	return 0;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

int n;
int ar[55];

int cnt[15];
void zero(){
  puts("0");
  exit(0);
}
int main(){
  cin>>n;
  REP(i,n){
    cin>>ar[i];
    ++cnt[ar[i]];
  }
  ++cnt[0];

  int m=13;
  REP(i,m) if(cnt[i]>=3) zero();
  if(cnt[0]>=2 || cnt[12]>=2) zero();

  int res=0;
  prl;
  REP(bit,(1<<m)){
    bool mark[25]={false};
    REP(i,m) if(cnt[i]){
      if(i==0 || i==12) mark[i]=true;
      else{
        int a=i,b=24-i;
        if(cnt[i]==2) mark[a]=mark[b]=true;
        else if(bit>>i&1) mark[a]=true;
        else mark[b]=true;
      }
    }
    int tmp=24;
    mark[24]=true;
    REP(i,25) REP(j,i) if(mark[i] && mark[j]) chmin(tmp,i-j);
    chmax(res,tmp);
  }
  cout<<res<<endl;
  return 0;
}





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

int main() {

 int a,b;
 std::cin >> a >>b;
 if(a==1&&b==1){
   std::cout << "Draw" << '\n';
 }else if(a==1){
   std::cout << "Alice" << '\n';
 }else if(b==1){
   std::cout << "Bob" << '\n';
 }else if(a<b){
   std::cout << "Bob" << '\n';
 }else if(a>b){
   std::cout << "Alice" << '\n';
 }else{
   std::cout << "Draw" << '\n';
 }
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Integer> arr = new ArrayList<>();
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        int sum = 0;
        Collections.sort(arr);
        for (int i = (n-k); i<n; i++){
            sum+=arr.get(i);
        }
        System.out.println(sum);

    }
}

Measured memory_bytes: 35832
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>  // std::unique
using namespace std;

/*
くじ引きをN 回行い、
i 回目には種類が文字列Si で表される景品を手に入れました。

何種類の景品を手に入れましたか？
*/

int main(void) {

	int itemNum;
	cin >> itemNum;

	vector<string> items;
	for (int i = 0; i < itemNum; ++i) {
		std::string name;
		cin >> name;
		items.push_back(name);
	}

	std::sort(items.begin(), items.end());
	items.erase(std::unique(items.begin(), items.end()), items.end());

	auto output = items.size();
	cout << output;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        boolean[] ns = new boolean[1000000];
        for (int i = 2; i < 1000000; i++) {
            if (ns[i])
                continue;
            for (int j = 2; j < 999999 / i + 1; j++) {
                if (!ns[i * j]) {
                    ns[i * j] = true;
                }
            }
        }

        while ((line = br.readLine()) != null && !line.isEmpty()) {
            int n = Integer.parseInt(line);
            int m = 0;
            for (int i = 2; i < n + 1; i++) {
                if (!ns[i]) {
                    m++;
                }
            }
            System.out.println(m);
        }
    }
}

Measured memory_bytes: 22124
#include<stdio.h>
int main()
{

  int n,m,sizi[1003],me[1002],i,j,place,x;

  while(1){
    scanf("%d%d",&n,&m);
    place=1;

    if(n==0 && m==0) break;

    for(i=1; i<=n; i++){
      scanf("%d",&sizi[i]);
    }

    for(i=0; i<m; i++){
      scanf("%d",&me[i]);      
    }

    for(i=0; i<m; i++){
      place+=me[i];

      if(place>=n){
	printf("%d\n",i+1);
	break;
      }
      
      place+=sizi[place];

      if(place>=n){
	printf("%d\n",i+1);
	break;
      }
    
  }
}

  return 0;

}

Measured memory_bytes: 608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int l = fs.nextInt();
		int r = fs.nextInt();
		int d = fs.nextInt();
		
		System.out.println((r/d) - ((l-1)/d));
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32732
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 5000
#define MAXH 4
#define MAXM 4
#define INF 1LL << 60
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
const int N = 100005;
int par[N],rnk[N];

void init(int n){
	for(int i = 0; i < n; ++i){
		par[i] = i;
	}
}

int find_par(int x){
	return (par[x] == x?x:par[x] = find_par(par[x]));
}

void unite(int x,int y){
	x = find_par(x);
	y = find_par(y);
	if(x != y){
		if(rnk[x] > rnk[y]){
			par[y] = x;
		}
		else{
			par[x] = y;
			rnk[y] = max(rnk[y], rnk[x] + 1);
		}
	}
}

vector<pair<ll,pll>> edges;

int main(){
	fast_io();
	int n;
	cin >> n;
	vector<pair<pii,int>> v(n);
	cu(i,0,n){
		cin >> v[i].F.F >> v[i].F.S;
		v[i].S = i;
	}
	init(n);
	cu(cnt,0,2){
		sort(all(v));
		cu(i,0,n-1){
			edges.pb({v[i+1].F.F - v[i].F.F, {v[i].S ,  v[i+1].S}});
			swap(v[i].F.S, v[i].F.F);
		}
		swap(v[n-1].F.S, v[n-1].F.F);
	}
	sort(all(edges));
	ll ans = 0;
	cu(i,0,edges.size()){
		int fst = edges[i].S.F;
		int sec = edges[i].S.S;
		if(find_par(fst) != find_par(sec)){
			ans+=edges[i].F;	
			unite(fst,sec);
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 10096
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(ll i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    ll N, M;
    cin >> N >> M;
    vl a(M);
    vl b(M-1);
    rep(i, 0, M) {
        cin >> a[i];
    }

    int ans = 0;
    sort(a.begin(), a.end());
    
    if(N>=M) {
        cout << ans << endl;
        return 0;
    } else {
        rep(i, 0, M-1) {
            b[i] = abs(a[i+1]-a[i]);
        }
        sort(b.begin(), b.end());
        rep(i, 0, M-N) {
            ans += b[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
    char Si[4];
    int x = 0;

    for (int i = 0; i < 8; i++)
    {
        scanf("%c", &Si[i]);

        if (Si[i] == '+')
        {
            x++;
        }
        else if (Si[i] == '-')
        {
            x--;
        }
    }
    printf("%d", x);
    return 0;
}

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

int main() {
	// your code goes here
	int K,S;
	cin >> K >> S;
	int cnt = 0;
	for(int x=0;x<=K;x++){
		for(int y=0;y<=K;y++){
			if(S-x-y >= 0 && S-x-y <= K) cnt++;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char a[51][51];
bool b;
int main()
{
	int i,j,m,n,s;
	cin>>n>>m;
	for (i=1;i<=n;i++)
	  for (j=1;j<=m;j++)
	  cin>>a[i][j];
	for (i=1;i<=n;i++)
	  for (j=1;j<=n;j++) 
	{
		s=0;
		if (a[i][j]=='#')
		{
			if (a[i+1][j]!='#') s++;
			if (a[i-1][j]!='#') s++;
			if (a[i][j-1]!='#') s++;
			if (a[i][j+1]!='#') s++;
			if (s==4) {
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



vector<int> buf;
int N, M, Q, ans = 0;
vector <int> a;
vector <int> b;
vector <int> c;
vector <int> d;


void dfs(int i, const int size, const int range_start, const int range_end)
{
    if (i == size) {
        // ここで所望の作業を行
        
        int sum = 0;
        for (int k = 0; k < Q; k++) {
            if (buf[b[k]-1] - buf[a[k]-1] == c[k]) sum += d[k];
        }
        //cout<<ans<<" "<<sum<<endl;
        ans = max(ans, sum);
    }
    else{
        if(i == 0){
            for(int j = range_start; j <= range_end; ++j){
                buf[i] = j;
                dfs(i + 1, size, range_start, range_end);
            }
        }
        else{
            for(int j = min(buf[i-1],range_end); j <= range_end; ++j){
                buf[i] = j;
                dfs(i + 1, size, range_start, range_end);
            }
        }
        
    }
}

int main()
{
    
    cin>>N>>M>>Q;
    int size = N;
    int range_start = 1;
    int range_end = M;
    
    buf.resize(size);
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    
    dfs(0, size, range_start, range_end);

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


Measured memory_bytes: 3644
#include<iostream>
#include<string.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    string str;
    int flag = 0;
    int i = 0;
    int j = 0;

    cin >> str;

    sort(str.begin(), str.end());

    while(str[i] != '\0'){
        if(str[i] == str[i + 1]){
            while(str[j] != '\0'){
                str[j] = str[j + 2];
                j++;
            }
            i = -1;
            j = 0;
        }
        else{
            flag = 1;
        }
        i++;
    }

    if(flag == 0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

    return 0;
}
   

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		int[] nums = Arrays.stream(stdin.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		String postalCode = stdin.readLine();
		String regexp = "[0-9]{" + nums[0] + "}-[0-9]{"+ nums[1] + "}";
		String answer = postalCode.matches(regexp) ? "Yes" : "No";
		System.out.println(answer);
	}
}

Measured memory_bytes: 28756
s = []
ans = 0
flag = True
N, M = map(int, input().split())
if M ==0:
    if N==1:
        print(0)
    elif N ==2:
        print(10)
    else:
        print(100)
else:
    for i in range(M):
        a = list(map(int, input().split()))
        if a not in s:
            s.append(a)
    S = sorted(s)

    for i in range(len(S)-1):
        if S[i][0]==S[i+1][0] and S[i][1]!=S[i+1][1]:
            flag = False

    if N>1 and S[0]==[1,0]:
        flag = False

    if flag == True:
        for i in range(len(S)):
            for j in range(N+1):
                if S[i][0]==j:
                    ans+=S[i][1]*10**(N-j)
        if N==3 and ans<100:
            ans+=100
        elif N ==2 and ans<10:
            ans+=10
        
        print(ans)
            
    else:
        print('-1')

Measured memory_bytes: 38256
def is_odd(num):
    return num % 2 == 1

def m():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    n = 0
    ans = []
    for i in range(h):
        for j in range(w-1):
            if is_odd(a[i][j]):
                a[i][j] -=1
                a[i][j+1] += 1
                n += 1
                ans.append((i,j,i,j+1))
    for i in range(h-1):
        if is_odd(a[i][w-1]):
            a[i][w-1] -=1
            a[i+1][w-1] -= 1
            n += 1
            ans.append((i, w-1, i+1, w-1))

    print(n)
    for i in range(n):
        print(ans[i][0]+1, ans[i][1]+1, ans[i][2]+1, ans[i][3]+1)


m()

Measured memory_bytes: 22804
#include <bits/stdc++.h>
using namespace std;
int main() {
    string input;
    cin >> input;
    int n = input.size();
    //cout << n << endl;
    //string second = input.substr((n+3)/2);
    bool kai=1;
    for(int i=0; i<n/2; ++i){
        if(input[i]==input[n-1-i]){
            continue;
        }
        else{
            kai=0;
            break;
        }
    }
    for(int i=0; i<(n-1)/4; ++i){
        if(input[(n+3)/2-1+i] == input[n-1-i]){
            continue;
        }
        else{
            kai=0;
            break;
        }
    }
    if(kai){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
x = []

for i in range(1, c+1):
    if c % i == 0:
        x.append(i)

count = 0
for j in range(0, len(x)):
    if a <= x[j] and x[j] <= b:
        count = count + 1

print(count)


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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  
  vector<ll> h(100001);
  
  for ( ll i = 0; i < n; i++ )
    cin >> h[i];
  
  for ( ll i = n - 2; i >= 0; i-- ){
    if ( h[i] > h[i+1] + 1 ){
      cout << "No" << endl;
      return 0;
    } else if ( h[i] == h[i+1] + 1 ){
      h[i]--;
      if ( h[i] < h[0] - 1 ){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
  
}

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

int main()
{
    static const double pi = 3.141592653589793;
    double a,b,h,m;cin >> a >> b >> h >> m;
  	if(h == 0 && m == h){
    	if(a >= b) {
        	cout << a - b << endl;
        }
      	else {
        	cout << b - a << endl;
        }
      	return 0;
    }
  
  	if(h == 0) h = 12;
  	if(m == 0) m = 60;
  
  	
  	if(h >= m / 5) {
    	if(h == 12) h = 0;
  		if(m == 60) m = 0;
      	double m_locate = pi * (m / 5) * 30 / 180;
  		double h_locate = pi * (h * 30 + (m / 60) * 30) / 180;
        double result2 = a*a + b*b - 2*a*b*cos(h_locate - m_locate);
      	printf("%.20lf\n", sqrt(result2));
    } else {
    	if(h == 12) h = 0;
	  	if(m == 60) m = 0;
      	double m_locate = pi * (m / 5) * 30 / 180;
      	double h_locate = pi * (h * 30 + (m / 60) * 30) / 180;
      	double result2 = a*a + b*b - 2*a*b*cos(m_locate - h_locate);
      	printf("%.20lf\n", sqrt(result2));
    }

    return 0;
}

Measured memory_bytes: 4116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;


class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		//区別できるボールを区別できる箱に入れる入れ方は、
		//1つのボールに付き、箱の個数通り有り、それぞれ独立なので、
		//n kが与えられた時 k^nである。
		long MOD=1000000007;
		long n=sc.nextLong();
		long k=sc.nextLong();
		long ans=1;
		for(long i=0; i<n; i++) {
			ans=(ans*k)%MOD;
		}
		pl(ans);

	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 24452
// D - Div Game
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll ans = 0, N; cin>>N;
  for(ll c, n=N, p=2; p*p<=N; ++p){
   	for(c=0; N%p==0; ++c) N/=p;
		for(ll pi=p, i=1; i<=c; i++, pi*=p){
			if(n%pi) continue;
			n /= pi;
			ans++;
		}
  }
  if(N != 1) ans++;
	cout<< ans <<endl;
}


Measured memory_bytes: 3664
#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long N, K;
    cin >> N >> K;
    map<long long, long long> arr;
    for (long long i = 0; i < N; ++i) {
        long long a, b;
        cin >> a >> b;
        if (arr.count(a) == 0) {
            arr.insert(make_pair(a, 0));
        }
        arr[a] += b;
    }

    long long nth = 0;
    long long ans = 0;
    for (auto e : arr) {
        nth += e.second;
        if (nth >= K) {
            ans = e.first;
            break;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

using namespace std;

int main(){
    int X, A, B; cin >> X >> A >> B;

    if((B-A) > X){
        cout << "dangerous" << endl;
    }else if((B-A) > 0){
        cout << "safe" << endl;
    }else{
        cout << "delicious" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
public class UnionFind {
    private int[] data;

    public UnionFind(int size) { //初期化
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }

    public bool Unite(int x, int y) { //xが属しているグループとyが属しているグループを統合する
        x = Root(x);
        y = Root(y);

        if (x != y) {
            if (data[y] < data[x]) {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }

    public bool IsSameGroup(int x, int y) { //xとyが同じグループに属しているかどうか
        return Root(x) == Root(y);
    }

    public int Root(int x) { //ノードxの根を求める
        return data[x] < 0 ? x : data[x] = Root(data[x]);
    }

    public int Size(int x) => -data[Root(x)];
}

class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        int M = cin.Int();
        var A = new int[M];
        var B = new int[M];
        for (int i = 0; i < M; i++) {
            A[i] = cin.Int();
            B[i] = cin.Int();
        }

        var ans = new long[M + 10];
        var uf = new UnionFind(N + 10);
        ans[M - 1] = (long)N * (N - 1) / 2;

        for (int i = M - 1; i > 0; i--) {
            if(uf.IsSameGroup(A[i], B[i])) {
                ans[i - 1] = ans[i];
            }
            else {
                long tmpA = uf.Size(A[i]);
                long tmpB = uf.Size(B[i]);
                ans[i - 1] = ans[i] - tmpA * tmpB;
                uf.Unite(A[i], B[i]);
            }
        }

        for (int i = 0; i < M; i++) {
            Console.WriteLine(ans[i]);
        }
        Console.ReadLine();
    }
}

Measured memory_bytes: 17992
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  char c[2000][2000];
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>c[i][j];
    }
  }
  int yoko[2000][2000]={};
  int tate[2000][2000]={};
  for(int i=0;i<h;i++){
  	int now=0;
  	while(c[i][now]=='#'){
  		now++;
  	}
  	while(now<w){
  		int s=now;
  		while(now<w&&c[i][now]=='.'){
  			now++;
  		}
  		int g=now;
  		for(int j=s;j<g;j++){
  			yoko[i][j]=g-s;
  		}
  		while(now<w&&c[i][now]=='#'){
  			now++;
  		}
  	}
  }
  for(int i=0;i<w;i++){
  	int now=0;
  	while(c[now][i]=='#'){
  		now++;
  	}
  	while(now<h){
  		int s=now;
  		while(now<h&&c[now][i]=='.'){
  			now++;
  		}
  		int g=now;
  		for(int j=s;j<g;j++){
  			tate[j][i]=g-s;
  		}
  		while(now<h&&c[now][i]=='#'){
  			now++;
  		}
  	}
  }
  int ans=0;
  for(int i=0;i<h;i++){
  	for(int j=0;j<w;j++){
  		ans=max(ans,yoko[i][j]+tate[i][j]);
  	}
  }
  cout<<ans-1<<endl;
  return 0;
}

Measured memory_bytes: 35456
N = int(input())
x = []
y = []
for i in range(N):
    a = tuple(map(int, input().split()))
    x.append(a[0] + a[1])
    y.append(a[0] - a[1])

x.sort()
y.sort()

print(max(abs(y[0] - y[-1]), abs(x[-1] - x[0])) if x and y else abs(x[-1] - x[0]) if x else abs(y[0] - y[-1]))




Measured memory_bytes: 26172
#include <stdio.h>
void call(int n);

int main(void) {
	int n;
	scanf("%d", &n);
	call(n);
	return 0;
}

void call(int n) {
	int i = 1;
	do {
		int x = i;
		if(x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			do {
				if(x % 10 == 3) {
					printf(" %d", i);
					break;
				}
				else {
					x /= 10;
				}
			} while(x);
		}
	} while (++i <= n);
printf("\n");
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

#define MAX_N 100000
struct UF{
    int par[MAX_N];
    int rank[MAX_N];
    int si[MAX_N];

    void init(int n){
        rep(i,n){
            par[i] = i;
            rank[i] = 0;
            si[i] = 1;
        }
    }

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

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        
        if(rank[x] < rank[y]){
            par[x] = y;
            si[y] += si[x];
        } else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            si[x] += si[y];
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
} uf;

int n, m;

int main() {
    cin >> n >> m;
    uf.init(n);
    rep(i,m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--; z--;
        uf.unite(x, y);
    }
    int cnt = 0;
    rep(i,n) {
        if (uf.find(i) == i) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1408
# データ読み込み

import sys
from collections import deque

def input_data(d=""):
  t = sys.stdin.read()
  if t:
    return t
  else:
    if d[0] == "\n":
      d = d[1:]
    if d[-1] == "\n":
      d = d[:-1]    
    return d

A,AA, *B  = map(int,input_data().split())

m = []

out = 0
t = [[] for i in range(8)]
for a,b,c  in zip(*[iter(B)] * 3):
  t[0].append(a+b+c)
  t[1].append(a+b-c)
  t[2].append(a-b+c)
  t[3].append(a-b-c)
  t[4].append(-a+b+c)
  t[5].append(-a+b-c)
  t[6].append(-a-b+c)
  t[7].append(-a-b-c)
for i in range(8):
  t[i].sort(reverse=True)
  if out < sum(t[i][:AA]):
    out = sum(t[i][:AA])
print(out)

Measured memory_bytes: 3828
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans,n,p;
void solve()
{
    cin>>p>>n;
    vector<vector<ll>> pre(p+1);
    vector<pi> vc(n);
    for(int i=0;i<n;i++)
    {
        cin>>vc[i].first>>vc[i].second;
        pre[vc[i].first].pb(vc[i].second);
    }
    for(int i=1;i<=p;i++)
    {
        sort(pre[i].begin(),pre[i].end());
    }
    for(int i=0;i<n;i++)
    {
        //cout<<vc[i].first<<" "<<vc[i].second<<endl;
        ll temp=lower_bound(pre[vc[i].first].begin(),pre[vc[i].first].end(),vc[i].second)-pre[vc[i].first].begin();
        temp++;
        //cout<<temp<<endl;
        string s="000000",ss="000000";
        //cout<<ss<<s<<endl;
        ll k=5;
        while(temp)
        {
            s[k--]=char(temp%10+'0');temp/=10;
        }
        temp=vc[i].first;k=5;
        while(temp)
        {
            ss[k--]=char(temp%10+'0');temp/=10;
        }
        cout<<ss<<s<<endl;
    }
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
 
#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)
#define f first
#define se second
#define M 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<long long, long long>
#define vi vector<int>
#define ll long long

vector<pair<pair<ll,ll>,ll>>seg;
int inf=1e9;

pair<pair<ll,ll>,ll> find(int st,int l,int r,int l1,int r1){
    if(l1>r||r1<l){
        return mp(mp(0,0),0);
    }
    if(l1<=l&&r1>=r){
        return seg[st];
    }
    if(l==r){
        //cout<<seg[st].first.second<<" "<<seg[st].first.first<<" "<<seg[st].second<<endl;
        return seg[st];
        
    }
    
    int mid=(l+r)/2;
    pair<pair<ll,ll>,ll> v1=find(st*2,l,mid,l1,r1);
    pair<pair<ll,ll>,ll> v2=find(st*2+1,mid+1,r,l1,r1);
    ll k=min(v1.first.first,v2.first.second);
    v1.second=v2.second+v1.second+2*k;
    v1.first.first=v1.first.first+v2.first.first-k;
    v1.first.second=v1.first.second+v2.first.second-k;
    //cout<<v1.second<<" "<<l<<" "<<r<<endl;
    return v1;

}
void update(int st,int pos,int l,int r,char val){
    if(l==r){
        if(val=='('){
            seg[st].first.first=1;
        }else {
            seg[st].first.second=1;
        }
        
        return;
    }
    int mid=(l+r)/2;
    if(pos<=mid){
        update(st*2,pos,l,mid,val);
        
    }else {
        update(st*2+1,pos,mid+1,r,val);
        //seg[st]=min(seg[st*2+1],seg[st*2+2]);
    }
    ll k=min(seg[st*2].first.first,seg[st*2+1].first.second);
    seg[st].second=seg[st*2].second+seg[st*2+1].second+2*k;
    seg[st].first.first=seg[st*2].first.first+seg[st*2+1].first.first-k;
    seg[st].first.second=seg[st*2].first.second+seg[st*2+1].first.second-k;
}


int main(){
  ll n;
  cin>>n;
  ll sum=0;
  for(int i=1;i<=n;i++){
    if(i%5!=0&&i%3!=0){
        sum+=i;
    }
  }
  cout<<sum;
} 


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

int main(){
    long long N, K, t, s;
    scanf("%lld %lld", &N, &K);
    if( K % 2 ){
        t = N / K;
        printf("%lld\n" , t * t * t);
    }else{
        t = N / K;
        s = (N + K / 2) / K ;
        printf("%lld\n" , t * t * t + s * s * s);
    }
    return 0;
}


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

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

    ll res=0;
    //全探索
    for(ll k=1;k<=K;++k){      //操作を何回するか
        for(ll i=0;i<=k;++i){
            ll take=k-i;    //take回まで取る操作をしていく
            if(take>min(N,K))continue;

            //左から取る個数
            for(ll j=0;j<=take;++j){

                priority_queue<ll, vector<ll>, greater<ll> > pq;  //取った宝石はpriority_queueに格納
                for(ll L=0;L<j;++L){
                    pq.push(V[L]);
                }
                //右から取る
                for(ll R=N-(take-j);R<N;++R){
                    pq.push(V[R]);
                }
                //小さい方から捨てる。
                for(ll x=0;x<i;++x){
                    if(pq.empty() || pq.top()>=0)break;
                    pq.pop();
                }
                ll sum=0;
                while(!pq.empty()){
                    sum+=pq.top();
                    pq.pop();
                }
                res=max(res,sum);

            }
        }
    }
    cout << res << endl;
}

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

int     main() {
        string A;
        cin >>A;
        long S=0;
        long N=A.size();
        vector<long> C(26, 0);
        for (long i=0; i<N; i++) {
                int c=A.at(i)-'a';
                C.at(c)++;
        }
        for (int i=0; i<26; i++) {
                long CC=C.at(i);
                long SSS;
                if (0==CC%2) {
                        SSS=CC/2;
                        SSS *= CC-1;
                } else {
                        SSS=(CC-1)/2;
                        SSS *= CC;
                }
                S += SSS;
        }
        long SS;
        if (0==N%2) {
                SS=N/2;
                SS *= N-1;
        } else {
                SS=(N-1)/2;
                SS *= N;
        }
        SS -= S;
        // for no change
        SS++;
        cout <<SS <<endl;
        return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int isp[1000001];

int main()
{
	for(int i=2;i<1000001;i++)
		isp[i]=1;
	for(int i=2;i<1000001;i++)
		if(isp[i])
			for(int j=i+i;j<1000001;j+=i)
				isp[j]=0;
	
	for(int a,d,n;cin>>a>>d>>n,a|d|n;){
		int i,j;
		for(i=a,j=0;j<n;i+=d)
			if(isp[i])
				j++;
		cout<<i-d<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    int ans = n/3;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto A = RDA;

	auto b = new long[](N+1);
	foreach_reverse (i; 0..N)
	{
		b[i] = b[i+1];
		b[i].moda(A[i]);
	}

	long ans;
	foreach (i; 0..N)
	{
		long t = A[i];
		t.modm(b[i+1]);
		debug writeln(t);
		ans.moda(t);
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 13296
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	vector<char> v1(s.begin(),s.end());
	vector<char> v2(s.begin(),s.end());
	v2.erase(std::unique(v2.begin(), v2.end()), v2.end());
	if(v1.size()==v2.size())
		cout<<"yes";
	else
		cout<<"no";
	//cout<<v1.size()<<" "<<v2.size();
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int x,a,b,A,B;
    cin>>x;
    cin>>a;
    cin>>b;

    if (a>x)
    {
        A=a-x;
    }
    else if(x>a)
    {
        A=x-a;
    }

    if (b>x)
    {
        B=b-x;
    }
    else if(x>b)
    {
        B=x-b;
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,A ;
  int answ=0,bnsw=0;
  cin>>N>>M>>X ;
  while(M--){
  cin>>A;
  if(X<A&&A<N){
    answ+=1;
  }else{
    bnsw+=1;
  }
  }
  cout <<min(answ,bnsw)<<endl ;
  return 0 ;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

int main()
{
	char S[101] = {0};
	int len = 0, i = 0;
	scanf("%s", S);
	len = strlen(S);
	for (i = 0; i < len; i++) {
		S[i] = 'x';
	}
	printf("%s\n", S);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a,ll b);

int main(){
  vint dp(100010);
  dp[0] = 0;
  erep1(n,100000){
    dp[n] = INF;
    int power = 1;
    while(power <= n){
      dp[n] = min(dp[n],dp[n-power] + 1);
      power *= 6;
    }
    int power2 = 1;
    while(power2 <= n){
      dp[n] = min(dp[n],dp[n-power2] + 1);
      power2 *= 9;
    }
  }
  int a;
  cin >> a;
  cout << dp[a] << endl; 
}






Measured memory_bytes: 768
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        H_in: usize,
        W_in: usize,
        Ss: [String; H_in],
    }

    // 簡単のため、周囲に壁を作って (H+2)*(W+2)とする。
    let H = H_in + 2;
    let W = W_in + 2;
    let mut is_road_arr: Vec<Vec<bool>> = vec![vec![false; W]; H];

    for h in 0..H_in {
        for w in 0..W_in {
            let is_road: bool = &Ss[h][w..=w] == ".";

            let expanded_h = h + 1;
            let expanded_w = w + 1;

            is_road_arr[expanded_h][expanded_w] = is_road;
        }
    }

    // 制約的に、O(HW)なら間に合う
    // 列ごと、行ごとに持っておく形
    // row_groups: (h, w) を横に見た時の照らされる数
    // col_groups: (h, w) を縦に見た時の照らされる数
    let mut row_groups = vec![vec![0_usize; W]; H];
    let mut col_groups = vec![vec![0_usize; W]; H];

    for h in 0..H {
        let mut w_st: usize = 0;

        for w in 0..W {
            if !is_road_arr[h][w] {
                let cnt = w - w_st;
                for w_tmp in w_st..w {
                    row_groups[h][w_tmp] = cnt;
                }
                w_st = w + 1;
            }
        }
    }

    for w in 0..W {
        let mut h_st: usize = 0;

        for h in 0..H {
            if !is_road_arr[h][w] {
                let cnt = h - h_st;
                for h_tmp in h_st..h {
                    col_groups[h_tmp][w] = cnt;
                }
                h_st = h + 1;
            }
        }
    }

    let mut ans = 0;
    for h in 0..H {
        for w in 0..W {
            if !is_road_arr[h][w] {
                continue;
            }

            let cand = row_groups[h][w] + col_groups[h][w] - 1;
            ans = max(ans, cand);
        }
    }

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


Measured memory_bytes: 76836
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

int main() {
	//入力;
	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);


	return 0;
}

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

using namespace std;

int main() {
	vector<int> abc(3);
	cin >> abc[0] >> abc[1] >> abc[2];
	sort(abc.begin(), abc.end());
	int cc = abc[2] - abc[1];
	abc[0] += cc;
	cc += (abc[2] - abc[0]) / 2;

	if ((abc[2] - abc[0]) % 2 == 1) {
		cc += 2;
	} 
	cout << cc << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
import cmath
L, R = map(int,input().split())
saisyo = 2019
if(R-L>=2019):
    print(0)
else:
    vec = np.arange(L,R+1)
    vec = vec%2019
    for i in range(0,len(vec)):
        minvec = np.where(vec==vec[i],2018,vec*vec[i]%2019)
        tmp = np.min(minvec)
        if tmp < saisyo:
            saisyo = tmp
    print(saisyo)


Measured memory_bytes: 12472
def main():
    height, width, difference = map(int, input().split())
    grid = [[int(x) for x in input().split()] for _ in range(height)]
    coordinate = [[] for _ in range(height * width + 1)]
    cost = [0 for _ in range(height * width + 1)]
    for i in range(height):
        for j in range(width):
            coordinate[grid[i][j]] = [i, j]
    for i in range(difference + 1, height * width + 1):
        cost[i] += cost[i - difference]
        cost[i] += abs(coordinate[i][0] - coordinate[i - difference][0]) + abs(coordinate[i][1] - coordinate[i - difference][1])
    queries = int(input())
    for _ in range(queries):
        left, right = map(int, input().split())
        print(cost[right] - cost[left])


if __name__ == '__main__':
    main()



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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;


ll n,k;
vll G[100005];
ll dist[100005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>k;
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<pll> q;
  q.emplace(0,0);
  vb visited(n);
  dist[0]=k;
  
  while(!q.empty()){
    auto p=q.front(); q.pop();
    ll v=p.first, c=p.second;
    if(visited[v]) continue;
    visited[v]=true;
    ll color;
    if(c==0) color=k;
    else if(c==1) color=k-1;
    else color=k-1;
    for(auto nv: G[v]){
      if(visited[nv]) continue;
      dist[nv]=--color;
      // cout<<nv<<" "<<dist[nv]<<endl;
      q.emplace(nv,c+1);
    }
  }
  
  ll ans=1;
  rep(i,n){
    // cout<<dist[i]<<endl;
    ans*=dist[i];
    ans%=MOD;
  }
  cout<<ans<<endl;
}

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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

ll POW(ll a, ll b){
	if(b==1) return a;
	if(b%2==0) return POW(a*a%INF, b/2);
	return a*POW(a, b-1)%INF;
}

int main(){
	int n;
	cin >> n;
	int s[n];
	REP(i, n) cin >> s[i];
	int ans = INF;
	REP(i, n){
		int t1 = 0, t2 = 0;
		REP(j, n){
			if(j <= i) t1 += s[j];
			else t2 += s[j];
		}
		ans = min(ans, abs(t1-t2));
	}
	cout << ans << endl;
	return 0;
} 


Measured memory_bytes: 256