akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	int w;
	cin>>S;
	cin>>w;
	cout<<S[0];
	for (int i=w;i<S.length();i+=w){
		cout<<S[i];
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

int main(){
    int N;
    string c;
    vector<int> reds, whites;

    cin >> N;
    cin >> c;

    for(int i = 0; i < c.size(); ++i){
        if(c[i] == 'R')
            reds.push_back(i);
        else
            whites.push_back(i);
    }

    int count = 0;
    int R = reds.size(), W = whites.size();

    for(; count < min(R, W) && reds[R - 1 - count] > whites[count]; ++count);

    cout << count << '\n';
}

Measured memory_bytes: 4684
//ABC 157 B
#include <bits/stdc++.h>
using namespace std;

int N, A[3][3], b[10];
bool appear[3][3];

int main() {
   for(int i = 0; i < 3; i++) {
      for(int j = 0; j < 3; j++) 
	     cin >> A[i][j];
   }
   
   cin >> N;
   for(int i = 0; i < N; i++) 
      cin >> b[i];
   
   for(int i = 0; i < N; i++) { 
      for(int j = 0; j < N; j++) {
	     appear[i][j] = false;
		 for(int k = 0; k < N; k++) {
		    if(A[i][j] == b[k]) appear[i][j] = true;
		 }
	  }
   }
   
   string ANS = "No";
   for(int i = 0; i < 3; i++) {
      if(appear[i][0] && appear[i][1] && appear[i][2])
	     ANS = "Yes";
   }
   
   for(int i = 0; i < 3; i++) {
      if(appear[0][i] && appear[1][i] && appear[2][i]) 
	     ANS = "Yes";
   }
   
   if(appear[0][0] && appear[1][1] && appear[2][2]) 
      ANS = "Yes";
   
   if(appear[0][2] && appear[1][1] && appear[2][0]) 
      ANS = "Yes";
   
   cout << ANS << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lb long double
#define N 110
#define pi acos(-1)
#define eps 1e-10
using namespace std;
struct Po{lb x,y;}a[N],yu;
int n;
lb r,ansn;
Po operator -(Po x,Po y){return (Po){x.x-y.x,x.y-y.y};}
Po operator +(Po x,Po y){return (Po){x.x+y.x,x.y+y.y};}
lb operator *(Po x,Po y){return x.x*y.y-x.y*y.x;}
lb operator ^(Po x,Po y){return x.x*y.x+x.y*y.y;}
Po operator *(Po x,lb y){return (Po){x.x*y,x.y*y};}
Po operator /(Po x,lb y){return (Po){x.x/y,x.y/y};}
void get(Po &x){scanf("%Lf %Lf",&x.x,&x.y);}
int pa(int x){if (x>n) return x-n;return x;}
lb dis(Po x){return sqrtl(x.x*x.x+x.y*x.y);}
lb dis2(Po x){return x.x*x.x+x.y*x.y;}
bool in(Po x){return (dis(x)<r-eps);}
lb queh(Po x,Po y){
	lb j=atan2(y.y,y.x)-atan2(x.y,x.x);
	if (j<-pi-eps)j+=pi+pi;
	if (j>pi+eps)j-=pi+pi;
	return r*r*j;
}
bool pa(Po x,Po y,Po z){
	if (y.x>z.x+eps) swap(y,z);
	if (x.x<y.x-eps||x.x>z.x+eps) return 0;
	if (y.y>z.y+eps) swap(y,z);
	if (x.y<y.y-eps||x.y>z.y+eps) return 0;
	return 1;
}
lb que(Po x,Po y){
	if (in(x)&&in(y))return x*y;
	Po tou=x+(y-x)*((y-x)^(yu-x))/dis2(y-x);
	Po dw=(y-x)/dis(y-x);
	lb di=dis(tou);
	if (di>r+eps) return queh(x,y);
	lb del=sqrtl(r*r-di*di);
	Po an1=tou+dw*(-del),an2=tou+dw*del;
	vector<Po> an;
	if (in(x)&&!in(y)){
		if (!pa(an1,x,y))swap(an1,an2);
		return x*an1+queh(an1,y);
	}
	if (!in(x)&&in(y)){
		if (!pa(an1,x,y))swap(an1,an2);
		return queh(x,an1)+an1*y;
	}
	if (!in(x)&&!in(y)){
		if (pa(an1,x,y))return queh(x,an1)+an1*an2+queh(an2,y);
		else return queh(x,y);
	}
}
int main(){
	scanf("%d",&n);scanf("%Lf",&r);yu.x=0;yu.y=0;
	for (int i=1;i<=n;i++)get(a[i]);
	for (int i=1;i<=n;i++)ansn+=que(a[i],a[pa(i+1)]);
	printf("%.10Lf\n",ansn/2);
	return 0;
}


Measured memory_bytes: 3304
L,  R =  list(map(int, input().strip().split()))
l = L // 2019
r = R //2019
ans= 0
if(l == r):
    ans = 2019
    for i in range(L, R):
        for j in range(i+1, R+1):
            ans = min(ans, (i*j)%2019)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<vector>
#include<queue>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;

signed main() {
	ll n, count = 0;
	cin >> n;
	while (n) {
		if (n <= 1) {
			break;
		}
		if (n <= 3) { count++; break; }
		if (n % 3) {
			n = n / 3 + 1; count++;
		}
		else {
			n = n / 3; count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class Program
    {
        public static void Main()
        {
            int X = int.Parse(Console.ReadLine());
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
           
                X -= A;
                if (X >= B)
                {
                    while (true)
                    {
                        X -= B;
                        if (X < B)
                        {
                            break;
                        }
                    }
                }
            
 
            Console.WriteLine("{0}", X);
        }
    }
}

Measured memory_bytes: 13268
D, G = map(int, input().split())
score_list = []
for i in range(D):
    p, c = map(int, input().split())
    score_list.append([(i + 1) * 100] * (p - 1) + [c + (i + 1) * 100])
full_score = [sum(i) for i in score_list]
sol = [format(i, 'b').zfill(D) for i in range(2 ** D)]
ans = []

for i in sol:
    problem = 0
    score = 0
    for j in range(D):
        if i[j] == '1':
            score += full_score[j]
            problem += len(score_list[j])
        else:
            continue
    if score >= G:
        ans.append(problem)
    else:
        if score + full_score[i.rfind('0')] < G:
            continue
        else:
            while score < G:
                score += score_list[i.rfind('0')][0]
                problem += 1
            ans.append(problem)

print(min(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,k,p[1003],cnt=0;
int main(void)
{
  	cin>>n>>k;
  	for(int i=0;i<n;i++)
  		cin>>p[i];
  	sort(p,p+n);
  	for(int i=0;i<k;i++)
    	cnt+=p[i];
    cout<<cnt;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

inline int max(int a,int b) {
	if (a > b) return a;
	return b;
}

inline int min(int a, int b) {
	if (a < b) return a;
	return b;
}

char w[4] = { 'L','R','U','D' };
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if ((i % 2 == 0 && s[i] == w[0]) || (i % 2 == 1 && s[i] == w[1])) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AC = [0]*N         
WA = [0]*N        
count_WA = 0
for i in range(M):
  P,s = map(str, input().split())
  p = int(P)
  if AC[p-1]==1:
    continue
  if s == "WA":
    WA[p-1] += 1
  else:           
    count_WA += WA[p-1]
    AC[p-1] = 1
print(AC.count(1), count_WA)

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

int main() {
  int N,count=0;
  char S;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> S;
    if (S == 'Y') {
      if (count == 0)
        count++;
      else
        continue;
    }
    else
      continue;
  }
  if (count == 0)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    map<string,int> m;
    rep(i,n){
        string enter;
        cin>>enter;
        m[enter]++;
    }
    int q;
    cin>>q;
    rep(i,q){
        string enter;
        cin>>enter;
        m[enter]--;
    }
    int max=0;
    for(auto i:m){
        if(i.second>max) max=i.second;
    }
    cout<<max<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

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

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	x, n := scanInt(), scanInt()
	p := scanInts(n)

	var s []int
	for i := 0; i <= 101; i++ {
		ok := true
		for _, e := range p {
			if i == e {
				ok = false
			}
		}
		if ok {
			s = append(s, i)
		}
	}

	m := math.MaxInt32
	var ans int
	for _, e := range s {
		a := abs(x - e)
		if a < m {
			m = a
			ans = e
		}
	}

	fmt.Println(ans)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


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

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

  //配列の準備(すでにおかしをもらったかを代入する)
  vector<int> d(n);

  rep(i,k) {
    int m;
    cin >> m;//お菓子の個数を入力
    rep(j,m) {
      int a;
      cin >> a;//お菓子をもらったすぬけ君の番号
      d[a-1] = 1;//配列に合わせるため"-1"し、お菓子をもらった人を"1"にする
    }
  }
  int ans = 0;
  rep(i,n) if (d[i] == 0) ++ans;//お菓子をもらっていないすぬけ君をカウント
  cout << ans << endl;
}

Measured memory_bytes: 3580
use proconio::{fastout, input};
use regex::Regex;

fn main() {
    input!(alpha: String);
    let upper = Regex::new(r"[A-Z]").unwrap();
    let lower = Regex::new(r"[a-z]").unwrap();
    if upper.is_match(alpha.as_str()) {
        println!("A")
    } else if lower.is_match(alpha.as_str()) {
        println!("a")
    }
}


Measured memory_bytes: 3032
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    return buf
}

fn main() {
  let line = gets();
  let mut s: Vec<&str> = line.trim().split("").collect();
  s.sort();
  s.dedup();
  s.remove(0);
  let mut done = false;
  for (i, x) in (97..123).enumerate() {
    let xx = x as u8;
    let a = xx as char;
    if (i > s.len() - 1) || (a.to_string() != s[i]) {
      println!("{}", a);
      done = true;
      break;
    }
  }
  if !done {
    println!("None");
  }
}


Measured memory_bytes: 6396
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MultiWayIf #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace


------------------
-- #   Read   # --
------------------

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    [a,[b0,'.',b1,b2]] <- words <$> getLine
    let aInteg = read a :: Integer
    let bInteg100 = read [b0,b1,b2] :: Integer
    
    print $ (aInteg * bInteg100) `div` 100


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
mint dp[1<<21];
ll a[22][22];
ll n;
int main(){
    cin>>n;
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
        }
    }
    dp[0]=1;
    for(int bit=1;bit<(1<<n);bit++){
        ll bitcnt=0;
        rep(i,n){
            if((bit>>i)&1)bitcnt++;
        }
        rep(i,n){
            if((bit>>i)&1){
                if(a[bitcnt-1][i])dp[bit]+=dp[bit-(1<<i)];
            }
        }
    }
    cout<<dp[(1<<n)-1].x<<endl;
    return 0;
}

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

int main(void) {
  int n, m, c;
  cin >> n >> m >> c;
  vector<vector<int>> ass(n, vector<int>(m));
  vector<int> bs(m);
  for (int &b : bs) {
    cin >> b;
  }
  for (vector<int> &as : ass) {
    for (int &a : as) {
      cin >> a;
    }
  }

  int result = 0;
  for (vector<int> &as : ass) {
    int code = 0;
    for (int i = 0; i < m; i++) {
      code += as[i] * bs[i];
    }
    result += code > -c ? 1 : 0;
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
 
#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mk(arr,n,type)  type *arr=new type[n];
 
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int main(){
	int n;
	string k;
	cin >> n;
	cin >> k;
	if(k.size() > n){
		cout << k.substr(0,n) << "...";
	}
	else{
		cout << k << "\n";
	}	
	return 0;
}


Measured memory_bytes: 3044
/* be name khoda */

// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

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

const ll maxn = 100010;

ll n;

void prt(ll a, ll b) {
    cout << a << ' ' << b << '\n';
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    // ifstream cin(".in");

    cin >> n;
    if ((n & -n) == n) return cout << "No\n", 0;
    cout << "Yes\n";
    prt(1, 2); 
    prt(2, 3); 
    prt(3, n + 1); 
    prt(n + 1, n + 2); 
    prt(n + 2, n + 3);
    for (ll i = 4; i < n; i += 2) {
        prt(i, n + 1);
        prt(i + 1, n + 1);
        prt(i, n + i + 1);
        prt(i + 1, n + i);
    }
    if (n % 2 == 0) {
        ll x = n & -n; // n & -n is even because n is even
        prt(n, x ^ 1);
        prt(n + n, n ^ x);
    }

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll H,A,rs=0;
    cin >> H >>A;
    
    while(H > 0){
        H-= A;
        rs++;

    }

    cout << rs << endl;
    
}

Measured memory_bytes: 3592
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int C = Integer.parseInt(st.nextToken());
        int[] wt = new int[N];
        int[] val = new int[N];

        for (int i=0; i<N; i++){
            st = new StringTokenizer(br.readLine());
            wt[i] = Integer.parseInt(st.nextToken());
            val[i] = Integer.parseInt(st.nextToken());
        }

        long[][] dp = new long[N+1][C+1];

        for (int i=1; i<=N; i++){
            for (int j = 1; j <= C; j++) {
                dp[i][j] = Math.max(dp[i][j], dp[i-1][j]);
                if(j-wt[i-1]>=0)
                    dp[i][j] = Math.max(dp[i][j], dp[i-1][j-wt[i-1]]+val[i-1]);
//                System.out.print(dp[i][j]+" ");
            }
//            System.out.println();
        }

        System.out.println(dp[N][C]);


    }
}


Measured memory_bytes: 126928
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

vector<ll> div(ll n){
    vector<ll> ret;
    for (ll i = 1LL;i*i <= n;i++){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i!=n)
                ret.push_back(n/i);
        }
    }
    sort(begin(ret),end(ret));
    return (ret);
}

int main(){
    ll n;
    cin >> n;
    vector<ll> div1 = div(n);
    vector<ll> div2 = div(n-1);
    int ans = div2.size()-1;
    for (auto d:div1){
        if(d==1)
            continue;
        ll tmp = n;
        while(tmp%d==0)
            tmp/=d;
        if((tmp-1)%d==0)
            ans ++;
   }
     cout <<ans<<endl;
        return 0;

}


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

using namespace std;
const int MAXN=310;
double dp[MAXN][MAXN][MAXN];

int a,b,c,n;

int main()
{
	cin>>n;
	for(int i=1,x;i<=n;++i)
	{
		cin>>x;
		if(x==1) ++a;
		if(x==2) ++b;
		if(x==3) ++c;
	}
	
	for(int k=0;k<=n;++k)
		for(int j=0;j<=n;++j)
			for(int i=0;i<=n;++i)
			{
				if(i||j||k)
				{
					if(i) dp[i][j][k]+=dp[i-1][j][k]*1.0*i/(i+j+k);
					if(j) dp[i][j][k]+=dp[i+1][j-1][k]*1.0*j/(i+j+k);
					if(k) dp[i][j][k]+=dp[i][j+1][k-1]*1.0*k/(i+j+k);
					dp[i][j][k]+=(double)n/(i+j+k);
				}

			}
		  
	cout<<fixed<<setprecision(11)<<dp[a][b][c]<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 224372
// Matrix Multiplication

package main

import "fmt"

// m行n列の行列を表示する
func disp_matrix(name string, mat [100][100]int, m int, n int) {
    // fmt.Println(name)
    for i:=0; i<m; i++ {
        for j:=0; j<n; j++ {
            fmt.Printf("%d", mat[i][j])
            if j == n-1 {
                fmt.Println("")
            } else {
                fmt.Print(" ")
            }
        }
    }
    // fmt.Println("")
}
func main() {
    var n, m, l int
    var a, b, c [100][100]int

    fmt.Scanf("%d %d %d", &n, &m, &l)

    // 行列aの読み込み
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            fmt.Scanf("%d", &a[i][j])
        }
    }

    // 行列bの読み込み
    for i:=0; i<m; i++ {
        for j:=0; j<l; j++ {
            fmt.Scanf("%d", &b[i][j])
        }
    }

    /*
    disp_matrix("行列A", a, n, m)
    disp_matrix("行列B", b, m, l)
    */

    // a * b
    for i:=0; i<n; i++ {
        for j:=0; j<l; j++ {
            c[i][j] = 0
            for k:=0; k<m; k++ {
                c[i][j] += (a[i][k] * b[k][j])
            }
        }
    }

    // c(=a * b) を表示
    disp_matrix("行列C", c, n, l)
}


Measured memory_bytes: 2648
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

#define ll long long
using namespace std;
int main(){
     int N;
     float x;
     string u;
     double sum = 0;
     cin >> N;
     for(int i = 0; i < N; i++){
          cin >> x >> u;
          if(u == "JPY"){
               sum += x;
          }else if(u == "BTC"){
               sum += x * 380000.0;
          }
     }
     cout << sum << endl;
     return 0;
}

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

void solver1(int H, int W, vector<vector<char>> in_arg, vector<vector<int>> &return_arg){

    int l{}, r{}, u{}, d{};

    for(int h = 0; h != H; ++h){
        for(int w = 0; w != W; ++w){

            l = max(0, w-1);
            r = min(w+1, W-1);
            u = max(0, h-1);
            d = min(h+1, H-1);

            if(in_arg.at(h).at(w) == '#'){

                for(int i = u; i <= d; ++i){
                    for(int j = l; j <= r; ++j){

                        return_arg.at(i).at(j) += 1;
                    }
                }
            }
        }
    }

    return;
}

void solver2(int H, int W, vector<vector<char>> in_arg1, vector<vector<int>> in_arg2, vector<vector<char>> &return_arg){

    for(int h = 0; h != H; ++h){
        for(int w = 0; w != W; ++w){
            return_arg.at(h).at(w) = '0' + (in_arg2.at(h).at(w));
        }
    }

    for(int h = 0; h != H; ++h){
        for(int w = 0; w != W; ++w){
            if(in_arg1.at(h).at(w) == '#') return_arg.at(h).at(w) = '#';
        }
    }    

    return;
}

int main(){

    int H, W;
    cin >> H >> W;
    vector<vector<char>> area(H, vector<char>(W));
    for(int h = 0; h != H; ++h){
        for(int w = 0; w != W; ++w){
            cin >> area.at(h).at(w);
        }
    }

    vector<vector<int>> ans_int(H, vector<int>(W));
    vector<vector<char>> ans_char(H, vector<char>(W));
    solver1(H, W, area, ans_int);
    solver2(H, W, area, ans_int, ans_char);


    for(int h = 0; h != H; ++h){
        for(int w = 0; w != W; ++w){
            cout << ans_char.at(h).at(w);
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

class Main{
    public static void main(String[] args){
        ArrayList<Integer> list = new ArrayList<Integer>();
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            list.add(String.format("%d",Math.abs(sc.nextInt() + sc.nextInt())).length());
        }
        for(int i = 0,size = list.size();i < size;i++){
            System.out.println(list.get(i));
        }
    }
}

Measured memory_bytes: 26484
<?php
  	fscanf(STDIN, "%d", $N);
  	$sequence = explode(" ", trim(fgets(STDIN)));
	$sortSequence = $sequence;
	sort($sortSequence);

	$diffCount = 0;
	for ($i=0;$i<$N;$i++) {
      	if ($sequence[$i] != $sortSequence[$i]) {
          	$diffCount++;
        }
    }

	if ($diffCount <= 2) {
      	echo "YES\n";
    } else {
      	echo "NO\n";
    }

Measured memory_bytes: 3700
#abc067 b
s=input()

def func(mid):
    flag=True
    for i in range(mid):
        if s[i]!=s[mid+i]:
            flag=False
    return flag

for i in range(len(s)-1,1,-1):
    if i%2==1:
        continue
    else:
        mid=i//2
        if func(mid):
            print(i)
            break


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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main(){
    string s;cin>>s;
    ll n=s.size();
    ll a=0;
    ll c=0;
    ll ans[n];
    for(ll i=0;i<n;i++){
        ans[i]=0;
    }
    for(ll i=1;i<n;i++){
        if(s[i-1]=='R' && s[i]=='L'){
            a=i;
        }else if(s[i-1]=='L' && s[i]=='R'){
            ans[a-1]=((a-c)+(a-c)%2)/2+((i-a)-(i-a)%2)/2;
            ans[a]=(i-c)-ans[a-1];
            c=i;
        }
        if(i==n-1){
            ans[a-1]=((a-c)+(a-c)%2)/2+((i+1-a)-(i+1-a)%2)/2;
            ans[a]=(i-c+1)-ans[a-1];
        }
    }
    cout<<ans[0];
    for(ll i=1;i<n;i++){
        cout<<' '<<ans[i];
    }
    cout<<endl;
    return 0;
}



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

int main() {
  string O, E;
  cin >> O >> E;
  for (int i = 0; i < O.size(); ++i) {
    if (E.size() == i) {
      cout << O[i];
    } else {
      cout << O[i] << E[i];
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int n, ans, a[105];
pi b[105];

int main() {
	fastio; cin >> n;
	FOR(i, 1, n-1) {
		cin >> b[i].f;
		b[i].s = i;
	}
	sort(b+1, b+n, greater<pi>());
	FOR(i, 1, n-1) {
		a[b[i].s] = b[i].f;
		a[b[i].s+1] = b[i].f;
	}
	cout << accumulate(a+1, a+n+1, 0);
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,d,x;

int main(){
	cin>>n>>d>>x;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		x+=(d+A-1)/A;
	}
	cout<<x<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
using namespace std;
int N, A[1000];

void print() {
    cout << A[0];
    for (int i = 1; i < N; i++) {
        cout << " " << A[i];
    }
    cout << endl;
}

void insertion_sort() {
    print();
    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        print();
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    insertion_sort();
    return 0;
}

Measured memory_bytes: 3084
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 2e5, Pt = 1e9 + 7;
int n;
LL fac[MaxN + 5];
LL cnt[MaxN + 5];
LL a[MaxN + 5];
LL l, r;

LL qwr(LL x, LL y)
{
	LL res = 1;
	while (y != 0) {
		if (y & 1) res = (res * x) % Pt;
		y >>= 1LL;
		x = (x * x) % Pt;
	}
	return res;
}

LL C(LL n, LL m)
{
	if (m > n) return 0;
	if (m == 0) return 1;
	return ((fac[n] * qwr(fac[n - m], Pt - 2)) % Pt) * qwr(fac[m], Pt - 2) % Pt;
}

void Init()
{
	memset(cnt, 0, sizeof(cnt));
	LL t;
	for (int i = 1; i <= n + 1; i++) {
		scanf("%lld", &a[i]);
		cnt[a[i]]++;
		if (cnt[a[i]] == 2) t = a[i];
	}
	l = -1; r = -1;
	for (int i = 1; i <= n + 1; i++) {
		if (a[i] == t && l == -1) l = i;
		else if (a[i] == t) r = i;
	}
}

void Solve()
{
	LL sum = l - 1 + n + 1 - r;
	//printf("%lld\n", sum);
	if (n + 1 >= 1) printf("%lld\n", (LL)n);
	if (n + 1 >= 2) printf("%lld\n", ((C(n + 1, 2) - sum) % Pt + Pt) % Pt);
	if (n + 1 >= 3) {
		for (LL k = 3; k <= n + 1; k++) {
			//LL ans = ((C(n + 1, k) + C(n + 1 - r, k - 1)) % Pt + C(l - 1, k - 1)) % Pt;
			LL ans = C(n + 1, k);
			ans = ((ans - C(sum, k - 1)) % Pt + Pt) % Pt;
			printf("%lld\n", ans);
		}
	}
}

int main()
{
	fac[0] = 1;
	for (int i = 1; i <= 2e5; i++) fac[i] = (fac[i - 1] * (LL)i) % Pt;
	while (~scanf("%d", &n)) {
		Init();
		Solve();
	}
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#define INFTY 1000000001
void mergeSort(int [],int,int);
void merge(int [],int,int,int);
int count = 0;
int L[250001];
int R[250001];

int main(){
    int n,i;
    int A[500002];
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    mergeSort(A,0,n);
    for(i=0;i<n;i++){
        if(i<n-1) printf("%d ",A[i]);
        else printf("%d\n",A[i]);
    }
    printf("%d\n",count);
    return 0;
}
void merge(int A[],int left,int mid,int right){
    int n1,n2,i,j,k;
    n1 = mid - left;
    n2 = right - mid;
    for(i=0;i<n1;i++){
        L[i] = A[left + i];
    }
    for(i=0;i<n2;i++){
        R[i] = A[mid+i];
    }
    L[n1] = INFTY;
    R[n2] = INFTY;
    i = 0;
    j = 0;
    for(k = left;k<right;k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i = i + 1;
            count++;
        }
        else{
            A[k] = R[j];
            j = j + 1;
            count++;
        }
    }
}
void mergeSort(int A[],int left,int right){
    int mid;
    if(left+1 < right){
        mid = (left + right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}


Measured memory_bytes: 5668
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

int LIS(vector<int> a){
	deque<int> dp;
	for (int i = 0; i< a.size(); i++){
		int p = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
		if (p == 0){
			dp.push_front(a[i]);
		}
		else
			dp[p - 1] = a[i];
	}
	return dp.size();
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	cout << LIS(a) << endl;

	return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M; cin>>N>>M;
    vector<pair<int64_t,int64_t>> nP(N),mP(M);
    rep(n,0,N){int64_t a,b; cin>>a>>b; nP.at(n)=make_pair(a,b);}
    rep(m,0,M){int64_t c,d; cin>>c>>d; mP.at(m)=make_pair(c,d);}

    for(auto np:nP){
        int64_t ans,minD=INT64_MAX,a=np.first,b=np.second;
        rep(m,0,M){
            int64_t c=mP.at(m).first, d=mP.at(m).second;
            int64_t dst=abs(a-c)+abs(b-d);
            if(minD>dst){ans=m+1; minD=dst;}
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp.to!int).array;

    auto B = new long[](2*10^^5+10);
    A = A.uniq.array;
    N = A.length.to!int;

    auto dp = new long[](N+1);
    dp[0] = 1;

    foreach (i; 1..N+1) {
        (dp[i] += dp[i-1]) %= MOD;
        (dp[i] += B[A[i-1]]) %= MOD;
        (B[A[i-1]] += dp[i-1]) %= MOD;
    }

    dp[N].writeln;
}


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

#define int double
using namespace std;
 

 
int calc(int h, int m)
{
	
 
 
	if (h == 12) h = 0;
	if (m == 60) m = 0;
 
	
	int hour_angle = 0.5 * (h * 60 + m);
	int minute_angle = 6 * m;
 
	int angle = abs(hour_angle - minute_angle);
 
	angle = min(360 - angle, angle);
 
	return angle;
}
 
signed main()
{
	std::cout << std::fixed;
	std::cout << std::setprecision(18);
	int a, b;
	cin >> a >> b;
	int h, m;
	cin >> h >> m;
	
	int k = calc(h, m);
	int p = 3.141592653589793238;
	k = (k* p) / 180;
	
	cout << sqrt((a * a) + (b * b) - (a * b * 2 * cos(k)));
 
 
	return 0;
}

Measured memory_bytes: 4224
import sys

from itertools import combinations


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    while True:
        n, x = map(int, input().split())
        if n == 0 and x == 0:
            break
        A = list(combinations(range(1, n + 1), 3))
        cnt = 0
        for a in A:
            if sum(a) == x:
                cnt += 1
        print(cnt)


if __name__ == "__main__":
    main()



Measured memory_bytes: 31420
import copy

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a % b)

N = int(input())
A = list(map(int, input().split()))
F = copy.copy(A)
B = copy.copy(A)
for i in range(N - 1):
  F[i+1] = gcd(F[i+1], F[i])
for i in range(N - 2, -1, -1):
  B[i] = gcd(B[i], B[i+1])
ans = max(F[N-2], B[1])
for i in range(1, N - 1):
  ans = max(ans, gcd(F[i-1], B[i+1]))
print(ans)


Measured memory_bytes: 14848
using System;
namespace AtCoder
{
public class Program
    {
        public static void Main(string[] args)
        {
       		string s = Console.ReadLine();
            int n = s.Length;
            int cnt = 1;
            string before_s = s.Substring(0,1);
          	int range = 1;
            for(int i = 1; i < n; i++)
            {
              	string ts = s.Substring(i-range+1,range);
           		//Console.WriteLine(before_s + " " +ts);
                if(!ts.Equals(before_s))
                {
                    before_s = ts;
                    cnt++;
                  	range = 1;
                }else{
                 	range++;
                }
                
	        }
            Console.WriteLine(cnt);
        }
	}
}

Measured memory_bytes: 17332
//============================================================================
// Name        : ABC.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((a+b<=a+c)&&(a+b<=b+c))printf("%d",a+b);
	else if((b+c<=a+c)&&(b+c<=a+b))printf("%d",b+c);
	else printf("%d",a+c);
	return 0;
}


Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 157 (https://atcoder.jp/contests/abc157)
// Problem: A: Duplex Printing (https://atcoder.jp/contests/abc157/tasks/abc157_a)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

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

    int n; cin >> n;
    cout << ((n + 1) / 2) << '\n';

    return 0;
}

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

int main() {
	int a[5],ans;
	for(int i=0;i<5;i++){
		cin >>a[i];
		if(a[i]==0){
			ans=i+1;
		}
	}
	cout<<ans<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3632
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
sort($a);
$x = $a[$n-1];
$q = $x / 2;
$m = PHP_INT_MAX;
foreach ($a as $v) {
	$d = abs($q - $v);
	if ($d < $m) {
		$y = $v;
		$m = $d;
	} elseif ($v > $q) {
		break;
	}
}
echo "$x $y";

Measured memory_bytes: 12920
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int n;
ll a[200005] = {};

ll f(ll b){
    ll c = 0;
    rep(i,0,n)c += abs(a[i] - (b+i+1));
    ret c;
}
int main(){
    cin >> n;
    inrep(n,a);

    ll b[n];
    rep(i,1,n+1)b[i-1]= a[i-1]-i;
    sort(b,b+n);
    P(min(f(b[n/2]) , f(b[n/2]+1)));
    
    return  0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n;
int a[1 << 18];
P f[1 << 18], s[1 << 18];
signed main() {
	cin >> n;
	rep(i, 1 << n) {
		cin >> a[i];
		f[i] = { a[i],i }; s[i] = { 0,-1 };
	}
	rep(i, 1 << n) {
		rep(j, n) {
			if (i >> j & 1)continue;
			int k = i | (1 << j);
			if (f[k] <= f[i] && f[k].second != f[i].second) {
				s[k] = f[k];
				f[k] = f[i];
				if (s[k] < s[i] && s[k].second != s[i].second)s[k] = s[i];
			}
			else if (s[k] < f[i] && s[k].second != f[i].second && f[k].second != f[i].second) {
				s[k] = f[i];
			}
		}
	}
	int ans = 0;
	REP(i, 1 << n) {
		chmax(ans, f[i].first + s[i].first);
		cout << ans << endl;
	}
}


Measured memory_bytes: 13312
#include<stdio.h>

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(r<=x && x<=(W-r) && r<=y && y<=(H-r))
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
using P = pair<string,pi>;

struct edge{
    int to;
    string s;
};

const int N = 450;
const string INF(N,'z');

int main(){
    int n,a,s,g;
    while(cin >>n >>a >>s >>g,n){
        vector<vector<edge>> G(n);
        rep(i,a){
            int x,y;
            string lab;
            cin >>x >>y >>lab;
            G[x].pb({y,lab});
        }

        vector<vector<string>> dp(n,vector<string>(N,INF));
        dp[s][0] = "";
        priority_queue<P,vector<P>,greater<P>> pq;
        pq.push({"",{s,0}});
        while(!pq.empty()){
            P now = pq.top();
            pq.pop();

            int v = now.se.fi, L = now.se.se;
            if(dp[v][L] > now.fi) continue;

            for(const auto &e:G[v]){
                int nv = e.to, nL = L+e.s.size();
                if(nL>=N) continue;
                string nx = dp[v][L]+e.s;
                if(dp[nv][nL] > nx){
                    dp[nv][nL] = nx;
                    pq.push({dp[nv][nL],{nv,nL}});
                }
            }
        }

        string ans = INF;
        rep(i,N) ans = min(ans, dp[g][i]);

        // rep(i,N){
        //     dbg(i);
        //     dbg(dp[g][i]);
        // }
        // dbg(ans.size());

        if(ans.size()>6*(n-1)) ans = "NO";
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 20640
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    cin>>a>>b;
    if(a>0)cout<<"Positive";
    else if(a==0||(a<0&&b>0))cout<<"Zero";
    else if((abs(b)-abs(a))%2!=0)cout<<"Positive";
    else cout<<"Negative";
    return 0;
}

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

int LCS(char *x, char *y){
    
    int i, j, m, n, c[1002][1002];
    
    m = strlen(x);
    n = strlen(y);
 
    for(i = 0; i <= m; i++){
        for(j = 0; j <= n; j++){
            if(i == 0 || j == 0) c[i][j] = 0;
            if(x[i] == y[j]) c[i+1][j+1] = c[i][j] + 1;
            else if(c[i][j+1] >= c[i+1][j]) c[i+1][j+1] = c[i][j+1];
            else c[i+1][j+1] = c[i+1][j];
        }
    }
    
    return c[m][n];
  
}

int main(){
    
    char x[1002], y[1002];
    int  q;
    
    scanf("%d", &q);
    
    while(q--){
        scanf("%s%s", x, y);
        printf("%d\n", LCS(x, y));
    }
   
    return 0;
    
}

Measured memory_bytes: 4528
#include <iostream>
#include <math.h>
using namespace std;

void solve(){
  long W,a, b;
  cin >> W >> a >> b ;
  long ans =0;
  if((a + W) < b) {
    ans = b - (a + W);
  }else if((b + W) < a){
    ans = a - (b+W);
  }
  std::cout << ans;
}


int main() {
  solve();
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double a[3000];
double dp[3000][3000];


//dp[i][x] denotes the probality of getting atleast x heads in toss of first i coins.
double solve(int i, int heads){
        if(heads==0){
            return 1.0;
        }

        if(i==0){
            return 0.0;
        }
   
    if(dp[i][heads] + 0.95 >0){
        return dp[i][heads];
    }

   return dp[i][heads]=a[i]*solve(i-1, heads-1 ) + (1.0-a[i])*solve(i-1, heads);
}
int main() {
    int n; 
    cin>>n;
    memset(dp, -1, sizeof dp);
    n++;
    for(int i=1;i<n;++i){
   cin>>a[i];
    }
   n--;
  cout<<fixed<<setprecision(10)<<solve(n ,  (n+1)/2);
   return 0;
}


Measured memory_bytes: 74340