akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
using namespace std;

bool isnum(char c){
	return '0'<=c && c<='9';
}
bool isnum(string &s){
	if(s[0]!='-' && !isnum(s[0])) return false;
	for(int i=1; i<(int)s.length(); i++){
		if(!isnum(s[i])) return false;
	}
	return true;
}
bool isop(string &s){
	return s=="+" || s=="-" || s=="*" || s=="/";
}

vector<string> parse(string &str){
	vector<string> ret;
	string num = "";
	for(int i=0; i<(int)str.length(); i++){
		if(isnum(str[i])){
			num += str[i];
			if(i+1 == (int)str.length() || !isnum(str[i+1])){
				ret.push_back(num);
			}
		}else{
			num = "";
			ret.push_back(string(1,str[i]));
		}
	}
	return ret;
}
void erasebrac(vector<string> &vs){
	while(1){
		bool end = true;
		for(int i=0; i<(int)vs.size()-2; i++){
			if(vs[i]=="(" && isnum(vs[i+1]) && vs[i+2]==")"){
				end = false;
				vs.erase(vs.begin() +i+2);
				vs.erase(vs.begin() +i);
				break;
			}
		}
		if(end) break;
	}
}
int calc(int a, int b, string &op){
	if(op == "+"){
		return a+b;
	}else if(op == "-"){
		return a-b;
	}else if(op == "*"){
		return a*b;
	}else if(op == "/"){
		if((long long int)a*b>=0) return abs(a)/abs(b);
		else return -(abs(a)/abs(b));
	}
	return -1;
}

void solve(vector<string> vs, set<int> &ans){
	erasebrac(vs);
	int n = vs.size();
	if(n==1){
		ans.insert(stoi(vs[0]));
	}
	for(int i=1; i<n-1; i++){
		if(isnum(vs[i-1]) && isop(vs[i]) && isnum(vs[i+1])){
			if(vs[i]=="/" && vs[i+1]=="0") continue;
			vector<string> next = vs;
			next[i-1] = to_string(calc(stoi(vs[i-1]), stoi(vs[i+1]), vs[i]));
			next.erase(next.begin()+i, next.begin()+i+2);
			solve(next, ans);
		}
	}
}

int main(){
	while(1){
		string str;
		cin >> str;
		if(str=="#") break;
		
		vector<string> vs = parse(str);
		set<int> ans;
		solve(vs, ans);
		cout << ans.size() << endl;
	}
	return 0;
}


Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define ll long long
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
using namespace std;

ll digit(ll num) {
  ll dig,sum=0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}
int main() {
  ll n;
  cin>>n;
  vector<ll>vec(n/2);
  for(ll i=1;i<=n/2;i++) {
    vec.at(i-1)=digit(i)+digit(n-i);
  }
  sort(vec);
  cout<<vec.at(0)<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string,string,char
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

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

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int SED(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;

	string s;
	cin >> s;

	int x = 0, y = 0;

	rep(i, s.size()) {
		if (s[i] == 'A') {
			x = i;
			break;
		}
	}

	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			y = i;
			break;
		}
	}

	cout << y - x + 1 << rt;

	please AC;
}

Measured memory_bytes: 720
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    char s[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
            cin>>s[i][j];
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
            cout<<s[i][j];
        cout<<endl;
        for(int j=0;j<w;j++)
            cout<<s[i][j];
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def yn(f) return (f)? "Yes": "No" end
def ynb(f) return (f)? "YES": "NO" end
def ap(a) a.each{|u| p u} end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
def f(s, m)
  unless($m[s])
    $m[s] = 1
  else
    p m
    exit
  end
  if s.even?
    f(s/2,m+1)
  else
    f(3*s + 1,m+1)
  end
end
$m = {}
f(inp[0],1)

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
string s,t;
main()
{
	while(cin>>s>>t,s!="0")
	{
		int a=0,b=0;
		for(int i=0;i<4;i++)
		{
			if(s[i]==t[i])
			{
				a++;s[i]='a';
			}
		}
		for(int i=0;i<4;i++)
		{
			bool f=0;
			for(int j=0;j<4;j++)if(s[i]==t[j]){f=1;break;}
			if(f)b++;
		}
		cout<<a<<" "<<b<<endl;
	}
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<ul, ul> puu;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define ls (i << 1)
#define rs (i << 1 | 1)
#define mid (l + r >> 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define mfil(x, k) memset(x, k, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y, true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y, true) : false; }
struct __init { __init()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cout.precision(16); cout << fixed;
    srand(time(0) ^ ui(ul(new char)));
} } static __init__;
/* default code ends here */

const int maxn = 2e5 + 10;
int n;
vi h[maxn];
pii operator + (pii p, int x)
{
    return pii(p.fi + x, p.se);
}
pii dfs(int x, int fa)
{
    pii ret = pii(1, x);
    for(int v : h[x])
        if(v != fa)
            chkmax(ret, dfs(v, x) + 1);
    return ret;
}

void yes()
{
    cout << "First\n";
    exit(0);
}
void no()
{
    cout << "Second\n";
    exit(0);
}

int main()
{
    cin >> n;
    int u, v;
    enum(i, 1, n - 1)
    {
        cin >> u >> v;
        h[u].pb(v);
        h[v].pb(u);
    }
    pii p = dfs(1, 0);
    p = dfs(p.se, 0);
    int x = p.fi;
    if(x % 3 == 2)
        no();
    else
        yes();
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    long long n = s.size(), sum = 0, i=0, j=1;

    for(; i<n; i++){
        if(s[i] == 'W'){
            sum += (i-j)+1;
            j++;
        }
    }

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

Measured memory_bytes: 3700
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

// O(log max(a, b))
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

    int A[N];
    int amax = -1;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        amax = max(amax, A[i]);
    }

    if (N == 0) {
        if (N == K) {
            cout << "POSSIBLE" << endl;
            return 0;
        } else {
            cout << "IMPOSSIBLE" << endl;
            return 0;
        }
    }

    int ret = gcd(A[0], A[1]);
    for (int i = 2; i < N; i++) {
        ret = gcd(ret, A[i]);
    }

    if (K % ret == 0 && K <= amax) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
 
int main(){
  int n;
  scanf("%d", &n);
 
  char s[n+2];
  scanf("%s",s);
 
  int stone[n][2];
 
  int i,white=0,black=0;
 
  for(i= 0;i<n;i++){
    if(s[i]=='#'){
      black++;
    } else {
      white++;
    }
    stone[i][0] = white;
    stone[i][1] = black;
  }
 
 /*int min = white;
 if(b<min) min = black;*/
  int min=(black>white)?white:black;
 
 for(i=0;i<n;i++){
   if(min>white-stone[i][0]+stone[i][1]) 
     min=white-stone[i][0]+stone[i][1];
 }
 
 printf("%d\n", min);
 
 return 0;
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var A = AB[0];
            var B = AB[1];

            if (A < 10 && B<10)
            {
                Console.WriteLine(A*B);
            }
            else
            {
                Console.WriteLine(-1);
            }

        }
    }
}


Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
using System.IO;

namespace ConsoleApp2
{
    class Program {
        static decimal C(int a,int b) {
            decimal res = 1;
            for (int i = 0; i < b; i++) {
                res *= (a - i);
                res /= (i + 1);
            }
            return res;
        }


        static void Main(string[] Args) {
            string s = ReadLine();
            if (s[0] == s[2])
                WriteLine("H");
            else
                WriteLine("D");

            ProgramEndPointLabel:;

            ReadLine();
        }
    }
}


Measured memory_bytes: 11092
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if(n%k==0){
            System.out.println(0);
        }
        else{
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  int N;
  cin >>  N;
  map<string,int> mp;
  rep(i,N){
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
typedef long long ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
const double PI=3.14159265358979323846;

using namespace std;

int n;

bool binarySearch(int a[], int k) {

	int left = 0, right = n;
	int i;

	while (left < right) {

		i = (left + right) / 2;
		if (k == a[i]) return true;
		if (k > a[i]) left = i + 1;
		else if (k < a[i]) right = i;
	}
	return false;
}

int main() {

	int q;
	int ans = 0;

	cin >> n;
	int s[n];
	rep(i, n) 
		cin >> s[i];

	//sort(s, s+n);
	
	cin >> q;
	int t[q];
	rep(j, q) {
		cin >> t[j];
		if (binarySearch(s, t[j]))
			ans++;
	}
		
	cout << ans << endl;
}



Measured memory_bytes: 3660
module WeightedGraph
  (* 辺の重み *)
  (Weight : sig
    type t
    val zero : t
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end)
  (* 辺の重みを優先度としたヒープの実装 *)
  (Heap : sig
    type t
    type elt (* 頂点に相当 *)
    type key = Weight.t (* 辺の重みに相当 *)
    (* ヒープが空ならNoneを，
       そうでなければ重みが最小となるbindingを一つ返す
       返したbindingはヒープから削除される *)
    val take_min_binding : t -> (key * elt) option
    (* ヒープにbindingを追加する
       既に同じ頂点についてのbindingが追加されていたら，
       重みが小さい方だけを残しても良いし，何も考えずに追加してもよい．
       前者の実装ならプリム法の実装が時間計算量O((V + E) log V)，
       空間計算量O(V)に改善する *)
    val add : t -> key -> elt -> unit
  end)
  (* 頂点を添字，辺の重みを要素とした配列の実装 *)
  (Array : sig
    type t
    type key = Heap.elt
    type elt = Heap.key
    val get : t -> key -> elt
    val set : t -> key -> elt -> unit
  end)
: sig
  type weight = Array.elt
  type vertex = Array.key

  (* プリム法で最小全域木を求める *)
  val minimum_spanning_tree :
    (* 空なヒープ *)
    Heap.t ->
    (* 全ての頂点について無限大で初期化された配列 *)
    Array.t ->
    (* 最小全域木を求めたいグラフの，ある頂点から伸びる辺に対してのイテレータ *)
    (vertex -> (vertex -> weight -> unit) -> unit) ->
    (* 頂点の一つ（これは必ず最小全域木に含まれる） *)
    vertex ->
    (* 最小全域木に含まれる辺の重みの総和 *)
    weight
end
= struct
  type weight = Array.elt
  type vertex = Array.key

  let minimum_spanning_tree q d es s =
    Heap.add q Weight.zero s;
    let rec prim acc u =
      Array.set d u Weight.zero;
      es u (fun v w ->
        if 0 < Weight.compare (Array.get d v) w then
          (Array.set d v w; Heap.add q w v));
      prim' acc
    and prim' acc =
      match Heap.take_min_binding q with
      | None -> acc
      | Some (w, u) ->
          if 0 < Weight.compare w (Array.get d u)
          then prim' acc
          else prim (Weight.( + ) acc w) u in
    prim Weight.zero s
end

module Int = struct
  type t = int
  let zero = 0
  let ( + ) = ( + )
  let compare = compare
end

module IntMap = Map.Make (Int)

module G = WeightedGraph (Int)
  (struct
    type t = int list IntMap.t ref
    type key = int
    type elt = int
    let take_min_binding q =
      match IntMap.min_binding !q with
      | exception Not_found -> None
      | (w, [v]) -> q := IntMap.remove w !q; Some (w, v)
      | (w, v :: vs) -> q := IntMap.add w vs !q; Some (w, v)
    let add q w v =
      q := IntMap.add w (v :: try IntMap.find w !q with Not_found -> []) !q
  end)
  (struct
    type t = int array
    type key = int
    type elt = int
    let get = Array.get
    let set = Array.set
  end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let xys = Array.init n @@ fun _ ->
    Scanf.scanf "%d %d\n" @@ fun x y -> [| x; y |] in
  let es = Array.make n [] in
  let is = Array.init n @@ fun i -> i in
  for d = 0 to 1 do
    Array.sort (fun i j -> compare xys.(i).(d) xys.(j).(d)) is;
    for j = 0 to n - 2 do
      let i = is.(j) in
      let i' = is.(j + 1) in
      let c = min (abs (xys.(i).(0) - xys.(i').(0))) (abs (xys.(i).(1) - xys.(i').(1))) in
      es.(i) <- (i', c) :: es.(i);
      es.(i') <- (i, c) :: es.(i')
    done
  done;
  Printf.printf "%d\n" @@
  G.minimum_spanning_tree (ref IntMap.empty) (Array.make n max_int)
    (fun i f -> List.iter (fun (j, w) -> f j w) es.(i)) 0


Measured memory_bytes: 41216
#include <iostream>
using ll = long long;
using namespace std;

/* initialize */
int n, q, A[20], m;
/* main */
int solve(int i, int m){
    if (m == 0){
        return 1;
    }else if (i >= n) return 0;
    int res = solve(i+1, m) || solve(i+1, m - A[i]);
    return res;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    cin >> q;
    for (int j = 0; j < q; ++j) {
        cin >> m;
        if (solve(0, m)) cout << "yes\n";
        else cout << "no\n";
    }
    return 0;
}


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

// #define ANS  //for answer
#define CMP  //for compe

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x,(x)
#define ncv(x) #x,":",(x)
#define ncvc(x) #x,":",(x),","
using ll = long long;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>void pPRINT(std::ostream& ost,const T t,const U... u) {ost<<t<<" ";pPRINT(ost, u...);}
template <class... T>void PRINT(const T... t) {pPRINT(std::cout, t...);}
template <class... T>void PRINTl(const T... t){pPRINT(std::cout,t...);std::cout<<"\n";}
template <class T>void PRINTa(const T* const t,const ll size){REP(i,size)PRINT(t[i]);PRINTl();}
template <class T>void PRINTal(const T* const t,const ll size){REP(i,size)PRINTl(i,":",t[i]);}
#ifdef CMP
using namespace std;
#else
#endif
#ifndef DBG
#define DEBUG(...)
void init(){}
#else
#define DEBUG(...) PRINT("##DEBUG##","file :",__FILE__,", line :",__LINE__,"[");PRINT(__VA_ARGS__);PRINTl("]");
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

void solve();

int main(int argc, char *argv[]) {

  init();
  DEBUG();
  solve();

  return 0;
}

void solve(){

  DEBUG("SOLVE START");

  ll n,m;cin>>n>>m;
  ll a[n],b[n];REP(i,n)cin>>a[i]>>b[i];
  vector<pair<ll,ll>> v(n);REP(i,n)v[i]=make_pair(a[i],b[i]);

  sort(v.begin(),v.end(),[](const pair<ll,ll>& lh,const pair<ll,ll>& rh){
    // if(lh.second>rh.second)return true;
    // else if(lh.second==rh.second&&lh.first<lh.second)return true;
    // else return false;

    if(lh.first<rh.first)return true;
    else if(lh.first==rh.first&&lh.second>rh.second)return true;
    else return false;
  });
  priority_queue<ll> pq;
  ll ind1=0;
  REP(i,n){DEBUG(ncv(i),ncv(v[i].first),ncv(v[i].second));}
  while(ind1<n&&v[ind1].first<=v[0].first){
    DEBUG("push!","value :",v[ind1].second);
    pq.push(v[ind1].second);
    ind1++;
  }
  ll ans=0;
  FOR(i,v[0].first,m+1){
    if(v[ind1].first<=i){
      while(ind1<n&&v[ind1].first<=i){
        DEBUG("push!","value :",v[ind1].second);
        pq.push(v[ind1].second);
        ind1++;
      }
    }
    if(pq.size()!=0){
      DEBUG("add!",ncv(i),ncv(pq.top()),ncv(ans));
      ans+=pq.top();
      pq.pop();
    }
  }
  PRINT(ans);
}

Measured memory_bytes: 4472
#include <bits/stdc++.h>
 
using namespace std;
 
const int md = 1000000007;
 
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
 
inline int mul(int a, int b) {
  return (long long) a * b % md;
}
 
const int N = 303;
 
int f[N][N][N];
 
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  f[0][1][1] = 1;
  int ans = 0;
  for (int i = 0; i < m; i++) {
    for (int vis = 1; vis <= n; vis++) {
      for (int cap = 1; cap <= n; cap++) {
        int ft = f[i][vis][cap];
        if (ft == 0) {
          continue;
        }
        if (i < m - 1) {
          add(f[i + 1][vis + 1][cap], mul(ft, n - vis));
          add(f[i + 1][vis][vis], mul(ft, cap));
          add(f[i + 1][vis][cap], mul(ft, vis - cap));
        } else {
          if (vis == n) {
            add(ans, mul(ft, cap));
          }
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 106752
import sys

for line in sys.stdin:
    if len(line)>1:
        x1, y1, x2, y2 = line.strip('\n').split()
        x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
        print ((x1-x2)**2+(y1-y2)**2)**0.5

Measured memory_bytes: 4288
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    ll sum = 0;
    for (int i = 1; i <= n; ++i) {
        if (i%3 && i%5) sum+=i;
    }

    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1) {
    for(int i = 0; i < N; i++) par.at(i) = i;
  }

  int find(int x) { 
    if (par.at(x) == x) return x;
    return par.at(x) = find(par.at(x));
  }

  void unite(int x, int y) {
    int rx = find(x); 
    int ry = find(y); 
    if (rx == ry) return; 
    if (sizes.at(rx) < sizes.at(ry)) swap(rx,ry);
    par.at(ry) = rx;
    sizes.at(rx) += sizes.at(ry);    
  }

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

  int size(int x){
    return sizes.at(find(x));
  }

  int num_of_connected_components(){
    int ret = 0;
    for(int i = 0; i < par.size(); i++){
      if(find(i) == i) ret++;
    }
    return ret;
  }
};

int main() {
  ll n; cin >> n;
  vector<ll> p(n);
  REP(i, n) cin >> p[i];

  UnionFind uf(n+1);
  vector<bool> seen(n+1, false);
  REP(i, n){
    ll t = p[i];
    seen[t] = true;
    if(seen[t-1]) uf.unite(t, t-1);
  }
  ll maxi = 0;
  FOR(i, 1, n+1) maxi = max(maxi, (ll) uf.size(i));
  cout << n -  maxi << endl;
}

Measured memory_bytes: 3456
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

bool sortCheck(int n, vector<int> A){
    int f = 1;
    REP(i, n - 1){
        if(A[i] > A[i + 1]){
            f = 0;
            break;
        }
    }
    if(f) return true;
    else return false;
}

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for(auto &x : A) cin >> x;

    int cnt = 0;
    while(1){
        if(sortCheck(n, A)) break;
        else{
            REP(i, n - 1){
                int mi = INT_MAX, idx, tmp;
                FOR(j, i + 1, n){
                    if(A[j] < mi){
                        idx = j;
                        mi = A[j];
                    }
                }
                if(A[i] > mi){
                    tmp = A[i];
                    A[i] = A[idx];
                    A[idx] = tmp;
                    cnt++;
                }
            }
        }
    }
    REP(i, n){
        if(i != n - 1) cout << A[i] << " ";
        else cout << A[i] << endl;
    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 3104
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


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


void solve() {
    int N, W; cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    vector<vector<long long>> dp(N, vector<long long>(W+1));

    if (w[0] <= W) dp[0][w[0]] = v[0];

    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            chmax(dp[i][j], dp[i-1][j]);
            if (j - w[i] >= 0) {
                chmax(dp[i][j], dp[i-1][j-w[i]] + v[i]);
            }
        } 
    }

    long long ans = 0;
    for (int i = 0; i <= W; i++) {
        chmax(ans, dp[N-1][i]);
    }

    cout << ans << endl;
}


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

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<vector<pair<int,int>>> g(n);
    for (int i = 0; i < n; i++) {
        int m; cin >> m;
        for (int _ = 0; _ < m; _++) {
            int x, y;
            cin >> x >> y;
            x--;
            g[i].emplace_back(x,y);
        }
    }

    const int MSK = 1<<n; 
    int res = 0;
    for (int msk = 0; msk < MSK; msk++) {
        for (int i = 0; i < n; i++) {
            if (msk & (1<<i)) {
                for (auto& _: g[i]) {
                    int j, y;
                    tie(j, y) = _;
                    if (((msk>>j)&1) != y) goto end;
                }
            }
        }
        res = max(res, __builtin_popcount(msk));
end:;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int a[101];

int main(){
  int N; cin >> N;
  for( int i = 0; i < N; i++ ){
    cin >> a[i];
  }

  int cnt = 0;
  for( int i = 0; i < N - 1; i++ ){
    int minj = i;
    for( int j = i; j < N; j++ ){
      if( a[j] < a[minj] ){
	minj = j;
      }
    }
    if( minj != i ){
      int t = a[minj];
      a[minj] = a[i];
      a[i] = t;
      cnt++;
    }
  }

  for( int i = 0; i < N; i++ ){
    cout << a[i];
    if( i == N - 1 ) cout << endl;
    else cout << " ";
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3104
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("YES\n")
#define no printf("NO\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

int n,m,x;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>m>>x;
    int a;
    vi vec(n+1);
    rep(i,m){
        cin>>a;
        vec[a]++;
    }
    int ansl=0;
    REV(i,0,x){
        if(vec[i]) ansl++;
    }
    int ansr=0;
    REP(i,x,n+1){
        if(vec[i]) ansr++;
    }
    int ans=min(ansl,ansr);
    
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

ll h,ans=0;
// void solve(ll hp){
//     if(hp==1){
//         ans++;
//         return;
//     }
//     ans++;
//     solve(hp/2);
//     solve(hp/2);
    
//     return;
// }
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>h;

    int i=0;
    do{
        ans |= 1LL<<i;
        h /=2;
        i++;
    }while(h>0);

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

Measured memory_bytes: 256
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
        i += 1
    table = list(set(table))
    return table

n = int(input())

div_list = divisor(n)
list.sort(div_list, reverse=True)
x = div_list[0]
y = n / x


print(int(x-1+y-1))

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h.at(i);
  vector<int> dp(n);
  dp.at(1) = abs(h.at(1) - h.at(0));
  for (int i = 2; i < n; i++) {
    dp.at(i) = min(dp.at(i - 2) + abs(h.at(i) - h.at(i - 2)),
                   dp.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
  }
  cout << dp.at(n - 1) << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>

using namespace std;
int main(){
    int n,min = 1000000,max = -1000000;
    long sum=0;
    int a[10000];

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum+=a[i];
        if(a[i] < min){
            min = a[i];
        }
        if(a[i] > max){
            max = a[i];
        }
    }

    cout  << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3128
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [a, b, n] = input[0].split(" ").map((x: string): number => +x);

const x = n < b ? n : b - 1;
console.log(Math.floor(x * a / b));


Measured memory_bytes: 29640
n = int(input())
ll = [list(map(int,input().split())) for _ in [0]*n]
t=1
a=1
for l in ll:
  if l[0]>=t and l[1]>=a:
    t=l[0]
    a=l[1]
  else:
    c = max([-(-t//l[0]), -(-a//l[1])])
    t = l[0]*c
    a = l[1]*c
print(t+a)

Measured memory_bytes: 3188
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter prnt = new PrintWriter(System.out);
        StringTokenizer st;
        String S = read.readLine();
        String T = read.readLine();
        prnt.println(getMinimumChange(S, T));


        prnt.close();
    }

    static int getMinimumChange(String S, String T) {
        int res = T.length();
        for (int i = 0; i < (S.length() - T.length() + 1); i++) {
            int count = 0;
            for (int j = 0; j < T.length(); j++) {
                // System.out.println(S.charAt(i+j) + " " + T.charAt(j));
                if (S.charAt(i + j) != T.charAt(j)) {
                    count++;
                }
            }
            res = Math.min(res, count);
        }
        return res;
    }
}

Measured memory_bytes: 32776
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int x;
  cin >> x;
  if (x == 0) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3604
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 0; ; i++) {
        if (i%2 == 0) {
            c -= b;
            if (c <= 0) {
                cout << "Yes" << endl;
                break;
            }
        } else {
            a -= d;
            if (a <= 0) {
                cout << "No" << endl;
                break;
            }
        }
    }
    return 0;
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back

#define PI 3.14159265358979323846
#define N 100000
#define MOD 1000000007

int n;
set<string> si;
void print_all(string s, int in, int ch)
{
	if (in == n)
		si.insert(s);
	else
	{
		for (int i = 0; i < ch + 1; ++i)
		{
			s[in] = 'a' + i;
			if (i == ch)
			{
				print_all(s, in + 1, ch + 1);
			}
			else	
				print_all(s, in + 1, ch);
		}
	}
}

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

	cin >> n;

	string s;
	s.resize(n);

	print_all(s, 0, 0);
	// cout << si.size() << "\n";
	for (auto e : si)
		cout << e << "\n";
	return 0;
}

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

int main(){
  int h, w;
  char c;
  int ans[101][101];
  cin >> h >> w;
  for(int i=0; i<=h; i++) fill(ans[i], ans[i]+w+1, -1);

  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      cin >> c;
      if( c == 'c' ) ans[i][j] = 0;
      else if( ans[i][j-1] >= 0 ) ans[i][j] = ans[i][j-1]+1;
      cout << ans[i][j];
      if( j != w ) cout << ' ';
    }
    cout << endl;
  }
}

Measured memory_bytes: 1196
#include <iostream>
#include <stdio.h>
#include <cmath>

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

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

  double ans = 0;
  for(int i=1; i<=N; i++){
    if(i>=K){
      ans += 1./N;
      continue;
    }
    int num = ceil(log2(K)-log2(i));
    ans += 1. / (N * pow(2,num));
  }

  printf("%2.12f\n", ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[m];
		int[] d = new int[m];
		int min = 99999999;
		int index = 0;
		int date = 99999999;
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		
		for(int i = 0; i < m; i++){
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		
		for(int i = 0;i < n; i++){
			for(int j = 0; j < m; j++){
				date = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
				if(date < min){
					min = date;
					index = j;
				}
			}
			System.out.println(index + 1);
			min = 999999999;
			index = 0;
		}
			
	}
 
}

Measured memory_bytes: 21844
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

using lli = long long int;

template <typename U, typename T>
std::vector<U> cumsum(std::vector<T> const &as) {
  std::vector<U> sum(as.size()+1, U());
  for (size_t i = 0; i < as.size(); ++i) {
    sum[i+1] = sum[i] + as[i];
  }
  return sum;
}

using namespace std;

void solve(int N, vector<lli> const &As) {
  vector<lli> sum = cumsum<lli>(As);
  vector<vector<lli>> dp(N+1, vector<lli>(N+1, 0));
  FOR(len, 1, N) for (int first = 0; len + first <= N; ++first) {
    auto const last = len + first;
    dp[len][first] = sum[last] - sum[first]
      - min(dp[len-1][first+1], dp[len-1][first]);
  }
  cout << 2 * dp[N][0] - (sum[N]-sum[0]) << endl;
}

int main() {
  int N; cin >> N;
  vector<lli> As;
  REP(i, N) {
    lli A;
    cin >> A;
    As.push_back(A);
  }
  solve(N, As);
  return 0;
}


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

using namespace std;

typedef long long ll;

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

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

// {left, right}
vector <pair<ll, ll>> bars;

ll solve(const ll N) {
    ll count = 1;
    pair<ll, ll> prev = bars[0];

    for (int i = 1; i < N; i++) {
        pair<ll, ll> cur = bars[i];
        if (prev.second <= cur.first) {
            count++;
            prev = cur;
        } else if (cur.second < prev.second) {
            prev = cur;
        }
    }

    return count;
}

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

    bars.resize(N);
    for (int i = 0; i < N; i++) {
        ll X, L;
        cin >> X >> L;
        bars[i].first = X - L;
        bars[i].second = X + L;
    }
    sort(bars.begin(), bars.end(), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
            return a.first < b.first;
            });

    cout << solve(N) << endl;

    return 0;
}


Measured memory_bytes: 1792
l,r = map(int, input().split())
import numpy as np
import itertools
MOD = 2019
if r-l+1 >= 673:
  print(0)
else:
  k = [i for i in range(l,r+1)]
  can = [0] * ((r-l+1)*(r-l)//2)
  for idx,(m,n) in enumerate(itertools.combinations(k,2)):
    can[idx] = (m*n)%MOD
  print(min(can))

Measured memory_bytes: 15712
#include <bits/stdc++.h>
 
#define infi            1e9
#define infl            1e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)
 
using namespace std;
 
inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
// inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
// inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
// inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}
 
// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//


int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif
    //freopen("in.txt", "r", stdin);

    int n=rr;
    int ar[30];
    loop(i,n)ar[i]=rr;
    int cnt=0;
    for(int i=1;i<n-1;i++){
       if((ar[i]>ar[i-1]&&ar[i]<ar[i+1])||(ar[i]<ar[i-1]&&ar[i]>ar[i+1]))cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
vector<int> v[100010];

int main(void){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
    }
    ll ans=0;
    priority_queue<ll,vector<ll>,less<ll>>pq;
    for(int i=1;i<=m;i++){
        for(auto itr=v[i].begin();itr!=v[i].end();++itr)
            pq.push(*itr);
        if(!pq.empty()){
            ans+=pq.top();
            pq.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> point(N);
    for(int i=0; i<N; i++) {
        point[i] = K;
    }
    for(int j=0; j<Q; j++) {
        int A;
        cin >> A;
        point[A-1]++;
    }
    for(int i=0; i<N; i++) {
        point[i] -= Q;
        if(point[i] <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ff;
typedef long long unsigned ul;
#define pf printf
#define sf scanf
#define mp make_pair
#define pb push_back
#define pfds(a) pf("%lld ",(a))
#define pfdn(a) pf("%lld\n",(a))
#define pffs(a) pf("%Lf ",(a))
#define pffn(a) pf("%Lf\n",(a))
#define pfss(a) pf("%s ",(a))
#define pfsn(a) pf("%s\n",(a))
#define scd(a) sf("%lld",&(a))
#define scf(a) sf("%Lf",&(a))
#define scs(a) sf("%s",(a))
#define scc(a) sf("%c",&(a))
#define FORF(i,a) for(ll (i)=0;(i)<(a);(i)+=1)
#define FORD(i,a) for(ll (i)=(a);(i)>=0;(i)-=1)
#define FORF2(i,a,b) for(ll (i)=(a);i<(b);(i)+=1)
#define FORD2(i,a,b) for(ll (i)=(a);i>=(b);(i)-=1)
#define max3(a,b,c) a>b?a>c?a:c:b>c?b:c
#define min3(a,b,c) a<b?a<c?a:c:b<c?b:c
void to_binary(int n){ if(!n) return; to_binary(n>>1); printf("%d",n&1 ? 1 : 0); }
const ul mod = 1e9+7;
const int size = 1e3 + 3;
int main()
{
	ll n;scd(n);
	ll sum=0;
	while(n--)
	{
		ll a,b;
		scd(a);scd(b);
		sum+=b-a+1;
	}
	pfdn(sum);
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 1000000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
int gcd(int a, int b)
{
	if(a==0){return b;}
	if(b==0){return a;}
	return gcd(b,a%b);
}
//try thinking from a different angle after spending some time
//edge cases when n=1,m=1.wrong variable in loop.if<->while;merge resize;LLONG_MAX
signed main()
{
	speed
	//global var
	int x;cin>>x;
	int lcm=(x*360)/gcd(x,360);
	cout<<lcm/x;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
struct node{
	int num;
	node *parent,*left,*right;
};
node *root,*NIL;
 
void find(int a){
	node *x=root;
	while(x!=NIL){
		if(x->num < a) x=x->right;
		else if(x->num>a) x=x->left;
		else {
			printf("yes\n");
			return ;
		}
	}
	printf("no\n");
	return ;
}
 
void print_inorder(node *x){
	if(x==NIL) return ;
	print_inorder(x->left);
	printf(" %d",x->num);
	print_inorder(x->right);
	return ;
}
 
void print_preorder(node *x){
	if(x==NIL) return ;
	printf(" %d",x->num);
	print_preorder(x->left);
	print_preorder(x->right);
	return ;
}
 
void insert(int a){
	node *x=root,*y=NIL;
	node *z=new node();
	z->num=a;z->left=NIL;z->right=NIL;
	while(x!=NIL){
		y=x;
		if(z->num < x->num) x=x->left;
		else x=x->right;
	}
	z->parent=y;
	if(y==NIL) root=z;
	else {
		if(z->num < y->num) y->left=z;
		else y->right=z;
	}
	return ;
}
 
int main(){
	int n;
	cin>>n;
	string s;
	int a;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s[0]=='i') cin>>a,insert(a);
		else if(s[0]=='p'){
			print_inorder(root);
			printf("\n");
			print_preorder(root);
			printf("\n");
		}
		else cin>>a,find(a);
	}
	return 0;
}


Measured memory_bytes: 21948
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int SIZE=110;
const int INF=1e18;
struct edge{
    int u,v,cost;
};

signed main()
{
    int N,M; cin>>N>>M;
    vector<vector<int>> dist(N,vector<int>(N,INF));
    for(int i=0;i<N;i++){
        dist[i][i]=0;
    }
    vector<edge> es;
    for(int i=0;i<M;i++){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        es.push_back({a,b,c});
        dist[a][b]=dist[b][a]=c;
    }

    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }

    int ans=0;
    for(edge e:es){
        if(dist[e.u][e.v]<e.cost) ans++;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384