akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

using namespace std;
int main(void){

    string s,t;
    cin >> s >> t;
    ll count = 0;
    for(int i=0;i<s.size();i++){
      if( s[i] != t[i] ) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> P;
#define rep(i,n) for(ll i=0;i<n;++i)
const int INF=1001001001;
int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  vector<ll> s(n+1);
  rep(i,n){
    s[i+1]=(s[i]+a[i])%k;
  }
  ll cnt=0;
  map<int,int> mp;
  queue <int> q;
  rep(i,n+1){
    int now=s[i];
  //  cout<<i<<'i'<<now<<'n'<<endl;
   cnt+=mp[now];
   mp[now]++;
   q.push(now);
   if (q.size()==k){
     mp[q.front()]--;
     q.pop();
   }


  }
  cout<<cnt;
}


Measured memory_bytes: 13568
import sys
stdin=sys.stdin

ns = lambda:stdin.readline().rstrip()
ni = lambda:int(stdin.readline().rstrip())
nm = lambda:map(int,stdin.readline().split())
nl = lambda:list(map(int,stdin.readline().split()))

A,B,C,K=nm()
ans=0

ans+=min(A,K)
K-=min(A,K)

if(K>0):
    K-=min(B,K)
if(K>0):
    ans-=min(C,K)

print(ans)

Measured memory_bytes: 9140
def INSTR():
	return input()

def INNUM():
	return int(INSTR())

def INSTR_S():
	return INSTR().split()

def INNUM_S():
	return map(int, INSTR_S())

def INSTR_SM(n):
	return [tuple(INSTR_S()) for _ in range(n)]

def INNUM_SM(n):
	return [tuple(INNUM_S()) for _ in range(n)]

N = INNUM()
S = list(INSTR())
x = xmax = 0
for s in S:
	x += 1 if s == "I" else -1
	xmax = max(xmax, x)
print(xmax)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdlib>

using namespace std;
typedef long long int ll;

bool debug = false;
#define show(x) if (debug) {cout << "" # x << " = " << x << endl;}
#define rep(x, a, b) for (int x = a; x < b; x++)

int main()
{
  ll n;

  cin >> n;

  vector<ll> a(n, 0);

  rep (i, 0, n) {
    cin >> a[i];
  }

  ll sum = 0;
  ll low = 1;
  
  rep(i, 0, n) {
    show(low);
    if (a[i] <= low) {
      low = max(a[i] + 1, low);
    } else {
      sum += (a[i] - low - 1) / low + 1;
      low = (2>low)?2:low;
    }
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.Collator;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      StringBuilder line  = new StringBuilder();
      String wordA;
      String wordB;
      Collator collator = Collator.getInstance();
      int turn = Integer.parseInt(br.readLine());
      int pointA = 0;
      int pointB = 0;
      int result = 0;


      for ( int i = 0; i < turn; i++ ) {

        line.append(br.readLine());
        wordA = line.substring(0, line.indexOf(" "));
        wordB = line.substring(line.indexOf(" ")+1, line.length());

        result = collator.compare(wordA,wordB);
        pointA += result == 0 ? 1 : result < 0 ? 0 : 3;
        pointB += result == 0 ? 1 : result < 0 ? 3 : 0;

        line.setLength(0);
      }

      System.out.println(pointA + " " + pointB);
    }
  }
}


Measured memory_bytes: 29540
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

vector<vector<int>> to;
vector<int> ans;

void dfs(int v, int p = -1) {
  for (auto &u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

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

  int N, Q;
  cin >> N >> Q;
  to.resize(N + 5);
  ans.resize(N + 5);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  for (int i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  dfs(0);

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

  return 0;
}


Measured memory_bytes: 23552
#include <algorithm>
#include <utility>
#include <cstdio>
#include <set>
#define MOD 998244353
#define mp std::make_pair
typedef long long ll; 
int x[405], y[405], seq[405]; 
std::set<std::pair<int, int> > se; 
inline bool comp(int a, int b)
{
	if (x[a] == x[b])
		return y[a] < y[b]; 
	return x[a] < x[b]; 
}
inline bool same(int a, int b, int c)
{
	return (x[b] - x[a]) * (y[c] - y[a]) == (x[c] - x[a]) * (y[b] - y[a]); 
}
inline int quick_pow(int a, int n)
{
	int res = 1; 
	while (n)
	{
		if (n & 1)
			res = (ll)res * a % MOD; 
		a = (ll)a * a % MOD; 
		n >>= 1; 
	}
	return res; 
}
int main()
{
	// freopen("ARC082-E.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	for (int i = 0; i < n; i++)
		scanf("%d%d", x + i, y + i); 
	int ans = (quick_pow(2, n) - n - 1 + MOD) % MOD; 
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i == j)
				continue; 
			int cnt = 0; 
			for (int k = 0; k < n; k++)
			{
				if (same(i, j, k))
					seq[cnt++] = k; 
			}
			std::sort(seq, seq + cnt, comp); 
			se.insert(mp(seq[0], seq[1])); 
		}
	}
	for (auto line : se)
	{
		int cnt = 0; 
		for (int i = 0; i < n; i++)
		{
			if (same(line.first, line.second, i))
				cnt++; 
		}
		ans = (ans - quick_pow(2, cnt) + cnt + 1 + MOD) % MOD; 
	}
	printf("%d\n", ans);
	return 0; 
}


Measured memory_bytes: 1152
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;

void ansYes(bool flag){
    if (flag) cout << "Yes" << endl; else  cout << "No" << endl;
}

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas{
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx,maxy;
public:
    ContainChecker(Int minx,Int miny,Int maxx, Int maxy) : minx(minx) , miny(miny) , maxx(maxx), maxy(maxy) {};
    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    Int h , w;
    cin >> h >> w;
    vector<string> m(h);
    REP(h,i){
        cin >> m.at(i);
    }
    ContainChecker cc(0,0,w-1,h-1);
    REP(h,i){
        REP(w,k){
            if (cc.in(k,i) && m[i][k] == '#'){
                bool flag = true;
                REP(4,p){
                    Int x = k + dx[p];
                    Int y = i + dy[p];
                    if (cc.in(x,y) && m[y][x] == '#') {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}




Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {

	int h, w;
	int yoko[101] = {}, tate[101] = {};

	cin >> h >> w;
	vector<string> a(h);

	FOR(i, 0, h-1) {
		cin >> a[i];
	}

	FOR(i, 0, h-1) {
		FOR(j, 0, w - 1) {
			if (a[i][j] == '#') {
				break;
			}
			if (j == w - 1) {
				tate[i] = 1;
			}
		}
	}

	FOR(i, 0, w - 1) {
		FOR(j, 0, h - 1) {
			if (a[j][i] == '#') {
				break;
			}
			if (j == h - 1) {
				yoko[i] = 1;
			}
		}
	}

	FOR(i, 0, h - 1) {
		if (tate[i] == 1) {
			continue;
		}
		FOR(j, 0, w - 1) {
			if (yoko[j] == 1) {
				continue;
			}
			cout << a[i][j];
		}
		cout << endl;
	}

	return 0;
}

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

int main(){
  int n,a[100];
  cin>>n;
  for (int i=0;i<n;i++) cin>>a[i];
  int t=0;
  for (int i=0;i<n;i++){
    for (int j=n-1;j>=i+1;j--){
      if (a[j]<a[j-1]) {
        swap(a[j],a[j-1]);
        t++;
    }
   }
    
  }
  for (int i=0;i< n;i++){
    if (i!=n-1)cout<<a[i]<<' ';
    else cout<<a[i]<<endl;
  }
  cout<<t<<endl;
}


Measured memory_bytes: 3104
x, y, a, b, c = map(int, input().split())
p = [int(_) for _ in input().split()]
q = [int(_) for _ in input().split()]
r = [int(_) for _ in input().split()]
 
p.sort()
q.sort()
r.sort()
 
x_list = p[-x:]
y_list = q[-y:]
all_apple = x_list + y_list + r
all_apple.sort()
 
print(sum(all_apple[-(x+y):]))

Measured memory_bytes: 23640
N, M = map(int, input().split())

l = 1
r = N
for _ in range(M):
    L, R = map(int, input().split())
    if L > l:
        l = L
    if R < r:
        r = R

num = r-l+1
if num < 0:
    num = 0
print(num)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9+7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

LL N;
vector<PLL> A;
map<PLL, LL> DP;

LL dp(LL n,LL s,LL e) {
	if (n == 0) {
		DP.insert(pair<PLL, LL>(PLL(s, s), abs(A[0].second - s) * A[0].first));
		return abs(A[0].second - s) * A[0].first;
	}
	//sに寄せた場合
	LL ssc = abs(A[n].second - s) * A[n].first;
	PLL tasks;
	tasks.first = s + 1;
	tasks.second = e;
	if (DP.find(tasks) == DP.end()) {
		dp(n - 1, s + 1, e);
	}
	ssc += DP.find(tasks)->second;
	LL esc = abs(e - A[n].second) * A[n].first;
	PLL taske;
	taske.first = s;
	taske.second = e - 1;
	if (DP.find(taske) == DP.end()) {
		dp(n - 1, s, e - 1);
	}
	esc += DP.find(taske)->second;
	DP.insert(pair<PLL, LL>(PLL(s, e), max(ssc, esc)));
	return max(ssc, esc);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> N;
	A.resize(N);
	for (LL n = 0; n < N; n++) {
		cin >> A[n].first;
		A[n].second = n;
	}
	sort(A.begin(), A.end(), [](PLL a, PLL b) {
		return a.first < b.first;
	});
	cout << dp(N - 1, 0, N - 1) << "\n";
	return 0;
}


Measured memory_bytes: 128416
import 'dart:io';

void main() {
  List nk = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  List l = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  List lList = [];
  for (int i = 0; i < nk[0]; i++) {
    lList.add(l[i]);
  }

  int sum = 0;
  List lSort = lList..sort((b, a) => a.compareTo(b)); // 大きい順にsort
  for (int i = 0; i < nk[1]; i++) {
    sum = sum + lSort[i];
  }
  print(sum);
}

Measured memory_bytes: 13212
#include <stdio.h>
#include <string.h>

#define LENGTH 256

int main(void) {
  char input[LENGTH];
  char *n;

  fgets(input, LENGTH - 1, stdin);

  n = strtok(input, ",");
  printf("%s ",n);

  while(n != NULL){
    n = strtok(NULL, ",");
    if(n != NULL){
      printf("%s ",n);
    }
  }
}
  
  

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

int main()
{
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int n = 0;
	for (int a = 0; a <= A; ++a) {
		for (int b = 0; b <= B; ++b) {
			for (int c = 0; c <= C; ++c) {
				int x = 500 * a + 100 * b + 50 * c;
				if (X == x)
					++n;
			}
		}
	}
	cout << n << endl;
	return 0;
}

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

#define int long long

int n, a, b;

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	
	cin >> n >> a >> b;
	for (int i = 1; i < n; i++) {
		int A, B, lasta = a, lastb = b;
		cin >> A >> B;
		b = B * ((b + B - 1) / B);
		a = (b / B) * A;
		assert(b >= lastb);
		
		if (a < lasta)
			a = A * ((lasta + A - 1) / A), b = (a / A) * B;
		assert(a >= lasta && b >= lastb);
	}
	cout << a + b << endl;
}

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

using namespace std;

int MOD = 1e9 + 7;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    vector<long long> suff(n + 1, 0);
    for(int i = n - 1; i >= 0; i--) {
        suff[i] = suff[i + 1] + a[i];
    }
    long long answer = 0;
    for (int i = 0; i < n; i++) {
        answer = answer + (a[i] % MOD) * (suff[i + 1] % MOD) % MOD;
        answer %= MOD;
    }
    printf("%lld\n", answer);
}


Measured memory_bytes: 5624
from heapq import heapify, heappush, heappop

N, M = map(int, input().split())
As = list(map(int, input().split()))

PQ = [-A for A in As]
heapify(PQ)

for _ in range(M):
    A = -heappop(PQ)
    heappush(PQ, -(A//2))

#print('PQ:', PQ)

print(-sum(PQ))


Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;

int main(){
  lint n, k, ans=INT_MAX;
  cin>>n >>k;
  vector<lint> h(n);
  for(lint i=0;i<n;i++)cin>>h[i];
  sort(h.begin(), h.end());
  for(lint i=0;i<n-k+1;i++)ans=min(ans, h[i+k-1]-h[i]);
  cout<<ans<<endl;
}

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

int main(void)
{
    int i, j, n;
    char *a, b;

    scanf("%d", &n);
    n += 2;
    a = (char *)malloc((n) * sizeof(char));
    for (i = 1; i < n; i++)
    {
        scanf("%c", &b);
        a[i] = b;
    }
    if ((n & 1) != 0)
    {
        printf("No\n");
        return 0;
    }
    int k = 2;
    for (j = (n >> 1) + 1; j < n; j++)
    {
        if (a[j] != a[k])
        {
            printf("No\n");
            return 0;
        }
        k++;
    }
    printf("Yes\n");
    return 0;
}

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

int64_t pow4(int n) {
  int64_t i = 1;
  for (int j = 0; j < n; j++) {
    i *= 4;
  }
  return i;
}

int main() {
  int n, a, b, c;
  std::cin >> n >> a >> b >> c;

  std::vector<int> l(n);
  for (auto & i : l) {
    std::cin >> i;
  }

  int64_t min_cost = std::numeric_limits<int64_t>::max();
  for (int64_t i = 0; i < pow4(n); i++) {
    int cost = 0, a_l = 0, b_l = 0, c_l = 0;

    for (int j = 0; j < n; j++) {
      int k = (i / pow4(j)) % 4;
      if (k == 1) {
        cost += 10;
        a_l += l[j];
      } else if (k == 2) {
        cost += 10;
        b_l += l[j];
      } else if (k == 3) {
        cost += 10;
        c_l += l[j];
      }
    }

    if (a_l != 0 && b_l != 0 && c_l != 0) {
      cost += std::abs(a_l - a) + std::abs(b_l - b) + std::abs(c_l - c);
      cost -= 30;
      if (cost < min_cost) {
        min_cost = cost;
      }
    }
  }

  std::cout << min_cost << std::endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

ifstream fin ("hps.in");
ofstream fout ("hps.out");

#define f first
#define s second
#define pb push_back

int h, n, dp[20002];
int a[1002], b[1002];


int main()
{
  cin >> h >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 1; i <= h + 10000; i++) {
    dp[i] = 2e9;
    for (int j = 1; j <= n; j++)
        if (a[j] <= i)
          dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
  }
  int ans = 2e9;
  for (int i = h; i <= h + 10000; i++)
    ans = min(ans, dp[i]);
  cout << ans;
  return 0;
}


Measured memory_bytes: 384
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  a=0
else:
  def func(x,y):
    a=10**5
    for i in range(1,x//3+2):
      s=i*y
      t=((x-i)//2)*y
      b=max(s,t,x*y-s-t)-min(s,t,x*y-s-t)
      t=(y//2)*(x-i)
      a=min(a,b,max(s,t,x*y-s-t)-min(s,t,x*y-s-t))
    return a
  a=min(func(w,h),func(h,w))
print(a)

Measured memory_bytes: 3064
n = int(input())

def dfs(s, mx_idx):
    if len(s) == n:
        print(s)
    else:
        for i in range(mx_idx+1):
            nc = chr(ord('a') + i)
            if i == mx_idx:
                dfs(s + nc, mx_idx + 1)
            else:
                dfs(s+nc, mx_idx)

dfs('a', 1)


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

int dp(vector<int>& h, vector<int>& mem, int n, int k) {
    if( n < k && n >= 0) {
        mem[n] = abs(h[n] - h[0]);
        return mem[n];
    }
    int temp = INT_MAX;
    for(int i = n-1; i >= n-k; i--) {
        int temp_dp = mem[i] > -1? mem[i]: dp(h, mem, i, k); 
        temp = min(temp, abs(h[n]-h[i]) + temp_dp);
        mem[n] = temp;
    }
    return mem[n];
}

int main() {
    int n, k;
    cin >> n;
    cin >> k;
    vector<int> ht(n, 0);
    vector<int> mem(n, -1);
    for(int i = 0; i < n; i++) {
        cin >> ht[i];
    }

    cout << dp(ht, mem, n-1, k);

    return 0;
} 

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

#define N 100000

int main()
{
  int i, n, q, v, x, y, z, dx, dy, x0, y0, ex, rx, sx, tmp;
  char *p, buf[32];
  buf[31]=0;
  buf[30]='\n';
  int *s = (int*)malloc(sizeof(int)*N+1);
  int *d = (int*)malloc(sizeof(int)*N+1);
  while (fgets(buf, 32, stdin)) {
    for (n=0,p=buf; *p!=' '; n=n*10+*(p++)-'0'); 
    for (q=0,p++; *p!='\n'; q=q*10+*(p++)-'0'); 
    if (n==0 && q==0) break;
    for (i=1; i<=n; s[i]=i,d[i++]=0);
    for (int t=0; t<q; t++) {
      fgets(buf, 32, stdin);
      for (x=0,p=buf+2; *p!=' '; x=x*10+*(p++)-'0');
      for (y=0,p++; *p>='0'; y=y*10+*(p++)-'0');

      if (buf[0]=='!') { // relate x y z
	for (z=0,p++; *p!='\n'; z=z*10+*(p++)-'0');
	for (x0=x,dx=0; s[x]!=x; dx+=d[x], x=s[x]);
	for (y0=y,dy=0; s[y]!=y; dy+=d[y], y=s[y]);
	s[x0]=x;
	d[x0]=dx;
	s[y0]=y;
	d[y0]=dy;
	if (x==y) continue;
	s[y] = x;
        d[y] = z + dx - dy;
	
      } else { // diff

	for (x0=x,dx=dy=0; s[x]!=x; dx+=d[x], x=s[x]);
	for (rx=x, x=x0, ex=dx; s[x]!=x; x=sx) {
	  sx=s[x];
	  s[x]=rx;
	  tmp=d[x];
	  d[x]=ex;
	  ex-=tmp;
	}
	for (y0=y; s[y]!=y; dy+=d[y], y=s[y]);
	v=-dx+dy;
	if (x!=y) {
	  fputs("UNKNOWN\n", stdout);
	} else {
	  i=30;
	  if (v>0)  for (; v>0; buf[--i]='0'+v%10,v/=10);
	  else if (v<0) {
	    for (; v<0; buf[--i]='0'-v%10,v/=10);
	    buf[--i] = '-';
	  } else  buf[--i] = '0';
	  fputs(buf+i, stdout);
	}
      }
    }
  }
  return 0;
}



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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int x,a;
    cin>>x>>a;
    if(x<a)
    {
    	cout<<0;
    }
    else
    	cout<<10;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n,m,c;
	cin >> n >> m >>c;
	int a[105][105];
	int b[105];

	for(int i=0;i<m;i++)
		cin >> b[i];
	int count=0;
	for(int i=0;i<n;i++)
	{
		int tmp=0;
		for(int j=0;j<m;j++)
		{
			cin >> a[i][j];
			tmp+=(a[i][j]*b[j]);
		}
		if(tmp+c>0)count++;
	}
	cout << count << endl;
}
	


Measured memory_bytes: 256
k,n=map(int,input().split())
x=list(map(int,input().split()))
xx=[]
for i in x:
    xx.append(i)
    xx.append(i-k)
y=sorted(xx)
z=[]
for i in range(n+1):
    z.append(y[i+n-1]-y[i])
print(min(z))

Measured memory_bytes: 34124
/* Coached by Dukkha */
#include <stdio.h>

#define D 10
#define INF 1001

int main() {
	static int pp[D], cc[D];
	int d, g, i, b, ans;

	scanf("%d%d", &d, &g);
	for (i = 0; i < d; i++)
		scanf("%d%d", &pp[i], &cc[i]);
	ans = INF;
	for (b = 0; b < 1 << d; b++) {
		int p = 0, q = 0, a;

		for (i = 0; i < d; i++)
			if (b & 1 << i) {
				a = 100 * (i + 1);
				p += pp[i];
				q += pp[i] * a + cc[i];
			}
		if (q < g) {
			for (i = d - 1; i >= 0; i--)
				if ((b & 1 << i) == 0)
					break;
			a = 100 * (i + 1);
			if (i >= 0 && q + (pp[i] - 1) * a >= g) {
				int p_ = (g - q + a - 1) / a;

				p += p_;
				q += p_ * a;
			}
		}
		if (q >= g && ans > p)
			ans = p;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
import sys
read = sys.stdin.read
def main():
    n, c = map(int, input().split())
    d = {e: [0] * (c + 1) for e in range(100001)}
    d1 = [0] * 100001
    m = map(int, read().split())
    stc = zip(m, m, m)
    for s, t, c in stc:
        if d[s][c]:
            d1[s - 1] -= 1
            d1[s] += 1
        else:
            d[s][c] = 1
        if d[t][c]:
            d1[t - 1] -= 1
            d1[t] += 1
        else:
            d[t][c] = 1
        d1[s - 1] += 1
        d1[t] -= 1

    cur = 0
    r = 0
    for i1 in range(100001):
        cur += d1[i1]
        r = max(r, cur)
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 72304
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>
#include<math.h>

int main(void){
    int N, X;
    scanf("%d%d", &N, &X);
    int i;
    int min = INT_MAX;
    int sum = 0;
    for(i=0; i<N; i++) {
        int temp;
        scanf("%d", &temp);
        sum += temp;
        if(temp < min) {
            min = temp;
        }
    }
    printf("%d\n", (int)((X - sum) / min) + N);
    return 0;
}

Measured memory_bytes: 128
#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(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vii;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


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

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	int first = 0, second = 0;

	rep(i, n)
	{
		cin >> a[i];

		if (first < a[i])
		{
			first = a[i];
		}
		else if (second < a[i])
		{
			second = a[i];
		}
	}

	rep(i, n)
	{
		if (a[i] == first)
		{
			ANS(second);
		}
		else
		{
			ANS(first);
		}
	}

}

Measured memory_bytes: 2432
#include<stdio.h>
//累乗(power)a^n(mod10^9+7)
long long power(long long a,long long n){
  long long count=a,sum=1;
  while(n>0){
    if(n%2==1)
      sum*=count;
    count*=count;
    count%=1000000007;
    sum%=1000000007;
    n/=2;
  }
  return sum;
}

//nCr(mod10^9+7)
long long int comb(long long int n,long long int r){
  long long x=1,y=1,i;
  for(i=0;i<r;i++){
    x*=n-i;
    y*=r-i;
    x%=1000000007;
    y%=1000000007;
  }
  //power(y,10^9+7-2)
  y=power(y,1000000005);
  return (x*y)%1000000007;
}

int main(){
  int n,k,i;
  scanf("%d%d",&n,&k);
  for(i=1;i<=k;i++)
    printf("%d\n",comb(k-1,i-1)*comb(n-k+1,i)%1000000007);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<stdlib.h>

using namespace std;

#define ll long long

int main(){
  
  ll n,c, mini;
  cin >> n;
  for(int i = 0;i < 5;i++){
    cin >> c;
    if(i == 0)mini = c;
    mini = min(mini, c);
  }

  ll ans = n/mini;
  ans += 5;
  if(n%mini == 0)ans--;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//おまじない



int main() {

	int a, b;

	cin >> a >> b;

	if (a + b >= 24) {
		cout << a + b - 24 << endl;
	}
	else {
		cout << a + b << endl;
	}

	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,'%d %d %d',$N,$A,$B);

$result = 0;

//小数点以下切り捨て
$set = intval($N / ($A + $B));
$rest = $N % ($A + $B);

$result += $A * $set;
$result += min($A,$rest);
/*
if($rest >= $A){
  $result += $A;
}else{
  $result += $rest;
}
*/
echo $result;



Measured memory_bytes: 4728
from collections import defaultdict
import sys

sys.setrecursionlimit(100000)


def main():
    N, M = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(M):
        x, y = list(map(int, input().split(' ')))
        x -= 1
        y -= 1
        adj_nodes[x].append(y)
    dp = [-1 for _ in range(N)]

    def rec(v):
        if dp[v] >= 0:
            return dp[v]
        ret = 0
        for nv in adj_nodes[v]:
            ret = max([ret, rec(nv) + 1])
        dp[v] = ret
        return ret

    ans = 0
    for v in range(N):
        ans = max([ans, rec(v)])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 82308
from collections import Counter
from heapq import heappush, heappop, heapreplace


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

AC = Counter(A)
BC = Counter(B)
S = AC + BC

q = []
for k, v in S.items():
    heappush(q, (-v, k))

ans = []
while q:
    v, k = q[0]
    if v == 0:
        heappop(q)
    elif v != -S[k]:
        heapreplace(q, (-S[k], k))
    else:
        heapreplace(q, (v + 1, k))
        if -v > N:
            print('No')
            exit()
        else:
            if AC[k] > 0:
                a = k
                for l in BC.keys():
                    if l != k:
                        b = l
                        break
            else:
                b = k
                for l in AC.keys():
                    if l != k:
                        a = l
                        break
            ans.append((a, b))
            S[a] -= 1; S[b] -= 1
            AC[a] -= 1; BC[b] -= 1
            if AC[a] == 0:
                AC.pop(a)
            if BC[b] == 0:
                BC.pop(b)

print('Yes')
X = [b for _, b in sorted(ans)]
print(*X)


Measured memory_bytes: 198852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,zero=0,p=10;
    cin>>n;
    if(n%2==1)
        cout<<0<<endl;
    else
    {
        while(n/p)
        {
            zero+=n/p;
            p*=5;
        }
        cout<<zero<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        String word;
        Scanner sc =new Scanner(System.in);
        String key = sc.next();
        String end = "END_OF_TEXT";

        int n;
        int m;
        int count=0;
        while(true){

            word=sc.next();
            if(end.equals(word)) {
                System.out.println(count);
                break;
            }
            else if(key.equalsIgnoreCase(word)) {
                count = count + 1;
            }
        }
    }
}


Measured memory_bytes: 26056
n = int(input())
ipt = [int(i) for i in input().split()]
d = ipt[0]
x = ipt[1]
a = [0 for i in range(n)]
total = x
for i in range(n):
    a[i] = int(input())
    total += 1+(d-1) // a[i]
print(total)


Measured memory_bytes: 3060
import java.util.*;

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

	public Main() {
		new AOJ0046().doIt();
	}
	
	class AOJ0046{
		void doIt(){
			ArrayList<Double> list = new ArrayList<Double>();
			while(in.hasNext())list.add(in.nextDouble());
			Collections.sort(list);
			System.out.println(Math.abs(list.get(0)-list.get(list.size()-1)));
		}
	}
	
}

Measured memory_bytes: 18688
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.DP
{
    class EDPC_U
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = new long[n][];
            for (int i = 0; i < n; i++)
                a[i] = Console.ReadLine().Split(' ').Select(j => long.Parse(j)).ToArray();

            var score = new long[1 << n];
            var dp = new long[1 << n];
            var bitToIndex = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
                bitToIndex.Add(1 << i, i);

            for (int bit = 1; bit < 1 << n; bit++)
            {
                var x = bit;
                while (x != 0)
                {
                    var bi = -x & x;
                    var y = x & ~bi;
                    int i = bitToIndex[bi];
                    while (y != 0)
                    {
                        int bj = -y & y;
                        var j = bitToIndex[bj];
                        score[bit] += a[i][j];
                        y = y & ~bj;
                    }
                    x &= ~bi;
                }
            }

            for (int i = 1; i < (1 << n); i++)
                for (int j = i; j > 0; j = (j - 1) & i)
                    dp[i] = Math.Max(dp[i], dp[i - j] + score[j]);

            Console.WriteLine(dp[(1 << n) - 1]);
        }

    }
}


Measured memory_bytes: 14432
rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

from collections import deque
def solve(N, A):
    ans = 0
    todo = N * (N-1)
    to_inspect = range(N)
    while True:
        ans += 1
        found = False
        to_inspect2 = set()
        for i in to_inspect:
            row = A[i]
            if row:
                j = row[0]
                if (i not in to_inspect2 and j not in to_inspect2 and
                        A[j] and A[j][0] == i):
                    row.popleft()
                    A[j].popleft()
                    found = True
                    todo -= 2
                    to_inspect2.add(i)
                    to_inspect2.add(j)
        if not todo: return ans
        if not found: return -1
        to_inspect = to_inspect2


N = rri()
A = []
for _ in xrange(N):
    row = rrm()
    A.append(deque(x-1 for x in row))
print solve(N, A)


Measured memory_bytes: 61148
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
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(){
    string S;
    ll white = 0;
    getline(cin,S);
    ll ans = 0;
    int N = S.length();

    REP(i,N){
        if (S[i] == 'W'){
            ans += (ll)i - (white);
            white++;
        }    
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
N = int(input())
act = list(list(map(int, input().split())) for _ in range(N))
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(N):
  dp[i + 1][0] = max(dp[i + 1][0], act[i][0] + max(dp[i][1], dp[i][2]))
  dp[i + 1][1] = max(dp[i + 1][1], act[i][1] + max(dp[i][0], dp[i][2]))
  dp[i + 1][2] = max(dp[i + 1][2], act[i][2] + max(dp[i][0], dp[i][1]))
print(max(dp[N]))

Measured memory_bytes: 79064
#include<bits/stdc++.h>
using namespace std;
 
int main(){
      int n;cin >> n;
      double ans = 0;
      for(int i = 0;i < n;i++){
            int t;cin >> t;
            ans += 1.0 / t;
      }
      printf("%.6f", 1.0 / ans);
}

Measured memory_bytes: 256
x1,y1,x2,y2 = gets.split.map(&:to_i)

x3 = x2 - (y2 - y1)
y3 = y2 + x2 - x1
x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)
puts "#{x3} #{y3} #{x4} #{y4}"

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const ll INF = 1LL<<60;




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

    int ans = A*B;
    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e18;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vector<vector<ld>> dp(n + 1, vector<ld>(n + 1));
  rep(i, n+1){
    rep(j,n+1){
      dp[i][j] = 0;
    }
  }
  vector<ld> p(n);
  rep(i,n){
    cin >> p[i];
  }
  dp[0][0] = 1;
  for (ll i = 1; i <= n; i++){
    dp[i][0] = dp[i - 1][0] * ((ld)1-p[i-1]);
    for (ll j = 1; j <= i; j++){
      dp[i][j] += dp[i - 1][j] * ((ld)1-p[i-1]) + dp[i - 1][j - 1] * p[i-1];
    }
  }
  ld ans = 0;
  for (ll i = (n + 1) / 2; i <= n; i++){
    ans += dp[n][i];
  }
  cout << fixed << setprecision(10)<<ans << endl;
}

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};

ll A, B;

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll N, K;

int main() {

    cin >> N;
    vector<ll> A, dp(N + 1, 1e9);
    ll c = 1;
    while (c <= N) {
        c *= 6;
        A.push_back(c);
    }
    c = 1;
    while (c <= N) {
        c *= 9;
        A.push_back(c);
    }
    dp[0] = 0;
    REP(i, N) {
        REP(k, A.size()) {

            if (i + A[k] <= N)
                dp[i + A[k]] = min(dp[i + A[k]], dp[i] + 1);
        }
    }
    ll res = 1e9;
    REP(i, N + 1)res = min(res, dp[i] + (N - i));
    cout << res << endl;

    return 0;

}



Measured memory_bytes: 1024
N=int(input())
A=list(map(int, input().split()))
if N==2:
  print(max(A))
  exit() 
  
dp=[[0,0,0] for i in range(N)]
dp[0][0]=A[0]
dp[1][1]=A[1]
dp[2][2]=A[2]
for i in range(N):
  if i>1:
    dp[i][0]=dp[i-2][0]+A[i]
  if i>2:
    dp[i][1]=max(dp[i-3][0],dp[i-2][1])+A[i]
  if i>3 :
    dp[i][2]=max(dp[i-4][0],dp[i-3][1],dp[i-2][2])+A[i]
if N%2==1:
  ans=max(dp[-1][2],dp[-2][1],dp[-3][0])
else:
  ans=max(dp[-1][1],dp[-2][0])
print(ans)

Measured memory_bytes: 68072
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


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


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper

a, b = inl()
x = (a - 2) % 13
y = (b - 2) % 13
if x > y:
    print('Alice')
elif x < y:
    print('Bob')
else:
    print('Draw')


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

int a[10];
int cur[10];
int n, A, B, C;
int ans = 2e9;

void recur(int cur_idx, int value) {
  if (cur_idx == n) {
    int sum_a = 0;
    int sum_b = 0;
    int sum_c = 0;
    int sz_a = 0, sz_b = 0, sz_c = 0;
    for (int i = 0; i < n; i++) {
      if (cur[i] == 1) {
        sum_a += a[i];
        sz_a++;
      }
      if (cur[i] == 2) {
        sum_b += a[i];
        sz_b++;
      }
      if (cur[i] == 3) {
        sum_c += a[i];
        sz_c++;
      }
    }
    if (sz_a == 0 || sz_b == 0 || sz_c == 0) {
      return;
    }
    int cur_ans = abs(A - sum_a) + abs(B - sum_b) + abs(C - sum_c);
    if (sz_a > 1) {
      cur_ans += 10 * (sz_a - 1);
    }
    if (sz_b > 1) {
      cur_ans += 10 * (sz_b - 1);
    }
    if (sz_c > 1) {
      cur_ans += 10 * (sz_c - 1);
    }
    ans = min(ans, cur_ans);
  } else {
    cur[cur_idx] = value;
    for (int i = 0; i < 4; i++) {
      recur(cur_idx + 1, i);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> A >> B >> C;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < 4; i++) {
    recur(0, i);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

bool isKaibun(string s) {
  int n = s.length();
  int l = n / 2;
  for(int i=0; i<l; i++) {
    if(s[i]!=s[n-1-i]) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  bool ok = isKaibun(s) && isKaibun(s.substr(0, (n-1)/2)) && isKaibun(s.substr((n+3)/2 - 1, n));
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //ABC 162_b
using namespace std;
int a,b,c,d,gao,qing;
int main(){
	cin>>a>>b>>c>>d;
	if(c%b==0&&a%d==0){
		qing=a/d;
		gao=c/b;
	}
	else if(c%b!=0&&a%d==0){
		qing=a/d;
		gao=c/b+1;
	}
	else if(c%b==0&&a%d!=0){
		qing=a/d+1;
		gao=c/b;
	}
	else if(c%b!=0&&a%d!=0){
		qing=a/d+1;
		gao=c/b+1;
	}
	if(gao>qing)
		cout<<"No";
	else if(gao<qing)
		cout<<"Yes";
	else if(gao==qing)
		cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 二つの値の最大値を求める関数
Int Max(const Int a, const Int b) {
    if (a >= b) {
        return a;
    } else {
        return b;
    }
}
// 分数の Ceil を求める関数
UInt Ceil(const UInt a, const UInt b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return a / b + 1;
    }
}

int main(void) {
    Int a, b;
    cin >> a >> b;
    Int a_max, a_min, b_max, b_min;
    if (a % 2 == 0) {
        a_min = 25 * (a / 2);
        a_max = a_min + 12;
    } else {
        a_max = 25 * Ceil(a, 2) - 1;
        a_min = a_max - 11;
    }
    b_min = 10 * b;
    b_max = b_min + 9;

    Int result = 0;
    if (a_max < b_min || b_max < a_min) {
        result = -1;
    } else {
        result = Max(a_min, b_min);
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 3684
#include <stdio.h>

int     main(void)
{
    int a;
    int b;
    
    scanf("%d %d", &a, &b);
    if (a > b)
        printf("a > b\n");
    else if(a < b)
        printf("a < b\n");
    else
        printf("a == b\n");
    return (0);
}


Measured memory_bytes: 2084
/*input
6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10
*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define is_empty(v) v.empty()
#define vs			vector< string >
#define vvi			vector< vector< ll,ll > >
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define inf         1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define reprr(i,a,b) for(ll int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sum(v)      accumulate(v.begin(),v.end(),(ll)0)
//map <long long int,long long int> ma;
//set <long long int, greater <long long int> > s;
const ll N =  2e5+5;
vector< vi > adj(N,vi ());
ll a[N];
ll ans[N];
void dfs(ll u,ll p){
	ans[u]+=a[u];
	rep(i,0,sz(adj[u])){
		if(adj[u][i]==p) continue;
		a[adj[u][i]]+=a[u];
		dfs(adj[u][i],u);
	}
	return;
}

int solve()
{
	ll n,q;cin>>n>>q;
	rep(i,0,n-1)
	{
		ll x,y;cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}


	while(q--)
	{
		ll v,x;cin>>v>>x;v--;
		a[v]+=x;
	}
	dfs(0,-1);
	rep(i,0,n) cout<<ans[i]<<" ";


}

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

	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 25856
import sys

n = int(input())
l = list(map(int, input().split(' ')))

for i in range(n):
    sum = 0
    for j in range(n):
        if (i != j):
            sum += l[j]
    if not (sum > l[i]):
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] lines = line.split(" ");
        int N = Integer.parseInt(lines[0]);
        int M = Integer.parseInt(lines[1]);
        if (N == M) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844