akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;

template<typename T> T maximum(T head, T tail) { return std::max(head, tail); }
template<typename Head, typename... Tail> Head maximum(Head head, Tail... tail) {
  return std::max(head, maximum(tail...));
}

template<typename T> T minimum(T head, T tail) { return std::min(head, tail); }
template<typename Head, typename... Tail> Head minimum(Head head, Tail... tail) {
  return std::min(head, minimum(tail...));
}

// print(x, y, z);
// printVec(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << *it << " ";
    if ((it - begin) % 20 == 19 || it == end - 1) { std::cout << std::endl; }
  }
}

int main(int argc, char* argv[])
{
  ll N, K;
  std::cin >> N >> K;
  std::vector< ll > vx(N, 0LL);
  std::vector< ll > vdist1;
  std::vector< ll > vdist2;

  ll pos = -1;
  for (ll i = 0; i < N; i++) {
    std::cin >> vx[i];
    if (vx[i] < 0) pos = i;
  }

  vdist1.push_back(0LL);
  for (ll i = pos; i >= 0; i--) {
    vdist1.push_back(std::abs(vx[i]));
  }
  //printVec(vdist1.begin(), vdist1.end());

  vdist2.push_back(0LL);
  for (ll i = pos+1; i < N; i++) {
    vdist2.push_back(vx[i]);
  }
  //printVec(vdist2.begin(), vdist2.end());

  ll ans = INF;
  for (ll i = 0; i <= K; i++) {
    if (i >= (ll)vdist1.size()) continue;
    if (K-i >= (ll)vdist2.size()) continue;
    ll res1 = vdist1[i] * 2 + vdist2[K-i] * 1;
    ll res2 = vdist1[i] * 1 + vdist2[K-i] * 2;
    ans = minimum(ans, res1, res2);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2);
  return x*POW(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n,a[300000],k,l,b[300000],ans;
  cin >> n;
  rep(i,n)b[i]=0;
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  per(i,32){
    k=0;
    l=n-1;
    while(k<l){
      if(b[k]==0&&b[l]==0&&a[k]+a[l]==POW(2,i)){b[k]=1;
                                                b[l]=1;
                                                k++;
                                                l--;
                                               }
      else if(a[k]+a[l]==POW(2,i)){if(b[k]==1)k++;
                                   if(b[l]==1)l--;
                                  }
      else if(a[k]+a[l]>POW(2,i))l--;
      else k++;
    }
  }
  ans=0;
  rep(i,n)if(b[i]==1)ans++;
  printf("%lld",ans/2);
}

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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

#define MAX_V 200005
struct edge {
	int to;
	int cost;
};
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.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;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;

	cin >> n >> m;

	ll a, b;
	rep(i, m) {
		cin >> a >> b;
		edge e;
		e.cost = 1;

		e.to = b;
		G[a].push_back(e);
		e.to = a;
		G[b].push_back(e);
	}

	dijkstra(1);
	if (d[n] == 2) {
		s_ans = "POSSIBLE";
	}
	else {
		s_ans = "IMPOSSIBLE";
	}

	cout << s_ans << "\n";
}

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

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 18564
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  vector<int> P(N);
  vector<int> Q(N);
  for(int i = 0; i < N; ++i) cin >> P[i];
  for(int i = 0; i < N; ++i) cin >> Q[i];
  iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
  int num = 1;
  int pnum = 1;
  int qnum = 1;
  do {
    if(v == P) pnum = num;
    if(v == Q) qnum = num;
    num++;
  } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成
  cout << abs(pnum - qnum) << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

f = [i for i in range(N)]
left, right = 0, 0
ans = 0
nowxor = 0
nowsum = 0
for left in range(N):
    while right < N and nowxor ^ A[right] == nowsum + A[right]:
        nowsum += A[right]
        nowxor = nowxor ^ A[right]
        right += 1
    ans += right - left
    if left == right:
        right += 1
    else:
        nowsum -= A[left]
        nowxor = nowxor ^ A[left]
print(ans)

Measured memory_bytes: 86988
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<algorithm>
#include<unordered_map>
 
#include<unordered_map>
#include<algorithm>
#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
 
#define ii pair<long long,long long>
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>

#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
#define mid l + ( (r-l)>>1)
 
using namespace std;

 
typedef long long ll;
typedef vector< int> vi;
typedef long double ld;

const int MAX = 1e2 + 10;
const int maxn = 1e6+100;

 

int n, a[maxn];

int main (){
	//~ in
	cin >> n;
	long long sum = 0;
	for(int i = 0;i < n;i++)
		cin >> a[i];
	
 
	for(int i = 0;i < n;i++)
		for(int j = i + 1;j < n;j++)
			sum += a[i]*a[j];
			
		cout << sum << '\n';
}




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

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

    queue<ll> q;
    q.push(1);
    q.push(2);
    q.push(3);
    q.push(4);
    q.push(5);
    q.push(6);
    q.push(7);
    q.push(8);
    q.push(9);

    ll tmp;
    int rem;
    rep(i,k) {
        tmp = q.front(); q.pop();
        rem = tmp % 10;
        if (rem == 0) {
            q.push(tmp*10+rem);
            q.push(tmp*10+rem+1);
        } else if (rem == 9) {
            q.push(tmp*10+rem-1);
            q.push(tmp*10+rem);
        } else {
            q.push(tmp*10+rem-1);
            q.push(tmp*10+rem);
            q.push(tmp*10+rem+1);
        }
        
        if (i == k-1) {
            cout << tmp << endl;
        }
        
    }
	return 0;
}

Measured memory_bytes: 1792
function Main(input) {
  input = input.trim().split("\n");
  const [R, C, n] = input.shift().split(" ").map((a) => parseInt(a, 10));
  const values = input.map((a) => a.split(" ").map((b) => parseInt(b, 10)));

  let i, j, k;
  a = [];
  dp = [];

  for (let i=0; i<n; i++) {
    const [r, c, v] = values[i];
    a[r - 1] = a[r - 1] || [];
    a[r - 1][c - 1] = v;
  }

  for (i=0; i<R; i++) {
    dp[i] = dp[i] || [];
    dp[i+1] = dp[i+1] || [];
    for (j=0; j<C; j++) {
      dp[i][j] = dp[i][j] || [0, 0, 0, 0];
      dp[i][j+1] = dp[i][j+1] || [0, 0, 0, 0];
      dp[i+1][j] = dp[i][j] || [0, 0, 0, 0];
      for (k = 2; k >= 0; k--) {
        dp[i][j][k+1] = Math.max(dp[i][j][k+1], dp[i][j][k]  + (a[i] && a[i][j] || 0));
      }
      for (k = 0; k<4; k++) {
        dp[i+1][j][0] = Math.max(dp[i+1][j][0], dp[i][j][k]);
        dp[i][j+1][k] = Math.max(dp[i][j+1][k], dp[i][j][k]);
      }
    }
  }

  let ans = 0;
  for (k = 0; k<4; k++) {
    ans = Math.max(ans, dp[R-1][C-1][k]);
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 202572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> a;
  vector<int> tmp_wa;

  rep(i, n + 1) {
    a.push_back(false);
    tmp_wa.push_back(0);
  }

  int ac = 0;
  int wa = 0;

  rep(i, m) {
    int p;
    string s;

    cin >> p >> s;

    if (a[p] == false) {
      if (s == "AC") {
        ac++;
        wa += tmp_wa[p];
        a[p] = true;
      } else {
        tmp_wa[p]++;
      }
    }
  }

  cout << ac << " " << wa << endl;
  return 0;
}


Measured memory_bytes: 892
#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 (Itr) = a; (Itr) < b; (Itr) += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)

#include "bits/stdc++.h"
using i64 = long long;
using namespace std;

int main() {
    string s;
    cin >> s;
    if (s.back() == 's') {
        cout << s << "es" << endl;
    }
    else {
        cout << s << "s" << endl;
    }
    return 0;
};


Measured memory_bytes: 3592
#include <iostream>
#include <climits>
#include <algorithm>


using namespace std;

int main() {
  long long a, b, c, d;
  long long result = LLONG_MIN;
  cin >> a >> b >> c >> d;
  result = max(a*c, a*d);
  result = max(result, b*c);
  result = max(result, b*d);
  cout << result << endl;
}

Measured memory_bytes: 3628
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    H = list(map(int, rl().split()))
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].append(b)
        graph[b].append(a)
    
    ans = 0
    for i in range(N):
        flg = True
        for child in graph[i]:
            if H[i] <= H[child]:
                flg = False
        ans += flg
    print(ans)


if __name__ == '__main__':
    solve()


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

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    vector<int> A(N + 2);
    A[0] = A[N + 1] = 0;
    REP(i, N){scanf("%d", &(A[i + 1])); getchar();}
    ll sum = 0;
    REP(i, N + 1){
        sum += abs(A[i + 1] - A[i]);
    }
    REP(i, N){
        // if (0 <= (A[i] - A[i + 1]) * (A[i + 1] - A[i + 2])){
        cout << sum + abs(A[i + 2] - A[i]) - abs(A[i + 1] - A[i]) - abs(A[i + 2] - A[i + 1]) << endl;
    }
}


Measured memory_bytes: 1664
#region using
using System;
using System.Collections.Generic;
using System.Linq;
using IEnumerable = System.Collections.IEnumerable;
using IEnumerator = System.Collections.IEnumerator;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;
#endregion

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            return Math.Max(consoleReader.Int * consoleReader.Int, consoleReader.Int * consoleReader.Int);
        }

        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    static class Ext
    {
        public static Dictionary<TKey, int> GroupCount<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) => source.GroupBy(keySelector).ToDictionary(g => g.Key, g => g.Count());
        public static Dictionary<TKey, int> GroupCount<TKey>(this IEnumerable<TKey> source) => source.GroupCount(i => i);
    }
    public class ConsoleReader { private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); private string[] line = Array.Empty<string>(); private int linePosition; private TextReader textReader; public ConsoleReader(TextReader tr) { textReader = tr; } public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string String { get { if (linePosition >= line.Length) { linePosition = 0; line = ReadLineSplit(); } return line[linePosition++]; } } public class SplitLine { private string[] splited; public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); } public int[] Int => String.Select(x => int.Parse(x)).ToArray(); public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray(); public long[] Long => String.Select(x => long.Parse(x)).ToArray(); public double[] Double => String.Select(x => double.Parse(x)).ToArray(); public string[] String => splited; } public SplitLine Split => new SplitLine(this); public class RepeatReader : IEnumerable<ConsoleReader> { ConsoleReader cr; int count; public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; } public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); public IEnumerable<string> String => this.Select(cr => cr.String); public IEnumerable<int> Int => this.Select(cr => cr.Int); public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1); public IEnumerable<long> Long => this.Select(cr => cr.Long); public IEnumerable<double> Double => this.Select(cr => cr.Double); } public RepeatReader Repeat(int count) => new RepeatReader(this, count); }
    #endregion
}


Measured memory_bytes: 11220
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

int main(){
    string s;
    cin>>s;
    int l= s.length();
    int ss[100007];
    int ssa[100007];
    rep(i,100007){
        ssa[i]=0;
    }
    rep(i,l-1){
        if(s[l-i-2]=='R'){
            if(s[l-i-1]=='L'){
                ss[l-i-2]=l-i-2;
            }else{
                ss[l-i-2]=ss[l-i-1];
            }
        }
    }
    rep(i,l-1){
        if(s[i+1]=='L'){
            if(s[i]=='R'){
                ss[i+1]=i+1;
            }else{
                ss[i+1]=ss[i];
            }
        }
    }
    rep(i,l){
        if(i%2==(ss[i]%2)){
            ssa[ss[i]]++;
        }else{
            if(s[i]=='R'){
                ssa[ss[i]+1]++;
            }else{
                ssa[ss[i]-1]++;    
            }
        }
    }

    rep(i,l){
        if(i!=l-1){
            cout<<ssa[i]<<" ";
        }else{
            cout<<ssa[i]<<endl;
        }
    }
}

Measured memory_bytes: 1408
#!/usr/bin/env fsharpi

open System;

let readIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let readInt1 ( str : string ) =
    readIntN str |> fun arr -> arr.[0]

let readInt2 ( str : string ) =
    readIntN str |> fun arr -> (arr.[0],arr.[1])

let readInt3 ( str : string ) =
    readIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let rec powMod (a: int64) (b : int64) (c : int64) =
    if b = 0L then 1L
    else if ( b % 2L ) = 1L then ( a * ( powMod a (b - 1L) c ) ) % c
    else 
        let d = powMod a (b / 2L ) c
        ( d * d ) % c

let check1 ( l : int array ) =
    let offset = l.Length % 2
    if offset = 1 && l.[0] <> 0 then false else true

let check2 ( l : int array ) =
    let offset = l.Length % 2
    let evens = seq { for i in offset .. 2 .. l.Length - 1 -> l.[i] }
    let odds = seq { for i in offset + 1 .. 2 .. l.Length - 1 -> l.[i] }
    Seq.fold (&&) true ( Seq.zip evens odds |> Seq.map (fun (a,b) -> a =b ) )

let check3 ( l : int array ) =
    let offset = l.Length % 2
    let v = seq { for i in offset .. 2 .. l.Length - 1 -> l.[i] }
    let e = seq { for i in offset + 1 .. 2 .. l.Length - 1 -> i }
    Seq.fold (&&) true ( Seq.zip v e |> Seq.map (fun (a,b) -> a = b ) )

let calc ( l : int array ) =
    let width : int64 = int64( l.Length - ( l.Length % 2 ) )
    powMod 2L ( width / 2L ) 1000000007L

let n = readInt1 <| Console.ReadLine()
let v = Array.sort ( readIntN <| Console.ReadLine() )
let res = if (check1 v) && (check2 v) && (check3 v) then ( calc v ) else 0L
Console.WriteLine res





Measured memory_bytes: 23904
x, n = map(int,input().split())

if n == 0:
    print(x)
    exit()

li = list(map(int,input().split()))

set = {i for i in range(x - 100, x + 100)}
for i in li:
    if i in set:
        set.remove(i)

min = 1000
for i in set:
    if abs(x - i) < min:
        min = abs(x - i)
        ans = i
print(ans)

Measured memory_bytes: 9204
while True:
    n,x=map(int,input().split())
    if n+x==0:break
    c = 0
    for i in range(1,n - 1):
        xi = x - i
        for j in range(i+1,n):
            if xi - j - j <= 0:
                break
            if xi - j <= n:
                c += 1
    print(c)

Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
ll k;
cin>>n>>k;
ll x;
ll sum=0;
for(int i=0;i<n;i++){
    cin>>x;
    sum+=min(x*2,(k-x)*2);
}
cout<<sum<<endl;
}












Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			if(N == 4 * i + 7 * j){
				System.out.println("Yes");
				System.exit(0);
			}
		}
	}
	System.out.println("No");

	}

}


Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>

using namespace std;

typedef struct s{
	int h,w;
} S;

bool operator<(S a,S b){
	return a.h*a.h+a.w*a.w<b.h*b.h+b.w*b.w||(a.h*a.h+a.w*a.w==b.h*b.h+b.w*b.w&&a.h<b.h);
}

int main(){

	int h,w;
	S data[150*150];
	int datac=0;

	for(int i=1;i<150;i++){
		for(int j=i+1;j<150;j++){
			data[datac].h=i;
			data[datac].w=j;
			datac++;
		}
	}

	sort(data,data+datac);

	while(1){
		cin>>h>>w;
		if(h==0&&w==0) break;

		for(int i=0;i<datac;i++){
			if(data[i].h==h&&data[i].w==w){
				cout<<data[i+1].h<<" "<<data[i+1].w<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int mex(const set<int>& se){
    int res=0;
    while(se.count(res))res++;
    return res;
}
int main(){
    int n,m;
    cin>>n>>m;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    vi dp(m+1);
    vector<set<int>> se(m+1);
    REP(i,m+1){
        dp[i]=mex(se[i]);
        REP(j,n){
            if(i+vec[j]<=m){
                se[i+vec[j]].insert(dp[i]);
            }
        }
    }
    cout<<(dp[m]?"First":"Second")<<endl;
    return 0;
}

Measured memory_bytes: 473856
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
using namespace std;

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

const long long INF = 1LL << 60;
int a[55];int b[55];int num[55];
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0;i < M;i++) {
		cin >> a[i] >> b[i];
	}

	for (int i = 0;i < M;i++) {
		num[a[i]-1]++;
		num[b[i]-1]++;
	}

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

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))

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

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int a, b;
  while(cin >> a >> b){
    if(a < b){
      cout << string(b, '0' + a) << endl;
    }else{
      cout << string(a, '0' + b) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

struct UnionFind
{
    int n, num;
    vector<int> r, p;
    UnionFind() {}
    UnionFind(int sz) : n(sz), num(sz), r(sz, 1), p(sz, 0) { iota(p.begin(), p.end(), 0); }
    int find(int x)
    {
        return (x == p[x] ? x : p[x] = find(p[x]));
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (r[x] < r[y])
            swap(x, y);
        r[x] += r[y];
        p[y] = x;
        num--;
    }
    int size(int x)
    {
        return r[find(x)];
    }
    int count() const
    {
        return num;
    }
};

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

    int n, k, l;
    cin >> n >> k >> l;
    UnionFind uf1(n), uf2(n), uf3(n);
    rep(i, k)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf1.unite(a, b);
    }
    rep(i, l)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf2.unite(a, b);
    }
    map<P, int> cnt;
    rep(i, n) cnt[P(uf1.find(i), uf2.find(i))]++;
    rep(i, n) cout << cnt[P(uf1.find(i), uf2.find(i))] << " ";
    cout << endl;
}

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

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

    int ans = 0;

    if (K <= A) ans = K;
    else {
        if (K - A <= B) ans = A;
        else {
            if (K - A -B <= C) ans = A - (K - A - B);
            else ans = A - C;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	ll n, p;
 	cin >> n >> p;
 	if(n == 1){
 		cout << p << endl;
 	} else {
 		ll i = 1000000;
 		while(1){
 			ll power = pow(i, n);
 			if(p % power == 0) break;
 			i--;
 		}
 		cout << i << endl;
 	}
 	
 	return 0;
 }

Measured memory_bytes: 256
use std::io;
use std::io::{BufRead, Write};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let _n:usize = buf.trim_right().parse().unwrap();
    buf.clear();
    input.read_line(&mut buf).unwrap();
    let mut a: Vec<usize> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let mut cnt = 0;
    for i in 0..a.len()-1 {
        if a[i+1] == a[i] {
            a[i+1] = 0;
            cnt+=1;
        }
    }
    writeln!(output, "{}", cnt).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "5
1 1 2 2 2
",
            "2\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "3
1 2 1
",
            "0\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "5
1 1 1 1 1
",
            "2\n",
        );
    }

    #[test]
    fn case4() {
        test(
            "14
1 2 2 3 3 3 4 4 4 4 1 2 3 4
",
            "4\n",
        );
    }
}


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var b = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
			List<int> c = new List<int>();
			for (int i = 0; i < n; i++) {
				for (int j = n - 1 - i; j >= 0; j--) {
					if (b[j] == j + 1) {
						c.Add(j + 1);
						b.RemoveAt(j);
						break;
					}
				}
			}

			if (b.Count != 0) {
				Console.WriteLine($"{-1}");
				return;
			}

			StringBuilder sb = new StringBuilder();
			for (int i = c.Count - 1; i >= 0; --i) {
				sb.AppendLine($"{c[i]}");
			}

			Console.WriteLine(sb.ToString());
		}
	}
}


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

int main() {
  int N;
  cin>>N;
  for(int i=0;i<=N;i++){
    int X=i*108;
    X/=100;
    if(X==N){cout<<i<<endl;break;}
    if(X>N){cout<<":("<<endl;break;}
  }
}





Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,m;
    ll d[200010],t[200010];
    map<ll,ll> mp;
    cin>>n;
    rep(i,n){
        cin>>d[i];
        mp[d[i]]++;
    }
    bool ok=true;
    cin>>m;
    rep(i,m){
        cin>>t[i];
        mp[t[i]]--;
        if(mp[t[i]]<0){
            ok=false;
        }
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

constexpr int m = 200;

int main(){
  int n; cin >> n;
  
  if(n< 105) cout << 0 << endl;
  else if(105 <= n && n < 135) cout << 1 << endl;
  else if(135 <= n && n < 165) cout << 2 << endl;
  else if(165 <= n && n < 189) cout << 3 << endl;
  else if(189 <= n && n < 195) cout << 4 << endl;
  else cout << 5 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
     
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n = Integer.parseInt(sc.next());
    		long a = Long.parseLong(sc.next());
    		long b = Long.parseLong(sc.next());
    		long sum = 0;
    		long from = Long.parseLong(sc.next());
    		long to = Long.parseLong(sc.next());
    		sum += (a*(to - from) < b) ? a*(to - from) : b;
    		for(int i = 0; i < n - 2; i++) {
    			from = to;
    			to = Long.parseLong(sc.next());
    			sum += (a*(to - from) < b) ? a*(to - from) : b;
    		}
    		System.out.println(String.valueOf(sum));
    	}
    }

Measured memory_bytes: 31132
H, W = gets.split.map(&:to_i)
MAX = H*W
Ch, Cw = gets.split.map(&:to_i)
Dh, Dw = gets.split.map(&:to_i)
S = Array.new H + 4
S[0] = Array.new(W+4, nil)
S[1] = Array.new(W+4, nil)
H.times do |i|
    S[i+2] = [nil,nil, *gets.chomp.split('').map{|x| x == "#" ? nil : MAX}, nil, nil]
end
S[H+2] = Array.new(W+4, nil)
S[H+3] = Array.new(W+4, nil)

res = 0

fillq = [[Ch+1, Cw+1, 0]]
S[Ch+1][Cw+1] = 0
warpq = []

dlist = [
    [-1,0],
    [+1,0],
    [0,-1],
    [0,+1]
]
wdlist = [
    [-2,-2],
    [-2,-1],
    [-2,0],
    [-2,+1],
    [-2,+2],
    [-1,-2],
    [-1,-1],
    [-1,+1],
    [-1,+2],
    [0,-2],
    [0,+2],
    [+1,-2],
    [+1,-1],
    [+1,+1],
    [+1,+2],
    [+2,-2],
    [+2,-1],
    [+2,0],
    [+2,+1],
    [+2,+2]
]

while fillq[0] || warpq[0] do
    while(fq = fillq.shift) do
        h, w, d = *fq
        if h == Dh+1 && w == Dw+1
            puts d
            exit
        end
        dlist.each do |dh, dw|
            t = S[_h=h+dh][_w=w+dw]
            if t && d < t
                fillq.push([_h,_w,d])
                S[_h][_w] = d
            end
        end
        warpq.push([h,w,d+1])
    end

    while wq = warpq.shift
        h,w,d = *wq
        list = []
        wdlist.each do |dh,dw|
            t = S[_h=h+dh][_w=w+dw]
            if  t && d < t
                S[_h][_w] = d
                fillq.push([_h,_w,d])
            end
        end
    end
end

puts -1

Measured memory_bytes: 27392
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  string s; cin>>s;
  if(s[0]=='7' || s[1]=='7' || s[2]=='7')
  	 cout<<"Yes\n";
  	else cout<<"No\n";
  return 0;
}

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


int main() {
  int N;
  ll H;
  cin >> N >> H;
  vector<ll> A(N), B(N);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i) >> B.at(i);
  }
  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  ll max_A = A.at(0);
  int result = 0;
  for (int i = 0; i < N; ++i) {
    if (max_A < B.at(i)) {
      ++result;
      H -= B.at(i);
    } else {
      break;
    }
    if (H <= 0) {
      break;
    }
  }
  if (0 < H) {
    result += (H + (max_A - 1)) / max_A;
  }
  cout << result << endl;
}

Measured memory_bytes: 1792
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

H, W, M = mapint()
from collections import Counter, defaultdict
h_count = Counter()
w_count = Counter()
dic = [set() for _ in range(W)]
for _ in range(M):
    h, w = mapint()
    h_count[h] += 1
    w_count[w] += 1
    dic[w-1].add(h)

h_max = 0
h_set = set()
for i, (num, cnt) in enumerate(h_count.most_common()):
    if i==0:
        h_max = cnt
        h_set.add(num)
    else:
        if cnt<h_max:
            break
        else:
            h_set.add(num)
w_max = 0
for i, (num, cnt) in enumerate(w_count.most_common()):
    if i==0:
        w_max = cnt
    if cnt<w_max:
        print(w_max+h_max-1)
        exit()
    else:
        if h_set-dic[num-1]:
            print(cnt+h_max)
            exit()
print(w_max+h_max-1)


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

int main() {
  int N;
  int nyanpass = 0;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  for (int i=0; i<(N-2); i++) {
    if (A[i] >= A[i+1] && A[i+1] > A[i+2]) {
      nyanpass++;
    }
    else if (A[i+2] >= A[i+1] && A[i+1] > A[i]) {
      nyanpass++;
    }
    else if (A[i+2] == A[i] && A[i+1] > A[i+2]) {
      nyanpass++;
    }
  }
  cout << nyanpass << endl;
}


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

typedef long double ld;

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
	ll L;
	cin>>L;
	
	ld a = L/3.0;
	ld b = L/3.0;
	ld c = L/3.0;
	

	
	cout<<setprecision(6)<<fixed<<(a*b*c)<<endl;
	
}


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

int main(){
    int w,d;
    while(cin>>w>>d,w){
        vector<int> W(w),D(d);
        for(int i=0;i<w;i++) cin>>W[i];
        for(int i=0;i<d;i++) cin>>D[i];
        sort(W.begin(), W.end());
        sort(D.begin(), D.end());
        int iw=0,id=0;
        int ans = 0;
        int i=0,j=0;
        while(i<w&&j<d){
            if(W[i]==D[j]){
                ans+=W[i];
                i++;
                j++;
            }else{
                if(W[i]>D[j]){
                    ans+=D[j];
                    j++;
                }else{
                    ans+=W[i];
                    i++;
                }
            }
        }
        while(i<w) ans+=W[i++];
        while(j<d) ans+=D[j++];
        cout<<ans<<endl;
    }


    return 0;
}

Measured memory_bytes: 3080
length = gets.to_i
arr = gets.split.map(&:to_i)

def selection_sort(arr, length)
  count = 0
  for i in 0..(length - 1) do
    min_idx = i
    for j in i..(length - 1) do
      if arr[j] < arr[min_idx]
        min_idx = j
      end
    end
    arr[i], arr[min_idx] = arr[min_idx], arr[i]
    if i != min_idx
      count += 1
    end
  end
  return [arr, count]
end

result, count = selection_sort(arr, length)
puts result.join(' ')
puts count


Measured memory_bytes: 6876
from heapq import heapify, heappush, heappop
from sys import stdin

def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    price = list(map(lambda x: x * -1, A))
    heapify(price)
    for _ in range(M):
        n = heappop(price)
        heappush(price, -(-n // 2))

    print(-sum(price))

main()


Measured memory_bytes: 14224
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;

int main() {
  int n, p;
  double h;
  double a[] = {165.0, 170.0, 175.0, 180.0, 185.0};
  int b[6];
  cin >> n;
  for (int i=0; i<6; i++) b[i] = 0;
  for (int i=0; i<n; i++) {
    cin >> h;
    ++b[distance(a, upper_bound(a, a+5, h))];
  }
  for (int i=0; i<6; i++) {
    cout << i+1 << ":";
    for (int j=0; j<b[i]; j++) {
      cout << "*";
    }
    cout << endl;
  }
}

Measured memory_bytes: 1232
function main(input) {
    const args = input.split(' ');
    const a = parseInt(args[0], 10);
    const b = parseInt(args[1], 10);

    if ((a * b) % 2 === 0) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 19528
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


int gcd(int a, int b) {//最大公約数
	if (b == 0)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
	int g = gcd(a, b);
	return a / g * b;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	int gc, fi;
	cin >> N >> M;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
		A[i] /= 2;
	}

	if (N == 1) {
		fi = A[0];
		gc = 2;
		//cout << (M - fi) / gc + 1 << endl;
		cout << (int)((M / (2.0*A[0])) - 0.5)+1 << endl;
		return 0;
	}



	gc = lcm(A[0], A[1]);
	FOR(i, 2, N) {
		gc = lcm(gc, A[i]);
		if (gc > INF * 10) {
			cout << 0 << endl;
			return 0;
		}
	}
	
	fi = gc;
	gc *= 2;
	//cout << fi << " " << gc << endl;
	if (fi > M) {
		cout << 0 << endl;
		return 0;
	}
	REP(i, N) {
		if ((fi / A[i]) % 2 == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	
	cout << (M - fi) / gc + 1 << endl;






	return 0;
}



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

int main(){

    int N, H;
    cin >> N >> H;
    vector<int> a(N), b(N);
    for(int i = 0; i < N; i++) cin >> a[i] >> b[i];

    int a_max = *max_element(a.begin(), a.end());
    sort(b.rbegin(), b.rend());

    int ans = H;
    for(int k = 0; k <= N; k++){
        if(k > 0) H -= b[k - 1];
        int count = 0;
        if(H > 0) count = ceil(1. * H / a_max);
        ans = min(ans, k + count);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur=nil->next;
	while(cur!=nil && cur->key!=key){
		cur=cur->next;
	}
	return cur;
}

void init(){
	nil=(Node *)malloc(sizeof(Node));
	nil->next=nil;
	nil->prev=nil;
}

void printList(){
	Node *cur=nil->next;
	int isf=0;
	while(1){
		if(cur==nil) break;
		if(isf++>0) printf(" ");
		printf("%d",cur->key);
		cur=cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if(t==nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x=(Node *)malloc(sizeof(Node));
	x->key=key;
	
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
	int key, n, i;
	int size=0;
	char com[20];
	int np=0, nd=0;
	scanf("%d",&n);
	init();
	for(i=0; i<n; i++){
		scanf("%s%d",com,&key);
		if(com[0]=='i'){insert(key); np++; size++;}
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F') deleteFirst();
				else if(com[6]=='L') deleteLast();
			}else{
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}

Measured memory_bytes: 33812
#include<bits/stdc++.h>
using namespace std;
typedef pair<long,long> P;
const long INF=10000000000000;
struct E{
  long to,cost;
  E(){}
  E(long t,long c):to(t),cost(c){}
};

vector<vector<long>> Distance(vector<vector<E>>&A){
  long N=A.size();
  vector<vector<long>>D(N,vector<long>(N,INF));
  for(long s=0;s<N;s++){
    priority_queue<P,vector<P>,greater<P>> q;q.push(P(0,s));D[s][s]=0;
    while(q.size()){
      P t=q.top();q.pop();
      if(t.first>D[s][t.second])continue;
      for(E e:A[t.second])if(D[s][e.to]>D[s][t.second]+e.cost){
          D[s][e.to]=D[s][t.second]+e.cost;q.push(P(D[s][e.to],e.to));
      }
    }
  }
  return D;
}

int main(){
  long N,M,L;cin>>N>>M>>L;
  vector<vector<E>>A(N);
  for(long i=0;i<M;i++){
    long a,b,c;cin>>a>>b>>c;
    A[a-1].push_back(E(b-1,c));A[b-1].push_back(E(a-1,c));
  }
  vector<vector<long>> D=Distance(A);
  vector<vector<E>>B(N);
  for(long i=0;i<N;i++)for(long j=0;j<N;j++)if(D[i][j]<=L)B[i].push_back(E(j,1));
  vector<vector<long>> D2=Distance(B);
  long Q;cin>>Q;
  for(long q=0;q<Q;q++){
    long s,t;cin>>s>>t;
    cout<<(D2[s-1][t-1]!=INF?D2[s-1][t-1]-1:-1)<<endl;
  }
}
  



Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    vector<int> num(26, 0);

    rep(i,s.size()){
        num[s[i] - 'a']++;
    }

    ll sum = 0;
    rep(i,26){
        if(num[i] %2 == 1) sum++;
    }

    if(s.size() %2 == 1) sum--;

    cout << (sum+1)/2 << endl;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	int ans = 0;
	for (int i = 1; i * i <= m; ++i) {
		if (m % i == 0) {
			if (i <= m / n) maxs(ans, i);
			if (m / i <= m / n) maxs(ans, m / i);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#!/usr/bin/env ruby

n = gets.chomp.to_i

dict = {}
n.times do
  action, str = gets.chomp.split
  str = str.each_codepoint.to_a.join.to_i
  case action
  when 'insert'
    dict[str] = 1
  when 'find'
    puts dict[str] ? 'yes' : 'no'
  end
end

Measured memory_bytes: 34136