akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)
using Graph = vector<vector<int>>;
using pint = pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
    int n;cin>>n;
    list<int> vec;
    string s;int x;
    rep(i,n){
        cin>>s;
        if(s=="deleteFirst"){
            vec.pop_front();
        }
        else if(s=="deleteLast"){
            vec.pop_back();
        }
        else{
            cin>>x;
            if(s=="insert") {
                vec.push_front(x);
            }
            else{
                auto itr =find(vec.begin(),vec.end(),x);
                if(itr==vec.end()) {
                    continue;
                }
                vec.erase(itr);
            }

        }

    }
    int u=0;
    //reverse(vec.begin(),vec.end());
    for(auto i:vec){
        if(u++) cout<<" "; 
        cout<<i;
    }
    cout<<"\n";

}


Measured memory_bytes: 34228
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n % 2 == 0) {
            System.out.println(n / 2);
        }else {
            System.out.println((n+1) / 2);
        }
        
    }
}

Measured memory_bytes: 21844
N = int(input())


def is_prime(num):
    div = 2
    ret = 1
    while True:
        if num % div == 0:
            ret = 0
            break
        div += 1
        if div * div > num:
            break
    if num == 2:
        ret = 1
    return ret


ans = [0] * N
p = 2
for i in range(N):
    while True:
        if is_prime(p):
            ans[i] = p
            break
        else:
            p += 5
    p += 5

print(' '.join(map(str, ans)))


Measured memory_bytes: 38512
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;
///////////////////////////
#define INF 1000000009
#define MAX_V 1000000
typedef pair<ll, ll> p;
typedef vector<ll> V;
struct edge{ll to, cost;};
multimap<V, ll> mp;
std::vector<std::vector<edge> > G(MAX_V);
std::vector<ll> pre(MAX_V,-1);
priority_queue<p, std::vector<p>, greater<p> > que; //class, inner, compair
std::vector<ll> d(MAX_V+1, INF);
void dijkstra(int start){
  d[start]=0;
  que.push(p(0, start));
  while(!que.empty()){
    p p_now=que.top(); que.pop();
    ll v = p_now.second;
    if(d[v]<p_now.first) continue;
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        pre[e.to] = v;
        que.push(p(d[e.to], e.to));
      }
    }
  }
}
/////////////////////////////////////////////
int main(int argc, char const *argv[]) {
  ll N, M, a, b, c;
  std::cin >> N >> M;
  ll n = 1;
  for(int i=1;i<=N;i++,n++) mp.emplace(V{i, -1}, n);
  for(int i=0;i<M;i++){
    scanf("%lld %lld %lld", &a, &b, &c);
    if(mp.find(V{a, c})==mp.end()) {
      mp.emplace(V{a, c}, n);
      G[n].push_back(edge{a, 0});
      G[a].push_back(edge{n, 1});
      n++;
    }
    if(mp.find(V{b, c})==mp.end()) {
      mp.emplace(V{b, c}, n);
      G[n].push_back(edge{b, 0});
      G[b].push_back(edge{n, 1});
      n++;
    }
    ll k = (*mp.lower_bound(V{a, c})).second;
    ll t = (*mp.lower_bound(V{b, c})).second;
    G[k].push_back(edge{t, 0});
    G[t].push_back(edge{k, 0});
  }
  dijkstra(1);
  //for(int i=1;i<=n;i++) std::cout << d[i] << '\n';
  std::cout << (d[N]==INF?-1:d[N]) << '\n';
  return 0;
}


Measured memory_bytes: 127600
#include <stdio.h>
int main(void){
	while(1){
		char number[1001];
		scanf("%s",&number);
		if(number[0]=='0'){
			break;
		}
		int sum;
		sum = 0;
		int n;
		for(n=0;number[n]!='\0';n++){
			sum += number[n] - '0';
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 536
import itertools 
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
w = 0
x = 0
S = []
T = []
for i in range(N):
    S.append(i+1)
for j in itertools.permutations(S):
    T.append(list(j))
a = T.index(P)
b = T.index(Q)
print(abs(a-b))


Measured memory_bytes: 14564
// 
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    string s,ans;
    getline(cin,s);
    ans="";
    for(int i=0;i<s.size();i++){
        if('a'<=s[i] and s[i]<='z')s[i]-='a'-'A';
        else if('A'<=s[i] and s[i]<='Z')s[i]+='a'-'A';
        ans+=s[i];
    }
    cout<<ans<<endl;
    return 0;
}


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


int main(){
	string N,a[18]={"KIHBR","AKIHBR","AKIHABR","AKIHBAR","AKIHBRA","AKIHABAR","AKIHABRA","AKIHBARA",
					"AKIHABARA","KIHABR","KIHABAR","KIHABRA","KIHABARA","KIHBAR","KIHBARA","KIHBRA"}; 
	int ans=0;
	cin >> N;
	for(int i=0; i<18; i++){
		if(N==a[i]){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

// using
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long long ull;

// assert
template <typename T>
void assert_between(T val, T min, T max)
{
    assert(min <= val && val <= max);
}

// math
// 最大公約数(Gratest Common Divisor)を求める.
template <typename T>
T gcd(T a, T b)
{
    assert(a > 0 && b > 0);
    T num1 = max(a, b);
    T num2 = min(a, b);
    T mod = num1 % num2;
    return (mod == 0) ? num2 : gcd(num2, mod);
}

// 最小公倍数(Least Common Multiple)を求める.
template <typename T>
T lcm(T a, T b)
{
    return (a * b) / gcd(a, b);
}

// 奇数の場合: 全ての要素がkで割り切れる必要がある.
int solve_odd(const int n, const int k)
{
    int num = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % k == 0) num++;
    }
    
    return pow(num, 3);
}

// 偶数の場合: 全ての要素がkで割り切れるか､余りがk/2となる必要がある.
int solve_even(const int n, const int k)
{
    int num = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % k == k / 2) num++;
    }

    return pow(num, 3) + solve_odd(n, k);
}

int main ()
{
    string STR;
    ll K;
    char tmp_buff[101];
    scanf("%s", tmp_buff); STR = tmp_buff;
    scanf("%lld", &K);
    assert_between<int>(STR.size(), 1, 100);
    assert_between<ll>(K, 1, pow(10, 18));

    size_t n = min((STR.size()), static_cast<size_t>(K));
    for (size_t i = 0; i < n; i++)
    {
        if (STR[i] >= '2') {
            printf("%c\n", STR[i]);
            return 0;
        }
    }

    printf("1\n");
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

const ll max_n = 100000;
ll bit1[max_n*2],bit0[max_n*2];

ll sum(ll i, ll* bit){
  ll s = 0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}

void add(ll i, ll x, ll* bit){
  while(i<=max_n){
    bit[i]+=x;
    i+=i&-i;
  }
}

int main(){
  ll n,q;
  cin >> n >> q;
  vector<ll> ans;
  REP(_,q){
    int a; cin >> a;
    if(!a){
      ll s,t,x; cin >> s >> t >> x;
      add(s,x,bit1);
      add(s,-x*(s-1),bit0);
      add(t+1,-x,bit1);
      add(t+1,x*t,bit0);
    }else{
      ll s,t; cin >> s >> t;
      ll res = sum(t,bit1)*t+sum(t,bit0);
      res -= sum(s-1,bit1)*(s-1)+sum(s-1,bit0);
      ans.push_back(res);
    }
  }
  for(ll out : ans){
    cout << out << endl;
  }
  return 0;
}



Measured memory_bytes: 5124
from itertools import product
N, M = map(int, input().split())

cakes = [tuple(map(int, input().split())) for _ in range(N)]

# 8通り?
ans = 0
for mask in product([1, -1], repeat=3):
    S = []
    for cake in cakes:
        s = 0
        for a, b in zip(mask, cake):
            s += a * b
        S.append((s, cake))
    S.sort(reverse=True)

    a, b, c = 0, 0, 0
    for _, (x, y, z) in S[:M]:
        a += x
        b += y
        c += z

    ans = max(ans, abs(a) + abs(b) + abs(c))

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, cnt, min = 1000000000;
    cin >> n;
    ll x;
    //vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> x;
        //v[i] = x;
        cnt = 0;
        while (x % 2 == 0) {
            x /= 2;
            cnt++;
        }
        if (cnt < min) {
            min = cnt;
        }
    }
    cout << min << endl;
    
    return 0;
}


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

int main ()
{
    string s,s11,s22;
    cin>>s;

    s11=s.substr(0,s.size()/2);
    s22=s.substr(s.size()/2,s.size());

    //cout<<s11<<endl;
    //cout<<s22<<endl;

    //sort(s22.begin(),s22.end(),greater<char>());

    //cout<<s22<<endl;
    int c=0;

    for(int i=0;i<s11.size();i++)
    {
        if(s11[i]!=s22[s22.size()-i-1])
        {
            c++;
        }
    }

    cout<<c<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int n, a;
int arr[100005];
int dp[100005];

int costo(int x, int y)
{
    return abs(x - y);
}

void inicializar()
{
    for(int i = 0; i < n + 3; i++)
    {
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
}

void imprimir(int a[])
{
    for(int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

int solution_botton_up()
{
    inicializar();
    for(int i = 0; i < n; i++)
    {
        int x = costo(arr[i], arr[i + 1]);
        int y = costo(arr[i], arr[i + 2]);

        dp[i + 1] = min(dp[i] + x, dp[i + 1]);
        dp[i + 2] = min(dp[i] + y, dp[i + 2]);
    }
    //imprimir(dp);
    return dp[n - 1];
}

int main()
{
    cin >> n;

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

    int resp = solution_botton_up();

    cout << resp << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, M;
  cin >> H >> W >> M;
  vector <pair <int, int>> bombs(M);
  for (int i = 0; i < M; i++) {
    cin >> bombs[i].first >> bombs[i].second;
    bombs[i].first--, bombs[i].second--;
  }
  vector <int> r(H), c(W);
  multiset <int> ms;
  vector <vector <int>> g(W);
  for (int i = 0; i < M; i++) {
    g[bombs[i].second].push_back(bombs[i].first);
    r[bombs[i].first]++;
    c[bombs[i].second]++;
  }
  for (int i = 0; i < H; i++)
    ms.insert(r[i]);
  int ans = 0;
  for (int col = 0; col < W; col++) {
    for (auto &now : g[col]) {
      ms.erase(ms.find(r[now]));
      ms.insert(r[now] - 1);
    }
    ans = max(ans, c[col] + *ms.rbegin());
    for (auto &now : g[col]) {
      ms.erase(ms.find(r[now] - 1));
      ms.insert(r[now]);
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 38292
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
# @lru_cache(None)






n=l()[0]
s=input()

A=[0 for i in range(n+1)]
B=[0 for i in range(n+1)]
for i in range(n):
    if(s[i]=="W"):
        A[i+1]=A[i]+1
    else:
        A[i+1]=A[i]
for i in range(n-1,-1,-1):
    B[i]=B[i+1]+(s[i]=="E")
ans=min(A[i]+B[i] for i in range(n+1))
print(ans)


Measured memory_bytes: 28504
import sys
for line in sys.stdin:
    a, b, c, d, e, f = map(int, line.split())
    x = (c*e - b*f) / (a*e - b*d)
    y = (a*f - c*d) / (a*e - b*d)
    if x == -0.0:
        x = 0
    if y == -0.0:
        y = 0
    print('{:.3f} {:.3f}'.format(x, y))

Measured memory_bytes: 7532
#include<iostream>
#include<string>
#define in register int
using namespace std;
signed main()
{
	register string h;
//	in n;
//	cin>>n;
//	while(n--)
//	{
		cin>>h;
		if(h.size()>=3)
		{
			cout<<h[0]<<h.size()-2<<h[h.size()-1]<<endl;
		}
		else cout<<h<<endl;
//	}
	return 0;
}

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

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

using C = pair<ld, P>;
#define rad first
#define pnt second

template <class iter>
std::pair<P, ld> min_ball(iter left, iter right, int seed = 1333) {
  const int n = right - left;

  assert(n >= 1);
  if (n == 1) {
    return {*left, ld(0)};
  }

  std::mt19937 mt(seed);
  std::shuffle(left, right, mt);
  // std::random_shuffle(left, right); // simple but deprecated

  iter ps = left;
  using circle = std::pair<P, ld>;

  auto make_circle_3 = [](const P &a, const P &b, const P &c) -> circle {
                         ld A = std::norm(b - c), B = std::norm(c - a), C = std::norm(a - b),
                           S = cross(b - a, c - a);
                         P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
                         ld r2 = std::norm(p - a);
                         return {p, r2};
                       };

  auto make_circle_2 = [](const P &a, const P &b) -> circle {
                         P c = (a + b) / (ld)2;
                         ld r2 = std::norm(a - c);
                         return {c, r2};
                       };

  auto in_circle = [](const P &a, const circle &c) -> bool {
                     return std::norm(a - c.first) <= c.second + eps;
                   };

  circle c = make_circle_2(ps[0], ps[1]);

  // MiniDisc
  for (int i = 2; i < n; ++i) {
    if (!in_circle(ps[i], c)) {
      // MiniDiscWithPoint
      c = make_circle_2(ps[0], ps[i]);
      for (int j = 1; j < i; ++j) {
        if (!in_circle(ps[j], c)) {
          // MiniDiscWith2Points
          c = make_circle_2(ps[i], ps[j]);
          for (int k = 0; k < j; ++k) {
            if (!in_circle(ps[k], c)) {
              c = make_circle_3(ps[i], ps[j], ps[k]);
            }
          }
        }
      }
    }
  }
  return c;
}

signed main(){
  int n;
  cin>>n;
  G ps(n);
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    ps[i]=P(x,y);
  }
  cout<<fixed<<setprecision(12);
  cout<<sqrt(min_ball(ps.begin(),ps.end()).second)<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	D := sc.Next()

	ans := ""
	count := 0
	for i := 0; i < N; i++ {
		if D[i] == '(' {
			count++
		} else {
			count--
			if count < 0 {
				ans = "(" + ans
				count = 0
			}
		}
		ans += string(D[i])
	}
	if count > 0 {
		ans += strings.Repeat(")", count)
	}
	fmt.Println(ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll MAXN = 8020;

int main()
{
  string s;
  cin >> s;
  int x,y;
  cin >> x >> y;

  vector<int> t;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'T'){
      if(cnt != 0) t.push_back(cnt);
      t.push_back(0);
      cnt = 0;
    }else{
      cnt++;
      if(i == s.size()-1) t.push_back(cnt);
    }
  }

  set<int> pos_x,pos_y;
  pos_x.insert(0);
  pos_y.insert(0);
  bool xy = true;
  for(int i = 0; i < t.size(); i++){
    set<int> pos;
    if(t[i] == 0) xy = !xy;
    else if(xy){
      for(auto itr = pos_x.begin(); itr != pos_x.end(); itr++){
        pos.insert(*itr+t[i]);
        if(i!=0) pos.insert(*itr-t[i]);
      }

      pos_x = pos;
    }else{
      for(auto itr = pos_y.begin(); itr != pos_y.end(); itr++){
        pos.insert(*itr+t[i]);
        if(i!=0) pos.insert(*itr-t[i]);
      }
      pos_y = pos;
    }
  }

  // for(auto itr = pos_x.begin(); itr != pos_x.end(); itr++){
  //       cout << *itr << endl;
  // }

  cout << ((pos_x.find(x) != pos_x.end() && pos_y.find(y) != pos_y.end()) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define p32 pair <int,int>
#define p64 pair <ll,ll>
#define mp make_pair
using namespace std;

const int M=1e9+7;
const int NM=2e5;

double dp[3000][3000];

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

    ///dp[i][j]=p-billity to get j heads from i tosses

    dp[0][0]=1;
    for(int i=1; i<=n; i++)
    {   double x;
        cin>>x;
        dp[i][0]=(1-x)*dp[i-1][0];
        for(int j=1; j<=n; j++)
            dp[i][j]=x*dp[i-1][j-1]+(1-x)*dp[i-1][j];
    }
    double sol=0;
    for(int j=1; j<=n; j++)
        if(j>n-j)
            sol+=dp[n][j];
    cout<<fixed<<setprecision(10)<<sol;
    return 0;
}

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

int n; ll ans,pw[29],mx[29][29];
void solve(int l,int r,ll now,ll tmp,bool flag){
	if (l>r){
		if (!now) ans+=tmp; return;
	}
	if (abs(now)>mx[l][r]) return;
	int i,x;
	for (i=-9; i<=9; i++){
		if (l==r && i!=0) continue;
		x=(flag)?10:9; x-=abs(i);
		if (x) solve(l+1,r-1,now+i*(pw[r]-pw[l]),tmp*x,1);
	}
}
int main(){
	scanf("%d",&n);
	int i,j;
	for (i=pw[0]=1; i<=17; i++) pw[i]=pw[i-1]*10;
	for (i=17; i>=0; i--)
		for (j=i; j<=17; j++) mx[i][j]=mx[i+1][j-1]+9*(pw[j]-pw[i]);
	for (i=0; i<=17; i++) solve(0,i,n,1,0);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

ll modpow(ll n,ll k){
	ll ret=1;
	for(int i=0;i<k;i++)ret=ret*n%MOD;
	return ret%MOD;
}

int main(){
	init();
	ll N,Y;cin>>N>>Y;
	for(ll s=0;s<=N;s++){
		for(ll t=0;t+s<=N;t++){
			ll u=N-s-t;
			if(1000*s+5000*t+10000*u==Y){
				cout<<u<<" "<<t<<" "<<s<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
}



Measured memory_bytes: 256
#![allow(unused_imports)]
use petgraph::{graph::UnGraph, graphmap::UnGraphMap, Direction};
use proconio::{input, marker::Usize1};
use std::collections::HashSet;

fn main() {
    input! {
        x: i64,
    };
    for b in -120i64..120i64 {
        for a in (b+1)..120 {
            if a.pow(5) - b.pow(5) == x {
                println!("{} {}", a, b);
                return;
            }
        }
    }
}


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

int main() {
  int H,W,K;
  int ans = 0;
  
  cin >> H >> W >> K;
  vector<vector<char>> vec(H,vector<char>(W));
  for(int i=0;i<H;++i){
    for(int j=0;j<W;++j){
      cin >> vec.at(i).at(j);
    }
  } 

  for(int tmp = 0;tmp < (1 << H);tmp++){
    bitset<6> s(tmp);
    vector<bool> high(H);
    for(int i=0;i<H;++i){
      if(s.test(i)){
        high.at(i) = true;
      }
    }
    for(int kas = 0;kas < (1 << W);++kas){
      bitset<6> k(kas);
      vector<bool> wide(W);
      int sum = 0;
      for(int i=0;i<W;++i){
        if(k.test(i)){
          wide.at(i) = true;
        }
      }
      for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
          if(!high.at(i) && !wide.at(j) && vec.at(i).at(j) == '#'){
            sum += 1;
          }
        }
      }
      if(sum == K) ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int group[12]={0,2,0,1,0,1,0,0,1,0,1,0};
    int x,y;
    cin>>x>>y;
    cout<<((group[x-1]==group[y-1])?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int n, m;
    cin >> n >> m;
    vi s(n), c(n);
    rep(i, m) {
        cin >> s[i] >> c[i];
        s[i]--;
    }

    rep(i, 1000) {
        string t = to_string(i);
        bool ok = true;
        if(t.size() != n) continue;
        rep(j, m) if(t[s[j]] != (char)(c[j] + '0')) ok = false; 
        if(ok) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N;
  while(cin >> N){
    vector<LLI> d(N); cin >> d;
    sort(ALL(d));

    int ans = d[N/2] - d[N/2-1];
    
    cout << ans << endl;
    
  }

  
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
a = list(map(int,input().split()))
x = dict()
y = []
if N==1:
    S = "1"+" "+"1"
    print(S)
    exit()
for i in range(N):
    if a[i]<=399:
        x["gray"] = 1
    elif a[i]<=799:
        x["brown"] = 1
    elif a[i]<=1199:
        x["green"] = 1
    elif a[i] <=1599:
        x["lightblue"] = 1
    elif a[i] <= 1999:
        x["blue"] = 1
    elif a[i]<=2399:
        x["yellow"] = 1
    elif a[i]<=2799:
        x["orange"] = 1
    elif a[i]<=3199:
        x["red"] = 1
    else:
        y.append(a[i])

ans = 0
for idx in x:
    ans += 1
n = len(y)
m = ans
M = ans + n
s = ""
if m==0:
    m=1
s = str(m)+" "+str(M)
print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define debug(a) cout <<  #a << " = " << a << endl;
using ll = long long;
using namespace std;

const ll inf = 100000000000000;
const int N = 100;
int w[N],v[N];
ll dp[200000];

// here dp[i] = minimum weight to make value exactly i 

int main(int argc, char const *argv[])
{
    int cap = 0,n;
    for(int i =0 ;i < 200000;i++)dp[i] = inf;
    // here dp[i] = minimum weight to make value exactly i 
    scanf("%d%d",&n,&cap);
    dp[0] = 0;
    for(int i = 0; i < n;i++){
        scanf("%d %d",&w[i],&v[i]);
        for(int x = 100000;x>=0;x--){
            if(x-v[i]>=0){
                dp[x] = min(dp[x],dp[x-v[i]]+w[i]);
            }
        }
    }
    ll ans = 0;
    //for(int i = 0; i <= 200;i++){
       // printf("%d = %lld\n",i,dp[i]);
    //}
    for(int i = 100004 ; i >=0 ; i--){
        if(dp[i] <= cap){ans = i;break;}
    }   
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1792
import math
N, M = [int(i) for i in input().split()]

def yakusu(m):
    y = []
    for i in range(1, math.ceil(math.sqrt(m))+1):
            if m % i == 0:
                y.extend([i, m//i])
    return y

if M % N == 0:
    print(M//N)
else:
    yaku = sorted(yakusu(M))
    for yi in yaku:
        if yi < N:
            continue
        else:
            break
    print(M//yi)

Measured memory_bytes: 3064
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    V, E, r = readi(3)
    edges = readi(E, 3)
    dist = arr(V, fill_value=INF)
    dist[r] = 0
    for i in range(V):
        for a, b, c in edges:
            new_d = dist[a] + c
            if new_d < dist[b]:
                dist[b] = new_d
                if i == V - 1:
                    print("NEGATIVE CYCLE")
                    return
    for i in range(V):
        print("INF" if dist[i] == INF else dist[i])


if __name__ == "__main__":
    main()



Measured memory_bytes: 7156
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#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, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 10000000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;

    vector<pair<long long, long long> > prm;

    prm=prime_factorize(m);
    
    ll ans=1;
    for(auto e:prm){
        //cout<<e.first<<' '<<e.second<<endl;
        ans*=COM(e.second+n-1,n-1)%MOD;
        ans%=MOD;
    }
    
    cout<<ans%MOD<<endl;
    

}

Measured memory_bytes: 234624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int N = in.nextInt();
            long[] k = new long[N + 1];
            long ans = 0;
            for (int i = 1; i <= N; i++) {
                int cn = i;
                while (cn <= N) {
                    k[cn]++;
                    cn += i;
                }
                ans += i * k[i];
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



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

int selectionSort (vector<int> &A, int N) {
  int sw = 0;
  int i = 0;
  for (i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (A.at(j) < A.at(minj)) {
        minj = j;
      }
    }
    if (i != minj) {
      swap(A.at(i), A.at(minj));
      sw++;
    }
  }
  return sw;
}
  
int main() {
  int N, sw;
  cin >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }  
  
  sw = selectionSort(A, N);
  
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    cout << A.at(i);
  }
  cout << endl;
  cout << sw << endl;
}



Measured memory_bytes: 3084
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import collections

N = int(input())
val = collections.Counter(prime_factorize(N))
val = {key:cnt for key,cnt in val.most_common()} 
if val=={}:
    print(0)
else:
    prev_ans = -1
    cnt = 1
    ans = 0
    while ans!=prev_ans:
        prev_ans = ans
        for key in val:
            if val[key]>=cnt:
                val[key]-=cnt
                ans+=1
        cnt+=1
    print(ans)

Measured memory_bytes: 9476
import sys
from collections import defaultdict
import numpy as np


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


MOD = 10 ** 9 + 7
n = int(sys.stdin.buffer.readline())
ab = list(map(int, sys.stdin.buffer.read().split()))
aaa = ab[0::2]
bbb = ab[1::2]
max_a = max(aaa)
max_b = max(bbb)
facts, invs = prepare(2 * (max_a + max_b), MOD)
dp_size = max_b * 2 + 1
ans = 0

dd_create_func = lambda: np.zeros(dp_size, dtype=np.int64)
get_ab = defaultdict(dd_create_func)
for a, b in zip(aaa, bbb):
    get_ab[a][b + max_b] += 1
    ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD

dp = np.zeros(dp_size, dtype=np.int64)
for i in range(-max_a, max_a + 1):
    if i < 0 and -i in get_ab:
        dp += get_ab[-i][::-1]
    dp = np.add.accumulate(dp) % MOD
    if i > 0 and i in get_ab:
        ans = (ans + (dp * get_ab[i]).sum()) % MOD

print(ans * invs[2] % MOD)


Measured memory_bytes: 91356
s = gets.chomp.to_s
ans = 0
previous_a_count = 0

# s を先頭から検索し "ABC" が含まれる限り、繰り返す
while s.index("ABC") do
  # 前半の文字列を "....A" とする
  former_s = s[0..s.index("ABC")]
  # 後半の文字列を "BC...." とする
  latter_s = s[s.index("ABC") + 1 ..s.length]
  a_count = 0
  bc_count = 0

  # 前半の文字列の末尾に "A" が何回連続で出現するか調べる
  while former_s.end_with?("A") do
    # 出現した "A" は削除する
    former_s.slice!(former_s.length - 1)
    a_count += 1
    # 削除した "A" を moved_a に格納しておく
  end

  # 後半の文字列の先頭に "BC" が何回連続で出現するか調べる
  while latter_s.start_with?("BC") do
    # 出現した "BC" は削除する
    latter_s.slice!(0, 2)
    bc_count += 1
  end

  if a_count - s.index("ABC") == 1
    a_count += previous_a_count
  end

  # "A" の出現回数と "BC" の出現回数をかけ合わせ、 ans に加算する
  # （例えば "AAABCBC" なら、"BCBCAAA" になるまで6回の操作が必要である）
  ans += a_count * bc_count

  # 次回のループには、 moved_a + 後半の文字列を用いる
  # （前半の文字列には "ABC" は含まれていないため）
  s  = latter_s
  previous_a_count = a_count

end

puts ans

Measured memory_bytes: 102824
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

int N;
vector<int> t,v;

vector<int> define_path(){
	vector<int> path(accumulate(t.begin(),t.end(),1));
	int x = 0;
	int T = 0;

	for(int i=0;i<N;i++){
		path[T] = min(x, v[i]);
		for(int j=T+1;j<=T+t[i];j++){
			path[j] = min(x+1,v[i]);
			x = min(x+1,v[i]);
		}
		T += t[i];
	}


	//cout << T+1 << " = " << path.size() << endl;

	x = 0;
	for(int i=N-1;0<=i;i--){
		path[T] = min(x,path[T]);
		for(int j=T-1;T-t[i]<=j;j--){
			path[j] = min(x+1,path[j]);
			x = min(x+1,path[j]);
		}
		T -= t[i];
	}

	return path;


}

int solve(){
	vector<int> path = define_path();

	//for(auto u:path) cout << u << endl;

	double ans = accumulate(path.begin(), path.end(),0)/4.0;

	printf("%.9f\n", ans);
	return 0;
}

int main(){
	cin >> N;
	t.resize(N);
	for(int i=0;i<N;i++){
		cin >> t[i];
		t[i] *= 2;
	}

	v.resize(N);
	for(int i=0;i<N;i++){
		cin >> v[i];
		v[i] *= 2;
	}

	solve();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	REP(i, n) cin >> h[i];
	vector<vector<int> > G(n);
	REP(i, m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	REP(i, n){
		bool f = true;
		for(auto j : G[i]){
			if(h[i] <= h[j]){
				f = false;
				break;
			}
		}
		if(f) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 9796
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = int(input())

s = list(range(1,N+1,2))
ans = 0
for i in s:

    if len(make_divisors(i)) == 8:
        ans += 1
print(ans)

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	int n;
	cin>>n;
	vector<int> p(n);
	REP(i,n){
		cin>>p[i];
	}
	int ans=0;
	FOR(i,1,n-1){
		if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1]))ans++;
	}
	cout << ans << endl;

	return 0;
}

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

void
solver(int n)
{
    int p;

    p = n/1.08;
    if (p*1.08-n)
        p++;
    if (n!=(int)(p*1.08)) {
        printf(":(\n");
    }
    else {
        printf("%d\n", p);
    }
    return;
}

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

    scanf("%d", &n);
    solver(n);
    return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize("03", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(i,n) for(i=0;i<n;i++)
#define FORn(i,j,n) for(i=j;i<n;i++)
#define pb push_back
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define vli vector<lli>
#define vi vector<int>
#define vs vector<string>
#define vprint(v) for(auto t:v)cout<<t<<" "
#define endl "\n"

typedef long long int lli;
typedef long int li;

const lli mod=1000000007;
const lli limit=1000000;

using namespace std;

void fc(lli &x)
    {
        bool neg=false;
        register char c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    }

int main() {

    fast()
    lli n,q,t;
    lli temp,temp1,temp2,temp3;
    lli i,j,k;
    string s;
    cin>>n;
    temp=(n/500)*1000 + ((n%500)/5)*5;
    cout<<temp<<endl;

 
}

Measured memory_bytes: 256
H, W = map(int, input().split())
C = [[j for j in input()] for i in range(H)]
C2 = [['' for j in range(W)] for i in range(2*H)]
for i in range(2*H):
    for j in range(W):
        C2[i][j] = C[i//2][j]
for i in range(2*H):
    print(''.join(C2[i]))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  vector<int> a(4);
  for (int i = 0; i < 4; i++) a[i] = s[i] - '0';

  for (int i = 0; i < (1 << 3); i++) {
    int total = a[0];
    for (int j = 0; j < 3; j++) {
      if (i & (1 << j)) total += a[j+1];
      else total -= a[j+1];
    }
    if (total == 7) {
      char op1 = (i & (1 << 0)) ? '+' : '-';
      char op2 = (i & (1 << 1)) ? '+' : '-';
      char op3 = (i & (1 << 2)) ? '+' : '-';
      cout << a[0] << op1 << a[1] << op2 << a[2] << op3 << a[3] << "=7" << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;

int main(){
    int n; cin >> n;
    int s[n], l[n], p[n]; rep(i, n) cin >> s[i] >> l[i] >> p[i];
    int m; cin >> m;
    int w[m]; rep(i, m) cin >> w[i];
    int dp[n+1][410];
    rep(i, n+1)rep(j, 400) dp[i][j] = -1;
    dp[0][0] = 0;
    rep(i, n)rep(j, 394)if(dp[i][j] >= 0){
        dp[i+1][j] = dp[i][j];
        For(k, s[i], l[i]+1) dp[i][min(j+k, 400)] = max(dp[i][min(j+k, 400)], dp[i][j] + p[i]);
    }
    int ans[m];
    rep(i, m){
        ans[i] = dp[n][w[i]];
        if(ans[i] == -1){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i, m) cout << ans[i] << endl;
}


Measured memory_bytes: 3700
N = gets.to_i
A = gets.split.map(&:to_i)

odd, even = 2.times.map{ Hash.new(0) }

A.each_with_index do |v,i|
  if i.odd?
    odd[v] += 1
  else
    even[v] += 1
  end
end

co = N / 2
ce = N - co

wo = odd.max_by(2){|k,v| v}
we = even.max_by(2){|k,v| v}

if we.size == 1 && wo.size == 1 && we.first[0] == wo.first[0]
  puts [we.first[1], wo.first[1]].min
else
  puts [ 
      we.first[0] == wo.first[0] ? N : ce - we.first[1] + co - wo.first[1], 
      we.first[0] == wo.last[0]  ? N : ce - we.first[1] + co - wo.last[1] ,
      we.last[0]  == wo.first[0] ? N : ce - we.last[1]  + co - wo.first[1],
      we.last[0]  == wo.last[0]  ? N : ce - we.last[1]  + co - wo.last[1] 
    ].min
end


Measured memory_bytes: 17172
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a <= b){
        for(int i=0; i<b; i++){
            cout << a;
        }
    }else{
        for(int i=0; i<a; i++){
            cout << b;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
a_excluing_index_number = []
ans = a.last
median_number = a.first

a.each_with_index do |ai , i|
  a_excluing_index_number[i] = ai - (i + 1)
end

median_number = (n % 2).zero? ? a_excluing_index_number.sort[n / 2 - 1, 2].inject(:+) / 2 : a_excluing_index_number.sort[n / 2]

puts a_excluing_index_number.map{|ae| (ae - median_number).abs }.inject(:+)

Measured memory_bytes: 20808
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
#define what(x) cerr << #x << " is " << x << endl;
const int INF = 1 << 30;
ll h[100010];
ll dp[100100];

int main() {
    int N, K;
    cin >> N >> K;
    // vl h(N + K, 0);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    // vl dp(N + K, INF);
    for (int i = 0; i < 100100; ++i) {
        dp[i] = INF;
    }
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            dp[i + j] = min(dp[i + j], abs(h[i] - h[i + j]) + dp[i]);
        }
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define N 20000
int main()
{
  int a,b,i,count;
  int data[N];
  char op;

  count=0;

  while(1)
  {
    scanf("%d %c %d",&a,&op,&b);
    if(op=='?') break;
    if(op=='+') data[count]=a+b;
    if(op=='-') data[count]=a-b;
    if(op=='*') data[count]=a*b;
    if(op=='/') data[count]=a/b;
    count++;
  }

  for(i=0;i<count;i++)
  {
    printf("%d\n",data[i]);
  }

  return 0;
}

Measured memory_bytes: 608