akhauriyash/Code-Regression huggingface dataset:
/*
 Educational Dp Contest Atcoder
 
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=1000000007;
const int INF=1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=1e5+5;
int a[N][3];int dp[N][3];
void solve()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
                if(j!=k)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
                }
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;

}

int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LINF = 4e18;
const ll delta = 10289;

const int N = 1e5 + 20;
vector<int> G[N];
int n, sz[N];
bool mat = 1;

void dfs(int v, int p = -1) {
	sz[v] = 1;
	for (int u : G[v])
		if (u - p)
			dfs(u, v), sz[v] += sz[u];
	int cnt = 0;
	for (int u : G[v])
		if (u - p)
			cnt += sz[u] % 2;
	cnt += (n - sz[v]) % 2;
	if (cnt != 1)
		mat = 0;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0, v, u; i < n - 1; i++) {
		cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	dfs(1);
	cout << (mat ? "Second" : "First") << endl;
}



Measured memory_bytes: 6272
//AGC 007-A(解２(H+W-1)個のマスを通ることと問題の条件を満たすことは同値)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  char a[10][10];
  for (int i = 0; i < H; i++)  {
    for (int j = 0; j < W; j++)  {
        cin >> a[i][j];
    }
  }
  int kosuu = 0;
  for (int i = 0; i < H; i++)  {
    for (int j = 0; j < W; j++)  {
      if (a[i][j] == '#') ++kosuu;
    }
  }
  if (kosuu == H + W - 1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  string s;
  cin>>k;
  cin>>s;
  if(s.length()<=k){
    cout<<s<<endl;
    return 0;}
  string ans="";
  for(int i=0;i<k;i++){
    ans+=s[i];
  }
  ans+="...";
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> v(n),c(n);
  rep(i,n) cin >> v.at(i);
  rep(i,n) cin >> c.at(i);
  int ans = 0;
  rep(i,n){
    ans += max(v.at(i)-c.at(i),0);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

constexpr int MOD = 1000000007;

int ctoi(char c) {
    if (c == 'A') return 0;
    if (c == 'T') return 1;
    if (c == 'G') return 2;
    else return 3;
}
char itoc(int n) {
    if (n == 0) return 'A';
    if (n == 1) return 'T';
    if (n == 2) return 'G';
    else return 'C';
}
int main() {
    int n;
    cin >> n;
    if (n == 3) {
        cout << 61 << endl;
        return 0;
    }
    set<string> ref;
    for (int i = 0; i < 4; ++i) {
        char c = itoc(i);
        ref.insert(string("AGC") + c);
        ref.insert(string() + c + "AGC");
        ref.insert(string("ACG") + c);
        ref.insert(string() + c + "ACG");
        ref.insert(string("GAC") + c);
        ref.insert(string() + c + "GAC");
        ref.insert(string("AG") + c + "C");
        ref.insert(string("A") + c + "GC");
    }
    map<string, int> m[2];
    for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) for (int k = 0; k < 4; ++k) {
        m[1][string() + itoc(i) + itoc(j) + itoc(k)] = 1;
    }
    for (int i = 4; i <= n; ++i) {
        m[i%2].clear();
        for (auto &&p: m[(i-1)%2]) {
            for (int j = 0; j < 4; ++j) {
                char c = itoc(j);
                if (ref.count(p.first + c) > 0) continue;
                else {
                    string nstr = p.first.substr(1, 2) + c;
                    m[i%2][nstr] += p.second;
                    m[i%2][nstr] %= MOD;
                }
            }
        }
    }

    int ans = 0;
    for (auto &&p: m[n%2]) {
        ans += p.second;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
	int n,m,i,j;
	cin >> n>>m;
	int matrix[n][m],vector[m],answer[n];

	for(i=0;i<n;i++){
		answer[i]=0;
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin >> matrix[i][j];
		}
	}
	for(i=0;i<m;i++){
		cin>>vector[i];
	}

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			answer[i]+=matrix[i][j]*vector[j];
		}
	}

	for(i=0;i<n;i++)cout <<answer[i]<<endl;



}

Measured memory_bytes: 1200
#define ll long long
#define pb push_back
#define make_pair mp
#define first f
#define second s
#define upper_bound ub
#define lower_bound lb

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;


#define ordered_set tree<pair<ll,ll> , null_type,less<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update>

void solve(){
    ll n,k;cin>>n>>k;
    ll seg[k][2],MOD=998244353;
    for(ll i=0;i<k;i++){
        cin>>seg[i][0]>>seg[i][1];
    }
    ll dp[n+1],ps[n+1];
    memset(dp,0,sizeof(dp));
    memset(ps,0,sizeof(ps));
    dp[1]=1;ps[1]=1;
    for(ll i=2;i<=n;i++){
        for(ll j=0;j<k;j++){
            ll low = i-seg[j][1]-1;
            ll high = i-seg[j][0];
            if(high>=0 && high<i){
                dp[i]+=ps[high];
                dp[i]%=MOD;
            }
            if(low>=0 && low<i){
                dp[i]-=ps[low];
                dp[i]+=MOD;dp[i]%=MOD;
            }
        }
        ps[i]=(dp[i]+ps[i-1])%MOD;
    }
    cout<<dp[n]<<endl;
}

int main ()
{
  ios_base::sync_with_stdio (false);
  cin.tie (NULL);
  ll t;
  //cin>>t;
  t = 1;
  while (t)
    {
      solve();t--;
      //cout<<"end of test case"<<endl;
    }
  return 0;
}


Measured memory_bytes: 6692
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1010;
int n , a[N];

vector<pii> solve(vi&degs) {
  int n = sz(degs);
  vector<pii> res(n);
  if(n == 4) {
    res[0] = mp(0 , 0);
    res[1] = mp(1 , 0);
    res[2] = mp(1 , 1);
    res[3] = mp(0 , 1);
  } else {
    int s = 0;
    rep(i,0,n) if(degs[i] == 90 && degs[(i+1)%n] == 270) {
      s = (i + n - 1) % n;
      break;
    }
    vi ndegs(n - 2);
    int tot = 0;
    ndegs[tot++] = degs[s];
    rep(i,3,n) ndegs[tot++] = degs[(s+i)%n];
    vector<pii> pts = solve(ndegs);
    while(!(pts[0].fi < pts[1].fi && pts[0].se == pts[1].se))
      for(auto&p : pts) p = mp(p.se , -p.fi);
    for(auto&p : pts) p = mp(p.fi * 2 , p.se * 2);
    pts[1].se++;
    pts.insert(pts.begin() + 1 , mp(pts[0].fi + 1 , pts[0].se + 1));
    pts.insert(pts.begin() + 1 , mp(pts[0].fi + 1 , pts[0].se));
    vi X , Y;
    for(auto&p : pts) X.pb(p.fi) , Y.pb(p.se);
    sort(all(X));X.erase(unique(all(X)),X.end());
    sort(all(Y));Y.erase(unique(all(Y)),Y.end());
    for(auto&p : pts) p = mp(lower_bound(all(X),p.fi)-X.begin() ,
        lower_bound(all(Y),p.se)-Y.begin());
    rep(i,0,n) res[(i+s)%n] = pts[i];
  }
  return res;
}

int main(){
  cin >> n;
  int deg = 0;
  rep(i,0,n) {
    cin >> a[i];
    deg += 180 - a[i];
  }
  if(deg != 360) {
    cout << -1 << endl;
    return 0;
  }
  vi degs;
  rep(i,0,n) degs.pb(a[i]);
  vector<pii> pts = solve(degs);
  for(auto p : pts)
    cout << p.fi << " " << p.se << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll inf=1000000000000007;
const ll maxinput=10005;
const ll mod=998244353;
#define mp make_pair
int main()
{
    ll n;cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];

    ll dp[n+5][n+5]; //dp[i][j] is the minimum cost of reducing a[i..j]
    ll pre[n];
    pre[0]=a[0];
    for(int i=1;i<n;i++)
        pre[i]=pre[i-1]+a[i];

    for(ll i=0;i<n+5;i++)
        for(ll j=0;j<n+5;j++)
        {
            dp[i][j]=inf;
            if(i>=j)
                dp[i][j]=0;
        }

    for(ll j=1;j<n;j++)
    {
        for(ll i=0;i<n-j;i++)
        {
            ll l=i;ll r=i+j;
            if(j==1)
            {
                dp[l][r]=a[l]+a[r];
                continue;
            }
            for(ll k=l;k<r;k++)
                dp[l][r]=min(dp[l][r],(dp[l][k]+dp[k+1][r]+(pre[r]-(l>0?pre[l-1]:0))));
        }
    }
    cout<<dp[0][n-1]<<"\n";
}


Measured memory_bytes: 1536
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <vector>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
int n,ans;
int rem[1000005];
bool dead[1000005];
vector<int> v[1000005];
inline int dfs(int dp){
	if(rem[dp]) return rem[dp];
	dead[dp]=1;
	int res=0;
	vector<int> gss;
	for(int i=0;i<v[dp].size();i++){
		if(dead[v[dp][i]]) continue;
		int t=dfs(v[dp][i]);
		gss.push_back(t);
	}
	sort(gss.begin(),gss.end());
	for(int i=0;i<v[dp].size();i++){
		res=max(int(gss[i]+v[dp].size()-i-1),res);
	}
	res++;
	rem[dp]=res;
	return res;
}
int main(){
	ios_base::sync_with_stdio(false);
	int i,j,t;
	cin>>n;
	for(i=2;i<=n;i++){
		cin>>t;
//		if(i==a[i]) exit(41234);
		v[t].push_back(i);
	}
//	if(v[1].size()==0) exit(1);
	cout<<dfs(1)-1<<endl;
//	for(i=1;i<=n;i++) cout<<gs[i]<<" ";
//	cout<<endl;
	return 0;
}

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

int main() {
    ll N, K; cin >> N >> K;
    vector<P> p;
    rep(i, N){
        int a, b; cin >> a >> b;
        p.push_back(make_pair(a, b));
    }
    sort(p.begin(), p.end());

    ll now = 0;
    for (auto f : p){
        int x = f.first;
        int y = f.second;
        now += y;
        if(now >= K){
            cout << x << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 4288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
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...));
}

int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    if (b - a <= 2) {
        cout << k + 1 << endl;
        return 0;
    }
    k -= a - 1;
    a += k / 2 * (b - a);
    a += k % 2;
    cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int arr[1000005];
using namespace std;
int main(){
    int n,a;
    cin>>n;
    int cnt=0;
    for(int i=0;i<n;i++){
    cin>>a;
    while(a%2==0){
    	a/=2;
    	cnt++;
    }
    }
    cout<<cnt;
    
}


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

#define oo 1e9
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)
#define _cos(xxxx) cos(xxxx*acos(-1)/180)
#define _sin(xxxx) sin(xxxx*acos(-1)/180)
#define _tan(xxxx) tan(xxxx*acos(-1)/180)
#define PE cout<<fixed

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;

int pa,vt,par[500009],n,m,u,v,i;
bool ok[500009];
vector<int> g[500009];
deque<pii> q;

void BFS(){
    q.push_back({1,1});
    ok[1]=true;
    while (!q.empty()) {
        pa=q.front().fi;
        vt=q.front().se;
        //cout<<pa<<' '<<vt<<'\n';
        q.pop_front();
        par[vt]=pa;
        for (int ii=0;ii<g[vt].size();ii++) {
            if (!ok[g[vt][ii]]) {
                q.push_back({vt,g[vt][ii]});
                ok[g[vt][ii]]=true;
            }
        }
    }
}

int main(){
    IO;
    cin>>n>>m;
    for (i=1;i<=m;i++) {
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    BFS();
    cout<<"Yes\n";
    for (i=2;i<=n;i++) {
        cout<<par[i]<<'\n';
    }
}

Measured memory_bytes: 20252
<?php
const INPUT_DELIMITER = " ";

// 標準入力
$input = fgets(STDIN);
$inputArray = explode(INPUT_DELIMITER, $input);

$A = $inputArray[0];
$B = $inputArray[1];
$C = $inputArray[2];

$Ans = $C - ($A - $B);

if ($Ans >= 0) {
    echo $Ans;
} else {
    echo 0;
}

Measured memory_bytes: 3828
import java.util.Scanner;
 
class Main{
	public static void main(String[] args){
        	Scanner sc = new Scanner(System.in);
	        int x,y,z;
        	while(true){
            		x = sc.nextInt();
            		y = sc.nextInt();
            		if( x == 0 && y == 0 ){
				 break;
			}
            		z = 0;
            		for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	}
          	System.out.println(z);
        	}
    	}
}

Measured memory_bytes: 19616
from itertools import product
N, M = map(int, input().split())
C = [list(map(int, input().split())) for i in range(N)]

P = product((1, -1), repeat=3)

ans = 0
for x, y, z in P:
    tmp = []
    for a, b, c in C:
        tmp.append(a*x + b*y + c*z)
    tmp.sort(reverse=True)
    ans = max(ans, sum(tmp[:M]))

print(ans)


Measured memory_bytes: 41072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fs ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
	 ll n,h[100001],dp[100001];
	 cin>>n;
	 for(ll i=1;i<=n;i++)
	     cin>>h[i];
	 dp[1]=0;
	 dp[2]=abs(h[1]-h[2]);
	 for(ll i=3;i<=n;i++){
	 	dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
	 	//cout<<i<<" "<<dp[i]<<endl;
	 }
	 cout<<dp[n];
}

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

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

  long long N, M;
  cin >> N >> M;

  cout << (M-2*N >= 0 ? N+(M-N*2)/4 : M/2) << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vl a(n), b(n), c(n-1);
    rep(i, n) {
        cin >> a[i];
        --a[i];
    }
    rep(i, n) cin >> b[i];
    rep(i, n-1) cin >> c[i];
    ll ans = 0LL;
    rep(i, n) {
        ans += b[a[i]];
        if(i > 0 && a[i-1]+1 == a[i]) ans += c[a[i-1]];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
int main(void){
    int r, c, i, j, k;
    int a[MAX][MAX];
    int e = 0,b = 0,d =0;
    scanf("%d %d", &r, &c);
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(i = 0; i < r + 1; i++){
        for(j = 0; j < c + 1; j++){
            if(j < c && i < r){
                e += a[i][j];
                printf("%d", a[i][j]);
                printf(" ");
            }
            else if(j == c && i < r){
                printf("%d\n", e);
                d += e;
                e = 0;
            }
            else if(i == r && j < c){
                for(k = 0; k < r; k++){
                    b += a[k][j];
                }
                printf("%d", b);
                printf(" ");
                b = 0;
            }
            else if(i == r && j == c){
                printf("%d\n", d);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2128
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int W,H,i,j,x,y;
	for(;;){
	cin>>H>>W;
	if(H==0&&W==0){
	break;
	}
	x=H-1;
	y=W-1;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(i==0||i==x||j==0||j==y){
				cout<<"#";
			}
			else{
			cout<<".";
			}
		}
		cout<<endl;
	}
	cout<<endl;
	}
return 0;
}


Measured memory_bytes: 2976
N, K = map(int, input().split())
d = []
A = []
s = [1] * N
for k in range(K):
  d.append(int(input()))
  A.append([int(i) for i in input().split()])
  
for k in range(K):
  for n in range(1, N+1):
    if n in A[k]:
      if s[n-1] == 1:
        s[n-1] = 0
print(sum(s))

Measured memory_bytes: 9196
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };


signed main() {
	int x, a, b;
	
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	cin >> x >> a >> b;
	cout << (x - a) % b;

	return 0;
}


Measured memory_bytes: 256
def resolve():
  a, b, c, d = input()
  for i in range(8):
    q = str(a)
    if (i>>0) & 1:
      q += '+'
    else:
      q += '-'
    q += str(b)
    if (i>>1) & 1:
      q += '+'
    else:
      q += '-'
    q += str(c)
    if (i>>2) & 1:
      q += '+'
    else:
      q += '-'
    q += str(d)

    if eval(q) == 7:
      q += '=7'
      print(q)
      return

  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 3064
N = int(input())
num = []
for _ in range(N + 1):
    num.append(1)
for i in range(2, N + 1):
    cnt = 1
    while cnt * i <= N:
        num[cnt * i] += 1
        cnt += 1
ans = 0
for i in range(1, N + 1):
    ans += num[i] * i
print(ans)


Measured memory_bytes: 224428
n, m = map(int, input().split())
dp = [[] for i in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    dp[p - 1].append([i, y])
for i, p in enumerate(dp):
    p = sorted(p, key=lambda x : x[1])
    dp[i] = p
ans = []
for i, p in enumerate(dp):
    for j, a in enumerate(p):
        s = '{:06}'.format(i + 1) + '{:06}'.format(j + 1)
        ans.append([a[0], s])
ans = sorted(ans)
for i, s in ans:
    print(s)

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

ll calc(ll v) {
  ll ans = 0;
  while (v != 0) {
    ll mask = 1;
    ll cnt = 0;
    while (mask <= v) {
      if (v & mask)
        cnt++;
      mask <<= 1;
    }
    v %= cnt;
    ans++;
  }

  return ans;
}

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

  ll n;
  string s;
  cin >> n >> s;

  reverse(all(s));

  ll pcnt = 0;
  rep(i, n) {
    if (s[i] == '1') {
      pcnt++;
    }
  }

  vvll val(n, vll(3));
  FOR(md, pcnt - 1, pcnt + 2) {
    ll tmp = 1;

    if (md == 0)
      continue;

    rep(i, n) {
      val[i][md - (pcnt - 1)] = tmp;
      tmp *= 2;
      tmp %= md;
    }
  }

  vll sum(3);
  rep(k, 3) {
    rep(i, n) {
      if (s[i] == '1')
        sum[k] += val[i][k];
    }
  }

  vll ans(n);

  rep(i, n) {
    if (s[i] == '0') {
      // 1に変えた時 pcnt+1
      ll s = sum[2] + val[i][2];
      s %= (pcnt + 1);
      ans[i] = calc(s) + 1;
    } else {
      // すでに0
      if (pcnt == 1) {
        ans[i] = 0;
        continue;
      }
      // 1に変えた時 pcnt-1
      ll s = sum[0] - val[i][0];
      s %= (pcnt - 1);
      ans[i] = calc(s) + 1;
    }
  }

  reverse(all(ans));

  for (auto it : ans) {
    cout << it << endl;
  }

  return 0;
}


Measured memory_bytes: 16004
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
  vector<int> v;
  while(1){
    string str;
    cin >> str;
    if(str.size() == 1 && str[0] == '0')break;
    int sum = 0;
    for(int i=0;i<str.size();i++){
      sum += (int)(str[i] - '0');
    }
    v.push_back(sum);
  }
  for(int i=0;i<v.size();i++){
    cout << v[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
// void fill(ll n, ll a[n], ll value){ rep(i,0,n) a[i] = value; }
void cin(ll *n){ scanf("%lld",&(*n)); }
void cin2(ll *a, ll *b){ scanf("%lld%lld",&(*a),&(*b)); }
void cin3(ll *a, ll *b, ll *c){ scanf("%lld%lld%lld",&(*a),&(*b),&(*c)); }
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    ll dp[30+1];
    rep(i,0,30+1) dp[i]=0;
    dp[0]=1;
    dp[1]=1;
    dp[2]=2;
    rep(i,3,30+1){
        dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
    }
    while(1){
        // char ;
        ll n;
        ll ans=0;
        cin(&n);
        if(!n) break; 
        // cin2(&,&);
        // cin3(&,&,&);
        ans = dp[n]%3650==0 ? dp[n]/3650 : dp[n]/3650 +1;
        
        printf("%lld\n",ans);

    }
    // rep(i,0,31) printf("%lld ",dp[i]);
    
    return 0;
}



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

namespace _0576
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int l = ReadInt();
            int a = ReadInt();
            int b = ReadInt();
            int c = ReadInt();
            int d = ReadInt();

            int japanese = a % c == 0 ? a / c : a / c + 1;
            int math =  b % d == 0 ? b / d : b / d + 1;

            Console.WriteLine(l-Math.Max(japanese, math));
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 15868
import heapq
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for i in range(n)]
# 必要な日数の照準にソートする
jobs.sort()
# 次に選ぶバイト候補の保存場所
money = []
ans = 0

i = 0
# より制約の強い、最終リミットに近い日に行うバイトの割当てから攻めていく
for limit in range(1, m + 1):
    # limit日までに報酬のもらえるアルバイトを抽出
    while i < n and jobs[i][0] <= limit:
        a = jobs[i][0]
        b = jobs[i][1]
        # 次に選ぶバイト候補に追加
        heapq.heappush(money, -b)
        i += 1
    # 要素数が空の場合のエラー処理
    if money != []:
        ans -= heapq.heappop(money)

print(ans)


Measured memory_bytes: 20792
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n) {
	return 0;
}


//最小公倍数を返す関数
int mcd(int n) {
	return 0;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1-x2),2) + pow(abs(y1-y2),2));
}


int main()
{
	ll n, k,score;
	cin >> n >> k;
	double ans = 0;
	double kaku;

	int count = 0;
	for (int i = 1;i <= n;++i) {
		kaku = 1.0 / n;
		//cout << "kaku: " << kaku << endl;
		count = 0;
		score = i;
		while (score < k) {
			//cout << "score: " << score << endl;
			score *= 2;
			count++;
		}
		//cout << "pow: " << pow(2, count) << endl;
		kaku /= (double)pow(2, count);
		//cout << "kaku :" << kaku << endl;
		ans += kaku;
	}

	cout << fixed << setprecision(12)<<ans << endl;

	system("pause");
	return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string a;
  cin >> a;
  int num = 0;
  if(a[0] == '1'){num++;}
  if(a[1] == '1'){num++;}
  if(a[2] == '1'){num++;}
  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)
 
int main() {
  int n, p;
  cin >> n;
  vector<pair<string, int>> l(n), maxl(1);
  int ja[n];
  for(int i = 0; i < n; i++) {
    cin >> l.at(i).first >> l.at(i).second;
    l.at(i).second *= -1;
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(l.at(j) >= maxl.at(0)){
        maxl.at(0) = l.at(j);
        ja[i] = j;
      }
    }
    l.at(ja[i]).first = maxl.at(0).first = "Z";
  }
  for(int i = n - 1; i >= 0; i--) cout << ja[i] + 1 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n, i, j, c;
	string s;

	cin >> s;

	n = s.length();
	n -= 1;
	if (n % 2 != 0) {
		n -= 1;
	}

	for (i = n; i >= 2; i -= 2) {
		c = 0;
		for (j = 0; j < i / 2; j++) {
			if (s[j] == s[j + i / 2]) {
				c++;
			}
		}
		if (c == i / 2) {
			break;
		}
	}

	cout << i << endl;

	return 0;
}

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

#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)                                      \
  cout << #v << ":";                                      \
  for (int i = 0; i < v.size(); i++) cout << " " << v[i]; \
  cout << endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int> >
#define vll vector<vector<ll> >
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
  int n, i0, i, j;
  scanf("%d", &n);
  vl x(n);
  for (i0 = 0; i0 < n; i0++) {
    scanf("%lld", &x[i0]);
  }
  ll l;
  int q;
  scanf("%lld", &l);

  vii dp(100, vi(n, inf));
  for (i = 0; i < n; i++) {
    auto itr = lower_bound(x.begin(), x.end(), x[i] + l);
    if (*(itr) == x[i] + l) {
      dp[0][i] = itr - x.begin();
    }
    else {
      dp[0][i] = itr - x.begin() - 1;
    }
  }
  for (i = 0; i < 99; i++) {
    for (j = 0; j < n; j++) {
      if (dp[i][j] == n - 1) {
	dp[i + 1][j] = n - 1;
	continue;
      }
      dp[i + 1][j] = dp[i][dp[i][j]];
    }
    if (dp[i + 1][0] == n - 1) {
      break;
    }
  }
  /*
  for (i = 0; i < 5; i++) {
    for (j = 0; j < n; j++) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  scanf("%d", &q);
  for (i0 = 0; i0 < q; i0++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a > b) {
      swap(a, b);
    }
    a--; b--;
    int now = a;
    ll cnt = 0;
    while (true) {
      //cout << now << " " << cnt << endl;
      for (i = 99; i >= 0; i--) {
	if (dp[i][now] < b) {
	  cnt += pow(2, i);
	  now = dp[i][now];
	  break;
	}
      }
      if (i == -1) {
	cnt++;
	cout << cnt << endl;
	break;
      }
    }
  }
}

/*
9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5
*/


Measured memory_bytes: 40824
#for _ in range(int(input())):
s = input()
q = int(input())
b=0
f,l="",""
for _ in range(q):
    qi = input().split(' ')
    #print(len(qi))
    if(len(qi)==1):
        b=b^1
    else:
        fi = int(qi[1])
        if(fi==1):
            if(b==0):
                f=f+qi[2]
            else:
                l=l+qi[2]
        elif(fi==2):
            if(b==0):
                l=l+qi[2]
            else:
                f=f+qi[2]
s = f[::-1]+s+l
if(b==1):
    s=s[::-1]

print(s)
    
            
    
    

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


#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ll long long


bool compara( int a, int b ) {
	return ('9' + 1) - to_string(a).back() < ('9' + 1) - to_string(b).back();
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    vi dishes(5);
    int t = 0;

    for ( int i = 0; i < 5; i++ ) cin >> dishes[i];

    sort(dishes.begin(), dishes.end(), compara);

	int aux = 0;
	while ( aux < 5 and to_string(dishes[aux]).back() != '0' ) {
		aux++;
	}
	aux--;
	// for ( int i = 0; i < 5; i++ ) cout << dishes[i] << endl;
    for ( int i = 0; i < 5; i++ ) {
    	while ( to_string(t).back() != '0' ) {
    		t++;
    	}
    	if ( i != aux ) {
    		t += dishes[i];
    	}
    }

    cout << t + dishes[aux] << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,s[101];
    std::cin >> n;
    int sum=0,min=101;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sum+=s[i];
        if(min > s[i] && s[i]%10!=0){
            min=s[i];
        }
    }
    if(min==101){
        std::cout << 0 << std::endl;
    }else if(sum%10!=0){
        std::cout << sum << std::endl;
    }else{
        std::cout << sum-min << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){

    int n,m;
    cin>>n>>m;
    int ans = INF;
    vector<vector<int>> v(n,vector<int>(m,0));
    rep(i,n){
        rep(j,m){
            cin>>v[i][j];
        }
    }
    set<int> s;
    while(s.size()!=m){
        map<int,int> ma;
        rep(i,n){
            rep(j,m){
                int k = v[i][j];
                if(s.find(k)==s.end()){
                    ma[k]++;
                    break;
                }
            }
        }


        int maxn = 0;
        int me=0;
        int minn = INF;

        for(auto &a:ma){

           if(maxn<a.second){
               me=a.first;
               maxn=a.second;
           }
        }
        ans = min(ans,maxn);
        s.insert(me);


    }
    cout<<ans<<endl;







return 0;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  vi x(n);
  vi y(n);
  rep(i, n) cin >> x[i] >> y[i];
  vi v(n);
  iota(v.begin(), v.end(), 0);
  double ans = 0.0;
  ll cnt = 0;
  do {
    int cx = x[v[0]];
    int cy = y[v[0]];
    for (int i = 1; i < n; i++) {
      double dx = abs(cx - x[v[i]]);
      double dy = abs(cy - y[v[i]]);
      ans += sqrt(dx * dx + dy * dy);
      cx = x[v[i]];
      cy = y[v[i]];
    }
    cnt++;
  } while (next_permutation(v.begin(), v.end()));
  cout << ans / cnt << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int n; ll a, b;
VL h;

bool check(ll x) {
    ll cnt = 0;
    ll dam = b * x;
    FOR(i, 0, n) {
        if (h[i] <= dam)continue;
        cnt += (h[i] - dam) / (a - b) + bool((h[i] - dam) % (a - b));
    }
    return cnt <= x;
}

int main() {
    init();

    cin >> n >> a >> b;
    h.resize(n); cin >> h;
    ll ng = -1, ok = INF;
    while (ok - ng > 1) {
        ll mid = (ng + ok) / 2;
        if (check(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";
}


Measured memory_bytes: 1024
n=int(input())
ans=0
for i in range(1,n+1):
    i2 = str(i)
    if int(i2[-1])==0:
        pass
    elif int(i2[0]) > int(i2[-1]):
        for j in range(len(i2)-1):
            ans+= (10**j)*2
    elif int(i2[0]) < int(i2[-1]):
        for j in range(len(i2)-2):
            ans+= (10**j)*2
    elif len(i2)>2:
        for j in range(len(i2)-2):
            ans+= (10**j)*2
        ans+=3
        ans+=int(i2[1:-1])*2
    else:
        ans+=len(i2)*2-1
print(ans)

Measured memory_bytes: 9044
#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	bool a = getchar() == 'R', b = getchar() == 'R', c = getchar() == 'R';
	if(a && b && c) puts("3");
	else if((a && b) || (b && c)) puts("2");
	else if(a || b || c) puts("1");
	else puts("0");
	return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int m=0,counter=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')counter++;
        else
        {
            m=max(counter,m);
            counter=0;
        }
    }
    m=max(m,counter);
    cout<<m<<endl;
}


Measured memory_bytes: 256
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;


const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>s;
    cout<<(s[0]=='7'||s[1]=='7'||s[2]=='7'?"Yes":"No")<<endl;

}   aryanc403();
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int M = 1e9+7;
const int INF = 1<<30;

int _;
int a[105];

ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b) {ll s=1;while(b){if(b&1)s=(s*a)%M;b>>=1;a=(a*a)%M;}return s;}


int main()
{
    int n;
    cin>>n;
    if(n<=9) {cout<<n;return 0;}
    priority_queue<ll,vector<ll>,greater<ll> > q;
    for(int i=1;i<=9;i++) q.push(i);
    int cnt = 9;
    while(1)
    {
        ll u = q.top();
        q.pop();
        if(u%10!=0)
        {
            ll t = u*10 + u%10 - 1;
            q.push(t);
            cnt++;
            if(cnt==n) {cout<<t<<endl;return 0;}
        }
        ll t = u*10 + u%10;
        q.push(t);
        cnt++;
        if(cnt==n) {cout<<t<<endl;return 0;}
        if(u%10!=9)
        {
            ll t = u*10 + u%10 + 1;
            q.push(t);
            cnt++;
            if(cnt==n) {cout<<t<<endl;return 0;}
        }
    }
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <math.h>
#include <algorithm>

using namespace std;
int main()
{
    int N, M;
    vector<int> itemlist;
 
    cin >> N >> M;
    itemlist.resize( N );
 
    int total = 0;
    for (auto i = 0; i < N; i++) {
        cin >> itemlist[i];
        total += itemlist[i];
    }
    sort(itemlist.begin(), itemlist.end(), greater<int>());
    int num = ceil((double)total / (double)(4*M));

 
    if (itemlist[M-1] >= num) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
    ll N, X;
    cin >> N >> X;
    
    ll ans = N;
    ll Y = N-X;
    if (X < Y) swap(X, Y);
    while (true) {
        if (X % Y == 0) {
            ans += Y*((X-Y)/Y)*2+Y;
            break;
        }
        ans += Y*2*(X/Y);
        ll Z = X%Y;
        X = Y;
        Y = Z;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll n,h,w;
    cin>>n>>h>>w;
    cout<<(1+n-w)*(1+n-h)<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void) {
  int K;
  int A;
  int B;
  int C;
  scanf("%d", &K);
  scanf("%d", &A);
  scanf("%d", &B);
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      printf("%s\n", "OK");
      return 0;
    }
  }
  printf("%s\n", "NG");
  return 0;
}

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

int k, m, n;
string s = "1122", t = "";
vector<int> v(4);

int main(){
    for (int i = 0; i++ < 6 && cin >> m ;) v[m - 1]++;
    sort(v.begin(), v.end());
    for (int i = 0; i < 4; i++) t = t + to_string(v[i]);
    cout << (s == t ? "YES" : "NO") << endl;
}

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

int N;

int main() {
    cin>>N;
    long ans=0;
    for (int i=1; i<=N; i++) {
        if (i%3==0||i%5==0) continue;
        else ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624