akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);

static const int MAX = 50;
static const int INF = 1e7;
int h, w;
vector<vector<char> > G;
vector<vector<int> > L;
vector<int> mx = {0, 0, -1, 1}, my = {1, -1, 0, 0};
void dfs(int x, int y){
    for (int i = 0; i < 4; i++){
        if (x+mx[i]<0 || x+mx[i]>=h || y+my[i]<0 || y+my[i]>=w) continue;
        if (G[x+mx[i]][y+my[i]] == '#') continue;
        if (L[x+mx[i]][y+my[i]] > L[x][y] + 1){
            L[x+mx[i]][y+my[i]] = L[x][y] + 1;
            dfs(x+mx[i], y+my[i]);
        }
    }
}
int main(){
    int cnt = 0;
    string x;
    sc(h) sc(w)
    G.resize(h);
    for (int i = 0; i < h; i++) G[i].resize(w);
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++) cin >> G[i][j];
    }
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (G[i][j] == '#') cnt += 1;
        }
    }
    L.resize(h);
    for (int i = 0; i < h; i++) L[i].resize(w, INF);
    L[0][0] = 1;
    if (G[0][0] != '#') dfs(0, 0);
    if (L[h-1][w-1] == INF) cout << -1 << endl;
    else cout << h*w - cnt - L[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 384
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  x <- getInt

  let m = 1000

      solve a b | a^5 - b^5 == x = (a, b)
                | b > m = solve (a+1) (-m)
                | otherwise = solve a (b+1)

      (a, b) = solve (-m) (-m)

  putStrLn $ show a ++ " " ++ show b



Measured memory_bytes: 3688
#include <iostream>
using namespace std;
 
int main() {
    int a, b;
    cin >> a >> b;
 
    int sum = a + b;
    if(sum% 2 == 0){
        cout << sum/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
  int a,b; cin>>a>>b;
  int less = min(a,b);
  int more = max(a,b);
  for(int i=0;i<more;i++)cout<<less;
  cout<<endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();
        int[] p = new int[n];
        int count = 0;
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (p[i] != i + 1)
                count++;
        }
        if (count == 2 || count == 0)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

Measured memory_bytes: 22868
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for(ll i = 0;i < n;i++) cin >> h.at(i);
  ll count = 0;
  for(ll i = 0;i < n;i++){
    if(h.at(i) >= k) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define N 4
#define NN 16
#define LIMIT 45

struct P{
  int f[NN];
  int t;
  int st;
  bool operator < (const P &p) const{
    for(int i=0;i<NN;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};

struct Cost{
  P p;
  int cost;
  bool operator < (const Cost &c) const{
    return cost+p.t > c.cost+c.p.t;
  }
};

int man(int f[]){
  int ans=0;
  for(int i=0;i<NN;i++){
    if(f[i]==0)continue;
    ans+=abs((f[i]-1)/N-i/N);
    ans+=abs((f[i]-1)%N-i%N);
  }
  return ans;
}

int main(){
  P in;
  map<P,bool> V;
  priority_queue<Cost> Q;
  for(int i=0;i<NN;i++){
    cin>>in.f[i];
    if(in.f[i]==0)in.st=i;
  }
  in.t=0;
  Cost t;
  t.p=in;
  t.cost=man(t.p.f);
  Q.push(t);
  while(!Q.empty()){
    P top=Q.top().p;
    Q.pop();

    if(man(top.f)+top.t<=LIMIT){
      V[top]=true;
      int flag=0;
      for(int i=0;i<NN;i++){
	if((i+1)%NN==top.f[i])flag++;
      }
      if(flag==NN){
	cout<<top.t<<endl;
	break;
      }
      int st=top.st;
      top.t++;
      P tmp;
      if(st-N>=0){
	tmp=top;
	swap(tmp.f[st],tmp.f[st-N]);
	tmp.st-=N;
	if(!V[tmp]&&man(tmp.f)+tmp.t<=LIMIT){
	  V[tmp]=true;
	  Cost t;
	  t.p=tmp;
	  t.cost=man(t.p.f);
	  Q.push(t);
	}
      }
      if(st+N<NN){
	tmp=top;
	swap(tmp.f[st],tmp.f[st+N]);
	tmp.st+=N;
	if(!V[tmp]&&man(tmp.f)+tmp.t<=LIMIT){
	  V[tmp]=true;
	   Cost t;
	  t.p=tmp;
	  t.cost=man(t.p.f);
	  Q.push(t);
	}
      }
      if(st%N!=N-1){
	tmp=top;
	swap(tmp.f[st],tmp.f[st+1]);
	tmp.st++;
	if(!V[tmp]&&man(tmp.f)+tmp.t<=LIMIT){
	  V[tmp]=true;
	  Cost t;
	  t.p=tmp;
	  t.cost=man(t.p.f);
	  Q.push(t);
	}
      }
      if(st%N!=0){
	tmp=top;
	swap(tmp.f[st],tmp.f[st-1]);
	tmp.st--;
	if(!V[tmp]&&man(tmp.f)+tmp.t<=LIMIT){
	  V[tmp]=true;
	  Cost t;
	  t.p=tmp;
	  t.cost=man(t.p.f);
	  Q.push(t);
	}
      }
    }
  }
  return 0;
}

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

using namespace std;
const int N=150000;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL);
	int n,i,j,dp[N],a[N];
	cin>>n;
	for(i=0;i<n;++i) cin>>a[i];
	dp[0]=0; dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;++i){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
const int MAX = 100100;

int calctime(string s) {
    int hh, mm, ss;
    hh = (s.at(0)-'0') * 10 + (s.at(1)-'0');
    mm = (s.at(3)-'0') * 10 + (s.at(4)-'0');
    ss = (s.at(6)-'0') * 10 + (s.at(7)-'0');
    return hh*3600 + mm*60 + ss;
}

int main() {
    while(1) {
        cin >> n;
        if(n == 0) break;
        vector<int> timer(MAX, 0);
        for(int i = 0; i < n; ++i) {
            string fins, sins;
            cin >> fins >> sins;
            int ftime = calctime(fins); int stime = calctime(sins);
            timer.at(ftime)++;
            timer.at(stime)--;
        }

        for(int i = 0; i < 100000; ++i) timer.at(i+1) += timer.at(i);
        int ans = 0;
        for(int i = 0; i < 100000; ++i) chmax(ans, timer.at(i));
        cout << ans << endl;
    }
}


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

int main() {
  int a,b;
  cin >> a >> b;
  if(b>=2*a&&b<=4*a&&b%2==0) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 3584
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
bool isOdd(int x){
    int cnt = 0;
    while(x > 0){
        x /= 10;
        cnt++;
    }
    if(cnt % 2 == 0) return false;
    return true;
}
int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(isOdd(i)) cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 256
function Main(input) {
    // const input = Number(input)
    const _500 = Math.floor(input / 500)
    const remain = input - (500 * _500)
    // if (_500 >= 1) {
        const _5 = Math.floor((remain) / 5)
        console.log(1000 * _500 + 5 * _5)
    // } else {
    //     console.log(1000 * _500)
    // }
}
// Main(12345613265)
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
N = int(input()) 
C = list(input().split())
C1 = C[:]
C2 = C[:]

def func(C):
    nums = []
    for i in range(N-1):
        for j in range(i+1,N):
            if C[i][1] in nums:
                continue
            elif C[i][1] == C[j][1]:
                nums.append(C[i][1])
    nums.sort()

    test = []
    for i in range(len(nums)):
        A = []
        for j in range(N):
            if C[j][1] == nums[i]:
                A.append(C[j])
        test.append(A)
    return test

def isStable(A,B):
    if func(A) == func(B):
        print("Stable")
    else:
        print("Not stable")

for i in range(N):
    for j in range(N-1,i,-1):
        if int(C1[j][1]) < int(C1[j-1][1]):
            C1[j],C1[j-1] = C1[j-1],C1[j]
print(*C1)
isStable(C,C1)

for i in range(N):
    minj = i
    for j in range(i,N):
        if int(C2[j][1]) < int(C2[minj][1]):
            minj = j
    C2[i],C2[minj] = C2[minj],C2[i]
print(*C2)
isStable(C,C2)


Measured memory_bytes: 5608
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define int long long
using namespace std;
signed main() {
	int N, M;
	cin >> N >> M;
	int X = 0;

	vector<int>A(M);
	for (int i = 0; i < M; i++) {
		cin >> A.at(i);
		X += A.at(i);
	}
	if (N >= X) {
		cout << N - X << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 3596
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = a-1;
		if(b>=a) ans++;
		System.out.println(ans);
		return;
	}
}

Measured memory_bytes: 22356
while 1:
    n = int(input())
    if n ==0 :break
    e = [1 for _ in range(2*n+1)]
    for i in range(2,n+1):
        if e[i] == 1:
            for j in range(2,int(2*n/i) + 1):
                e[i*j] = 0
    print(sum(e[n+1:2*n+1]))

Measured memory_bytes: 13352
import java.util.*;

class Main{

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        Integer n = sc.nextInt();
        Long k = sc.nextLong();
        int[] a = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }

        int[] check = new int[n+1];
        int now = 1;
        List<Integer> path = new ArrayList<>();
        while(true){
            path.add(now);
            if(check[now]==1)break;
            if(path.size()==k+1){
                System.out.println(now);
                return;
            }
            check[now] = 1;
            now = a[now];
        }

        Long count = 0L;
        for(Integer p : path){
            if(p==now)break;
            count++;
        }

        Long loop_size = path.size() - count - 1L;

        
        long rest = (k-count)%loop_size;
        System.out.println(path.get((int)(count+rest)));

    }
}


Measured memory_bytes: 52812
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
struct Edge {
    int to;
    int cost;
};
using Graph = vector<vector<Edge>>;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q, W, H, R, C;
string S;

int fb[110000][2];  // 0:friend, 1:block
int id;
// 深さ優先探索
vector<int> seen;  // 既に見たことがある頂点か記録
vector<int> vs;
void dfs(const Graph &G, int v, int &cnt) {
    seen[v] = id;
    vs.push_back(v);
    cnt++;
    for (auto e : G[v]) {
        if (seen[e.to] == -1 && e.cost != INF) {
            dfs(G, e.to, cnt);
        }
    }
}

int main() {
    cin >> N >> M >> K;
    Graph G(N);
    vector<int> A(M), B(M);
    REP(i, M) {
        cin >> A.at(i) >> B.at(i);
        A[i]--, B[i]--;
        fb[A[i]][0]++;
        fb[B[i]][0]++;
        G[A[i]].push_back({B[i], 0});
        G[B[i]].push_back({A[i], 0});
    }
    vector<int> C(K), D(K);
    set<P> s;
    REP(i, K) {
        cin >> C.at(i) >> D.at(i);
        C[i]--, D[i]--;
        s.insert(make_pair(C[i], D[i]));
        fb[C[i]][1]++;
        fb[D[i]][1]++;
        G[C[i]].push_back({D[i], INF});
        G[D[i]].push_back({C[i], INF});
    }

    seen.assign(N, -1);  // 初期化

    map<int, int> ans;
    REP(i, N) {
        if (seen[i] == -1) {
            vs.resize(0);
            int cnt = 0;
            dfs(G, i, cnt);
            for (auto v : vs) {
                // cout << "v:" << v << " cnt:" << cnt << " " << fb[v][0] << " " << fb[v][1] << endl;
                ans[v] = cnt - 1 - fb[v][0] - fb[v][1];
            }
            id++;
        }
    }

    REP(i, K) {
        if (seen[C[i]] != seen[D[i]]) {
            ans[C[i]]++;
            ans[D[i]]++;
        }
    }

    for (auto p : ans) {
        cout << p.second;
        if (p.first != N - 1) cout << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 23288
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
int K, S;

int main(int argc, const char * argv[]) {
    cin >> K >> S;

    int xbegin = max(0, (S-2*K));
    int xend = min(K, S);

    ll count = 0;
    repd(x, xbegin, xend+1) {
        int xy = S - x;
        int ymin = max(0, xy - K);
        int ymax = min(K, xy);
        // printf("%d, %d, %d, %d\n", x, ymin, ymax, xy);
        count += ymax - ymin + 1;
    }

    output(count);

    return 0;
}

Measured memory_bytes: 256
(let ((n (read))
      (k (read))
      (p 1000000007)
      (ans 0))
  (loop :for i :from k :to (1+ n)
        :for x := (mod (+ (mod (* (- n i -1) i) p) 1) p)
        :do (setf ans (mod (+ ans x) p)))
  (format t "~A~%" ans))


Measured memory_bytes: 24548
#include <stdio.h>

int main(void)
{
	int n = 1;
	int p = 1;
	int pt[64] = {0};
	int out[10000] = {0};

	int now = 0;
	int maxp = 0;

	int round = 0;
	int endflag = 1;

	int i;

	while(1)
	{

		scanf("%d",&n); scanf("%d",&p);

		if( p == 0 && n == 0 )
		break;

		maxp = p;

		while(1)
		{
	

			for( now = 0 ; now < n ; now++ )
			{
				if(pt[now] == maxp)
				{
				out[round] = now;
				endflag = 0;
				break;
				}
	
				else if(p)
				{	
				pt[now]++;
				p--;
				}

				else
				{
				p += pt[now];
				pt[now] = 0;
				}
			}


		now = 0;

		if(endflag)
			{continue;}

		else
			{
			endflag = 1;
			round++;
			for( i = 0 ; i < 64 ; i++)
			{pt[i] = 0;}
			break;
			}

		}
	}


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

	return 0;

}

	

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}
void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}
int N, M, Q;
int a[50];
int b[50];
int c[50];
int d[50];
int ans = 0;
class CManyRequirements {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    cin >> N >> M >> Q;
    ans = 0;
    rep(i, Q) {
      cin >> a[i];
      cin >> b[i];
      cin >> c[i];
      cin >> d[i];
    }
    foreach_comb(M+N-1, N, [](int *indexes) {
      vector<int> comb(N);
      rep(i, N) comb[i] = 1 + indexes[i] - i;
      int temp_ans          = 0;
      rep(i, Q) {
        if (comb[b[i] - 1] - comb[a[i] - 1] == c[i]) {
          temp_ans += d[i];
        }
      }
      ans = max(ans, temp_ans);
    });
    cout << ans << endl;
  }
};


signed main() {
  CManyRequirements solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3520
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>

using namespace std;

inline long long read()
{
    char c;long long out=0,f=1;
    for (c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
    if (c=='-'){f=-1;c=getchar();}
    for (;c>='0'&&c<='9';c=getchar()){out=(out<<3)+(out<<1)+c-'0';}
    return out*f;
}
void write(long long x)
{
	if (x<0){putchar('-');write(-x);return;}
    if (x>9){write(x/10);}
	putchar(x%10+'0');
}

int n,p[20],maxx,sum;

int main()
{
	int i;
	
	cin>>n;
	
	for (i=1;i<=n;++i)
	{
		cin>>p[i];
		sum+=p[i];
		maxx=max(maxx,p[i]);
	}
	
	sum-=maxx/2;
	
	cout<<sum; 
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  int ans = 1;
  while (ans <= N) ans *= 2;
  print(ans / 2);
}


Measured memory_bytes: 256
#include <stdio.h>

typedef enum {false, true} bool;

int main(void)
{
    char S[101];
    int K;
    char c;
    int i;
    int ctr, ctr2;
    int index;
    bool single, parity;
    long long ans;
    
    
    scanf("%s", S);
    scanf("%d%c", &K, &c);
    
    
    ctr = 0;
    index = -1;
    
    single = true;
    
    for(i=1; S[i] != '\0'; i++)
    {
        if(S[i-1] == S[i])
        {
            ctr++;
            
            index = i++;
            
            if(S[i] == '\0')
                break;
        }
        else
            single = false;
    }
    
    
    if(S[i-1] == S[0])
    {
        if(index == i-1)
        {
            ctr2 = 0;
            
            i = 1;
        }
        else
        {
            ctr2 = 1;
            
            i = 2;
        }
        
        for(; S[i] != '\0'; i++)
        {
            if(S[i-1] == S[i])
            {
                ctr2++;
                
                i++;
                
                if(S[i] == '\0')
                    break;
            }
        }
    }
    else
        ctr2 = ctr;
    
    
    if(ctr == ctr2)
        parity = false;
    else
        parity = true;
    
    
    if(single)
    {
        if(parity)
            ans = (long long)K*ctr+K/2;
        else
            ans = (long long)K*ctr;
    }
    else
    {
        if(parity)
            ans = (long long)K*ctr+K-1;
        else
            ans = (long long)K*ctr;
    }
    
    
    printf("%lld\n", ans);
    
    
    //system("pause");
    
    return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = 1000100100;

int main()
{
    int n; cin >> n;
    int x[n];
    rep(i,n) cin >> x[i];
    int ans = INF;
    for(int i=1;i<=100;i++){
        int res = 0;
        rep(j,n){
            res += (x[j]-i)*(x[j]-i);
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var l = new List<char>();
		foreach(var c in S){
			if(l.Count == 0 || (l[l.Count - 1] != c)) l.Add(c);
		}
		Console.WriteLine(l.Count - 1);
		
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

public static class StreakYabai
{
    public static void Main()
    {
        var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        Console.WriteLine(a[0] % 3 == 0 || a[1] % 3 == 0 || a.Sum() % 3 == 0 ? "Possible" : "Impossible");
        return;
    }
}


Measured memory_bytes: 27960
#define _USE_MATH_DEFINES
#include <iostream> 
using namespace std; 
int main(){
	int n, a[1000];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		if(n-i-1==0){
			cout << a[n-i-1] <<endl;
		}
		else{
			cout << a[n-i-1] <<" ";
		}
	}
	return 0;
}


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

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()

vector<int> calc_z(string s) {
	int n = s.size();
	vector<int> z(n, 0);
	int l = 0, r = 0;
	for(int i = 1; i < s.size(); i++) {
		if(i > r) {
			l = r = i;
			while(r < n && s[r - l] == s[r]) r++;
			z[i] = r - l;
			r--;
		}
		else {
			if(z[i - l] < r - i + 1) {
				z[i] = z[i - l];
			}
			else {
				l = i;
				r++;
				while(r < n && s[r - l] == s[r]) r++;
				z[i] = r - l;
				r--;
			}
		}
	}
	return z;
}
int main() {
	string s, t;
	cin >> s >> t;
	string a = t + s;
	int n = s.size();
	int m = t.size();
	int ans = 0;
	reverse(ALL(t));
	reverse(ALL(s));
	string b = t + s;
	vector<int> z1 = calc_z(a);
	vector<int> z2 = calc_z(b);
	rep(i, n) {
		if(i + m - 1 >= n) break;
		int l = z1[m + i];
		int r = z2[n - i];
		if(l + r + 1 == m) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8512
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		Arrays.setAll(A, i -> sc.nextInt());
		Map<Integer, Long> x = new HashMap<>();
		int[] S = new int[N];
		S[0] = A[0] % M;
		x.put(0, 1L);
		x.put(S[0], x.getOrDefault(S[0], 0L) + 1);
		for(int i = 1; i < N; i++) {
			S[i] = (S[i-1] + A[i]) % M;
			x.put(S[i], x.getOrDefault(S[i], 0L) + 1);
		}
		long ans = 0;
		for(int i : x.keySet())
			ans += x.get(i) * (x.get(i) - 1) / 2;
		System.out.println(ans);
	}
 
}

Measured memory_bytes: 54724
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, tt: i64,
        t: [i64; n],
    }
    let mut tot: i64 = 0;
    let mut cur = 0;
    for i in 0..n {
        tot += min(tt, t[i] - cur);
        cur = t[i];
    }
    tot += tt;
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <inttypes.h>

int main(void){
	int a,b,h,m;
	double ans=0;
	int b_an;
	double a_an;
	double angle;

	scanf("%d %d %d %d",&a,&b,&h,&m);
	b_an=6*m;
	a_an=30*h+0.5*m;
	if(b_an>a_an){
		angle=b_an-a_an;
	}else{
		angle=a_an-b_an;
	}
	if(angle>180){
		angle-=360;
	}
	if(angle==180){
		ans=a+b;
	}else if(angle==0){
		ans=abs(a-b);
	}else if(angle==90){
		ans=sqrt(a*a+b*b);
	}else{
		ans=sqrt(a*a+b*b-2*a*b*cos(angle*M_PI/180));
	}
	printf("%.10f",ans);
	return 0;
}


Measured memory_bytes: 2524
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int Y = sc.nextInt();

        int A = 10000;
        int B = 5000;
        int C = 1000;


        for (int ai = 0; ai <= N; ai++) {
            for (int bi = 0; bi<=N-ai; bi++) {

                int ci = N - ai - bi;
                int sum = ai * A + bi * B + ci * 1000;
                if (sum == Y) {
                    System.out.println(ai + " " + bi + " " + ci);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}


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

 
int main() {
  int A, B, C, D, R, L;
  cin >> A >> B >> C >> D;
  R = C + D;
  L = A + B;
  if (R > L) {
  	cout << "Right" << endl;
  }
  if (R == L) {
  	cout << "Balanced" << endl;
  }
  if (R < L) {
  	cout << "Left" << endl;
  }
  

}

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

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    if (s[0] == s[1] && s[1] == s[2] && s[0] == 'R') {
        cout << 3 << endl;
    }
    else if (s[1] == 'R' && (s[0] == 'R' || s[2] == 'R')) {
        cout << 2 << endl;
    }
    else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}



Measured memory_bytes: 3596
//
// Created by sposa on 26.09.2020.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
    char s[4];
    int n= 0;
    strcpy(s,"ACL");
    scanf("%d",&n);

    for(int i= 0; i < n; i++){
        printf("%s",s);
    }


}


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

int main() {
  int N, M;
  cin >> N >> M;

  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<pair<ll, ll>> v;
  rep(i, M) {
    int b, c;
    cin >> b >> c;
    v.emplace_back(c, b);
  }

  sort(A.begin(), A.end());
  sort(v.rbegin(), v.rend());

  ll ans = 0;
  int p = 0;
  rep(i, M) {
    int np = p;
    while (A[np] < v[i].first && np - p < v[i].second && np < N)
      ++np;
    ans += v[i].first * (np - p);
    p = np;
  }
  for (int i = p; i < N; ++i)
    ans += A[i];
  cout << ans << endl;
}

Measured memory_bytes: 3188
S = input()
flg = True
for i in range(1, len(S) + 1):
    if i % 2 and (S[i - 1] in ['R', 'U', 'D']):
        pass
    elif i % 2 == 0 and (S[i - 1] in ['L', 'U', 'D']):
        pass
    else:
        flg = False
    if not flg:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 9104
<?php
  $target = trim(fgets(STDIN));

  $target = str_replace("eraser", "", $target);
  $target = str_replace("erase", "", $target);
  $target = str_replace("dreamer", "", $target);
  $target = str_replace("dream", "", $target);
  
  if($target == ""){
    echo "YES\n";
  } else { 
    echo "NO\n";
  }
?>

Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repc(i, b, e) for(auto i = (b); i != (e); i++)

struct UnionFind {
    int n, cnt;
    vector<int> par, rank, sz;

    UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        if(x == par[x])
            return x;
        return par[x] = find(par[x]);
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return sz[find(x)]; }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y)
            return;
        if(rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    auto uf = UnionFind(N);
    ll x, y, z;
    for(ll i; i < M; i++) {
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }
    auto st = set<ll>();
    for(ll i; i < N; i++) {
        st.insert(uf.find(i));
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 6144
import java.util.*;
	import java.io.*;
class Main{
		static int n,arr[],k	;
		static long dp[];
		public static void main(String[] args) throws IOException{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			int t=1;
	//		Integer.parseInt(br.readLine().trim());
			StringBuilder printans=new StringBuilder();
			while(t-->0)
			{
				StringTokenizer tok=new StringTokenizer(br.readLine()," ");
				n=Integer.parseInt(tok.nextToken());
				k=Integer.parseInt(tok.nextToken());
				
				arr=new int[n];
				tok=new StringTokenizer(br.readLine()," ");
				for(int i=0;i<n;i++) {
					arr[i]=Integer.parseInt(tok.nextToken());
				
				}
				dp=new long[n];
//				memset();
				
				printans.append(call());
			    
			}
			System.out.println(printans);
	
		}
		
		static long call() {
			dp[0]=0;
			dp[1]=Math.abs(arr[1]-arr[0]);
			for(int i=2;i<n;i++) {
				long temp=Integer.MAX_VALUE;
				for(int j=i-k;j<i ;j++){
					if(j>=0) {
						temp=Math.min(temp,dp[j]+Math.abs(arr[i]-arr[j]));
					}
//					
				}
				dp[i]=temp;
				
			}
//			System.out.println(Arrays.toString(dp));
			return dp[dp.length-1];
		}
	
	}


Measured memory_bytes: 32912
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <time.h>
#include <stdio.h>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>
#define MAX 100000
typedef long long ll;
using namespace std;

ll n, k;
ll T[MAX];

ll check(ll P)
{
    ll i = 0;
    for (ll j = 0; j < k; j++)
    {
        ll s = 0;
        while (s + T[i] <= P)
        {
            s += T[i];
            i++;
            if (i == n)
                return n;
        }
    }
    return i;
}

ll solve()
{
    ll left = 0;
    ll right = MAX * 10000;
    ll mid;
    while (right - left > 1)
    {
        mid = (left + right) / 2;
        ll v = check(mid);
        if (v >= n)
            right = mid;
        else
            left = mid;
    }
    return right;
}

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> T[i];
    ll ans = solve();
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    int n = s.length();
    int ans = 0;
    rep(i, n) if (s[i] != t[i]) ans++;

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

Measured memory_bytes: 3848
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
char S[300][301];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	int ans = 0;
	for (int A = 0; A < N; A++) {
		bool ok = 1;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (S[(i - A + N) % N][j] != S[(j - A + N) % N][i]) {
					ok = 0;
					break;
				}
			}
			if (!ok) break;
		}
		if (ok) ans += N;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
n = int(input())
d = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    d[int(str(i)[0])][i % 10] += 1
ret = 0
for s in range(10):
    for e in range(10):
        ret += d[s][e] * d[e][s]
print(ret)


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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 301;
const int mod = 1e9 + 7;

double dp[N][N][N];
int n;
int cnt[4];

double dfs(int a, int b, int c)
{
    // if (a > n || b > n || c > n) return 0;
    if (dp[a][b][c] >= 0) return dp[a][b][c];
    double s = a + b + c;
    double ret = n / s;

    if (a > 0) ret += dfs(a - 1, b, c) * a / s;
    if (b > 0) ret += dfs(a + 1, b - 1, c) * b / s;
    if (c > 0) ret += dfs(a, b + 1, c - 1) * c / s;
    return dp[a][b][c] = ret;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (~scanf("%d", &n))
    {
        clr(cnt, 0);
        for (int i = 1; i <= n; i++)
        {
            int v;
            scanf("%d", &v);
            cnt[v]++;
        }

        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= n; j++)
                for (int k = 0; k <= n; k++) dp[i][j][k] = -1;

        dp[0][0][0] = 0;
        double ans = dfs(cnt[1], cnt[2], cnt[3]);
        printf("%.10lf\n", ans);
    }

    return 0;
}


Measured memory_bytes: 216916
#include<iostream>
using namespace std;
int main(){

  int x,y;
  for(int i=0;i<3000;i++){ 
    cin>>x>>y;
    if( x==0 && y==0 )break;

    int t;
    if(x>y){
      t=x;
      x=y;
      y=t;
    }

    cout <<x<<" "<<y<<endl;
 
  }

  return 0;
}

Measured memory_bytes: 2996
#include <iostream>
#include <queue>

using namespace std;

#define MAX 110
int matrix[MAX][MAX];
int dst[MAX];

void input(int num){
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void bfs(){

}

int main(){
    int num; cin >> num;
    input(num);

    for(int i=0;i<num;i++){
        for(int j=0;j<num;j++){
            if(j==0)
                cout << matrix[i][j];
            else
                cout << " " << matrix[i][j];
        }
        cout << endl;
    }

}

Measured memory_bytes: 1212
#include <cstdio>
using namespace std;
int n, arr[15];
bool flag;
void dfs(int x1, int x2, int y1, int y2, int cnt)
{
    if (x2 < x1 || y2 < y1)
        return;
    if (cnt == 10)
    {
        flag = true;
        return;
    }
    dfs(x2, arr[cnt], y1, y2, cnt + 1);
    dfs(x1, x2, y2, arr[cnt], cnt + 1);
}
int main()
{
    scanf("%d", &n);
    while (n--)
    {
        for (int i = 0; i < 10; i++)
            scanf("%d", &arr[i]);
        flag = false;
        dfs(0, 0, 0, 0, 0);
        if (flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 2520
a = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())])

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll n;
        
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    FOR(i, n) cout << s1[i] << s2[i];
    cout << '\n';
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    while (cin >> n, n) {
        vector<ll> a(n); cin >> a;
        vector<vector<ll>> dp(n, vector<ll>(n+1, 0));
        auto check = [&](const ll idx1, const ll idx2) {
            return abs(a[idx1] - a[idx2]) <= 1;
        };
        rep(i, n-1) {
            if (check(i, i+1)) dp[i][i+2] = 2;
        }
        rep(w, 3, n+1) rep(l, n) {
            ll r = l + w;
            if (r > n) break;
            rep(m, l+1, r) {
                chmax(dp[l][r], dp[l][m] + dp[m][r]);
            }
            if (check(l, r-1) && dp[l+1][r-1] == r-l-2) {
                chmax(dp[l][r], dp[l+1][r-1]+2);
            }
        }
        cout << dp[0][n] << endl;
    }
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int main(){
    string s;
    int n;
    cin >> n;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        s[i] += n;
        if(s[i]>90){
            s[i] -= 26;
        }
    }
    cout << s << endl;
    return 0;
}

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int P, Q, R;
  cin >> P >> Q >> R;
  int ans=min(P+Q, P+R);
  ans=min(ans, Q+R);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256