akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> v(m);
  rep(i,m) cin>>v[i];

  sort(all(v));
  priority_queue<int, vector<int>, greater<int>> pq;
  rep(i,m-1) pq.push(v[i+1] - v[i]);

  long ans = 0;
  while(m-n > 0){
    ans += pq.top(); pq.pop();
    n++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1276
import java.util.*;
 
class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    StringBuffer s[]=new StringBuffer[n];
    String ss[]=new String[n];
    for(int i=0;i<n;i++){
      s[i]=new StringBuffer(sc.next());
    }
    
    for(int i=0;i<n;i++){
      for(int j=1;j<10;j++){
        for(int k=j;k>0;k--){
          if(s[i].charAt(k)<s[i].charAt(k-1)){
            char t=s[i].charAt(k);
            s[i].setCharAt(k,s[i].charAt(k-1));
            s[i].setCharAt(k-1,t);
          }
        }
      }
      ss[i]=new String(s[i]);
    }
    Arrays.sort(ss);
    
    long sum=0;
    long kk=0;
    long sk=0;
    while(kk<n){
        kk=calc(ss,n,sk);
        sum+=( ((kk-sk)*((kk-sk)-1))/2 );
        sk=kk;
    }
    sum+=( ((kk-sk)*((kk-sk)-1))/2 );
    System.out.println(sum);
  }
  static long calc(String[] ss,int n,long f){
    for(long i=f+1;i<n;i++){
      if(!ss[(int)f].equals(ss[(int)i])){
        return (long)i;
      }
    }
    return (long)n;
  }
}

Measured memory_bytes: 58480
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

func main() {
	times := []int{nextInt(), nextInt(), nextInt()}
	max := 0
	sum := 0

	for i := 0; i < 3; i++ {
		sum += times[i]

		if max < times[i] {
			max = times[i]
		}
	}

	fmt.Println(sum - max)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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(){
  cout << fixed << setprecision(15);
  int n; cin >> n;
  vi h(n); rep(i, n) cin >> h[i];

  ll ans = 0;
  vi d(n + 1);
  d[0] = h[0];
  rep(i, n - 1) d[i + 1] = h[i + 1] - h[i];
  d[n] = -1 * h[n - 1];
  rep(i, n){
    if (d[i] >= 0) ans += d[i];
  }
  
  cout << ans << endl;
  return 0;
}

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

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

  bool NotFound = true;
  for( int i = 0; i <= 100; ++i ){
    for( int j = 0; j <= 100; ++j ){
      if( i+j ==X && 2*i+4*j == Y){
        NotFound = false;
      }
    }
  }

  if( NotFound ){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define U 10050
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#define sp
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
int w[U];
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, sum = 0;
	cin>>n>>k;
	rep(i, 0, n) cin>>w[i];
	sort(w, w+n);
	rep(i, 0, k) sum += w[i];
	cout<<sum<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 3664
from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw):
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1
    longest = 0
    while stack:
        h, w = stack.popleft()
        # # ゴールの条件
        # if h == gh and w == gw:
        #     break
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
                new_w < 0 or new_w >= W:
                    continue
            elif maze[new_h][new_w] != "#" and \
                visited[new_h][new_w] == -1:
                    visited[new_h][new_w] = visited[h][w] + 1
                    longest = max(longest, visited[new_h][new_w])
                    stack.append([new_h, new_w])
    
    # return visited[gh][gw]
    return longest

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    vd = [[[[0 for _ in range(W)] for _ in range(H)] for _ in range(W)] for _ in range(H)]
    ans = 0
    for sh in range(H):
        for sw in range(W):
            if maze[sh][sw] != "#": 
                visited = [[-1] * W for _ in range(H)]
                step_cnt = bfs(maze, visited, sh, sw)
                ans = max(ans, step_cnt)
    print(ans - 1)


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;
 
#define REP(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)(a); i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007
#define _SPLIT " "
 
template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T,class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << setprecision(24) << a << endl;}
template<class T,class ...Args> void write(T a, Args... args){cout << setprecision(24) << a << _SPLIT; write(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
template<class T> void warr(T begin, T end, const char* c = " "){cout << *begin;for(auto i = begin+1; i != end; i++)cout << c << *i;cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    string s;
    read(s);
    char bef=s[0];
    int res=0;
    REP(i,1,s.size()){
        if(bef!=s[i])res++;
        bef=s[i];
    }
    write(res);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int a = h2 - h1;
  int b = m2 - m1;
  cout<<a * 60 + b - k<<endl;
  return 0;
}


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

int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

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

  int ans = 360 / gcd(360, X);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
  int n, a;
  cin >> n >> a;
  cout << n * n - a << endl;
  return 0;
}

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

const string YES = "YES";
const string NO = "NO";

void solve(std::string S){
    string ans;
    vector<string> unit_string = {"dream", "dreamer", "erase", "eraser"};
    for(int i = 0; i < 100000; ++i){
        //cout << S << endl;
        if(S.size() == 0){
            ans = YES;
            break;
        }
        else if(S.size() < 5 && S.size() > 0){
            ans = NO;
            break;
        }
        else if(S.size() == 5){
            string s5 = S.substr(S.size()-5, 5);
            bool check = true;
            for(auto t : unit_string){
                if(s5 == t){
                    S.erase(S.size()-5, 5);
                    check = false;
                    break;
                }
            }
            if(check){
                ans = NO;
                break;
            }
        }
        else if(S.size() == 6){
            string s6= S.substr(S.size()-6, 6);
            bool check = true;
            for(auto t : unit_string){
                if(s6 == t){
                    S.erase(S.size()-6, 6);
                    check = false;
                    break;
                }
            }
            if(check){
                ans = NO;
                break;
            }
        }
        else if(S.size() == 7){
            string s7 = S.substr(S.size()-7, 7);
            bool check = true;
            for(auto t : unit_string){
                if(s7 == t){
                    S.erase(S.size()-7, 7);
                    check = false;
                    break;
                }
            }
            if(check){
                ans = NO;
                break;
            }
        }
        else{
            string s5 = S.substr(S.size()-5, 5);
            string s6 = S.substr(S.size()-6, 6);
            string s7 = S.substr(S.size()-7, 7);
            bool check = true;
            for(auto t : unit_string){
                if(s5 == t){
                    S.erase(S.size()-5, 5);
                    check = false;
                    break;
                }
                else if(s6 == t){
                    S.erase(S.size()-6, 6);
                    check = false;
                    break;
                }
                else if(s7 == t){
                    S.erase(S.size()-7, 7);
                    check = false;
                    break;
                }
            }
            if(check){
                ans = NO;
                break;
            }
        }
    }
    cout << ans << endl;
    return;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n,k,d;
    cin >> n >> k;
    vector<int>a(n,0);
    for(int i=0;i<k;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int z;
            cin >> z;
            z--;
            a.at(z)++;
        }
    }
    ll ans =0;
    for(int i=0;i<n;i++){
        if(a.at(i)==0)ans++;
    }
    cout << ans << endl;
}
    



Measured memory_bytes: 3604
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//ARC004
		//https://arc004.contest.atcoder.jp/tasks/arc004_1
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		
		int N = Integer.parseInt(sc.next());
		int longest=0;
		int sum=0;
		for(int i=0;i<N;i++){
			int length = Integer.parseInt(sc.next());
			if(length > longest) longest = length;
			sum += length;
		}
		int other_sum_length = sum - longest;
		if(other_sum_length > longest){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	
	}
	
}


Measured memory_bytes: 23760
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void) {

	int i;
	char str[1201];

	fgets(str, 1201, stdin);
		
	for (i = 0; i < strlen(str); ++i) {
		if (isupper(str[i])) {
			printf("%c", tolower(str[i]));
		} else {
			printf("%c", toupper(str[i]));
		}
	}

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll x,y;cin>>x>>y;
  cout<<x+y/2<<endl;
  return 0;
}





Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	var S, T string
	fmt.Scan(&S, &T)
	for i := 0; i < N; i++ {
		fmt.Print(string(S[i]))
		fmt.Print(string(T[i]))
	}
	fmt.Println()
}


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


int main(){
int n,d;
cin >> n >> d;
int member = 0;
while(n>0){
    int reng = 2*d+1;
    n -= reng;
    member++;
}
cout << member << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int n;
map<ll, ll> mp;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    vector<ll> a(n);
    ll mx = 0;
    rep(i, n)
    {
        cin >> a[i];
        chmax(mx, a[i]);
        mp[a[i]]++;
    }
    ll k = (mx + 1) / 2;
    ll d = k;
    ll mi=k;
    for (auto &it : mp)
    {
        if (it.first != mx)
        {
            if (abs(it.first - k) <= d)
            {
                d=abs(it.first - k);
                mi=it.first;
            }
        }
    }
    if (mp[k] == 0 || k == mx)
        k = mx - k;
    cout << mx << " " << mi << endl;
    return 0;
}


Measured memory_bytes: 7296
#include<cstdio>
int n,m,v[100010];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1,a,b; i<=m; i++) scanf("%d%d",&a,&b),v[a]^=1,v[b]^=1;
	for (int i=1; i<=n; i++) if (v[i]) {
		puts("NO"); return 0;
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
		int s = 0;
		if(a>=b) {
			s+=b;
		} else {
			s+=a;
		}
		if(c>=d) {
			s+=d;
		} else {
			s+=c;
		}
		System.out.println(s);
	}

}


Measured memory_bytes: 35688
### constant

DXYS = [[1, 0], [0, 1], [-1, 0], [0, -1]]

### subroutines

def rotate(mat, r, c, size, angle)
  tmat = Array.new(size){Array.new(size)}

  while angle > 0
    for dy in (0...size)
      for dx in (0...size)
        tmat[dx][size - 1 - dy] = mat[r + dy][c + dx]
      end
    end
    for dy in (0...size)
      for dx in (0...size)
        mat[r + dy][c + dx] = tmat[dy][dx]
      end
    end
    angle -= 90
  end

  mat
end

def reverse(mat, r, c, size)
  for dy in (0...size)
    for dx in (0...size)
      mat[r + dy][c + dx] ^= 1
    end
  end
  mat
end

def lshift(mat, r)
  n = mat[r].length
  tmp = mat[r][0]
  for i in (0...(n - 1))
    mat[r][i] = mat[r][i + 1]
  end
  mat[r][n - 1] = tmp
  mat
end

def rshift(mat, r)
  n = mat[r].length
  tmp = mat[r][n - 1]
  (n - 1).downto(1) do |i|
    mat[r][i] = mat[r][i - 1]
  end
  mat[r][0] = tmp
  mat
end

def paint(mat, r, c)
  n = mat.length
  d = mat[r][c]
  mat[r][c] ^= 1
  q = [[c, r]]

  while ! q.empty?
    ux, uy = q.shift
    DXYS.each do |dx, dy|
      vx = ux + dx
      vy = uy + dy
      if vx >= 0 && vx < n && vy >= 0 && vy < n && mat[vy][vx] == d
        mat[vy][vx] ^= 1
        q << [vx, vy]
      end
    end
  end

  mat
end

### main

n, m = gets.split.map(&:to_i)

mat = Array.new(n)

for y in (0...n)
  mat[y] = gets.split.map(&:to_i)
end
#p mat

m.times do
  ops = gets.split.map(&:to_i)

  case ops[0]
  when 0
    mat = rotate(mat, ops[1] - 1, ops[2] - 1, ops[3], ops[4])
  when 1
    mat = reverse(mat, ops[1] - 1, ops[2] - 1, ops[3])
  when 2
    mat = lshift(mat, ops[1] - 1)
  when 3
    mat = rshift(mat, ops[1] - 1)
  when 4
    mat = paint(mat, ops[1] - 1, ops[2] - 1)
  end
  #p mat
end

for cols in mat
  puts cols.join(' ')
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf 10000000000000000ll
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-9
#define endl "\n"
/*ll gcd(ll a,ll b)
{
    if(a==0){return b;}
    return gcd(b%a,a);
}
ll modexp(ll x,ll y,ll p)
{
    ll res=1;x%=p;
    while(y>0)
    {   if(y%2==1){res=(res*x)%p;}
        y=y>>1;x=(x*x)%p;
    }return res;
}*/


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    vi p(n+1);
    rep(i,1,n){cin>>p[i];}
    int ans=0;
    rep(i,2,n-1)
    {
        if(p[i]<p[i-1] && p[i]>p[i+1])
        {
            ans++;
        }
        if(p[i]>p[i-1] && p[i]<p[i+1])
        {
            ans++;
        }
    }
    cout<<ans<<"\n";




    return 0;

    /*check for long long or int*/
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argv, char **argc) {
    char s[11];
    scanf("%s", s);
    if (s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I') {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String args[]) throws IOException{
		PrintWriter out = new PrintWriter(System.out);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1);
		int N = Integer.parseInt(reader.readLine());
		if(N == 1) {
			out.println("Hello World");
		}else {
			out.println(Integer.parseInt(reader.readLine()) + 
					Integer.parseInt(reader.readLine()));
		}
		out.flush();
	}

}

Measured memory_bytes: 22484
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<typeinfo>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

/*
 1 partition(A, p, r)
 2   x = A[r]
 3   i = p-1
 4   for j = p to r-1
 4     if A[j] <= x
 5       i = i+1
 6       A[i] と A[j] を交換
 7   A[i+1] と A[r] を交換
 8   return i+1
 */

ll Part(vector<ll> &A,ll p,ll r){
    ll x=A[r];
    ll i=p-1;
    for(ll j=p;j<r;j++){
        if(A[j]<=x){swap(A[++i],A[j]);}
    }
    swap(A[i+1],A[r]);
    return i+1;
}



int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){cin>>a[i];}
    ll w=Part(a,0,n-1);
    for(int i=0;i<n;i++){
        if(i==w){
            cout<<"["<<a[i]<<"]";
        }
        else{
            cout<<a[i];
        }
        if(i+1!=n){cout<<" ";}
    }
    cout<<endl;
    
    return 0;
}



Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<int> D;
int R[][6]={{0,3,1,4,2,5},{2,1,5,0,4,3},{4,0,2,3,5,1}};
void rot(D &d,int a){
	D r(6); rep(i,6)r[i]=d[R[a][i]]; d=r;
}
int main(){
	map<char,int> M; M['R']=0,M['Y']=1,M['B']=2,M['M']=3,M['G']=4,M['C']=5;
	int n;
	while(cin>>n,n){
		set<D> s,alld; char b[9];
		rep(ii,n){
			D d(6),t(6);
			alld.clear();
			rep(jj,6)cin>>b,d[jj]=M[b[0]];
			rep(i,4)rep(j,4)rep(k,4){
				t=d;
				rep(p,i)rot(t,0);rep(q,j)rot(t,1);rep(r,k)rot(t,2);
				alld.insert(t);
			}
			s.insert(*alld.begin());
		}
		cout<<n-s.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 924
//https://atcoder.jp/contests/abc120/tasks/abc120_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int A, B, K;
    cin >> A >> B >> K;
    set<int> stA;
    for( int i = 1; i <= A; i++ )
    {
        if( A % i == 0 )
        {
	       stA.emplace( i );
        }
    }
    set<int> stB;
    for( int i = 1; i <= B; i++ )
    {
        if( B % i == 0 )
        {
	       stB.emplace( i );
        }
    }
    set<int> result;
    set_intersection( ALL(stA), ALL(stB), inserter(result, result.end()) );
    auto itr = result.end();
    for( int i = 0; i < K; ++i ){
        --itr;
    }
    cout << *itr << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
    int n=0;
    int x=0;
    int nMax=0;
    scanf(" %d",&n);
    for(int i=0;i<n;i++){
        char temp;
        scanf(" %c",&temp);
        if(temp=='I'){
            x++;
        }else{
            x--;
        }
        nMax=max(x,nMax);
    }
    printf("%d\n",nMax);
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_063
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long[] nab = ReadLongs();
            int n = (int)nab[0];
            long a = nab[1];
            long b = nab[2];
            long c = a - b;
            var hs = new long[n];
            for(int i = 0; i < n; i++)
            {
                hs[i] = ReadLong();
            }
            long tBottom = 0;
            long tTop = 1000000000;
            while(tTop- tBottom > 1)
            {
                bool ok = true;
                long t = (tBottom + tTop) / 2;
                long cnt = t;
                for(int i = 0; i < n; i++)
                {
                    long remain = hs[i] - t * b;
                    if (remain <= 0) continue;
                    if (remain > cnt * c)
                    {
                        ok = false;
                        break;
                    }
                    else
                    {
                        cnt -= remain / c;
                        if (remain % c > 0) cnt--;
                    }
                }
                if (ok)
                {
                    tTop = t;
                }
                else
                {
                    tBottom = t;
                }
            }
            Console.WriteLine(tTop);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 15836
#include <bits/stdc++.h>
using namespace std;
int main() {
    
    int n;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++)  
    cin>>a[i];

    double sum = 0;
    for(int i = 0; i < n; i++)
        sum+=a[i];

    int n1 = ceil(sum/(n*1.0));
    int n2 = floor(sum/(n*1.0));
    int ans1 = 0,ans2 = 0;
    for(int i = 0; i < n; i++){
        ans1 += (n1-a[i])*(n1-a[i]);
        ans2 += (n2-a[i])*(n2-a[i]);
    }

    cout<<min(ans1,ans2)<<"\n";

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
d = list(map(int, input().split()))
d_c = Counter(d)
m = int(input())
t = list(map(int, input().split()))

# print(d_c)

for i in range(m):
    if t[i] in d_c:
        d_c[t[i]] -= 1
        if d_c[t[i]]<0:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

# print(d_c)
print("YES")

Measured memory_bytes: 46560
#include <bits/stdc++.h>
int main() {
    int n;
    scanf("%d", &n);
    int v[n];
    int c[n];
    for (int i = 0; i < n; i++) { scanf("%d", &v[i]); }
    for (int i = 0; i < n; i++) { scanf("%d", &c[i]); }
    
    int total = 0;
    for (int i = 0; i < n; i++) { 
        if (v[i] - c[i] > 0) { total += v[i] - c[i]; }
    }

    printf("%d", total);

    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
p = [0]*m
V = [[] for i in range(n+1)]
for i in range(m):
    p[i] = list(map(int,input().split())) + [i]
    V[p[i][0]].append(p[i][1:])
W = []
for i in range(n+1):
    if V[i] == []:
        pass
    else:
        V[i].sort(key= lambda val : val[0])
        for j in range(len(V[i])):
            K = ["0"]*(6 - len(str(i))) + list(str(i)) + ["0"]*(6 - len(str(j+1))) + list(str(j+1))
            W.append(["".join(K),V[i][j][1]])
W.sort(key= lambda val : val[1])
for ans in W:
    print(ans[0])
        
    



Measured memory_bytes: 62128
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

bool S[2001];

bool memo[4002];
int Sum[4002], n[4002], amari[4002];

pair<int, int> E[4002];
int Head[2001];
void dfs(int To, int from, int head) {
	if (memo[head]) return;
	memo[head] = true;
	int saidai = 0;
	for (int i = Head[To]; i; i = E[i].second) {
		if (E[i].first != from) {
			dfs(E[i].first, To, i);
			Sum[head] += Sum[i];
			n[head] += n[i];
			saidai = max(saidai, amari[i]);
		}
	}
	if (saidai + saidai < Sum[head]) amari[head] = (Sum[head] + 1) / 2;
	else amari[head] = saidai;
	if (S[To]) n[head]++;
	Sum[head] += n[head];
	amari[head] += n[head];
}

const int cm = 1 << 15;
char cn[cm], *ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int main() {

	fread_unlocked(cn, 1, cm, stdin);

	int N = getint();
	int kazu = 0;
	rep1(i, N) {
		if (*ci++ == '1') {
			kazu++;
			S[i] = true;
		}
	}
	if (kazu == 1) {
		printf("0");
		return 0;
	}
	ci++;

	int Deg[2001] = {};
	for (int i = 1; i < 2 * N - 2; i += 2) {
		int a = getint(), b = getint();
		Deg[a]++;
		Deg[b]++;
		E[i] = mp(a, Head[b]);
		Head[b] = i;
		E[i + 1] = mp(b, Head[a]);
		Head[a] = i + 1;
	}

	bool OK = 0;
	int saishou = 1e9;
	queue<int> que;
	int kari = 0;
	rep1(i, N) if (Deg[i] > 1) kari = i;
	que.push(kari);
	while(que.size()) {
		int j = que.front();
		que.pop();
		if (Deg[j] > 1) {
			Deg[j] = 1;
			int s = 0;
			int saidai = 0;
			int Nsaidai = 0;
			for (int i = Head[j]; i; i = E[i].second) {
				dfs(E[i].first, j, i);
				s += Sum[i];
				saidai = max(saidai, amari[i]);
				Nsaidai = max(Nsaidai, n[i]);
			}
			if (saidai + saidai > s) {
				for (int i = Head[j]; i; i = E[i].second) {
					if (amari[i] == saidai) que.push(E[i].first);
				}
			}
			else {
				if ((s & 1) == 0) {
					OK = 1;
					saishou = min(saishou, s / 2);
				}
				if (OK && saishou <= s / 2) {
					if (Nsaidai + Nsaidai >= kazu - S[j]) {
						for (int i = Head[j]; i; i = E[i].second) {
							if (n[i] == Nsaidai) que.push(E[i].first);
						}
					}
				}
				else {
					for (int i = Head[j]; i; i = E[i].second) que.push(E[i].first);
				}
			}
		}
	}

	if (OK) printf("%d", saishou);
	else printf("-1");

	Would you please return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void dfs(vector<vector<pair<int, int>>> &tree, int index, int parentColor, vector<int> &ans) {
    int color = 1;
    for (int i = 0; i < tree[index].size(); i++) {
        if (ans[tree[index][i].second] != -1) continue;
        if (color == parentColor) color++;
        ans[tree[index][i].second] = color;
        dfs(tree, tree[index][i].first, color, ans);
        color++;
    }
}

void solve() {
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> tree(N);
    vector<int> ans(N-1, -1);
    REP(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(make_pair(b, i));
        tree[b].push_back(make_pair(a, i));
    }

    dfs(tree, 0, -1, ans);
    int cnt = 0;
    REP(i, N) {
        cnt = max(cnt, int(tree[i].size()));
    }

    print(cnt);
    REP(i, N-1) {
        print(ans[i]);
    }

}

signed main() {
    solve();
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

ll H, W, K;

ll f(ll w) {
  if(w<=0) return 1;
  ll i;
  ll res=0;
  
  for(ll S=0; S<1<<w; S++) {
    vector<ll> v;
    for(i=0; i<w; i++) {
      if(S>>i&1) v.push_back(i);
    }
    
    ll f=1;
    for(i=0; i<(ll)v.size()-1; i++) {
      if(v[i]+1==v[i+1]) f=0;
    }
    
    if(f) res++;
  }
  
  return res;
}

int main(void) {
  cin >> H >> W >> K;
  ll i, j, k, l;
  ll dp[111][11]={};
  
  dp[0][1]=1;
  for(i=0; i<H; i++) {
    for(j=1; j<=W; j++) {
      
      //left
      if(j==2||j==W) {
        moC(dp[i+1][j-1], +, dp[i][j]*f(W-3)%MOD);
      }else if(2<j && j<W) {
        moC(dp[i+1][j-1], +, dp[i][j]*f(j-3)%MOD*f(W-j-1)%MOD);
      }
      
      //right
      if(j==1||j==W-1) {
        moC(dp[i+1][j+1], +, dp[i][j]*f(W-3)%MOD);
      }else if(1<j && j<W-1) {
        moC(dp[i+1][j+1], +, dp[i][j]*f(j-2)%MOD*f(W-j-2)%MOD);
      }
      
      //down
      if(j==1||j==W) {
        moC(dp[i+1][j], +, dp[i][j]*f(W-2)%MOD);
      }else {
        moC(dp[i+1][j], +, dp[i][j]*f(j-2)%MOD*f(W-j-1)%MOD);
      }
      
      
    }
  }
  
  pt(dp[H][K]);
  
}




Measured memory_bytes: 256
import numpy as np
n, m = map(int, input().split())
g = [input() for _ in range(n)]
maze = np.array(list(map(list, g)))

from collections import deque


def dfs(s, maze):
    H, W = maze.shape

    visited = np.array([[-1 for _ in range(W)] for _ in range(H)])
    visited[s[0]][s[1]] = 0

    actions = [(-1,0),(1,0),(0,-1),(0,1)]
    queue = deque([s])

    while queue:
        x,y = queue.popleft()
        for action in actions:
            nx = x + action[0]
            ny = y + action[1]
            if nx in range(H) and ny in range(W) and maze[(nx,ny)]=='.' and visited[(nx,ny)]==-1:
                visited[(nx,ny)] = visited[(x,y)] + 1
                queue.append((nx,ny))
    return np.max(visited)
    
ret = -1
H, W = maze.shape

for sx in range(H):
    for sy in range(W):
        if maze[sx][sy] == '.':
            ret = max(dfs((sx,sy), maze), ret)
print(ret) 

Measured memory_bytes: 12256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL M = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int main(){
	DRII(n,x);
	if(x==1||x==2*n-1){puts("No");return 0;}
	puts("Yes");
	if(x==2*n-2){
		REP(i,n){
			printf("%d ",2*i+1);
		}
		for(int i=n-1;i;i--){
			printf("%d ",2*i);
		}
		return 0;
	}
	vector<int> buff;
	REPP(i,1,2*n){
		if(i<x-1||i>x+2)buff.PB(i);
	}
	REP(i,n-2){
		printf("%d ",buff[i]);
	}
	printf("%d %d %d %d ",x+1,x-1,x,x+2);
	REPP(i,n-2,SZ(buff)){
		printf("%d ",buff[i]);
	}
}


Measured memory_bytes: 2420
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n,m;
    while(cin>>n>>m &&n&&m){
        vector<vector<int>> v(n,vector<int>(n,INF));
        rep(i,0,n)v[i][i]=0;

        rep(p,0,m){
            int cmd; cin>>cmd;
            if(cmd==1){
                int to,from,cost; 
                cin>>to>>from>>cost;
                to--; from--;
                if(v[to][from]>cost)v[to][from]=v[from][to]=cost;
                rep(i,0,n){
                    rep(j,0,n){
                        v[i][j]=min(v[i][j],v[i][to]+v[to][j]);
                    }
                }
                rep(i,0,n){
                    rep(j,0,n){
                        v[i][j]=min(v[i][j],v[i][from]+v[from][j]);
                    }
                }

            }else {
                int to,from; cin>>to>>from; to--; from--;
                cout<<(v[to][from]==INF?-1:v[to][from])<<endl;
            }
        }
    }



    
}


/*
3 8
1 3 1 10
0 2 3
1 2 3 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 343750
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 5 843468
1 4 5 15934
0 2 1
0 4 1
0 3 2
0 4 2
0 4 3
0 5 3
0 0
*/



Measured memory_bytes: 3084
n = int(input())
#n,m = map(int,input().split())
lst1 = list(map(int,input().split()))
flag = 1
for i in lst1:
    if i%2==0:
        if i%3!=0 and i%5!=0:
            flag = 0

if flag:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
const int nax = 1e5+5;
int dp[nax];
int main(){
    int n; cin >> n;
    
	dp[0] = 0, dp[1] = 1;
    
    for(int i=1;i<=n;i++){
    	
    	dp[i] = i;
    	
    	for(int j=6;j<=i;j*=6){
    		dp[i] = min(dp[i], 1 + dp[i-j]);
		}
		for(int j=9;j<=i;j*=9){
    		dp[i] = min(dp[i], 1 + dp[i-j]);
		}
	}
	
	cout << dp[n];
	
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const int mod=10007;
#define ll long long

int main(){
    int n;
    cin>>n;
    vector<int>L(n);
    int sum=0;
    rep(i,n)cin>>L[i];
    sort(L.begin(),L.end());
    rep(b,n)rep(a,b){
        int ab=L[a]+L[b];
        int r=lower_bound(L.begin(),L.end(),ab)-L.begin();
        int l=b+1;
        sum+=(r-l);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
integer N
integer,allocatable,dimension(:)::A,B
integer(16) ans
read*,N
allocate(A(N+1),B(N))
read*,A
read*,B
ans=0
do i=1,N
  if(A(i)>=B(i))then
    ans=ans+B(i)
  else
    ans=ans+A(i)
    B(i)=B(i)-A(i)
    if(A(i+1)>=B(i))then
      ans=ans+B(I)
      A(i+1)=A(i+1)-B(i)
    else
      ans=ans+A(i+1)
      A(i+1)=0
    endif
  endif
end do

print"(I0)",ans
end

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    VI A(N);
    REP(i,N) cin >> A[i];
    map<LL,int> mp;
    LL ans = 0;
    REP(i,N){
        ans += mp[i-A[i]];
        mp[i+A[i]]++;

    }
    cout << ans << endl;

}

Measured memory_bytes: 26480
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll h,w;
    cin>>h>>w;
    ll first,second,third;
    ll ans=INF;
    int fi,si,thi;
    ll oth=h*w;
    rep(i,0,2){
        if(i)swap(h,w);
    rep(r,0,h-1){
        if(abs(3*(r+1)*(w)-oth)>abs(3*(r+2)*w-oth))continue;
        fi=r+1,first=(r+1)*w;
        break;
    }
    ll rr=h-fi;
    ll sa=INF;
    rep(c,0,w-1){
        second=(c+1)*rr,third=(w-(c+1))*rr;
        chmin(sa,abs(second-third));
    }
    second=(rr*w-sa)/2;
    third=rr*w-second;
    chmin(ans,max({first,second,third})-min({first,second,third}));
    second=(rr/2*w);
    third=rr*w-second;
    chmin(ans,max({first,second,third})-min({first,second,third}));
    }
    cout<<ans<<endl;
   return 0;
}




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

int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	int ans = x * a + y * b;
	for (int i = 2; i <= 2 * 1E+05; i += 2) {
		if (i * c + max(x - i / 2, 0) * a + max(y - i / 2, 0) * b < ans) {
			ans = i * c + max(x - i / 2, 0) * a + max(y - i / 2, 0) * b;
		}
	}

	cout << ans << endl;

 	return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli n;
	cin>>n;
	lli a[n-1],i;
	lli count[n+1]={0};
	fr(i,n-1)
	{
		cin>>a[i];
		count[a[i]]++;
	}
	for(i=1;i<=n;i++)
	{
		cout<<count[i]<<"\n";
	}

	
	return 0;
}

Measured memory_bytes: 6740
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    int a,b,c,d,ac,bc;
    cin>>a>>b>>c>>d;
    if(a%d==0)bc=a/d;
    else bc=a/d+1;
    if(c%b==0)ac=c/b;
    else ac=c/b+1;
    if(ac<=bc)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <math.h>

void dprint(double p[]){
    printf("%f %f\n",p[0],p[1]);
}

void cohho(int n,double p1[],double p5[]){
    if(n==0){return;}
    double p2[2],p3[2],p4[2];
    double th = M_PI/3;
    p2[0] = (p1[0]*2+p5[0])/3;
    p2[1] = (p1[1]*2+p5[1])/3;
    p4[0] = (p1[0]+p5[0]*2)/3;
    p4[1] = (p1[1]+p5[1]*2)/3;
    p3[0] = cos(th)*(p4[0]-p2[0])-sin(th)*(p4[1]-p2[1])+p2[0];
    p3[1] = sin(th)*(p4[0]-p2[0])+cos(th)*(p4[1]-p2[1])+p2[1];
    cohho(n-1,p1,p2);
    dprint(p2);
    cohho(n-1,p2,p3);
    dprint(p3);
    cohho(n-1,p3,p4);
    dprint(p4);
    cohho(n-1,p4,p5);
}

int main(void){
    int n;
    double p1[] = {0.0,0,0};
    double p2[] = {100.0,0,0};
    scanf("%d",&n);
    dprint(p1);
    cohho(n,p1,p2);
    dprint(p2);
    return 0;
}




Measured memory_bytes: 2092
n, m = map(int, input().split())

ans = 0
for i in range(1, int(m ** 0.5) + 1):
    if m % i == 0:
        div = m // i

        if i <= m // n:
            ans = max(ans, i)

        if div <= m // n:
            ans = max(ans, div)

print(ans)


Measured memory_bytes: 63388