akhauriyash/Code-Regression huggingface dataset:
/*
      H   H
       \ / 	
        C
       / \ 
      H   H
*/

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vvi			vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)		for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)	((c).find(x) != (c).end()) 
#define cpresent(c,x)	(find(all(c),x) != (c).end()) 
#define int ll
using namespace std;

#define N  100005

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n, k;
		cin >> n >> k;

		int a[n];

		rep(i, 0, n)
		{
			cin >> a[i];
			a[i]--;
		}

		int c = 1;
		vi v1;

		int i = a[0];
		v1.pb(0);
		v1.pb(i);

		set<int> s;
		s.insert(0);
		int num;
		while(1)
		{
			if(s.find(i)!=s.end())
			{
				num = i;
				break;
			}
			s.insert(i);
			i = a[i];
			v1.pb(i);
		}

		vi v;

		for(i = 0; i<sz(v1); i++)
		{
			if(v1[i]==num)
			{
				i++;
				break;
			}
			k--;
			if(k==0)
			{
				cout << v1[i+1]+1;
				return 0;
			}
		}

		for(i; i<sz(v1); i++)
			v.pb(v1[i]);

		// for(auto it: v)
		// 	cout << it << " ";
		// cout << endl;
		c = sz(v);
		int x = (k%c-1+c)%c;
		cout << v[x]+1;
	}
	return 0;
}

Measured memory_bytes: 16460
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int n;
priority_queue< double > pq;

int main(){
	cin >> n;
	rep(i, n){
		double d;
		cin >> d;
		pq.push(-d);
	}
	while(!pq.empty()){
		double now1 = pq.top(); pq.pop();
		if(pq.empty()){
			cout << fixed << setprecision(12) << -now1 << endl;
			return 0;
		}
		double now2 = pq.top(); pq.pop();
		double nxt = (now1 + now2) / 2.00;
		pq.push(nxt);
	}
	return 0;
}

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

int main() {
	int n,k;
	while(cin >> n && n>-1) {
		k=1150;
		if (n>30) k+=(n-30)*160+1400+1250;	else if (n>20) k+=(n-20)*140+1250; else if (n>10) k+=(n-10)*125;
		cout << 4280-k << endl;
	}
	return 0;
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n, k;
int x[200000];

int main(){
    cin >> n >> k;
    rep(i,n) {
        int tmp; cin >> tmp;
        tmp--; x[tmp]++;
    }
    sort(x, x+200000, greater<int>());
    int ans = n;
    rep(i,200000) {
        if (x[i] == 0) continue;
        ans -= x[i];
        k--;
        if (k == 0) break;
    }
    cout << ans << endl;
}
































Measured memory_bytes: 1024
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
using namespace std;

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

#define scan1(a) scanf("%d", &a)
#define scan2(a,b) scanf("%d%d", &a,&b)
#define scan3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scan4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define print1(a) printf("%d\n", a)
#define print2(a,b) printf("%d%d\n", a,b)
#define print3(a,b,c) printf("%d%d%d\n", a,b,c)
#define print4(a,b,c,d) printf("%d%d%d%d\n", a,b,c,d)

int main(void){
    int N, maxv = 0;
    string S;
    
    cin >> N >> S;
    
    rep(i,N-1) {
        string s = S.substr(0,i+1);
        string t = S.substr(i+1);
        int cnt = 0;
        
        for ( char c = 'a'; c <= 'z'; c++) {
            
            if ( s.find(string {c}) != string::npos) {
                if ( t.find(string {c}) != string::npos) cnt++;
            }
        }
        maxv = max( maxv, cnt);
    }
    cout << maxv << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#define N 100000

int A[N];

int main(){
  int i,j,n,y;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  y = partition(0,n-1);

  for(i=0;i<n;i++){
    if(i != 0){
      printf(" ");
    }

    if(i == y){
      printf("[");
    }
    printf("%d",A[i]);
    if(i == y){
      printf("]");
    }

  }
  printf("\n");

  return 0;
}

int partition(int m, int n){
  int i,j,x,tmp;

  x = A[n];
  i = m-1;

  for(j=m;j<n;j++){
    if(x >= A[j]){
      tmp  = A[j];
      A[j] = A[i+1];
      A[i+1] = tmp;
      i++;
    }
  }

  tmp = A[i+1];
  A[i+1] = A[n];
  A[n] = tmp;

return i+1;
}


Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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 keta setprecision(15) //15桁表示



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

	string s, t;
	cin >> s >> t;

	cout << t << s << endl;

	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

ll mod=1e9+7;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

vector<ll> tfact(ll(1e7)+1,-1);
ll fact(ll n) {
  if(tfact[n]<0) {
    if(n==0) {
      tfact[n]=1;
    }
    else {
      tfact[n]=fact(n-1)*n%mod;
    }
  }
  return tfact[n];
}

//nCk
ll comb(ll n, ll k) {
  ll res=1;
  if(n-k<k) {
    k=n-k;
  }
  for(ll i=n;i>=n-k+1;i--) {
    res=res*i%mod;
  }
  res=res*mpow(fact(k),mod-2)%mod;
  return res;
}

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans=(mpow(2,n)-1+mod)%mod;
  ans=(ans+(mod-comb(n,a))%mod)%mod;
  ans=(ans+(mod-comb(n,b))%mod)%mod;
  cout << ans << endl;
}

Measured memory_bytes: 84608
import java.util.*;

public class Main{
    Scanner in = new Scanner(System.in);

    void solve(){
        String s = in.nextLine();
        int a = s.replace("dreamer", "").replace("dream", "").replace("eraser", "").replace("erase", "").length();
        int b = s.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "").length();
        if(a == 0 || b == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

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

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


Measured memory_bytes: 3632
N = int(input())
X = [int(input()) for i in range(N)]
X = sorted(X)

if N%2 == 0:
    n = N//2
    print(sum(X[:n-1])*(-2) + sum(X[n+1:])*2 + X[n] - X[n-1])
else:
    n = (N-1)//2
    print(max(sum(X[:n-1])*(-2) + sum(X[n+1:])*2 - X[n] - X[n-1], sum(X[:n])*(-2) + sum(X[n+2:])*2 + X[n] + X[n+1]))

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,d;
vector<int> v;

main() {
    cin >> n;
    rep(i,n) {
        cin >> d;
        v.pb(d)
    }
    sort(all(v));
    vdelete(v)
    ct(v.size())
}






Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <climits>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <list>

#define FOR(i,n)    for(int i = 0 ; i < n ; i++)
#define FORrev(i,n) for(int i = n - 1 ; i >= 0 ; i--)
#define ALL(a)      a.begin(),a.end()

typedef long long int ll; 

using namespace std;

int main() {
	int n;
	cin>>n;
	int a[n];
	FOR(i , n)
		cin>>a[i];
	int dp[n];
	memset(dp , 0 , sizeof(dp));
	int ans = 0;
	for(int i = 1 ; i < n ; i++) {
		if(a[i] <= a[i - 1])
			dp[i] = dp[i - 1] + 1;
		ans = max(dp[i] , ans);
	}
	cout<<ans;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

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

	ll ans=2LL;
	rep(loop,x) ans=2LL*ans+2LL;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    
    if(x<=0 || y<=0 || x>=W || y>=H){
        cout<<"No"<<endl;
    }
    else{
        if(x+r>W || x-r<0) cout<<"No"<<endl;
        else if(y+r>H || y-r<0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
 
bool vector_finder(std::vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) {
    return true;
  }
  else {
    return false;
  }
}

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}
 
 
int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> p(N);

  ll ans = 0;

  for (ll i = 0; i < N; i++) {
    cin >> p.at(i);
  }

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

  for (ll i = 0; i < K; i++) {
    ans += p.at(i);
  }
  


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

Measured memory_bytes: 3620
import math
from decimal import Decimal

a, b, c = map(int, input().split())

# if math.sqrt(a) + math.sqrt(b) < math.sqrt(c):
#     print('Yes')
# else:
#     print('No')

if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5076
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: u64,
        B: u64,
        H: u64,
    }
    println!("{}",(A+B)*H/2);
}

Measured memory_bytes: 4352
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine


getMax as i k l m' m
  | l < i + k = m
  | m'' > m = getMax as (i + 1) k l m'' m''
  | otherwise = getMax as (i + 1) k l m'' m
  where
    m'' = m' - as ! i + as ! (i + k)

main = do
  [n, k] <- getIntList
  ps <- getIntList
  let ps' = listArray (1, length ps) ps
  let l = length ps
  let m = sum (take k ps)
  let a = if k == n then m else getMax ps' 1 k l m m
  print $ (fromIntegral (a + k)) / 2


Measured memory_bytes: 33212
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
  sc.Split(bufio.ScanWords)
  n := nextInt()
  k := nextInt()
  var c int
  for i := 0; i < n; i++ {
    if h := nextInt(); h >= k {
      c++
    }
  }
  fmt.Println(c)
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	priority_queue <pair<int,int> > h;
	while(a--)
	{
		int w;
		cin>>w;
		h.push(make_pair(w,1));
	}
	while(b--)
	{
		int w;
		cin>>w;
		h.push(make_pair(w,2));
	}
	while(c--)
	{
		int w;
		cin>>w;
		h.push(make_pair(w,3));
	}
	int z=x+y,ans=0;
	
	while(z)
	{
		pair <int,int> f=h.top();
		h.pop();
		if(f.second==3)
		{
			z--;
			ans+=f.first;
		}
		if(f.second==1 && x)
		{
			z--;
			x--;
			ans+=f.first;
		 } 
		if(f.second==2 && y)
		{
			z--;
			y--;
			ans+=f.first;
		 } 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 10604
import sys

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

ans = 0
N, M, Q = map(int, rl().split())
abcd = [list(map(int, rl().split())) for _ in range(Q)]


def calc(A):
    if len(A) == N:
        tmp = 0
        for a, b, c, d in abcd:
            if A[b - 1] - A[a - 1] == c:
                tmp += d
        global ans
        ans = max(ans, tmp)
    else:
        for i in range(A[-1], M + 1):
            calc(A + [i])


def solve():
    for i in range(1, M + 1):
        calc([i])
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();

		K = K - A;
		if (K <= 0) {
			System.out.println(K + A);
		} else {
			K = K - B;
			if (K <= 0) {
				System.out.println(A);
			} else {
				System.out.println(A - K);
			}
		}
	}
}

Measured memory_bytes: 35552
fun <T> permutationList(sortedList: List<T>): List<List<T>> {
    val queue = mutableListOf<List<T>>()
    queue.add(arrayListOf())
    val permutations = mutableListOf<List<T>>()
    while (queue.isNotEmpty()) {
        val p = queue.removeAt(0)

        if (p.size == sortedList.size) {
            permutations.add(p)
            continue
        }

        for (item in (sortedList - p)) {
            queue.add(p + item)
        }
    }

    return permutations
}

fun main(args: Array<String>) {
    val n = readInteger()
    val p = readIntegerList()
    val q = readIntegerList()

    val per = permutationList((1..n).toList())
    Math.abs(per.indexOf(p) - per.indexOf(q)).let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 57644
/* Problem Description:

*/

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

using namespace std;

#define REP(i,a,b) for (int i = (a); i < (b); i++)
#define RREP(i,a,b) for (int i = (a); i > (b); i--)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define TRvi(it, c) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define inf 0x3f3f3f3f
#define EPS 1e-10
#define PI acos(-1.0)
#define scan(x) scanf("%d",x)
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(x) ((x)*(x))
#define LSOne(x) x&(-x)
#define debug(x) cout << #x << " " << x << endl;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
   //  freopen("in" , "r" , stdin);
   //  freopen("out" , "w" , stdout);
    #endif
    int n;
    cin >> n;
    int height[n];
    for (int i = 0; i < n; i++){
      cin >> height[i];
    }

    vector<int> dp(n+1, inf);
    dp[0] = 0;
    for (int i = 0; i < n; i++){
      for (int j = i+1; j <= i+2; j++)
        if (j < n)
          dp[j] = min(dp[j],dp[i]+abs(height[i]-height[j]));
    }

    cout << dp[n-1] << endl;
    return 0;
 }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    set<int> s;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        if(s.count(ai)) s.erase(ai);
        else s.insert(ai);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
 
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  ll n;
  cin>>n;
  vll v(5);
  rep(i,5)cin>>v[i];
  
  vsort(v);
  ll min=v[0];
  ll ans=4+(n+min-1)/min;
  cout(ans);
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#define maxn 100010
using namespace std;
int n,a[maxn],ans,tmpa,tmpsum;
int read()
{
	int f=1,x=0;
	char ch=getchar();
	while(isdigit(ch)==0 && ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	    a[i]=read();
	sort(a+1,a+n+1);
	a[n+1]=-2;
	for(int i=1;i<=n+1;i++)
	{
		if(a[i]!=tmpa && i!=1)
		{
			if(tmpsum!=tmpa)ans+=tmpa>tmpsum?tmpsum:(tmpsum-tmpa);
			tmpa=a[i];
			tmpsum=0;
		}
		if(i==1)
		    tmpa=a[i];
		tmpsum++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
 char exchange(char c)
 {
     if ('A' <= c && c <= 'Z'){
         return c + ('a' - 'A');
     }
     else if ('a' <= c && c <= 'z'){
         return c - ('a' - 'A');
     }
     else 
     return c;
 }
 
 int main(void){
    int i, len;
    char s[4096];  
    fgets(s, sizeof(s), stdin);
    len = strlen(s);   
    for(int i = 0; i < len;i++) {
        s[i] = exchange(s[i]);
    }
    printf("%s",s);
    
    return 0;
 }
 


Measured memory_bytes: 2088
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

int main()
{
    string s;
    getline(cin, s);

    for(auto& c: s) if (c==',' or c=='.') c=' ';

    istringstream is(s);
    string t;
    vector<string> res;
    while (is>>t) if (2<t.size() and t.size()<7) res.push_back(t);

    for(int i=0; i<res.size(); ++i)
        cout<<res[i]<<(i+1<res.size() ? ' ' : '\n');
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;


ll n;
class neig {
    public:
    neig(){};
    template<class T>
    neig(T id){
        if(id == 0){pre = n-1; nex = 1;}
        else if(id == n-1){pre = n-2; nex = 0;}
        else{pre = id - 1; nex = id + 1;}
    }
    ll pre, nex;
};

ll ceil(ll a,ll b){
    return (a + b - 1) / b;
};

int main(){
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    priority_queue<Pll> pq;
    vector<ll> b(n);
    rep(i,n) {
        cin >> b[i];
        if(b[i] != a[i])pq.push({b[i], i});
    }
    bool ok = true;
    ll ans = 0;
    while(pq.size()){
        Pll temp = pq.top();pq.pop();
        neig tn = neig(temp.second);
        ll sum = b[tn.pre] + b[tn.nex];
        // debug(temp.first);debug(temp.second);
        // debug(sum);
        if(temp.first < sum){ok = false;break;}
        //if(temp.first == a[temp.second])continue;
        if(temp.first > max(a[temp.second], sum)){
            ll t = temp.first - ((temp.first / sum) * sum);
            if(t < a[temp.second] ){
                if((b[temp.second] - a[temp.second]) % sum != 0){
                    ok = false;
                    break;
                }
            }
            ans += (b[temp.second] - max(t, a[temp.second])) / sum;
            b[temp.second] = max(t, a[temp.second]);
        }
        if(b[temp.second] != a[temp.second])pq.push({b[temp.second], temp.second});
    }

    cout << (ok ? ans : -1) << endl;
}


Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SemiCommonMultiple | diff SemiCommonMultiple.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SemiCommonMultiple.cpp && ./a.out

/*

 7/27/2020

 20:49-

 */

const int MAX_N=1e6+1;
int A[MAX_N];
int N,M;

LL gcd(LL a, LL b) { return b==0?a:gcd(b,a%b); }
LL lcm(LL a, LL b) { return a/gcd(a,b)*b; }
LL solve() {
  VI as(A,A+N);
  REP(i,N) as[i]/=2;
  int e2=0;
  REP(i,N) {
    int a=as[i],cnt=0;
    while(a>0&&a%2==0) a/=2,cnt++;
    if(i==0) e2=cnt;
    else if(cnt!=e2) return 0;
  }

  LL l=as[0];
  REP(i,N) {
    l=lcm(l,as[i]);
    if(l>M) return 0;
  }
  LL res=M/l;
  res=(res+1)/2;
  return res;
}

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

  cin>>N>>M;
  REP(i,N) cin>>A[i];
  cout<<solve()<<endl;

  return 0;
}


Measured memory_bytes: 4020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(int argc, const char * argv[]) {
    int N;
    SCD(N);
    int h[N];
    FOR(i, 0, N, 1)
        SCD(h[i]);
    int a = 0;
    int b = abs(h[1] - h[0]);
    int i = 1;
    while (i != N - 1) {
        i++;
        int t = min(a + abs(h[i] - h[i - 2]), b + abs(h[i] - h[i - 1]));
        a = b;
        b = t;
    }
    
    printf("%d\n", b);
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string>

int main()
{
	int A, B, K;

    // 整数の入力
    scanf("%d %d %d", &A, &B, &K);

	int takahashi = A;
	int aoki = B;

	bool is_K_odd = K % 2 != 0;
	int lp = K / 2;
	int given;
	for(int l=0; l<lp; l++){
		// takahashi
		if(takahashi & 1){
			takahashi--;
		}
		takahashi /= 2;
		aoki += takahashi;

		// aoki
		if(aoki & 1){
			aoki--;
		}
		aoki /= 2;
		takahashi += aoki;
	}
	if(is_K_odd){
		// takahashi
		if(takahashi & 1){
			takahashi--;
		}
		takahashi /= 2;
		aoki += takahashi;
	}

    // 出力
    printf("%d %d", takahashi, aoki);
    return 0;
}

Measured memory_bytes: 888
<?php
    $num = trim(fgets(STDIN));
    $input = explode(" ",trim(fgets(STDIN)));
    $flag = 0;
    sort($input);
//    var_dump($input);
    
    if($num % 2 == 0){
        $ans = $num/2;
        for($i=0;$i<$num;$i++){
            $should_be = 2*(floor($i/2)+1)-1;
//            echo "input:".$input[$i]." should_be:".$should_be;
//            echo PHP_EOL;
            if($input[$i] != $should_be){
                $flag = 1;
            }
        }
    } else {
        $ans = ($num-1)/2;
        for($i=0;$i<$num;$i++){
            $should_be = ceil($i/2)*2;
            if($input[$i] != $should_be){
                $flag = 1;
            }
        }        
    }
    
    $answer = 1;
    if($flag==0){
        for($i=0;$i<$ans;$i++){
            $answer = ($answer * 2) % 1000000007;
        }
        echo $answer;
    } else {
        echo 0;
    }



?>  

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

int main(){
    long long N, Y, tmp=0, ans=0;
    cin >> N >> Y;
    tmp = N;
    while(true){
	ans++;
	tmp *= 2;
	if(tmp > Y)
	    break;
    }
    cout << ans << endl;    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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


const string YES = "Yes";
const string NO = "No";

void solve(long long D, long long T, long long S){
    if(D<=T*S){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long D;
    scanf("%lld",&D);
    long long T;
    scanf("%lld",&T);
    long long S;
    scanf("%lld",&S);
    solve(D, T, S);
    return 0;
}


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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  
  while(1) {
    int w, h; cin >> w >> h;
    if(w == 0 && h == 0) break;
    vector<vector<bool>> c(h);
    int tmp = 0;
    REP(i, h) {
      c[i].resize(w);
      REP(j, w) {
        cin >> tmp;
        c[i][j] = (tmp == 1);
      }
    }

    int cnt = 0;
    vector<vector<bool>> sel(h);
    REP(i, h) {
      sel[i].resize(w, false);
    }

    REP(i, h) {
      REP(j, w) {
        if(!sel[i][j] && c[i][j]) {
          P st = make_pair(i, j);
          // cout << i << ":" << j << endl;
          vi dx = {-1, 0, 1}, dy = {-1, 0, 1};
          queue<P> q;
          q.push(st);
          sel[i][j] = true;
          while(!q.empty()) {
            P now = q.front();q.pop();
            REP(k, 3) {
              REP(l, 3) {
                int tmpx = now.fi + dx[k], tmpy = now.se + dy[l];
                if(0 <= tmpx && tmpx <= h-1 &&
                   0 <= tmpy && tmpy <= w-1 &&
                   !sel[tmpx][tmpy] && c[tmpx][tmpy] && (dx[k] != 0 || dy[l] != 0)) {
                  q.push(make_pair(tmpx, tmpy));
                  sel[tmpx][tmpy] = true;
                }
              }
            }
          }
          cnt++;
        }
      }
    }

    cout << cnt << endl;
  }

}



Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <math.h>
#include<algorithm>
using namespace std;
 
int main(){
  string w;
  cin >> w;
  char b[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  int c[26];
  for(int i=0;i<26;i++){
    c[i]=0;
    for(int j=0;j<w.size();j++){
     if(w[j]==b[i]){
       c[i]=c[i]+1;
     }
    }
  }
  bool flag=true;
  for(int i=0;i<26;i++){
   if(c[i]%2==1){
    flag=false; 
   }
  }
  if(flag==false){
   cout << "No" << endl; 
  }
  else{
   cout << "Yes" << endl; 
  }
  return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int, int>
#define int              long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

const int inf = 1e6;
const int cont = 1e18;
using namespace std;

void solve(){
   int n;
   cin>>n;
   string s;
   cin>>s;
   int cnt = 0;
   int ans = 0;
   for(int i=0; i<n; i++){
        if(s[i] == 'I')cnt++;
        else cnt --;
        ans = max(ans, cnt);
   }
   cout<<ans<<endl;
}

int32_t main() {
    Fast;
    solve();
    return Okay;
}


Measured memory_bytes: 3644
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]
for i in range(N):
    ans = 0
    for j in range(i, N-1):
        if ans >= CSF[j][1]:
            ans = -(-ans//CSF[j][2]*CSF[j][2]) + CSF[j][0]
        else:
            ans = CSF[j][1] + CSF[j][0]
    print(ans)


Measured memory_bytes: 44396
from itertools import combinations
n = int(input())
L = list(map(int,input().split()))
ans = 0
for x in combinations(L,3):
    a,b,c = map(int,x)
    if a == b or b == c or c == a:
        continue
    ans += (2*max(a,b,c) < a+b+c)
print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int *a=(int*)malloc(sizeof(int)*100000000);
  long int n;
  int f=1;
  cin>>n;
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n;i++){
  	if(a[i]==a[i+1]){
	  f=0;
	  break;
  }
}
	  if(f) cout<<"YES";
	  else cout<<"NO";
  
return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

#define N 26

const int INF = 1 << 30;

int c[N];
int s[365][N];
int last[N];
std::chrono::time_point<std::chrono::steady_clock> start, endt;

struct ContestInfo {
	int D;
	int score;
	vector<int> t;
	set<int> held[N];
	ContestInfo(int dd) : D(dd), score(0) {
		t.resize(D, -1);
		for (int i = 0; i < N; i++) {
			held[i].insert(-1);
			held[i].insert(D);
			score -= c[i] * D * (D + 1) / 2;
		}
	}

	void add(int dd, int qq) {
		if (t[dd] != -1) {
			cout << "Add faild!" << endl;
			exit(1);
		}

		t[dd] = qq;
		score += s[dd][qq];
		held[qq].insert(dd);
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score -= c[qq] * range(*litr, *ritr);
		score += c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
	}

	void erase(int dd) {
		if (t[dd] == -1) {
			cout << "Erase faild!" << endl;
			exit(1);
		}
		int qq = t[dd];
		t[dd] = -1;
		score -= s[dd][qq];
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score += c[qq] * range(*litr, *ritr);
		score -= c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
		held[qq].erase(itr);
	}

	void change(int dd, int qq) {
		erase(dd);
		add(dd, qq);
	}

	void output() {
		for (int i = 0; i < D; i++)
			cout << t[i] + 1 << endl;
	}
};

void tic() {
	start = std::chrono::steady_clock::now();
}

double toc() {
	endt = std::chrono::steady_clock::now();
	std::chrono::duration<double> elapsed_seconds = endt - start;
	return elapsed_seconds.count();
}

int main() {
	tic();
	int d;
	cin >> d;
	for (int i = 0; i < N; i++)
		cin >> c[i];
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < N; j++) {
			cin >> s[i][j];
		}
	}

	int t;
	ContestInfo ci(d);
	for (int i = 0; i < d; i++) {
		t = rand() % N;
		ci.add(i, t);
	}

	int current_score = ci.score;

	int dd, qq;
	while (toc() < 1.9) {
		dd = rand() % d;
		qq = rand() % N;
		int old_q = ci.t[dd];
		ci.change(dd, qq);
		int new_score = ci.score;
		current_score = new_score;
		if (new_score < current_score)
			ci.change(dd, old_q);
		else
			current_score = new_score;
	}
	ci.output();
	// cout << ci.score << endl;
}

Measured memory_bytes: 3692
import sys

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])

P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero and k%2:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod

print(ans)

Measured memory_bytes: 31652
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

vector<string> S {
  "dream",
  "dreamer",
  "eraser",
  "erase",
};

int main() {
  string t; cin >> t;
  reverse(t.begin(), t.end());
  for (auto&& s: S) reverse(s.begin(), s.end());
  while (t != "") {
    bool ok = false;
    for (auto &&s: S) {
      if (t.find(s) == 0) {
        t = t.substr(s.size());
        ok = true;
        break;
      }
    }
    
    if (!ok) {
      cout << "NO" << endl;
      return 0;
    }
  }
  
  cout << "YES" << endl;
  return 0;
}


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

vector<vector<int> > flag(9,vector<int>(9,0));
vector<int> v;


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

    for(int i=1;i<=N;i++){
        v.push_back(i);
    }
    int ans=0;
    do{
        int cnt=0;
        for(int i=0;i<N-1;i++){
            if(flag[v[i]][v[i+1]]) cnt++;
        }
        ans+=(cnt==N-1);
    }while(next_permutation(v.begin()+1,v.end()));

    cout<<ans<<endl;

        
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 405
#define M 1000000007
#define ll long long
#define inf 1000000000000000000
ll n, arr[N];
pair<ll ,ll >dp[N][N];

pair<ll, ll> cal(int i, int j)
{
    if(i == j) return dp[i][j] = {arr[i], 0};
    if(dp[i][j].second != inf) return dp[i][j];
    for(int k = i; k < j; k++)
    {
        auto fs = cal(i, k);
        auto ss = cal(k + 1, j);
        ll cn = fs.first + ss.first;
        ll cc = cn + fs.second + ss.second;
        if(cc < dp[i][j].second)
        {
            dp[i][j] = {cn, cc};
        }
    }
    //cout << i <<" " << j << " " << dp[i][j].second << endl;
    return dp[i][j];
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> arr[i];
    for(int i = 1; i <= n; i++) for(int j = 1; j <= n ; j++) dp[i][j].second = inf;
    cout << cal(1, n).second << endl;
}




Measured memory_bytes: 2816
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    ll n, a[5]; cin>>n;
    for(int i=0; i<5; i++) cin>>a[i];
    ll mn=*min_element(a, a+5);
    cout<<(n+mn-1)/mn+4<<endl;
    return 0;
}

Measured memory_bytes: 256
S = gets.chomp
ans = []
S.chars do |i| # 文字列の各文字を文字列の配列で返す。(self.each_char.to_a と同じ)
  if i != "B"
    ans << i # 文字列を破壊的に連結
  else
    ans.pop  ## 自身の末尾から要素を取り除きそれを返す。
  end
end

puts ans.join


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int A[505*505];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int N; cin>>N;
  vector<pair<int,int> > X(N);
  for(int i=1;i<=N;i++){
    int x; cin>>x;
    X[i-1]={x,i};
    A[x]=i;
  }
  sort(X.begin(),X.end());
  int l=1;
  for(auto p:X){
    int x=p.first, num=p.second;
    int cnt=num-1;
    while(l<x&&cnt>0){
      if(A[l]==0){
        A[l]=num;
        cnt--;
      }
      l++;
    }
    if(cnt>0){
      cout<<"No\n";
      return 0;
    }
  }
  reverse(X.begin(),X.end());
  int r=N*N;
  for(auto p:X){
    int x=p.first, num=p.second;
    int cnt=N-num;
    while(r>x&&cnt>0){
      if(A[r]==0){
        A[r]=num;
        cnt--;
      }
      r--;
    }
    if(cnt>0){
      cout<<"No\n";
      return 0;
    }
  }
  cout<<"Yes\n";
  for(int i=1;i<=N*N;i++) cout<<A[i]<<" ";
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 2176
package main

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

type Data struct {
	X   int
	L   int
	Min int
	Max int
	Al  int
}

type Datas []Data

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	return p[i].Max < p[j].Max
}

func check(d Datas, n, i int) bool {
	min := d[n].Min
	if i == -1 {
		return true
	}
	//for i := pos; i < n; i++ {
	if (d[i].Al == 1) && (d[i].Max > min) {
		return false
	}
	//}
	return true
}

func main() {
	//	fmt.Println("start")
	var N int
	sc.Split(bufio.ScanWords)
	N = nextInt()

	d := make(Datas, N)
	for i := 0; i < N; i++ {
		d[i].X = nextInt()
		d[i].L = nextInt()
		//fmt.Scanf("%d %d", &d[i].X, &d[i].L)
		d[i].Min = d[i].X - d[i].L // + 1
		d[i].Max = d[i].X + d[i].L //- 1
		d[i].Al = 0
	}

	sort.Sort(d)
	cnt := 0
	pos := -1
	for i := 0; i < N; i++ {
		//fmt.Println("pass")
		if check(d, i, pos) {
			//fmt.Println("get", i)
			d[i].Al = 1
			pos = i
			cnt++
		}
	}
	//	fmt.Println(N, d[:N])
	fmt.Println(cnt)
}


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

int main() {
  int n;
  cin >> n;
  ll total = 0;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  rep(i, n) { total += a[i / 2]; }
  cout << total - a[0] << endl;
}


Measured memory_bytes: 4840
#include<iostream>

int main() {
	int a,b,c,d,e,k;
	std::cin >> a>>b>>c>>d>>e>>k;

	if (e - a > k) {
		std::cout << ":("<< std::endl;
	}
	else {
		std::cout << "Yay!" << std::endl;
	}

	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
int dx[]={1,1,1,0,0,-1,-1,-1};
int dy[]={1,0,-1,1,-1,1,-1,0};
char str[7][7];
int tmp[7][7];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		int row,col;
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)if(str[i][j]=='@'){
			row=i;col=j;str[i][j]='.';
		}
		set<pair<int,pair<int,int> > >S;
		int s=0;
		for(int i=0;i<a;i++)for(int j=0;j<a;j++){
			s*=2;
			if(str[i][j]=='#')s++;
		}
		S.insert(make_pair(s,make_pair(row,col)));
		queue<pair<pair<int,int>,pair<int,int> > >Q;
		Q.push(make_pair(make_pair(0,s),make_pair(row,col)));
		bool yet=true;
		while(Q.size()){
			int cost=Q.front().first.first;
			int at=Q.front().first.second;
			int r=Q.front().second.first;
			int c=Q.front().second.second;
			Q.pop();
//			printf("%d %d %d %d\n",cost,at,r,c);
			if(at==0){
				yet=false;
				printf("%d\n",cost);
				break;
			}
			int t=at;
			for(int i=a-1;i>=0;i--)for(int j=a-1;j>=0;j--){
				tmp[i][j]=t%2;
				t/=2;
			}
			for(int i=0;i<8;i++){
				int tr=r+dx[i];int tc=c+dy[i];
				if(tr<0||tr>=a||tc<0||tc>=a)continue;
				if(tmp[tr][tc])continue;
				tmp[tr][tc]=1;
				int num=0;
				for(int j=0;j<a;j++)for(int k=0;k<a;k++){
					int val=0;
					for(int l=0;l<8;l++)if(j+dx[l]>=0&&j+dx[l]<a&&k+dy[l]>=0&&k+dy[l]<a&&tmp[j+dx[l]][k+dy[l]])val++;
					num*=2;
					if(tr==j&&tc==k)continue;
					if(tmp[j][k]&&(val==2||val==3))num++;
					if(!tmp[j][k]&&val==3)num++;
				}
				if(!S.count(make_pair(num,make_pair(tr,tc)))){
					S.insert(make_pair(num,make_pair(tr,tc)));
					Q.push(make_pair(make_pair(cost+1,num),make_pair(tr,tc)));
				}
				tmp[tr][tc]=0;
			}
		}
		if(yet)printf("-1\n");
	}
}

Measured memory_bytes: 2780