akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include <algorithm>

using namespace std;

int C[200004];

int N, K, A[200004];

vector<int> V;

int main(void) {

	cin >> N >> K;

	for (int i = 1; i <= N; i++) { cin >> A[i]; }

	for (int i = 1; i <= N; i++) {
		C[A[i]]++;
	}

	for (int i = 1; i <= N; i++) {
		 V.push_back(C[i]); 
	}

	sort(V.rbegin(), V.rend());

	int ans = 0;
	for (int i = K; i <N; i++) {
		ans += V[i];
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 2936
# -*- coding: utf-8 -*-

N=int(input())
As=list(map(int, input().split()))

inds=sorted(range(len(As)), key=lambda k: As[k])[::-1]
#ds=[[0 for j in range(N+1-i)] for i in range(N+1)]

ds=[0]
for xy in range(1,N+1):
    i=inds[xy-1]
    a=As[i]
    nds=[0]*(xy+1)
    nds[-1]=ds[-1]+a*(i-(xy-1))
    nds[0]=ds[0]+a*(N-xy-i)

    for x in range(1,xy):
        y=xy-x
        c1=ds[x-1]+a*abs(i-(x-1))
        c2=ds[x]+a*abs(N-y-i)
        nds[x]=max(c1,c2)
    ds=nds.copy()
    #print(ds)


print(max(ds))
#print(ds)
#print(inds)




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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int N,C;
    cin >> N >> C;
    VVI time(C,VI(500000,0));
    for (int i = 0; i < N; i++) {
        int s,t,c;
        cin >> s >> t >> c;
        for (int j = s*2-1; j <= t*2; j++) {
            time[c-1][j] = 1;
        }
    }
    int ans = 0;
    for (int j = 0; j < 300000; j++) {
        int tmp = 0;
        for (int i = 0; i < C; i++) {
            tmp += time[i][j];
        }
        ans = max(ans,tmp);
    }
    std::cout << ans << std::endl;
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<bool> is_prime((int) 1e6 + 1, true);
  vector<int> v;
  for (long long i = 2; i <= (long long) 1e6; i++) {
    if (is_prime[i]) {
      v.push_back(0);
      while (n % i == 0) {
        v.back()++;
        n /= i;
      }
      for (long long j = 2 * i; j <= (long long) 1e6; j += i) {
        is_prime[j] = false;
      }
    }
  }
  if (n > 1) {
    v.push_back(1);
  }
  int ans = 0;
  for (auto& x : v) {
    for (int i = 1; x >= i; x -= i, i++, ans++);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4008
#include<iostream>
#include<vector>
#include<cstring>
#include<climits>
using namespace std;
vector<int> gr[100001];
int dp[100001];
int solve(int src)
{
    if(dp[src]!=-1)
    {
        return dp[src];
    }
    int best=0;
    bool leaf=true;
    for(int ch:gr[src])
    {
        leaf=false;
        best=max(best,solve(ch));
    }
    return dp[src]=leaf?0:1+best;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int u,v;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<m;i++)
    {
        cin>>u>>v;
        gr[u].push_back(v);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,solve(i));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 11488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

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

  set<char> st;
  rep(i, s.size()){
    st.insert(s[i]);
  }

  if(st.size() == 1){
    cout << (ll)s.size() * k / 2 << endl;
    return 0;
  }

  ll ans = 0;
  if(s[0] != s[s.size() - 1]){
    ll same = 1;
    for(int i = 1; i < s.size(); ++i){
      if(s[i - 1] == s[i]){
        same++;
      }
      else{
        ans += same / 2;
        same = 1;
      }
    }
    ans += same / 2;
    cout << ans * k << endl;
  }
  else{
    ll lsame = 1;
    for(int i = 1; i < s.size(); ++i){
      if(s[0] == s[i]){
        lsame++;
      }
      else{
        break;
      }
    }
    ll rsame = 1;
    for(int i = s.size() - 2; i >= 0; --i){
      if(s[0] == s[i]){
        rsame++;
      }
      else{
        break;
      }
    }
    ll msame = 1;
    ll msamet = 0;
    for(int i = lsame + 1; i < s.size() - rsame; ++i){
      if(s[i - 1] == s[i]){
        msame++;
      }
      else{
        msamet += msame / 2;
        msame = 1;
      }
    }
    msamet += msame / 2;
    ans = msamet * k + lsame / 2 + rsame / 2 + (lsame + rsame) / 2 * (k - 1);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
long long h,w,n,x,a[201][201],tx=1,ty=0;
bool r=0;
int main() {
    cin >> h >> w >> n;
    for(int i=1;i<=n;i++){
        cin >> x;
        for(int j=0;j<x;j++){
            if(!r)ty++;else ty--;
            if((ty==w+1)&&(!r)){
                tx++;
                ty=w;
                r=1;
            }
            if((ty==0)&&(r)){
                tx++;
                ty=1;
                r=0;
            }
            a[tx][ty]=i;
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
	return 0;
}


Measured memory_bytes: 384
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
const (
	sheep = 0
	wolf  = 1
)

func nextAnimal(a1, a2 int, s2 bool) int {
	var a3 int
	if a2 == sheep {
		if s2 {
			a3 = a1
		} else {
			a3 = 1 - a1
		}
	} else {
		if s2 {
			a3 = 1 - a1
		} else {
			a3 = a1
		}
	}
	return a3
}

func check(a1, a2, a3 int, s2 bool) bool {
	if a2 == sheep {
		if s2 {
			return a1 == a3
		} else {
			return a1 != a3
		}
	} else {
		if s2 {
			return a1 != a3
		} else {
			return a1 == a3
		}
	}
}

func main() {
	defer stdout.Flush()

	n := readInt()
	answers := readString()

	s := make([]bool, n)
	for i, r := range answers {
		if r == 'o' {
			s[i] = true
		}
	}

	a := make([]int, n)
	for _, d1 := range []int{sheep, wolf} {
	loop:
		for _, d2 := range []int{sheep, wolf} {
			a[0] = d1
			a[1] = d2
			for i := 2; i < n; i++ {
				a[i] = nextAnimal(a[i-2], a[i-1], s[i-1])
			}
			for i := 0; i < 6; i++ {
				x := (n - 3 + i) % n
				y := (n - 2 + i) % n
				z := (n - 1 + i) % n
				if !check(a[x], a[y], a[z], s[y]) {
					continue loop
				}
			}
			for _, animal := range a {
				c := 'W'
				if animal == sheep {
					c = 'S'
				}
				printf("%c", c)
			}
			println()
			return
		}
	}
	println(-1)
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
 
int main() {
  int a;cin>>a;double ans;
  if (a%2) {
    double A=a;
    ans=(A+1)/2;
    ans /= A;
  }
  else ans=0.5;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    x = Scanner.int()
    if x == 0:
        print(1)
    else:
        print(0)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10796
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <fstream>
 
using namespace std;
 
#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)
 
typedef long long ll;

#define MAX_N 51
#define MAX_F 31

vector<int> ans_list;

int main(){

  
  while(true){

    int N;
    bool flag[MAX_N][MAX_F];
    memset(flag, 0, sizeof(flag));
    cin >> N;

    if(N == 0)
      break;

    for(int i = 1; i <= N; i++){
      int m;
      cin >> m;
      for(int j = 0; j < m; j++){
	int t;
	cin >> t;
	flag[i][t] = true;
      }
    }

    int ans = 0;

    bool have[MAX_N][MAX_N];
    memset(have, 0, sizeof(have));

    for(int i = 1; i <= N; i++){
      have[i][i] = true;
    }

    for(ans = 1; ans <= 30; ans++){
      bool S[MAX_N];
      memset(S, 0, sizeof(S));
      
      for(int i = 1; i <= N; i++){
	if(flag[i][ans]){
	  for(int j = 1; j <= N; j++){
	    if(have[i][j]){
	      S[j] = true;
	    }
	  }
	}
      }

      int cnt = 0;
      for(int i = 1; i <= N; i++){
	if(S[i])
	  cnt++;
      }

      if(cnt == N)
	break;

      for(int i = 1; i <= N; i++){
	if(flag[i][ans]){
	  for(int j = 1; j <= N; j++){
	    if(S[j]){
	      have[i][j] = true;
	    }
	  }
	}
      }

    }

    if(ans <= 30)
      ans_list.push_back(ans);
    else
      ans_list.push_back(-1);

  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }

  return 0;

}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string K;ll D;
    cin>>K>>D;
    vector<vector<vector<ll>>> dp(10010/*i桁目まで見ている*/,vector<vector<ll>>(105/*余り*/,vector<ll>(2,0)/*smaller?*/));
    dp[0][0][false]=1;

    for(ll i=0;i<K.size();i++){
        ll now=K[i]-'0';
        for(ll j=0;j<D;j++){
            //1つ前がsmaller
            for(ll k=0;k<=9;k++){    
                dp[i+1][(j+k)%D][true]+=dp[i][j][true];
                dp[i+1][(j+k)%D][true]%=mod;
            }

            //1つ前がsame 今smaller
            for(ll k=0;k<now;k++){    
                dp[i+1][(j+k)%D][true]+=dp[i][j][false];
                dp[i+1][(j+k)%D][true]%=mod;
            }

            //1つ前がsame 今same
            dp[i+1][(j+now)%D][false]+=dp[i][j][false];
            dp[i+1][(j+now)%D][false]%=mod;
        }
    }


    cout<<(dp[K.size()][0][true]+dp[K.size()][0][false]-1+mod)%mod<<endl;//0除く
    return 0;
}

Measured memory_bytes: 61204
n=int(input())
a=list(map(int,input().split()))
max=0
for i in range(n):
  if a[i]>max:
    max=a[i]
min=1000000000000
minans=0
for i in range(n):
  if a[i]==max:
    continue
  if abs(a[i]-max/2)<min:
    min=abs(a[i]-max/2)
    minans=a[i]
print(max)
print(minans)

Measured memory_bytes: 14428
from sys import stdin
N = int(stdin.readline().rstrip())
cnt = 0
accumlation = 0
for i in range(1, N+1):
    accumlation += i
    cnt += 1
    if accumlation > N:
        break
for j in range(1, cnt+1):
    if j != (accumlation - N):
        print(j)

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

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
const ll MOD = 1'000'000'007;
const int MN = 200'000;

vector<int> G[MN+1];
bool visited[MN+1];

int TSIZE(int node, int parent)
{
    int size = 1;
    visited[node] = true;
    for(int child : G[node]){
        if(visited[child]) continue;
        size += TSIZE(child, node);
    }
    return size;
}

int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    int n, m;
    cin >> n >> m;
    
    set<pair<int,int>>  pv;
    int a, b;
    
    REP(i, 0, m){
        cin >> a >> b;
        auto pab = make_pair(a, b);
        auto pba = make_pair(b, a);
        if(pv.count(pab) > 0 || pv.count(pba) > 0) continue;
        G[a].push_back(b);
        G[b].push_back(a);
        pv.insert(pab);
        pv.insert(pba);
    }

    int ans = 0;
    visited[0] = true;
    for(int i = 1; i <= n; i++){
        if(!visited[i]){
            ans = max(ans, TSIZE(i, 0));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 42724
N, K = [int(x) for x in input().split()]
h = [int(input()) for _ in range(N)]

h.sort()
ans = h[N - 1] - h[0]
for i in range(N - K + 1):
    ans = min(ans, h[i + K - 1] - h[i])

print(ans)


Measured memory_bytes: 7432
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  vector<ll> b(a);
  FOR(i, 1, n) b[i] += b[i-1];

  vector<ll> v;
  REP(i, n) FOR(j, i, n) {
    v.push_back(b[j] - (i==0?0:b[i-1]));
  }
  ll m = v.size();

  ll mask = 0;
  for(ll i=40; i>=0; --i) {
    mask |= 1LL<<i;
    ll cnt = 0;
    REP(j, m) {
      if((v[j]&mask) == mask) cnt++;
    }
    if(cnt < k) mask ^= 1LL<<i;
  }
  cout << mask << endl;

  return 0;
}


Measured memory_bytes: 6000
s = list(input())
t = list(input())
letter_list = list()
id_list = list()

for i in s:
    if i not in letter_list:
        letter_list.append(i)
        id_list.append(len(set(id_list)) + 1)
    else:
        id_list.append(letter_list.index(i) + 1)
        
        
letter_list = list()
id_list2 = list()

for i in t:
    if i not in letter_list:
        letter_list.append(i)
        id_list2.append(len(set(id_list2)) + 1)
    else:
        id_list2.append(letter_list.index(i) + 1)
        
if id_list == id_list2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9776
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String line = in.nextLine();
		in.close();
		List<Integer> indexes = getSplitIndexes(line);
		if (indexes.isEmpty()) {
			System.out.println(line.length());
		} else if (indexes.size() == 1) {
			System.out.println(Math.max(indexes.get(0), line.length() - indexes.get(0) - 1));
		} else {
			int max = indexes.get(0);
			for (int i = 1; i < indexes.size(); ++i) {
				max = Math.max(max, indexes.get(i) - indexes.get(i - 1) - 1);
			}
			System.out.println(max);
		}

	}

	static List<Integer> getSplitIndexes(String line) {
		List<Integer> result = new ArrayList<>();
		for (int i = 0; i < line.length(); ++i) {
			char c = line.charAt(i);
			if (c == 'A' || c == 'T' || c == 'G' || c == 'C') {
				continue;
			}
			result.add(i);
		}
		return result;
	}

}


Measured memory_bytes: 21204
using System;
using System.Linq;

public class AtCoder_157_A
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int n = int.Parse(Console.ReadLine());
        Console.WriteLine((n + 1) / 2);
    }
}


Measured memory_bytes: 11092
n,m = map(int, input().split())
Y = [[] for _ in range(n)]
for i in range(m):
    p,yi = map(int, input().split())
    Y[p-1].append((yi,i))
ans = [-1 for _ in range(m)]
for i,d in enumerate(Y):
    d.sort()
    for k,(a,b) in enumerate(d):
        ans[b] = str(i+1).rjust(6,"0") + str(k+1).rjust(6,"0")
print(*ans, sep = "\n")


Measured memory_bytes: 37456
import itertools
n = int(input())
lr = [[int(i) for i in input().split()] for _ in range(n)]
m = 101010
p = [1]*m
p[0] = p[1] = 0
for i in range(2, m):
    if p[i] == 0: continue
    else:
        for j in range(2*i, m, i):
            p[j] = 0
a = [0]*m
for i in range(1, m, 2):
    if p[i] == p[(i+1)//2] == 1: a[i] = 1
a = list(itertools.accumulate(a))
for l, r in lr:
    print(a[r] - a[l-1])

Measured memory_bytes: 25880
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
    x=0;static char ch;static bool flag;flag = false;
    while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
deque<int>q;
int main(){
    int n;read(n);
    int p = 1,x;
    if(n&1) p ^= 1;
    rep(i,1,n){
	read(x);
	if(p&1) q.push_back(x);
	else q.push_front(x);
	p ^= 1;
    }
    while(!q.empty()){
	printf("%d",q.front());
	q.pop_front();
	if(q.empty()) putchar('\n');
	else putchar(' ');
    }
    
    return 0;
}


Measured memory_bytes: 2944
#!/usr/bin python3
# -*- coding: utf-8 -*-

import bisect
n,k = map(int, input().split())
a = sorted(list(map(int, input().split())))

def cnt(x):
  ret = 0
  for ai in a:
    ret += (ai+(x-1))//x - 1
  return ret

ok, ng = a[-1], 0
while ok - ng > 1:
  nw = (ok + ng) // 2
  if cnt(nw)<=k:
    ok = nw
  else:
    ng = nw

print(ok)


Measured memory_bytes: 31228
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
import java.util.stream.IntStream;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] weight = IntStream.range(0, 10).map(e -> (int) Math.pow(2, e)).toArray();
        while (sc.hasNext()) {
            int n = sc.nextInt();
            Deque<Integer> list = new ArrayDeque<>();
            for (int i = weight.length - 1; i >= 0; i--) {
                if (n >= weight[i]) {
                    n -= weight[i];
                    list.push(weight[i]);
                }
            }
            System.out.print(list.pop());
            while (!list.isEmpty()) {
                System.out.print(" " + list.pop());
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 32116
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    ll a=0;
    for (int i = 0; i < s.length(); ++i)
    {
        a+=s[i]-'0';
    }
    if(a%9)
    {
        cout<<"No"<<'\n';
    }
    else
    {
        cout<<"Yes"<<'\n';
    }
}


Measured memory_bytes: 3784
#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max
#include <string>	//string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline

using namespace std;

int main() {

	string S;
	cin >> S;

	if (S == "SSS") {
		cout << 0 << endl;
		return 0;
	}

	if (S == "RRR") {
		cout << 3 << endl;
	}
	else if (S.find("RR") != string::npos) {
		cout << 2 << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int N; 
    char c[200000];
    cin >> N;
    rep(i, N) 
    {
        cin >> c[i];
    }
    int a[200000];
    int b[200000];
    int d[200000];
    rep(i, N)
    {
        if(c[i] == 'R') a[0]++; 
        b[0] = 0;
        d[0] = max(a[0], b[0]);
        
    }
   // cout << d[0] << endl;
   int ans = d[0];
    rep2(i, 1, N+1)
    {
        a[i] = a[i-1];
        b[i] = b[i-1];
        if(c[i-1] == 'R')  a[i]--;
        else             b[i]++;
        d[i] = max(a[i], b[i]);
        chmin(ans, d[i]);
        //cout << a[i] << b[i] << d[i] << endl;
    }
    sort(d, d+N+1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6124
#include <stdio.h>
int main(void){
	
	int a,b,c;
	
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	
	
	if(a<b && b<c){
		printf("Yes\n");
	}
	
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
def deg2rad(a)
	return a / 180.0 * Math::PI
end

s = 0.0
x = 0.0
y = 0.0

while line = gets do
	h, r = line.split(',').map(&:to_i)
	if h == 0 && r == 0 then
		break
	end
	
	x += Math.sin(deg2rad(s)) * h
	y += Math.cos(deg2rad(s)) * h

	s += r
	if s > 180.0 then
		s -= 360.0
	elsif s < -180.0 then
		s += 360.0
	end
end

puts x.to_i
puts y.to_i

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

using namespace std;

int main() {

	int n, p;

	while (cin >> n, cin >> p) {
		if (n == 0 && p == 0) {
			break;
		}
		else {
			int i = -1;
			vector<int> a(n, 0);//n個の配列を全て0で初期化
			while (1) {
				i++;
				if (i == n) {
					i = 0;
				}
				if (p == 0) {
					p += a[i];
					a[i] = 0;
				}
				else {
					p--;
					a[i]++;
					if (p == 0) {
						int z = 0;
						for (int j = 0; j < n; j++) {
							if (a[j] == 0) {
								z++;
							}
						}
						if (z == n - 1) {
							cout << i << endl;
							break;
						}
					}
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2
0 -2
0 1000
)");
#define cin input
#endif

int main()
{
	int n, t, a;
	cin >> n >> t >> a;

	t *= 1000;
	a *= 1000;

	map<int, int> h;

	REP (i, n)
	{
		int x;
		cin >> x;
		h[t - x * 6] = i + 1;
	}

	auto it = h.lower_bound(a);
	if (it != h.begin())
	{
		auto x = it->first;
		if (it != h.end())
		{
			if (a - (--it)->first > x - a)
				++it;
		} else
			--it;
	}

	cout << it->second << endl;

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    int loc = a[n - 1], fg = 0;
    long long ans = 1;
    for (int i = n - 2; i >= 0; i--) {
        if (a[i] == a[i + 1]) {
            ans *= a[i];
            i--;
            fg++;
            if (fg == 2) break;
        }
    }
    if (fg != 2) ans = 0;
    printf("%lld\n", ans);
}


Measured memory_bytes: 640
n = input()
taro = 0
hanako = 0
for i in range(n):
    x = map(str, raw_input().split())
    #print x[0]
    #print x[1]
    if(x[0] > x[1]):
        taro += 3
    elif(x[0] == x[1]):
        taro += 1
        hanako += 1
    else:
        hanako += 3
print '%d %d' %(taro, hanako)

exit(0)

Measured memory_bytes: 4220
N = int(input())
x = ['']*N
u = ['']*N
for i in range(N):
  x[i], u[i] = input().split()
x = list(map(float, x))
s = 0
for i in range(N):
  if u[i] == 'BTC':
    s += x[i] * 380000
  else:
    s += x[i]
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double angle1 = (2 * M_PI) / 12 * h;
    double angle2 = (2 * M_PI) / 60 * m;
    angle1 += (2 * M_PI) / (12 * 60) * m;
    double diff = angle1 - angle2;
    if (diff < 0)
        diff += 2 * M_PI;
    double ans = a * a + b * b - (2 * a * b * cos(diff));
    ans = sqrtl(ans);
    cout << fixed << setprecision(12) << ans << "\n";
}

Measured memory_bytes: 4172
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func Input_int() int {
	stdin.Scan()
	out,err := strconv.Atoi(stdin.Text())
	if err != nil{
		panic(err)
	}
	return out
}

func main(){
	stdin.Split(bufio.ScanWords)
	A,B,T := Input_int(),Input_int(),Input_int()
	num := T/A
	fmt.Println(num*B)
}

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

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main()
{
    //fastio
    ll x;
    string s;
    sfl(x);
    cin>>s;
    ll cnt = 0,j=x-1;
    while (s[j]!='R' && j>0)
    {
        j--;
    }
    
    for(ll i=0;i<j;i++)
    {
        if(s[i]=='W')
        {
            swap(s[i],s[j]);
            cnt++;
            while (s[j]!='R' && j>0)
            {
                j--;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3772
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const arr = [...input];
let str ='';
let obj = {
  a: 0,
  b: 0,
  c: 0,
  d: 0,
  e: 0,
  f: 0,
  g: 0,
  h: 0,
  i: 0,
  j: 0,
  k: 0,
  l: 0,
  m: 0,
  n: 0,
  o: 0,
  p: 0,
  q: 0,
  r: 0,
  s: 0,
  t: 0,
  u: 0,
  v: 0,
  w: 0,
  x: 0,
  y: 0,
  z: 0,
}
for(let i = 0; i < arr.length; i++){
  if((/[^A-Z,a-z]/).test(arr[i])) continue;
  if(/[Aa]/.test(arr[i])) obj.a++;
  if(/[Bb]/.test(arr[i])) obj.b++;
  if(/[Cc]/.test(arr[i])) obj.c++;
  if(/[Dd]/.test(arr[i])) obj.d++;
  if(/[Ee]/.test(arr[i])) obj.e++;
  if(/[Ff]/.test(arr[i])) obj.f++;
  if(/[Gg]/.test(arr[i])) obj.g++;
  if(/[Hh]/.test(arr[i])) obj.h++;
  if(/[Ii]/.test(arr[i])) obj.i++;
  if(/[Jj]/.test(arr[i])) obj.j++;
  if(/[Kk]/.test(arr[i])) obj.k++;
  if(/[Ll]/.test(arr[i])) obj.l++;
  if(/[Mm]/.test(arr[i])) obj.m++;
  if(/[Nn]/.test(arr[i])) obj.n++;
  if(/[Oo]/.test(arr[i])) obj.o++;
  if(/[Pp]/.test(arr[i])) obj.p++;
  if(/[Qq]/.test(arr[i])) obj.q++;
  if(/[Rr]/.test(arr[i])) obj.r++;
  if(/[Ss]/.test(arr[i])) obj.s++;
  if(/[Tt]/.test(arr[i])) obj.t++;
  if(/[Uu]/.test(arr[i])) obj.u++;
  if(/[Vv]/.test(arr[i])) obj.v++;
  if(/[Ww]/.test(arr[i])) obj.w++;
  if(/[Xx]/.test(arr[i])) obj.x++;
  if(/[Yy]/.test(arr[i])) obj.y++;
  if(/[Zz]/.test(arr[i])) obj.z++;
}
Object.keys(obj).forEach(key => {
  str += key + ' : ' + obj[key] + '\n';
})
console.log(str.trim());


Measured memory_bytes: 20484
#include<cstdio>
using namespace std;
int main(){
 int w,h;

 while(1){
  scanf("%d %d",&h,&w);
  if(w==0 && h==0){
   return 0;
  }
  for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
    printf("#");
   }
   printf("\n");
  }
  printf("\n");
 }
}


Measured memory_bytes: 2552
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0097
{
    public class Program

    {
        public static void Main(string[] args)
        {


            long[,] dp = new long[11, 1001];
            dp[0, 0] = 1;

            for (int k = 0 ; k <= 100 ; k++)
            {
                for (int i = 10 ; i > 0 ; i--)
                {
                    for (int j = k ; j <= 1000 ; j++)
                    {
                        dp[i, j] += dp[i - 1, j - k];
                    }
                }
            }

            while (true)
            {
                int[] items = RIntAr();
                if (items.Sum() == 0) break;

                Console.WriteLine(dp[items[0], items[1]]);
            }
        }

        /// <summary>
        /// 配列の組み合わせを列挙する
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items">配列</param>
        /// <param name="r">取得数</param>
        /// <returns>配列の組み合わせの列挙</returns>
        public static IEnumerable<IEnumerable<T>> GetCombination<T>(IEnumerable<T> items, int r)
        {
            if (r == 0)
            {
                yield return Enumerable.Empty<T>();
            }
            else
            {
                var i = 0;
                foreach (var x in items)
                {
                    i++;
                    var xs = items.Skip(i);
                    foreach (IEnumerable<T> c in GetCombination(xs, r - 1))
                    {
                       yield return Concat(x, c);
                    }
                }
            }
        }

        private static IEnumerable<T> Concat<T>(T first, IEnumerable<T> items)
        {
            yield return first;
            foreach (var i in items) yield return i;
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 18284
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include<algorithm>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;i++)
using namespace std;
using ll = long long;
const ll inf = 1LL << 50;





int main()
{
	int N, W;
	cin >> N >> W;
	vector< vector<ll> > data;

	rep(i, 0, N) {
		ll w, v;
		cin >> w >> v;
		data.push_back({ w,v });
	}
	//dp[i][j]:i個の品物の中からjを超えないようにとった時の価値の最大値
	vector< vector<ll> >dp(N+1,vector<ll>(W+1,0));

	rep(i, 1, N + 1) {
		rep(j, 0, W + 1) {
			if (j - data[i - 1][0] >= 0) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - data[i - 1][0]] + data[i - 1][1]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[N][W] << endl;
	
	return 0;
}



Measured memory_bytes: 80256
n, k = map(int, input().split())
reds = n-k
blues = k

mod = pow(10, 9) + 7

maxn = 2000
C = [[0]*(maxn+1) for i in range(maxn+1)]

def preprocess():
	global C
	for i in range(maxn+1):
		for j in range(i+1):
			if i == 0 or j== i :
				C[i][j] = 1
			else:
				C[i][j] = (C[i-1][j-1] + C[i-1][j])%mod
preprocess()


for i in range(k):
	slots = reds + 1
	res = (C[slots][i+1]*C[blues - 1][i])%mod
	print(res)

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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;
  const int MAX = 1e7+1;

  // array to store prime factors
  int factor[MAX] = { 0 };

  // function to generate all prime factors
  // of numbers from 1 to 10^6
  void generatePrimeFactors()
  {
      factor[1] = 1;

      // Initializes all the positions with their value.
      for (int i = 2; i < MAX; i++)
          factor[i] = i;

      // Initializes all multiples of 2 with 2
      for (int i = 4; i < MAX; i += 2)
          factor[i] = 2;

      // A modified version of Sieve of Eratosthenes to
      // store the smallest prime factor that divides
      // every number.
      for (int i = 3; i * i < MAX; i++) {
          // check if it has no prime factor.
          if (factor[i] == i) {
              // Initializes of j starting from i*i
              for (int j = i * i; j < MAX; j += i) {
                  // if it has no prime factor before, then
                  // stores the smallest prime divisor
                  if (factor[j] == j)
                      factor[j] = i;
              }
          }
      }
  }

  // function to calculate number of factors
  ll calculateNoOFactors(int n)
  {
      if (n == 1)
          return 1;

    ll ans = 1;

      // stores the smallest prime number
      // that divides n
    ll dup = factor[n];

      // stores the count of number of times
      // a prime number divides n.
      ll c = 1;

      // reduces to the next number after prime
      // factorization of n
      ll j = n / factor[n];

      // false when prime factorization is done
      while (j != 1) {
          // if the same prime number is dividing n,
          // then we increase the count
          if (factor[j] == dup)
              c += 1;

          /* if its a new prime factor that is factorizing n,
             then we again set c=1 and change dup to the new
             prime factor, and apply the formula explained
             above. */
          else {
              dup = factor[j];
              ans = ans * (c + 1);
              c = 1;
          }

          // prime factorizes a number
          j = j / factor[j];
      }

      // for the last prime factor
      ans = ans * (c + 1);

      return ans;
  }


  int main(){
    IOS
    generatePrimeFactors();
    int n;
    cin >> n;
    ll ans =0;
    for(ll i=1;i<=n;i++){
      ans += (i*calculateNoOFactors(i));
    }
    cout << ans;

       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 42860
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
template<class T>inline bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head
int n;
double dp[310][310][310];

// double rec(int i, int j, int k) {
//     if (dp[i][j][k] >= 0) return dp[i][j][k];
//     if (i == 0 && j == 0 && k == 0) return 0.0;

//     double res = 0.0;
//     if (i > 0) res += rec(i-1, j, k) * i;
//     if (j > 0) res += rec(i+1, j-1, k) * j;
//     if (k > 0) res += rec(i, j+1, k-1) * k;
//     res += n;
//     res *= 1.0 / (i + j + k);

//     return dp[i][j][k] = res;
// }

double rec(int a,int b, int c){
  if (!(a >= 0 && b >= 0 && c >= 0)){ return 0.0;}
  if (a == 0 && b == 0 && c == 0){  return 0.0;}
  if (dp[a][b][c] >= 0) { return dp[a][b][c];}
  double result = 0.0;
  result += n;
  result += rec(a-1,b,c) * a;
  result += rec(a+1,b-1,c) * b;
  result += rec(a,b+1,c-1) * c;
  result *= 1.0/(a+b+c);

  return dp[a][b][c] = result;
  }


// int main() {
//     cin >> n;
//     int one = 0, two = 0, three = 0;
//     for (int i = 0; i < n; ++i) {
//         int a; cin >> a;
//         if (a == 1) ++one;
//         else if (a == 2) ++two;
//         else ++three;
//     }

//     // 初期化
//     memset(dp, -1, sizeof(dp));

//     // 答え
//     cout << fixed << setprecision(10) << rec(one, two, three) << endl;
// }
int main(){
  cin >> n;
  int A,B,C;
  A=B=C=0;
  for range(i,n){
    int a;
    cin >> a;
    if (a == 1){ A++ ;}
    else if (a == 2) { B ++ ;}
    else {C ++ ;}
  }
  memset(dp,-1,sizeof(dp));
  cout << fixed << setprecision(10) <<  rec(A,B,C) <<  endl ;
}

Measured memory_bytes: 233088
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

ll fact[7000];
ll ifact[7000];

// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

ll comb(ll n, ll k, ll m) {
  return fact[n] * ifact[k] % m * ifact[n-k] % m;
}

ll pmod(ll x, ll i, ll m) {
  if (i == 0) return 1;
  if (i % 2 == 1) return pmod(x, i-1, m) * x % m;
  ll h = pmod(x, i/2, m);
  return h * h % m;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;
  cin>>n>>m;
  fact[0] = 1;
  REP(i,7000-1) {
    fact[i+1] = (i+1) * fact[i] % m;
  }
  ifact[6999] = inv(fact[6999], m);
  REP(i,7000-1) {
    int j = 7000-i-1;
    ifact[j-1] = j * ifact[j] % m;
  }
  ll inv3 = inv(3, m);
  ll inv2 = inv(2, m);
  ll ans = 0;
  REP(i,n+1) {
    REP(j,n+1-i) {
      ll tmp = comb(3*n, 3*i, m);
      tmp *= fact[3*i] * ifact[i] % m;
      tmp %= m;
      tmp *= pmod(inv3, i, m);
      tmp %= m;
      ll rem = 3*n - 3*i;
      tmp *= comb(rem, 2*j, m);
      tmp %= m;
      tmp *= fact[2*j] * ifact[j] % m;
      tmp %= m;
      tmp *= pmod(inv2, j, m);
      tmp %= m;
      ans += tmp;
      ans %= m;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
n,m=map(int,input().split())
x_list=[0]
y_list=[0]
z_list=[0]
for i in range(n):
    x,y,z=map(int,input().split())
    x_list.append(x)
    y_list.append(y)
    z_list.append(z)
dp=[]
for i in range(n+1):
    sub_list=[]
    for j in range(m+1):
        sub_list.append(0)
    dp.append(sub_list)
for i in range(1,m+1):
    dp[0][i]=-10**16
op=[(1,1,1),(1,1,-1),(1,-1,1),(-1,1,1),(1,-1,-1),(-1,1,-1),(-1,-1,1),(-1,-1,-1)]
answer=[]
for k in op:
    a=k[0]
    b=k[1]
    c=k[2]
    for i in range(1,n+1):
        for j in range(m+1):
            if j>=1:
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]+a*x_list[i]+b*y_list[i]+c*z_list[i])
            else:
                dp[i][j]=dp[i-1][j]
    answer.append(dp[n][m])
print(max(answer))


Measured memory_bytes: 54624
N,H = [int(x) for x in input().split()]
from collections import deque
import math
c = []
d = []
for i in range(N):
  e,f = [int(x) for x in input().split()]
  c.append(e)
  d.append(f)
c.sort()
d.sort()
b = deque(d)
count = 0
while b:
  x = b.pop()
  if x > c[-1]:
    H -= x
    count += 1
    if H <= 0:
      print(count)
      exit()
count += math.ceil(H/c[-1])
print(count)

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

int main(){
  int N; cin >> N;
  int a[3*N]; int num;
  for(int i=0; i<N; i++){
    cin >> num;
    a[3*i] = num-1;
    a[3*i+1] = num;
    a[3*i+2] = num+1;
  }
  
  sort(a,a+3*N);
  
  int count=1; int max=0;
  for(int i=0; i<3*N-1; i++){
    if(a[i]==a[i+1]){count++;}
    else{
      if(count>max){max = count;}
      count = 1;
    }
  }
  
  if(count>max){max = count;}
  
  cout << max;
  
  return 0;
}


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

void show_me(int *a, size_t size)
{
    for (size_t i = 0; i < size; ++i)
    {
        cout << (i == 0 ? "" : " ") << a[i];
    }
    cout << endl;
}

void insertion_sort(int *a, size_t size)
{
    int v;
    for (int i = 1; i < size; ++i)
    {
        v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v)
        {
            a[j + 1] = a[j];
            --j;
        }
        a[j + 1] = v;
        show_me(a, size);
    }
}

int main()
{
    int a[100] = {};
    size_t n;
    cin >> n;
    for (size_t i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    show_me(a, n);
    insertion_sort(a, n);
}



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

using namespace std;

int main() {

   double x[2]{}, y[2]{}, distance{};

   cin >> x[0] >> y[0] >> x[1] >> y[1];

   distance = sqrt(pow(x[0] - x[1], 2) + pow(y[0] - y[1], 2));
   cout << fixed << distance;

   return 0;

}

Measured memory_bytes: 3284