akhauriyash/Code-Regression huggingface dataset:
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    lines.next();
    let a = lines.next().unwrap().unwrap();
    let mut a: Vec<(usize, usize)> = a
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .enumerate()
        .collect();
    a.sort_by_key(|&(_, j)| j);
    let ans = a
        .iter()
        .map(|&(i, _)| (i + 1).to_string())
        .collect::<Vec<String>>()
        .join(" ");
    println!("{}", ans);
}


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

namespace cskyopro {
    class Solver : Reader {
        public void Solve() {
            long X = NextLong();
            long ans = X / 500 * 1000 + (X % 500) / 5 * 5;
            Console.WriteLine(ans);
        }
    }

    class Mint {
        const long MOD = 1000000007;
        private long n;

        public Mint(long n) {
            this.n = n;
        }

        public static Mint operator +(Mint a, Mint b) => new Mint((a.n + b.n) % 5);
        public static Mint operator -(Mint a, Mint b) => new Mint((a.n + 5 - b.n) % 5L);
        public static Mint operator *(Mint a, Mint b) => new Mint((a.n * b.n) % 5);
        public static implicit operator Mint(int n) => new Mint(n);

        public override string ToString() => n.ToString();
    }

    class Reader {
        public string Next() {
            StringBuilder sb = new StringBuilder();
            while (true) {
                int x = Console.Read();
                if (x == -1 || x == ' ' || x == '\n') break;
                sb.Append((char)x);
            }
            return sb.ToString();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
    }

    class Program {
        static void Main(string[] args) => new Solver().Solve();
    }
}


Measured memory_bytes: 11220
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define db double
#define ld long double
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define all(x) (x).begin(),(x).end()
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define TEST int T; cin >> T; while(T--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//#define int long long
 
const int N = 1e5 + 1, inf = 2e9 + 7, mod = 1e9 + 7;
const ll INF = 2e18 + 7, MOD = 1e15 + 7;

int n, all;
int dp[1 << 21];
bool v[21][21], was[1 << 21];

bool has(int mask, int i) {
    return (mask >> i) & 1;
}

int rec(int mask) {
    if(was[mask]) return dp[mask];
    int ans = 0, bits = __builtin_popcount(mask);
    for(int i = 0; i < n; i++) {
        if(has(mask, i) && v[bits - 1][i]) {
            ans = (ans * 1LL + rec(mask ^ (1 << i))) % mod;
        }
    }
    was[mask] = 1;
    return dp[mask] = ans;
}

signed main() { __
//    freopen("lcm.in", "r", stdin);
//    freopen("lcm.out", "w", stdout);
    cin >> n;
    all = (1 << n) - 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> v[i][j];
        }
    }
    dp[0] = 1;
    was[0] = 1;
    cout << rec(all);
    return 0;
}



Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
ll N, A, B;

bool check(ll x, vector<ll> h)
{
    ll cnt = 0;
    rep(i, N)
    {
        ll v = h[i] - x * B;
        if (v <= 0) {
            continue;
        } else {
            cnt += v / A;
            if (v % A) {
                ++cnt;
            }
        }
    }
    return cnt <= x;
}

signed main()
{
    cin >> N >> A >> B;
    vector<ll> h(N);
    A -= B;
    ll ng = 0, ok = 1e9; // ちょうど魔物を倒す回数
    rep(i, N)
    {
        cin >> h[i];
    }
    while (ng + 1 != ok) {
        ll x = (ng + ok) / 2;
        if (check(x, h)) {
            ok = x;
        } else {
            ng = x;
        }
    }
    cout << ok << endl;
    return 0;
}

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

int main(){
    int N;
    int64_t A[100000], S = 0;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> A[i];
        S += A[i] * (i%2 == 0 ? 1 : -1);
    }
    int64_t ans[100000];
    ans[0] = S;
    ans[1] = -S + 2*A[0];
    for(int i=2; i<N; i++) ans[i] = ans[i-2] + 2*(A[i-1] - A[i-2]);
    for(int i=0; i<N; i++) cout << ans[i] << " \n"[i==N-1];
    return 0;
}


Measured memory_bytes: 2816
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();

        long ans = 0;
        if (N > 1 && M > 1) {
            ans = (N - 2) * (M - 2);
        }

        if (N > 1 && M < 2) {
            ans = (N - 2);
        }

        if (N < 2 && M > 1) {
            ans = (M - 2);
        }

        if (N < 2 && M < 2) {
            ans = 1;
        }

        System.out.println(ans);
    }
}

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

int main(){
    string s;
    int n;
    cin >> n;
    cin >> s;
    if(n%2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i<n/2;i++){
        if(s[i] != s[i+n/2]){
            cout << "No" << endl;
            return 0;
        }
        if(i == n/2-1){
            cout << "Yes" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  
  for(int i=0;i<3;i++){
    if(S.at(i)=='1'){
       S.replace(i,1,"9");
      continue;
    }
    if(S.at(i)=='9'){
       S.replace(i,1,"1");
    }
  }
  
  cout<<S<<endl;
  return 0;

}
    

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a[5], k;
  rep(i,0,5) cin >> a[i];
  cin >> k;
  if(a[4] - a[0] > k) co(":(");
  else co("Yay!");
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int numbits(int n)
{
    int res = 0;
    while (n > 0) {
        if (n & 1)
            res++;
        n >>= 1;
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> f(n);
    for (int i =0; i < n; i++) {
        int b = 0;
        for (int j = 0; j < 10; j++) {
            int c;
            cin >> c;
            b <<= 1;
            b |= c;
        }
        f[i] = b;
    }
    vector<vector<int>> p;
    for (int i = 0; i < n; i++) {
        p.emplace_back(11);
        for (int j = 0; j <= 10; j++)
            cin >> p[i][j];
    }

    int ans = INT_MIN;
    for (int i = 1; i < (1<<10); i++) {
        int prof = 0;
        for (int j = 0; j < n; j++) {
            prof += p[j][numbits(f[j] & i)];
        }
        ans = max(ans, prof);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 H;
  std::cin >> H;

  i64 answer = 0;
  i64 monster_count = 1;
  while (H > 0) {
    answer += monster_count;
    H /= 2;
    monster_count *= 2;
  }

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

Measured memory_bytes: 256
MOD = 10**9 + 7
N, K = [int(s) for s in input().split()]
cnt = 0
for i in range(K, N + 2):
    if i != N + 1:
        cnt += i * ((N + 1) - i) + 1
    else:
        cnt += 1
    cnt %= MOD

print(cnt)

Measured memory_bytes: 9184
#include<iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  int a = n % 10;
  string ans;
  if (a == 3)
  {
    ans = "bon";
  }
  else if(a == 0 || a == 1 || a == 6 || a == 8)
  {
    ans = "pon";
  }
  else
  {
    ans = "hon";
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,tmp=0x3f3f3f3f,cnt;
int main()
{
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
	{
		scanf("%d",&m);
		if(m<=tmp) cnt++;
		tmp=min(tmp,m);
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define sqr(x) (x)*(x)
using namespace std;

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

int main(){
#ifdef LOCAL
    freopen("inp.txt", "r", stdin );
    freopen("ans.txt", "w", stdout);
#endif
    ll n, m;
    cin >> n >> m;
    vector<int>a(n);
    for(int i=0; i<n; i++){
    	cin >> a[i];
    	a[i] /= 2;
    }
    ll l = a[0];
    for(int i=1; i<n; i++){
    	l = lcm(l, a[i]);
    }
    for(int i=0; i<n; i++){
    	if((l / a[i]) % 2 == 0){
    		cout << 0 << '\n';
    		return 0;
    	}
    }
    cout << m/(l*2) + (m/l)%2 << '\n';
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tc() ll T;cin>>T;while(T--)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    /*-----------------Code Begins Here------------------*/
    
    ll x; cin>>x;
    if(x<600) cout<<8;
    else if(x<800) cout<<7;
    else if(x<1000) cout<<6;
    else if(x<1200) cout<<5;
    else if(x<1400) cout<<4;
    else if(x<1600) cout<<3;
    else if(x<1800) cout<<2;
    else cout<<1;
    
    /*------------------Code Ends Here-------------------*/
    
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] s = sc.next().toCharArray();
		
		System.out.println(isHitachi(s) ? "Yes" : "No");
		
		sc.close();
	}
	
	static boolean isHitachi(char[] s) {
		if(s.length%2!=0)
			return false;
		for(int i=0; i<s.length/2; i++) {
			if(s[i*2]!='h')
				return false;
			if(s[i*2+1]!='i')
				return false;
		}
		return true;
	}
}


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

using namespace std ;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<ll,ll> pll ;
typedef vector<pii> vpii ;
typedef vector<pll> vpll ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define NP next_permutation
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}
//-----------------------------------------




















//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  str s, t ;
  cin >> s >> t ;
  ll ans = 1 ;
  int i=0;
  vector<int> vec ;
  while(i<n){
    if(s[i]==s[i+1] && i+1<n){
      vec.PB(2) ;
      i += 2 ;
    }
    else{
      vec.PB(1) ;
      i++ ;
    }
  }
  
  if(vec[0]==1){
    ans *= 3  ;
  }
  else{
    ans *= 6 ;
  }
  
  for(int i=1;i<SZ(vec);i++){
    if(vec[i-1]==1 && vec[i]==1){
      ans *= 2 ;
        ans %= MOD ;
      }
      else if(vec[i-1]==1 && vec[i]==2){
        ans *= 2 ;
        ans %= MOD ;
      }
      else if(vec[i-1]==2 && vec[i]==2){
        ans *= 3 ;
        ans %= MOD ;
      }
      else{
        ans *= 1 ;
        ans %= MOD ;
      }
    }

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

Measured memory_bytes: 256
//C - Boxes and Candies: 9Min
//Assunto:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, x, aux;
    ll ans1 = 0, ans2 = 0, ans;
    cin >> n >> x;
    vector<int> caixas(n), caixas2(n);
    loop(i, 0, n) {
        cin >> caixas[i];
        caixas2[i] = caixas[i];
    }
    loop(i, 0, n-1) {
        aux = (caixas[i] + caixas[i+1]) - x;
        if(aux < 0) aux = 0;
        ans1 += aux;
        caixas[i+1] -= aux;
        if(caixas[i+1] < 0) caixas[i+1] = 0;
        //cout << aux << "\n";
    }
    loop(i, 1, n) {
        aux = (caixas2[i] + caixas2[i-1]) - x;
        if(aux < 0) aux = 0;
        ans2 += aux;
        caixas2[i] -= aux;
        if(caixas2[i] < 0) caixas2[i] = 0;
    }
    ans = min(ans1, ans2);
    cout << ans << "\n";
}
    

Measured memory_bytes: 1024
use std::collections::HashSet;
fn main() {
    let mut init = String::new();
    std::io::stdin().read_line(&mut init).unwrap();
    let x = init
        .split_whitespace()
        .map(|i| i.parse::<i32>().unwrap())
        .nth(0)
        .unwrap();
    let mut input: HashSet<i32> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.split_whitespace()
            .map(|i| i.parse::<i32>().unwrap())
            .collect()
    };
    
    let mut value = 102;
    let mut count = 0;
    for n in 0..102 {
        if input.contains(&n) {
            continue;
        }
        if (n - x).abs() < value {
            value = (n - x).abs();
            count = n;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 2188
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main() {
    int c[3],d;
   REP(i,3) cin>>c[i];
   sort(c,c+3,greater<int>());

   cout<<c[0]*10+c[1]+c[2]<<endl;

}



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

vector<vector<int>> G;
vector<int> indeg;  // 入次数
vector<bool> visited;
vector<int> ans;

void bfs(int s) {
  queue<int> q;
  q.push(s);
  visited.at(s) = true;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int nx : G.at(cur)) {
      if (visited.at(nx)) continue;
      indeg.at(nx)--;
      if (indeg.at(nx) == 0 && !visited.at(nx)) {
        visited.at(nx) = true;
        ans.at(nx) = cur + 1;  // nx の親は cur + 1
        q.push(nx);
      }
    }
  }
}

int main() {
  int N, M; cin >> N >> M;
  G.resize(N);
  indeg.resize(N);
  visited.resize(N);
  ans.resize(N);
  for (int i = 0; i < N-1+M; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b);
  }
  for (int i = 0; i < N; i++) {
    for (int e : G.at(i)) indeg.at(e)++;
  }
  for (int i = 0; i < N; i++) {
    if (indeg.at(i) == 0 && !visited.at(i)) bfs(i);
  }
  for (int v : ans) cout << v << endl;
}

Measured memory_bytes: 9584
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll 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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s; cin >> s;
	int ans = 0;
	rep(i, s.size()/2) {
		if (s[i] != s[s.size() - i - 1])++ans;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInts();
            var A = ReadInts();

            WriteLine(Max(-1,NM[0] - A.Sum()));
        }

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


Measured memory_bytes: 28944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pi 3.14159265358979323846264338327950L
int main(){
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    long double alp = 2 * pi * H / 12.0 + 2 * pi / 12.0 * (M / 60.0);
    long double bet = 2 * pi * M / 60.0;
    long double  res = (long double)(A * A + B * B) - (long double)(2 * A * B)* cosl(alp - bet);

    printf("%20.20Lf\n", sqrtl(res));
}

Measured memory_bytes: 4088
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,a=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n;i++){
    if(s[i]!=s[i+1]){
      a++;
    }
  }
  cout<<a<<"\n";
}


Measured memory_bytes: 512
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N, vector<int>(N, 0));
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a][b] = G[b][a] = 1;
  }

  vector<int> perm(N);
  for (int i = 0; i < N; i++) {
    perm[i] = i;
  }
  int ans = 0;
  do {
    if (perm[0] != 0) continue;
    bool flag = true;
    for(int i = 0; i < N - 1; i++) {
      if (!G[perm[i]][perm[i + 1]]) {
        flag = false;
      }
    }
    if (flag) ans++;
  } while(next_permutation(perm.begin(), perm.end()));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <complex>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#define test
using namespace std;
typedef long long ll;
int n,k,ans;
int main()
{
#ifdef test
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
    cin>>n>>k;
    for (int i=0;i<n;i++)
    {
        int x;
        cin>>x;
    }
    cout<<(n+k-3)/(k-1)<<endl;
    //system("pause");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int H,W;
	cin>>H>>W;
	char s[52][52];
	rep1(i,H)rep1(j,W)cin>>s[i][j];
	rep(i,W+2)s[0][i]='.';
	rep(i,W+2)s[H+1][i]='.';
	rep(i,H+2)s[i][0]='.';
	rep(i,H+2)s[i][W+1]='.';
	bool pos=true;
	rep1(i,H)rep1(j,W){
		if(s[i][j]=='#'&&s[i-1][j]=='.'&&s[i][j-1]=='.'&&s[i+1][j]=='.'&&s[i][j+1]=='.')pos=false;
	}
	if(pos)cout<<"Yes";
	else cout<<"No";
}

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

using namespace std;
const int maxn = 200005;
int n, ans;
char c[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> c[i];
    int i = 1, r = n;
    for (; i <= n; i++) {
        while (c[r] == 'W' && r > i) r--;
        if (c[i] == 'W' && i < r && c[r] == 'R') {
            swap(c[i], c[r]);
            ans++;
        }
    }
    for (int j = i + 1; j <= n - 1; j++) {
        if (c[j] == 'W' && c[j + 1] == 'R') c[j] = 'W', ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3800
object Main extends App {
  // val n = io.StdIn.readLine.toInt
  val ans = Iterator.continually(io.StdIn.readLine)
    // .take(n)
    .drop(1)
    .takeWhile(_ != null)
    .map(_.split(" "))
    .forall(in => {
      val c = in(0).toInt - in(1).toInt - in(2).toInt
      if (c >= 0 && (c & 1) == 0) true else false
    })

  println(if(ans) "Yes" else "No")
}

Measured memory_bytes: 43352
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int N;

    int h, t, o;
    cin >> N;
    h = N/100;
    t = (N%100)/10;
    o = N%10;

    if(h==7 || t == 7 || o == 7) cout << "Yes"  << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;

ll gcd(ll A, ll B){
  if(A<B){
    swap(A,B);
  }
  ll r = A%B;
  while(r!=0){
    A = B;
    B = r;
    r = A % B;
  }
  return B;
}
ll lcm(ll A,ll B){
  return A*B/gcd(A,B);
}

  



int main(){
  ll A,B;
  cin>>A>>B;
  ll X = lcm(A,B);
  cout << X << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
using namespace std;
typedef long long ll;

int main(void){
    int n, l;
    cin>>n>>l;
    int all_taste=0;
    rep(i, n){
        all_taste+=l+i;
    }
  
    int eatapple=1000;
    rep(i, n){
    
        if ((abs(l+i))<abs(eatapple)){
            eatapple=l+i;
        }
    }

    int ans=all_taste-eatapple;
    cout<<ans<<endl;
}

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

itv = []
for i in range(n):
  tx,tl = map(int,input().split())  
  itv.append([tx+tl,tx-tl] )

itv = sorted(itv)

ans = 0
right = float('-inf')

for i in range(n):  
  if right <= itv[i][1]:    
    ans += 1
    right = itv[i][0]
    
print(ans)    

Measured memory_bytes: 59976
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	char c;
	cin>>c;
	string s="ACCGGG";
	cout<<"ATGC"[count(all(s),c)]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;


int main()
{
	int n;
	scanf("%d", &n);
	for (int testCase = 0; testCase < n; ++testCase)
	{
		int score = 0;
		int out = 0;
		bool runner[3];
		fill(runner, runner+3, false);
		while (out < 3)
		{
			char buf[128];
			scanf("%s", buf);
			char c = buf[1];
			if (c == 'I')
			{
				if (runner[2])
					++score;
				runner[2] = runner[1];
				runner[1] = runner[0];
				runner[0] = true;
			}
			else if (c == 'U')
				++out;
			else
			{
				for (int i = 0; i < 3; ++i)
				{
					if (runner[i])
						++score;
					runner[i] = false;
				}
				++score;
			}
		}
		printf("%d\n", score);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int dp[1<<21];
int a[30][30];

int main(){
	int n;scanf("%d",&n);
	rep(i,n)rep(j,n)scanf("%d",&a[i][j]);
	dp[0]=1;
	rep(i,1<<n){
		int d=__builtin_popcount(i);
		rep(j,n){
			if(!a[d][j])continue;
			if(i>>j&1)continue;
			(dp[i|1<<j]+=dp[i])%=MOD;
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
}

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

string s[44];
int tanku[5] = {5, 7, 5, 7, 7};

void solve(int n) {
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            // use from i to j
            bool is_tanku = true;
            int now_idx = 0;
            int now_cnt = 0;
            for (int k = i; k <= j; k++) {
                now_cnt += s[k].size();
                if (now_cnt > tanku[now_idx]) {
                    is_tanku = false;
                    break;
                }
                else if (now_cnt == tanku[now_idx]) {
                    now_cnt = 0;
                    now_idx++;
                }
                if (now_idx == 5) break;
            }
            if (is_tanku && now_idx == 5) {
                cout << i + 1 << endl;
                return;
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while (true) {
        cin >> N;
        if (N == 0) break;
        solve(N);
    }
    return 0;
}


Measured memory_bytes: 3176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b,c;
	cin >> a >> b >> c;
	cout << ((a+b+c<22)?"win":"bust") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() { 
  int N;
  cin >> N;
  vector<int> p(N);
  
  int min = 200001;
  int cnt = 0;
  
  for(int i = 0; i < N; i++) {
    cin >> p.at(i);
    if(p.at(i) <= min) {
      cnt++;
      min = p.at(i);
    }
  }
  
  cout << cnt << endl;

}

Measured memory_bytes: 1024
import itertools

N, M, R = map(int, input().split())
r = map(int, input().split())
A = [[1 << 64]*N for _ in range(N)]
for i in range(N):
    A[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    A[a-1][b-1] = A[b-1][a-1] = c

# Warshall-Floyd
for k in range(N):
    for i in range(N):
        for j in range(N):
            A[i][j] = min(A[i][j], A[i][k] + A[k][j])

res = 1 << 64
for perm in itertools.permutations([x-1 for x in r]):
    cost = 0
    for i in range(R-1):
        cost += A[perm[i]][perm[i+1]]
    if cost < res:
        res = cost

print(res)


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

int main()
{
    int n;
    cin>>n;
    int A[n+1], B[n];
    for(int i=0; i<=n; i++)
        cin>>A[i];
    for(int j=0; j<n; j++)
        cin>>B[j];
    long long count=0;
    for(int i=0; i<n; i++)
    {
        int m1 = min(A[i], B[i]);
        A[i]-=m1, B[i]-=m1, count+=m1;
        int m2 = min(A[i+1], B[i]);
        A[i+1]-=m2, B[i]-=m2, count+=m2;
    }
    cout<<count;
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut a: Vec<i32> = vec![0; 200001];
    for _i in 0..n {
        let x: usize = sc.read();
        a[x] += 1;
    }
    let mut cnt: Vec<i32> = Vec::new();
    for i in 0..200001 {
        if a[i] > 0 {
            cnt.push(a[i]);
        }
    }
    cnt.sort(); cnt.reverse();
    let mut ans = 0;
    while cnt.len() > k {
        ans += cnt.pop().unwrap();
    }
    println!("{}", ans);
}

Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    intf n,x,su=0;
    cin >>n >>x;
    vector<intf> a(n);
    for(auto &e:a) cin >>e;

    sort(a.begin(),a.end());

    rep(i,n+1){
        if(su==x){
            cout << i<<endl;
            return 0;
        }else if(su>x){
            cout << i-1 <<endl;
            return 0;
        }
        su += a[i];
    }

    cout << n-1 <<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int H,W; cin >> H >> W;
    char C[H][W];
    rep(i,H) rep(j,W) cin >> C[i][j];
    int dis[H][W];
    rep(i,H) rep(j,W) dis[i][j]=INF;
    if(C[0][0]=='#') {dis[0][0]=1;}
    else dis[0][0]=0;
    rep(i,H-1) {
        if((C[i+1][0]=='#' && C[i][0]=='.')) dis[i+1][0]=dis[i][0]+1;
        else dis[i+1][0]=dis[i][0];
    }
    rep(i,W-1) {
        if((C[0][i+1]=='#' && C[0][i]=='.')) dis[0][i+1]=dis[0][i]+1;
        else dis[0][i+1]=dis[0][i];
    }
    rep(i,H-1){
        rep(j,W-1){
            int a,b;
            if((C[i+1][j+1]=='#' && C[i][j+1]=='.')) {
                a=dis[i][j+1]+1;
            } else a=dis[i][j+1];
             if((C[i+1][j+1]=='#' && C[i+1][j]=='.')) {
                b=dis[i+1][j]+1;
            } else b=dis[i+1][j];
            dis[i+1][j+1]=min(a,b);
        }
    }
    cout << dis[H-1][W-1] << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <math.h>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

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


int main() {
    Int N;
    cin >> N;

    string ans;
    Int two = 0;
    Int four = 0;
    rep(i,N){
        Int a;
        cin >> a;
        if (a%4==0){
            four++;
        }else if(a%2==0){
            two++;
        }
    }

    four += two/2;
    if (N-(four*2+1)<=0){
        ans = "Yes";
    }else{
        ans = "No";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <iostream>
#include <vector>

const int nmax = 100005;
struct edge {
  int node;
  int weight;

  edge(int n, int w) : node(n), weight(w){};
};

int ans = 0;
std::array<std::vector<edge>, nmax> adjlist;

int dfs(int current, int parent) {
  std::vector<int> dist;
  for (size_t i = 0; i < adjlist[current].size(); ++i) {
    auto e = adjlist[current][i];
    if (e.node != parent) {
      dist.push_back(e.weight + dfs(e.node, current));
    }
  }

  // std::cout << current << ": ";
  // for (size_t i = 0; i < dist.size(); ++i) {
  //   std::cout << dist[i] << " ";
  // }
  // std::cout << std::endl;

  if (dist.size() >= 1) {
    std::sort(dist.begin(), dist.end(), [](int a, int b) { return a > b; });
    dist.push_back(0);
    ans = std::max(ans, dist[0] + dist[1]);
    return dist[0];
  } else {
    return 0;
  }
}

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

  int s, t, w;
  for (int i = 0; i < n - 1; ++i) {
    std::cin >> s >> t >> w;
    adjlist[s].push_back(edge(t, w));
    adjlist[t].push_back(edge(s, w));
  }

  dfs(0, -1);
  std::cout << ans << std::endl;
}



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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    string S[N];
    REP(i,N){
        cin >> S[i];
    }
    bool rule = true;
    REP(i,N-1){
        for(int j = i + 1; j < N; ++j){
            if(S[i] == S[j]) rule = false;
        }
    }
    char e;
    REP(i,N){
        string a = S[i];
        if(i==0) e = a[a.size() - 1];
        else{
            if(a[0] == e) e = a[a.size()-1];
            else rule = false;
        }
    }
    if(rule) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	char ch;
	int count[26] = {0};
	while ( cin >> ch ) {
		if (isalpha(ch)) {
			char u = 'A';
			char l = 'a';
			for (int i = 0; i < 26; i++) {
				if (ch == u++ || ch == l++) {
					count[i] += 1;
					break;
				}
			}
		}
	}
	char l = 'a';
	for (int i = 0; i < 26; i++)
		cout << l++ << " : " << count[i] << endl;
	return 0;
}

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

#define N 16

int ans[N];
int cur[N];
int anspos[N];
int movepos[4] = {-4, 1, 4, -1};

int checkAns() {
  for (int i = 0; i < N; i++) {
    if (ans[i] != cur[i]) return 0;
  }
  return 1;
}

int calcEst() {
  int total = 0, t;
  for (int i = 0; i < N; i++) {
    if (cur[i]==0)continue;
    t = (i % 4) - (anspos[cur[i]] %4);
    if (t >= 0)
      total += t;
    else
      total -= t;

    t = (i / 4) - (anspos[cur[i]] / 4);
    if (t >= 0)
      total += t;
    else
      total -= t;
  }
  return total;
}

int dfs(int x, int px, int lim) {
  int res = -1, minres = -1;

  if (checkAns()) return 0;
  if (lim == 0) return -1;
  if (calcEst() > lim) return -1;
  for (int i = 0; i < 4; i++) {
    if (x + movepos[i] == px) continue;
    if ((x % 4 == 0 && movepos[i] == -1) || (x % 4== 3 && movepos[i] == 1))
      continue;
    if (x + movepos[i] >= N || x + movepos[i] < 0) continue;
    swap(cur[x], cur[x + movepos[i]]);
    res = dfs(x + movepos[i], x, lim - 1);
    if (res != -1) {
      if (minres == -1) {
        minres = res + 1;
      } else {
        minres = min(minres, res + 1);
      }
      break;
    }
    swap(cur[x], cur[x + movepos[i]]);
  }
  return minres;
}

int main() {
  int x, lim = 0, res;

  for (int i = 0; i < N; i++) ans[i] = i + 1;
  ans[N - 1] = 0;
  for (int i = 0; i < N; i++) anspos[i] = i - 1;
  anspos[0] = N - 1;

  for (int i = 0; i < N; i++) {
    cin >> cur[i];
    if (cur[i] == 0) x = i;
  }

  while (true) {
    res = dfs(x, x, lim);
    if (res >= 0) break;
    lim++;
  }

  // cout << lim << endl;
  cout << res << endl;
  return 0;
}


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

using ull = unsigned long long;
int main() {

	ull q{}, n{};
	std::vector<ull> S, T;

	std::cin >> n;
	for (ull i{}; i < n; i++){
		ull tmp{};
		std::cin >> tmp;
		S.emplace_back(tmp);
	}

	std::cin >> q;
	for (ull i{}; i < q; i++)	{
		ull tmp{};
		std::cin >> tmp;
		T.emplace_back(tmp);
	}

	std::sort(std::begin(S), std::end(S)); 
	auto es = std::unique(std::begin(S), std::end(S));
	std::sort(std::begin(T), std::end(T));
	auto et = std::unique(std::begin(T), std::end(T));


	ull c{};
	for (auto its=std::begin(S); its!=es;++its)
		for (auto itt=std::begin(T);itt!=et;++itt)
			if (*its == *itt)c++;

	std::cout << c << "\n";
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // 一年の秒数
  int a1,a2,a3,sum;
  cin >> a1 >>a2 >> a3;
  sum = a1+ a2+ a3;

  if(sum <= 21)
  {
    cout << "win" << endl;
  }
  else
  {
    cout << "bust" << endl;
  }
}

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

kane=[None]*(N+1)
kabu=[None]*(N+1)
kane[0]=1000
kabu[0]=(0,1000)
for i in range(1,N+1):
    kane[i] = max(kane[i-1],kabu[i-1][0]*A[i-1]+kabu[i-1][1])
    
    cand1 = (kane[i-1]//A[i-1],kane[i-1]%A[i-1])
    if A[i-1]<=kabu[i-1][1]:
        cand2 = (kabu[i-1][0]+1,kabu[i-1][1]-A[i-1])
    else:
        cand2 = (kabu[i-1][0],kabu[i-1][1])
    kabu[i] = max(cand1,cand2)

print(kane[-1])

Measured memory_bytes: 62092
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,W;
    cin>>n>>W;
    V<ll> w(n),v(n);
    rep(i,n) cin>>w[i]>>v[i];
    ll ans=0;
    V<V<ll>> c(4);
    rep(i,n) c[w[i]-w[0]].push_back(v[i]);
    ll s[5][101];
    rep(i,4) sort(all(c[i]),greater<ll>());
    rep(i,4){
        rep(j,c[i].size()+1) s[i][j]=0;
    }
    rep(i,4){
        rep(j,c[i].size()) s[i][j+1]=s[i][j]+c[i][j];
    }
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=n;j++){
            for(ll k=0;k<=n;k++){
                if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)>W) continue;
                ll l=min((W-(i*w[0]+j*(w[0]+1)+k*(w[0]+2)))/(w[0]+3),(ll)c[3].size());
                if(i>c[0].size()||j>c[1].size()||k>c[2].size()) continue;
                chmax(ans,s[0][i]+s[1][j]+s[2][k]+s[3][l]);
            }
        }
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 256
import heapq as hq

N,M=map(int,input().split())
wl=[];hq.heapify(wl) # workList
for i in range(N):
    A,B=map(int,input().split())
    hq.heappush(wl,(A,B))

w=[];hq.heapify(w)
ans=0
for i in range(M): # 0日後からM-1日後まで
    while wl and wl[0][0]<=i+1:
        hq.heappush(w,-hq.heappop(wl)[1])
    if w:
        ans+=-hq.heappop(w)

print(ans)

Measured memory_bytes: 86104
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

void solve(int src,int dst)
{
	vi res;
	if(src<=5 && dst<=5){
		if(src<dst)
			for(int i=src;i<=dst;i++)
				res.push_back(i);
		else
			for(int i=src;i>=dst;i--)
				res.push_back(i);
	}
	else if(src<=5){
		for(int i=src;i<=dst;i++)
			res.push_back(i);
	}
	else if(dst<=5){
		for(int i=src;i<=9;i++)
			res.push_back(i);
		for(int i=5;i>=dst;i--)
			res.push_back(i);
	}
	else if(src<dst){
		for(int i=src;i<=dst;i++)
			res.push_back(i);
	}
	else{
		for(int i=src;i<=9;i++)
			res.push_back(i);
		for(int i=5;i>0;i--)
			res.push_back(i);
		for(int i=0;i<5;i++)
			res.push_back(i);
		for(int i=5;i<=dst;i++)
			res.push_back(i);
	}
	for(int i=0;i<res.size();i++)
		printf("%d%c",res[i],i==res.size()-1?'\n':' ');
}

int main()
{
	int n;
	cin>>n;
	rep(i,n){
		int src,dst;
		cin>>src>>dst;
		solve(src,dst);
	}
	
	return 0;
}

Measured memory_bytes: 0