akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 2000
using P = pair<i64, i64>;
i64 dp[MAX_N + 1][MAX_N + 1];

int main() {
    i64 N; cin >> N;
    vector<P> A(N);
    REP(i, N) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.rbegin(), A.rend());
    REP(i, N + 1) REP(j, N + 1) dp[i][j] = 0;

    REP(l, N) {
        REP(r, N) {
            if (l + r == N) break;
            auto f = [](i64 a, i64 orig_i, i64 i) {
                return a * abs(orig_i - i);
            };
            chmax(dp[l + 1][r], dp[l][r] + f(A[l + r].first, A[l + r].second, l));
            chmax(dp[l][r + 1], dp[l][r] + f(A[l + r].first, A[l + r].second, N - 1 - r));
        }
    }

    i64 maxv = 0;
    REP(l, N) chmax(maxv, dp[l][N - l]);
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 34956
#include <iostream>
#include <utility>
#include <queue>
using namespace std;
int INF= 1001001001;
typedef pair<int,int> pp;
int H, W, N;
int A[1001][1001];
pp F[11];
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
int d[1001][1001];

int bfs(int c) {
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) d[i][j] = INF;
    }
    int fx = F[c].first, fy = F[c].second, tx = F[c+1].first, ty = F[c+1].second;
    d[fx][fy] = 0;
    queue<pp> Q;
    Q.push(pp(fx,fy));
    while(!Q.empty()) {
        pp cur = Q.front(); Q.pop();
        int x = cur.first, y = cur.second;
        for(int i=0; i<4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W && A[nx][ny] == 0 && d[nx][ny] == INF) {
                d[nx][ny] = d[x][y] + 1;
                if(nx == tx && ny == ty) return d[nx][ny];
                Q.push(pp(nx,ny));
            }
        }
    }
    return -1;
}

int main() {
    cin >> H >> W >> N;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            char tmp; cin >> tmp;
            switch(tmp) {
                case 'X': {A[i][j] = -1; break;}
                case 'S': {F[0].first = i; F[0].second = j; A[i][j] = 0; break;}
                case '.': {A[i][j] = 0; break;}
                default: {int n = tmp - '0'; F[n].first = i; F[n].second = j; A[i][j] = 0;}
            }
        }
    }
    int res = 0;
    for(int i=0; i<N; i++) res += bfs(i);
    cout << res << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int H, W;
string s[410];
const int dr[4] = {0, 1, 0, -1};
const int dc[4] = {1, 0, -1, 0};

bool vis[410][410];
pair<int,int> dfs(int a, int b) {
  if (vis[a][b]) return {0, 0};
  vis[a][b] = true;
  pair<int, int> res = {0, 0};

  if (s[a][b] == '#') res.first++; else res.second++;
  REP(i, 4) {
    int nr = a + dr[i];
    int nc = b + dc[i];
    if (0 <= nr && nr < H && 0 <= nc && nc < W) {
      if (s[a][b] != s[nr][nc]) {
        auto r = dfs(nr, nc);
        res.first += r.first;
        res.second += r.second;
      }
    }
  }
  return res;
}
int main2() {
  H = nextInt();
  W = nextInt();
  REP(i, H) cin >> s[i];
  CLR(vis, 0);
  ll ans = 0;
  REP(i, H) REP(j, W) {
    if (vis[i][j] == false) {
      auto res = dfs(i, j);
      ans += (ll)res.first * (ll)res.second;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 23168
#include<stdio.h>
#include<string.h>
int main()
{
    int l,i,k=0;
    char A[3];
    gets(A);
    for(i=0;i<3;i++)
    {
        if(A[i]==A[i+1])
        {
            k++;
        }
    }

    if(k>=2)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
    return 0;
}


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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

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

  vector<int> d(n);
  for (int i=1; i<n; i++) {
    d[i] = a[i] - a[i-1];
  }
  d[0] = k - a[n-1] + a[0];

  auto sum = accumulate(d.begin(), d.end(), 0LL);
  auto max = max_element(d.begin(), d.end());
  cout << sum - *max << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    ostringstream os;
    while(1) {
        int m, f, r;
        cin >> m >> f >> r;
        if (m == -1){
            if(f == -1 && r == -1)
                break;
            os << "F" << endl;
            continue;
        }
        if (f == -1){
            os << "F" << endl;
            continue;
        }
        if(m + f >= 80)
            os << "A" << endl;
        else if (m + f >= 65)
            os << "B" << endl;
        else if (m + f >= 50)
            os << "C" << endl;
        else if (m + f >= 30)
            os << ((r < 50) ? "D" : "C") << endl;
        else
            os << "F" << endl;
    }

    cout << os.str();
    return 0;
}

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

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }



int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N);
    for (int i = 0; i < N; ++i) cin >> P[i], --P[i];

    for (int i = 0; i < N; ++i) Q[P[i]] = i;
    for (int i = 0; i < N; ++i) cout << Q[i]+1 << " ";
    cout << endl;
}


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

const int N = 3010;

typedef long long LL;

int mod;

inline int Pow(int x, int y, int mod = mod) {
	int res = 1;
	for (; y; y >>= 1, x = (LL)x * x % mod) if (y & 1) res = (LL)res * x % mod;
	return res; 
}

int S[N][N], C[N][N];

inline void init(int n) {
	S[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++) 
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
	}
	for (int i = 1; i <= n; i++) {
		S[i][1] = 1;
		for (int j = 1; j <= i; j++)
			S[i][j] = (S[i - 1][j - 1] + (LL)S[i - 1][j] * j) % mod;
	}
}

int main() {
	int n, res = 0; cin >> n >> mod, init(n + 1);
	for (int i = 0; i <= n; i++) {
		int other = Pow(2, Pow(2, n - i, mod - 1)), tmp = (LL)C[n][i] * other % mod, base = Pow(2, n - i);
		for (int j = 1, t = base; j <= i; j++) {
			tmp = (tmp + (LL)C[n][i] * t % mod * other % mod * S[i + 1][j + 1]) % mod;
			t = (LL)t * base % mod;
		}
		if (i & 1) res = (res - tmp + mod) % mod;
		else res = (res + tmp) % mod;
	}
	cout << res << endl;
}


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

int main(){

  long double a,sum;

  while(cin>>a){
    sum=a;

    for(int i=2; i<=10; i++){
      if(i%2==0){
	a*=2.0;
	sum += a;
      }
      else{
	a/=3.0;
	sum += a;
      }
    }

    printf("%.8Lf\n",sum);

  }

  return 0;
}

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

vector<string> selection(vector<string> vStr) {
    vector<string> vRet = vStr;
    int mini;
    for (int i = 0; i < vRet.size(); i++) {
        mini = i;
        for (int j = i; j < vRet.size(); j++) {
            if ( (vRet[j])[1] < (vRet[mini])[1] ) mini = j;
        }
        swap(vRet[i], vRet[mini]);
    }
    return vRet;
}

vector<string> bubble(vector<string> vStr) {
    vector<string> vRet = vStr;
    for (int i = 0; i < vRet.size(); i++) {
        for (int j = vRet.size()-1; j >= i+1; j--) {
            if ( (vRet[j])[1] < (vRet[j-1])[1] ) swap(vRet[j], vRet[j-1]);
        }
    }
    return vRet;
}

bool isStable(vector<string> in, vector<string> out) {
    int n = in.size();
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int a = 0; a < n; a++) {
                for (int b = a+1; b < n; b++) {
                    if ( ( (in[i])[1] == (in[j])[1] ) && ( in[i] == out[b] ) && ( in[j] == out[a]) ) return false;
                }
            }
        }
    }
    return true;
}

int main() {
    int n;
    vector<string> vStr;
    vector<string> bubbled;
    vector<string> selected;
    string temp;
//    int stability = 1;
    bool stability_b;
    bool stability_s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        vStr.push_back(temp);
    }
    bubbled = bubble(vStr);
    selected = selection(vStr);

    //Stability check
    stability_b = isStable(vStr, bubbled);
    stability_s = isStable(vStr, selected);

    for (int i = 0; i < n; i++) {
        cout << bubbled[i];
        if (i != n-1) cout << " ";
    }
    cout << endl;
    // Print stability
    if (stability_b) cout << "Stable";
    else cout << "Not stable";
    cout << endl;

    for (int i = 0; i < n; i++) {
        cout << selected[i];
        if (i != n-1) cout << " ";
    }
    cout << endl;
    // Print stability
    if (stability_s) cout << "Stable";
    else cout << "Not stable";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1224
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

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

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    let mut time = 0;
    for i in a..b+1 {
        if i.to_string().chars().rev().collect::<String>() == i.to_string() {
            time+=1;
        }
    }
    println!("{}", time);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

#define N 15
int d[N] = {0, 1, 2, 3, 4, 5 ,6 ,7 ,8 ,9 ,5 ,4 ,3 ,2 ,1};

int main(void){
  int n ;
  cin>>n;
  while(n--){
    int a,b;
    cin>>a>>b;
    if(a<=5 && b < a){
      a = 15 - a;
    }
    while(d[a] != b){
      cout<<d[a]<<" ";
      a = (a + 1) % N; 
    }
    cout<<d[a]<<endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	int a,sum_seven = 0, sum_five = 0,flag = 0; 
	for (int i = 0 ; i < 3;i++) {
		cin >> a;
		if (a == 7)
			sum_seven++;
		if (a == 5)
			sum_five++;
	}
	if (sum_seven == 1){
		if(sum_five == 2){
			flag = 1;
		}
	}
	
	
	if (flag == 1)
		cout <<"YES"<<endl;
	else
		cout <<"NO"<<endl;
		
return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln         PIC X(400).
01 maxlen     PIC 9(10) VALUE 100 COMP.
01 cur        PIC 9(10) VALUE 1 COMP.
01 i          PIC 9(10) VALUE 1 COMP.
01 j          PIC 9(10) COMP.
01 len        PIC 9(10) COMP.
01 ans        PIC 9(10).
01 zs         PIC Z(9)9.
01 x1.
   03 x11 OCCURS 5 INDEXED BY ix.
      05 x    PIC S9(10).

PROCEDURE DIVISION.
  ACCEPT ln.
  MOVE 5 TO maxlen.
  PERFORM maxlen TIMES
    PERFORM VARYING j FROM cur BY 1 UNTIL ln(j:1) = SPACE
    END-PERFORM
    COMPUTE len = j - cur
    MOVE ln(cur:len) TO x(i)
    COMPUTE cur = j + 1
    ADD 1 TO i
  END-PERFORM.
  SET ix TO 1.
  PERFORM UNTIL 5 < ix
    SEARCH x11 VARYING ix
      AT END
        CONTINUE
      WHEN ZERO = x(ix)
        MOVE ix TO ans
        SET ix UP BY 1
    END-SEARCH
  END-PERFORM.
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.


Measured memory_bytes: 3768
#include<iostream>
using namespace std;
int main(){
    long long n,d,x,y,s=0;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        cin>>x>>y;
    	if(x*x+y*y<=d*d)s++;
    }
	cout<<s;
	return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
  
}
ll dp[LIMIT1][2]={0};
int ca[LIMIT1],cb[LIMIT1];
ll type=0;
int tmp(cv *p,cv *q){
  return dp[*(int *)q][type]-dp[*(int *)p][type];
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a;
  
  scanf("%lld",&n);
  tmpInit(ca,100001);
  tmpInit(cb,100001);
  rep(i,n){
    scanf("%d",&a);
    dp[a][i%2]++;
  }
  type=0;
  qsort(ca,100001,sizeof(int),tmp);
  type=1;
  qsort(cb,100001,sizeof(int),tmp);
  if(ca[0]!=cb[0]){
    result = n-dp[ca[0]][0]-dp[cb[0]][1];
  }else{
    result = n-max(dp[ca[0]][0]+dp[cb[1]][1],dp[ca[1]][0]+dp[cb[0]][1]);
  }
  printf("%lld\n",result);
  return 0;
}

Measured memory_bytes: 3836
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
vp po;
vvi _T;
int n,m,w,t;
void dfs(int now,int pre){
	rep(j,n)if((now&1<<j)==0){
		int to=now|1<<j;
		int q;
		if(pre+1)q=-abs(po[pre].first)-abs(po[pre].second)+abs(po[pre].first-po[j].first)+abs(po[pre].second-po[j].second)+abs(po[j].first)+abs(po[j].second);
		else q=2*(abs(po[j].first)+abs(po[j].second));
		_T[j][to]=min(_T[j][to],(pre+1?_T[pre][now]:0)+q);
		dfs(to,j);
	}
}
int main(){
	cin>>n>>m>>w>>t;
	
	map<string,int>ma;//name -> weight value
	vp syo(m);
	rep(i,m){
		string a;
		int b,c;
		cin>>a>>b>>c;
		ma[a]=i;
		syo[i]=pii(b,c);
	}
	vvp in(n);
	po=vp(n);
	rep(i,n){
		int l;
		cin>>l>>po[i].first>>po[i].second;
		vp q(l);
		rep(j,l){
			string s;int b;
			cin>>s>>b;
			q[j]=pii(ma[s],b);
		}
		in[i]=q;
	}
	int N=1<<n;
	vi W(N);
	_T=vvi(n,vi(N,inf));
	loop(i,1,N){
		vi ne(m,inf);
		rep(j,n)if(i&1<<j){
			rep(k,in[j].size()){
				ne[in[j][k].first]=min(ne[in[j][k].first],in[j][k].second);
			}
		}
		rep(j,m)if(ne[j]!=inf)ne[j]=max(0ll,syo[j].second-ne[j]);
		else ne[j]=0;
		vi dp(w+1);
//		rep(j,m)cout<<" "<<ne[j];cout<<endl;
		rep(j,m)rep(k,w+1)if(k+syo[j].first<=w)dp[k+syo[j].first]=max(dp[k+syo[j].first],dp[k]+ne[j]);
//		int ma=0;
//		rep(j,w+1)ma=max(ma,dp[j]);
		W[i]=dp[w];
	}
	dfs(0,-1);
	vi T(N,inf);
	rep(i,N){
		ll mi=inf;
		rep(j,n)mi=min(mi,_T[j][i]);
		T[i]=mi;
	}
//	rep(i,N)cout<<W[i]<<" "<<T[i]<<endl;
	vi dp(t+1);
	loop(i,1,N)rep(j,t+1)if(j+T[i]<=t)dp[j+T[i]]=max(dp[j+T[i]],dp[j]+W[i]);
	cout<<dp[t]<<endl;
}

Measured memory_bytes: 3280
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cumA, cumB = [0], [0]
sa, sb = 0, 0

for a in A:
    sa += a
    cumA.append(sa)
for b in B:
    sb += b
    cumB.append(sb)

ans = 0

for i in range(N, -1, -1):
    a = cumA[i]
    if a > K:
        continue

    b = K - a

    low = 0
    high = M

    while low <= high:
        mid = (low + high) //2
        guess = cumB[mid]
        if guess <= b:
            if mid == M:
                break
            elif cumB[mid+1] > b:
                break

        if guess > b:
            high = mid -1
        else:
            low = mid + 1

    """
    for j in range(M, -1, -1):
        if i + j == ans:
            break
        if a + cumB[j] <= K:
            break
    """
    ans = max(i + mid, ans)   

print(ans)


Measured memory_bytes: 126996
#include <bits/stdc++.h>
#define N 2010
#define ll long long
#define db double
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define Edge(x) for(int i=head[x];i;i=e[i].nxt)
#define lson l,mid,o<<1
#define rson mid+1,r,o<<1|1
#define mset(x,y) memset(x,y,sizeof(y))
#define mcpy(x,y) memcpy(x,y,sizeof(x))
#define p_b push_back
using namespace std;
int a[N],deg[N],head[N],n,cnt;
bool vis[N];
int gcd(int x,int y){
	if(x<y) swap(x,y);
	return x%y?gcd(y,x%y):y;
}
struct abc{
	int id,val;
	bool operator <(const abc &x)const{ return val<x.val; }
};
priority_queue<abc> q;
struct ed{
	int v,nxt;
}e[N*N];
void add(int u,int v){ e[++cnt]=(ed){v,head[u]},head[u]=cnt; }
void dfs(int x,int id){
	vis[id]=1;
	For(i,1,n) if(!vis[i] && gcd(x,a[i])!=1){
		add(id,i),deg[i]++,dfs(a[i],i);
	}
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	For(i,1,n) if(!vis[i]) dfs(a[i],i);
	For(i,1,n) if(!deg[i]) q.push((abc){i,a[i]});
	while(!q.empty()){
		abc x=q.top();q.pop();
		printf("%d ",x.val);
		Edge(x.id){
			int to=e[i].v;
			deg[to]--;
			if(!deg[to]) q.push((abc){to,a[to]}); 
		}
	}
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> exista;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        exista.insert(a[i]);
    }
    sort(a.begin(), a.end());

    cout << a[n - 1] << " ";

    for (int i = 0; i < n - 1; i++)
    {
        if(a[n - 1] - a[i] < a[i])
        {
            a[i] = a[n - 1] - a[i];
        }
    }
    sort(a.begin(), a.end());

    if(!exista.count(a[n - 2]))a[n - 2] = a[n - 1] - a[n - 2];
    cout << a[n - 2] << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define vin vector<long long>
#define vch vector<char>
#define vst vector<string>
#define vbo vector<bool>
#define vvin vector<vin>
#define vvch vector<vch>
#define int long long
#define pin pair<int,int>
#define ppin pair<int,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repf(i,f,n) for(int i=f;i<n;i++)
#define maxel(vec, j) *max_element(vec.begin(), vec.begin()+j)

using namespace std;
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
int vsum(vin v){ return accumulate(v.begin(), v.end(), 0); }
int msum(vvin v){
    int ans = 0;
    rep(i, v.size()){
        ans += vsum(v[i]);
    }
    return ans;
}
const int MOD = 1000000007;
signed main() {
    int N, M;
    cin >> N >> M;
    vector<bool> ok(N+1, true);
    rep(i, M){
        int a;
        cin >> a;
        ok[a] = false;
    }
 
    vin dp(N+1, 0);
    dp[0] = 1;
    repf(i, 1, N+1){
        // 1つ下から
        if(ok[i-1]){
            dp[i] += dp[i-1];
            dp[i] %= MOD;
        }
        // 2つ下から
        if(i > 1 && ok[i-2]){
            dp[i] += dp[i-2];
            dp[i] %= MOD;
        }
    }
    cout << dp[N] << endl;
 
    return 0;
}
/*
 *
 *
6 1
3
 */


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

public class Hello{
    public static void Main(string[] args){
        // 自分の得意な言語で
        // Let's チャレンジ！！
        
        int count = 0;
        var dList = new List<int>();

        var arg1 = System.Console.ReadLine();
        string[] valueNX =arg1.Split(' ');
        
        var arg2 = System.Console.ReadLine();
        string[] valueL =arg2.Split(' ');
        
        
        for(int i=0; i<=Int32.Parse(valueNX[0]); i++){
            
            if(i == 0){
                dList.Add(0);
            }else{
                dList.Add(dList[i-1] + Int32.Parse(valueL[i-1]));
            }
            
            if(dList[i] < Int32.Parse(valueNX[1]) + 1){
                
                count = count +1;

            }
        }
        
        System.Console.WriteLine(count);
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string S,T,U;
ll K;
ll n;
ll N[101];
ll ans;
ll M;
ll dp[101][101];
ll cnt;
ll cntt;
ll A,B,C,D;
 
 
 
int main(){
    cin >> A >> B >> C >> D;
    
    cnt = (C+B-1)/B;
    cntt = (A+D-1)/D;
    if(cnt<=cntt){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
    
}
 
 


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define INF 10000
using namespace std;

set<int> dp[31][50];
vector<int> list[50];
int n;


int main(){
	while(cin >> n,n){
		for(int i=0;i<50;i++)
			while(list[i].size())
				list[i].pop_back();

		for(int i=0;i<=30;i++)
			for(int j=0;j<50;j++)
				dp[i][j].clear();

		for(int i=0;i<n;i++)
			dp[0][i].insert(i);

		for(int i=0;i<n;i++){
			int m; cin >> m;
			for(int j=0;j<m;j++){
				int tmp; cin >> tmp;
				list[i].push_back(tmp);
			}
		}
		for(int i=0;i<n;i++)
			sort(list[i].begin(),list[i].end());
		for(int i=1;i<=30;i++){
			vector<int> con;
			for(int j=0;j<n;j++)
				if(binary_search(list[j].begin(),list[j].end(),i))
					con.push_back(j);
			for(int j=0;j<n;j++)
				dp[i][j].insert(dp[i-1][j].begin(),dp[i-1][j].end());
			for(int j=0;j<con.size();j++)
				for(int k=0;k<con.size();k++)
					dp[i][con[j]].insert(dp[i-1][con[k]].begin(),dp[i-1][con[k]].end());
		}
		int ans=INF;
		for(int i=1;i<=30;i++){
			for(int j=0;j<n;j++)
				if(dp[i][j].size()==n)
					ans=min(ans,i);
		}
		if(ans==INF) ans=-1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4680
R, G, B, N = map(int, input().split())
num = 0
for i in range(N + 1):
    if N - R * i < 0:
        break
    for j in range(N + 1):
        if N - R * i - G * j < 0:
            break
        if 0 <= N - R * i - G * j and (N - R * i - G * j) % B == 0:
            num += 1

print(num)

Measured memory_bytes: 40688
using System;
  namespace test
  {
    class program
    {
        static void Main()
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] num = new int[3];
            num[0] = int.Parse(str[0]);
            num[1]= int.Parse(str[1]);
            num[2] = int.Parse(str[2]);
            //Array????????????Sort??????????????§????????????
            Array.Sort(num);
            Console.WriteLine(num[0] + " " + num[1] + " " + num[2]);
        }
    }
}

Measured memory_bytes: 9344
N = gets.to_i
as = N.times.map{gets.to_i}.sort

if N%2 == 0
    ans = 0
    (0..(N/2-2)).each do |i|
        ans -= as[i]*2
    end
    ans += as[N/2] - as[N/2-1]
    ((N/2+1)...N).each do |i|
        ans += as[i]*2
    end
    puts ans
else
    ans1 = 0
    (0..(N/2-1)).each do |i|
        ans1 -= as[i]*2
    end
    ans1 += as[N/2] + as[N/2+1]
    ((N/2+2)...N).each do |i|
        ans1 += as[i]*2
    end

    ans2 = 0
    (0..(N/2-2)).each do |i|
        ans2 -= as[i]*2
    end
    ans2 -= as[N/2-1] + as[N/2]
    ((N/2+1)...N).each do |i|
        ans2 += as[i]*2
    end

    puts [ans1, ans2].max
end

Measured memory_bytes: 6704
n = int(input())
ans = 0
keta = 1
if(n // 10 == 0):
    ans = n
else:
    ans += 9
    for i in range(2, 5, 2):
        now = n // (10 ** i)
        if now < 10 and now > 0:
            ans += (now - 1) * 10 ** i + n % 10 ** i + 1
        if now >= 10:
            ans += 10 ** i * 9
print(ans)


Measured memory_bytes: 38496
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define input(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int n, m, r, visit[10], a, b, c, d[205][205], ans = INF, cnt;
signed main() {
	cin >> n >> m >> r;
	rep(i, r)cin >> visit[i], visit[i]--;
	sort(visit, visit + r);
	rep(i, n)rep(j, n)d[i][j] = INF;
	rep(i, m) {
		cin >> a >> b >> c;
		d[a - 1][b - 1] = c;
		d[b - 1][a - 1] = c;
	}
	rep(k, n)rep(i, n)rep(j, n)d[i][j] = min(d[i][j], d[i][k] + d[j][k]);
	do {
		cnt = 0;
		rep(i, r - 1)cnt += d[visit[i]][visit[i + 1]];
		ans = min(ans, cnt);
	} while (next_permutation(visit, visit + r));
	cout << ans << endl;
	endre;
}

Measured memory_bytes: 512
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  rep(dataIndex, n) {
    cout << "Data " << dataIndex + 1 << ':' << endl;
    vs v(8);
    rep(i, v.size()) cin >> v[i];
    int sx, sy;
    cin >> sx >> sy;
    --sx, --sy;
    v[sy][sx] = '1';
    queue<pii> q;
    q.emplace(sx, sy);
    while (q.size()) {
      int x, y;
      tie(x, y) = q.front();
      q.pop();
      if (x < 0 || y < 0 || x >= 8 || y >= 8 || v[y][x] == '0') continue;
      v[y][x] = '0';
      vi dx = {-3, -2, -1, 1, 2, 3, 0, 0, 0, 0, 0, 0}, dy = {0, 0, 0, 0, 0, 0, -3, -2, -1, 1, 2, 3};
      rep(i, dx.size()) q.emplace(x + dx[i], y + dy[i]);
    }
    for (auto &x : v) cout << x << endl;
  }
}

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

int main() {
  int A,B;
  cin >> A;
  cin >> B;
  
  string chk = "000" ;
  
  if(A == 1){
    chk = "100";
  }
  else if( A == 2){
    chk = "010";
  }
  else{
    chk = "001";
  }
  
  if(B == 1){
    chk.at(0) = '1';
  }
  else if( B == 2){
    chk.at(1) = '1';
  }
  else{
    chk.at(2) = '1';
  }


  int res;
  
  if(chk.at(0) == '0'){
    res = 1;
  }
  else if( chk.at(1) == '0'){
    res = 2;
  }
  else{
    res = 3;
  }
  
    cout << res << endl;

}





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

int n, k;
int cnt;
bool f[101010];

int main()
{
  while (cin >> n >> k, n){
    memset(f, false, sizeof(f));
    cnt = 0;

    for (int i = 0; i < k; i++){
      int x;
      cin >> x;
      if (x--) f[x] = true;
      else cnt++;
    }

    int max_d = -1;
    queue<int> q;

    int l = 0, r = 0;
    while (q.size() <= cnt){
      while (f[r]){
        r++;
        if (r + 1 == n) break;
      }
      q.push(r);

      max_d = max(max_d, r - l);
      r++;
      if (r >= n) break;
      if (q.size() == cnt + 1){
        l = q.front(); q.pop();
      }
    }

    cout << max_d - 1 << endl;
  }
}

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

using namespace std;

typedef long long ll;

const int maxn=1e6+5,mod=1e9+7;
const double pi=acos(-1);

int main()
{
    int n,k;
    cin>>n>>k;
    int a[1005];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++)
        sum+=a[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define gcu getchar_unlocked
#define pc(x) putchar(x);
#define pcu(x) putchar_unlocked(x);
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll gcd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

void readint(ll &x)
    {
        bool neg=false;
        ll c;
        x =0;
        c=gc();
        if(c=='-')
        {
            neg = true;
            c=gc();
        }
        for(;(c>47 && c<58);c=gc())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    }

inline void writeInt (ll n)
{
    ll N = n, rev, count = 0;
    rev = N;
    if (N == 0) { pc('0'); pc('\n'); return ;}
    if (N*(-1)>0){pc('-');rev=rev*(-1);N=N*(-1);}
    while ((rev % 10) == 0) { count++; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;}
    while (count--) pc('0');
}
int main()
{
  SPEED;
  char s[4];
  cin>>s;
  if(((s[2]=='1'&&(s[3]=='0'||s[3]=='1'||s[3]=='2'))||(s[2]=='0'&&(s[3]>='1'&&s[3]<='9')))&&((s[0]=='1'&&(s[1]=='0'||s[1]=='1'||s[1]=='2'))||(s[0]=='0'&&(s[1]>='1'&&s[1]<='9'))))
    cout<<"AMBIGUOUS"<<"\n";
  else if((s[2]=='1'&&(s[3]=='0'||s[3]=='1'||s[3]=='2'))||(s[2]=='0'&&(s[3]>='1'&&s[3]<='9')))
    cout<<"YYMM"<<"\n";
  else if((s[0]=='1'&&(s[1]=='0'||s[1]=='1'||s[1]=='2'))||(s[0]=='0'&&(s[1]>='1'&&s[1]<='9')))
    cout<<"MMYY"<<"\n";
  else
    cout<<"NA"<<"\n";
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pradyumn
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            for (long i = 1; i <= 100000L; ++i) {
                if (i * i > n) {
                    out.println((i - 1) * (i - 1));
                    return;
                }
            }
            throw new RuntimeException();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        private static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,P; cin>>N>>P;
    bool odd=0;
    REP(i,N){
        int a; cin>>a;
        if(a%2==1) odd=1;
    }
    if(!odd){
        if(P==0) cout<<(1LL<<N)<<endl;
        else cout<<0<<endl;
    }
    else cout<<(1LL<<(N-1))<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200000+5;
struct point{
	long double x,y;
	point(){}
	point(long double _x,long double _y){
		x=_x;y=_y;
	}
	point operator -(const point &b) const{
		return point(x-b.x,y-b.y);
	}
	double operator *(const point &b) const{
		return x*b.y-y*b.x;
	}
};
long double a[N],b[N],A[N],B[N],c[N],ans;
bool check(int i,int j,int k){
	return (point(j,a[j])-point(i,a[i]))*(point(k,a[k])-point(i,a[i]))>=0;
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>A[i];
	for(int i=1;i<=n;++i)
		cin>>B[i];
	int pos=max_element(A+1,A+n+1)-A;
	for(int i=pos;i<=n;++i)
		a[i-pos]=A[i],b[i-pos]=B[i];
	for(int i=1;i<=pos;++i)
		a[n-pos+i]=A[i],b[n-pos+i]=B[i]; 
	for(int i=2;i<=n;++i)
		c[i]=2*(c[i-1]+b[i-1])-c[i-2],ans+=c[i],a[i]-=c[i];
	vector<int> vec;vec.push_back(0);
	for(int i=1;i<=n;++i){
		while(vec.size()>1 && check(vec[vec.size()-2],vec[vec.size()-1],i)) vec.pop_back();
		vec.push_back(i);
	}	
	for(int i=0;i<vec.size()-1;++i){
		int l=vec[i],r=vec[i+1];
		for(int j=l+1;j<r;++j)
			ans+=1.0L*((j-l)*a[r]+(r-j)*a[l])/(r-l);
		ans+=a[r];
	}
	printf("%.12Lf",ans/n);
	return 0;
}

Measured memory_bytes: 19888
#include "bits/stdc++.h"

using namespace std;

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

	vector<int>A(N), B(N), C(N);
	vector<int>D(M), E(M), F(M);

	std::set<int>x_org = {0};
	std::set<int>y_org = {0};

	struct pair3 {
		int a, b, c;
		pair3(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
	};
	std::vector<pair3>Xpair;//N ko
	std::vector<pair3>Ypair;//M ko


	for (int n = 0; n < N ; ++n) {
		cin >> A[n]>> B[n]>>C[n];
		Xpair.emplace_back(A[n], B[n], C[n]);
		x_org.insert(A[n]); 
		x_org.insert(B[n]); 
		y_org.insert(C[n]);
	}

	for (int m = 0; m < M ; ++m) {
		cin >> D[m] >> E[m] >> F[m]; 
		Ypair.emplace_back(D[m], E[m], F[m]);
		x_org.insert(D[m]);
		y_org.insert(E[m]);
		y_org.insert(F[m]); 
	}

	vector<int>X, Y;//縮小から元
	std::map<int, int>mx;//元から縮小
	std::map<int, int>my;//元から縮小
	for (auto itr = x_org.begin(); itr != x_org.end(); ++itr) {
		mx[*itr] = X.size();
		X.push_back(*itr);
	}

	for (auto itr = y_org.begin(); itr != y_org.end(); ++itr) {
		my[*itr] = Y.size();
		Y.push_back(*itr);
	}
	int x = 2 * X.size() + 1;
	int y = 2 * Y.size() + 1;

	vector<vector<int>>XY(x,vector<int>(y));//all 0
	
	for (int n = 0 ;n < (int)Xpair.size() ; ++n) {
		for (int m = mx[Xpair[n].a] * 2 + 1; m <= mx[Xpair[n].b] * 2 + 1;++m) {
			XY[m][my[Xpair[n].c]*2+1] = -1;
		}
	}

	for (int n = 0; n < (int)Ypair.size(); ++n) {
		for (int m = my[Ypair[n].b] * 2 + 1; m <= my[Ypair[n].c] * 2 + 1; ++m) {
			XY[mx[Ypair[n].a] * 2 + 1][m] = -1;
		}
	}


	queue<pair<int,int>> q; 
	XY[mx[0] * 2 + 1][my[0] * 2 + 1] = 1;
	q.emplace(mx[0] * 2 + 1, my[0] * 2 + 1);
	while (!q.empty()) {
		int x0 = q.front().first; 
		int y0 = q.front().second;
		q.pop();
		//範囲内かつ0を4セット
		{
			int x1 = x0 + 1;
			int y1 = y0;
			if ((0 <= x1) && (x > x1) && (0 <= y1)&&(y > y1)&&(0 == XY[x1][y1])) {
				XY[x1][y1] = 1;
				q.emplace(x1,y1);
			}
		}
		{
			int x1 = x0 - 1;
			int y1 = y0;
			if ((0 <= x1) && (x > x1) && (0 <= y1) && (y > y1) && (0 == XY[x1][y1])) {
				XY[x1][y1] = 1;
				q.emplace(x1, y1);
			}
		} 
		{
			int x1 = x0;
			int y1 = y0 +1;
			if ((0 <= x1) && (x > x1) && (0 <= y1) && (y > y1) && (0 == XY[x1][y1])) {
				XY[x1][y1] = 1;
				q.emplace(x1, y1);
			}
		} 
		{
			int x1 = x0;
			int y1 = y0 - 1;
			if ((0 <= x1) && (x > x1) && (0 <= y1) && (y > y1) && (0 == XY[x1][y1])) {
				XY[x1][y1] = 1;
				q.emplace(x1, y1);
			}
		}
	}

	long long nAns = 0;
	for (int a = 0;a <= (int)X.size();++a ) {//どっちかが奇数out
		for (int b = 0; b <= (int)Y.size(); ++b) {
			if (1 != XY[2*a][2*b]) {
				continue;
			}
			if ((a == 0) || (a == (int)X.size()) || (b == 0) || (b == (int)Y.size())) {
				cout << "INF" << endl;
				return 0;
			}
			long long a1 = (X[a] - X[a - 1]);
			long long a2 = (Y[b] - Y[b - 1]);
			nAns += a1 * a2;
		}
	}
	cout << nAns << endl;
	return 0;
}

Measured memory_bytes: 145024
import static java.util.Arrays.deepToString;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			int n = sc.nextInt(); sc.nextLine();
			if (n == 0) break;
			
			Map<String, Integer> count = new HashMap<String, Integer>();
			
			for (int i = 0; i < n; i++) {
				String[] words = sc.nextLine().split(" ");
				for (String w : words) {
					Integer k = count.get(w);
					if (k == null) { k = 0; }
					k++;
					count.put(w, k);
				}
			}
			char c = sc.next().charAt(0);
			
			ArrayList<P> ps = new ArrayList<P>();
			for (String w : count.keySet()) {
				if (w.charAt(0) == c) {
					P p = new P();
					p.w = w;
					p.count = count.get(w);
					ps.add(p);
				}
			}
			Collections.sort(ps);
			
			if (ps.size() == 0) {
				System.out.println("NA");
			} else {
				System.out.print(ps.get(0).w);
				for (int i = 1; i < Math.min(ps.size(), 5); i++) {
					System.out.print(" " + ps.get(i).w);
				}
				System.out.println();
			}
		}
	}
	
	class P implements Comparable<P> {
		int count;
		String w;
		@Override
		public int compareTo(P o) {
			if (count != o.count) return -count + o.count;
			return w.compareTo(o.w);
		}
	}
}

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

using namespace std;

int main()
{
	long long n,k;
	scanf("%lld %lld",&n,&k);
	long long ans = 0;
	for(long long b = k+1; b <= n; b++)
	{
		long long q = n/b;
//		cout << b << ' ' << b-k << endl;
		ans += (b-k)*q;
		if(k == 0)
			ans--;
		ans += max(0LL,n-(b*q+k)+1);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
void main() {
	auto S = rs.map!(i => i == '0').array;
	auto k = S.length;
	ulong cnt;
	while(true) {
		bool flag = false;
		if(S.length <= 1) break;
		foreach(i; 0..S.length-1) {
			if(S[i] != S[i+1]) {
				cnt++;
				flag = true;
				S = S[0..i] ~ S[i+2..$];
				break;
			}
		}
		if(!flag) break;
	}
	writeln(cnt*2);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MOD = 1e9+7;

int main(){
    int N;cin >> N;
    vector<vector<int>> vec;
    for(int i = 0;i < N;i++){
        vector<int> w;
        for(int j = 0;j < N;j++){
            int b;cin >> b;
            w.push_back(b);
        }
        vec.push_back(w);
    }
    vector<int> dp(1 << N,-1);
    function<int(int)> calc = [&](int flag) -> int{
        if(dp[flag] != -1)return dp[flag];
        if(flag == (1 << N)-1)return dp[flag] = 1;
        int cnt = __builtin_popcount(flag);
        int ins = 0;
        for(int i = 0;i < N;i++){
            if(!(flag&(1<<i)) && vec.at(cnt).at(i)){
                ins += calc(flag | (1<<i));
                ins %= MOD;
            }
        }
        return dp[flag] = ins%MOD;
    };
    cout<<calc(0)%MOD<<endl;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;


ll N,K;
ll A[100010],B[100010];

ll F(ll x){
    ll cnt = 0;
    rep(i,N){
        ll d = x - A[i];
        if(d < 0) continue;
        cnt += (d + B[i] - 1) / B[i];
    }
    return cnt;
}

int main(){
    cin >> N >> K;
    rep(i,N) cin >> A[i] >> B[i];
    ll l = 0,r = 2000000000000000010;
    while(r-l > 1){
        ll mid = (l+r) / 2;
        if(F(mid) >= K) r = mid;
        else l = mid;
    }
    cout << r - 1 << endl;
}


Measured memory_bytes: 1792
s = input()
x = 0
y = 0
s = list(set(s))
for i in range(len(s)):
    if s[i] == 'N':
        y += 1
    elif s[i] == 'W':
        x -= 1
    elif s[i] == 'S':
        y -= 1
    else:
        x += 1
print('Yes' if x == 0 and y == 0 else 'No')


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
const int M = 100000;
const double pi = 3.141592653589;

int main(){
	int r, c;
	int a[1000][1000] = { 0 };
	cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int k = 0; k < c; k++) {
			cin >> a[i][k];
		}
	}
	for (int i = 0; i < r; i++) {
		for (int k = 0; k < c; k++) {
			a[i][c] += a[i][k];
		}
	}
	for (int i = 0; i <= c; i++) {
		for (int k = 0; k < r; k++) {
			a[r][i] += a[k][i];
		}
	}

	for (int i = 0; i <= r; i++) {
		for (int k = 0; k <= c; k++) {
			cout << a[i][k];
			if (k == c)cout << endl;
			else cout << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 6992