akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <random>
#include <string>
#include <stack>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

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

  int N, a[2][101];

  cin >> N;

  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> a[i][j];
    }
  }

  int ans = 0;

  for (int i = 0; i < N; ++i) {
    int idx = 0, tmp = 0;

    for (int j = 0; j < N; ++j) {
      tmp += a[idx][j];
      if (i == j) {
        idx++;
        tmp += a[idx][j];
      }
    }

    ans = std::max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main (void) {
	int n; cin >> n;
	vector <int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	long long op = 0;
	long long prev_sum = 0;
 
	for (int i = 0; i < n; i++) {
		long long new_sum = prev_sum + v[i];
		if (i == 0 && v[i] != 0)
			prev_sum = new_sum;
		else if (i == 0 && v[i] == 0) {
			op += 1;
			prev_sum = 1;
		}
		else if (prev_sum >= 0 && new_sum >= 0) {
			op += new_sum + 1;
			prev_sum = -1;
		}
		else if (prev_sum <= 0 && new_sum <= 0) {
			op += -new_sum + 1;
			prev_sum = 1;
		}
		else
			prev_sum = new_sum;
	}
	prev_sum = 0;
	long long op2 = 0;
	for (int i = 0; i < n; i++) {
		long long new_sum = prev_sum + v[i];
		if (i == 0 && v[i] != 0)
			prev_sum = new_sum;
		else if (i == 0 && v[i] == 0) {
			op2 += 1;
			prev_sum = -1;
		}
		else if (prev_sum >= 0 && new_sum >= 0) {
			op2 += new_sum + 1;
			prev_sum = -1;
		}
		else if (prev_sum <= 0 && new_sum <= 0) {
			op2 += -new_sum + 1;
			prev_sum = 1;
		}
		else
			prev_sum = new_sum;
	}
	prev_sum = 0;
	long long op3 = 0;
	
	for (int i = 0; i < n; i++) {
		long long new_sum = prev_sum + v[i];
		if (i == 0 && v[i] > 0) {
			op3 += new_sum + 1;
			prev_sum = -1;
		}
		
		else if (prev_sum >= 0 && new_sum >= 0) {
			op3 += new_sum + 1;
			prev_sum = -1;
		}
		else if (prev_sum <= 0 && new_sum <= 0) {
			op3 += -new_sum + 1;
			prev_sum = 1;
		}
		else
			prev_sum = new_sum;
	}
	prev_sum = 0;
	long long op4 = 0;
	for (int i = 0; i < n; i++) {
		long long new_sum = prev_sum + v[i];
		if (i == 0 && v[i] < 0) {
			op4 += -new_sum + 1;
			prev_sum = 1;
		}
		
		else if (prev_sum >= 0 && new_sum >= 0) {
			op4 += new_sum + 1;
			prev_sum = -1;
		}
		else if (prev_sum <= 0 && new_sum <= 0) {
			op4 += -new_sum + 1;
			prev_sum = 1;
		}
		else
			prev_sum = new_sum;
	}
	long long a = min (op2, op3);
	
	cout << min(op, min(op4,a)) << endl;
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	s := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		fmt.Scan(&s[i])
		sum += s[i]
	}
	if sum%10 == 0 {
		sort.Ints(s)
		for i, v := range s {
			if v%10 != 0 {
				fmt.Println(sum - v)
				break
			}
			if i == N-1 {
				fmt.Println(0)
			}
		}
	} else {
		fmt.Println(sum)
	}

}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
            int x = sc.nextInt();
            String ans = "Yes";
            if (x <  30) {
            	ans = "No";
            }

            System.out.println(ans);

		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}


Measured memory_bytes: 35756
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int n=0;
		for (String ss:s.split("")){
			if (ss.equals("a")){
				n+=1;
			}
			if (ss.equals("b")){
				n+=10;
			}
			if (ss.equals("c")){
				n+=100;
			}
		}
		if (n==111){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i, l, r) for (ll i = (l); i < (r); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
int upll(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); }

char s[210];
char t[110];
int main()
{
  scanf("%s%s", s, t);
  ll n = strlen(s);
  rep(i, 0, n)
  {
    if (!strcmp(s + i, t))
    {
      puts("Yes");
      return 0;
    }
    s[n + i] = s[i];
  }
  puts("No");
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

//x^n mod
ll mod_pow(ll x, ll n, ll mod) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 1) { //奇数
        return mod_pow(x, n - 1, mod) * x % mod; //偶数の再帰にできるように変形
    } else { //偶数
        ll t = mod_pow(x, n / 2, mod); //半分のものを求めて、2乗する
        return t * t % mod;
    }
}

int main() {

    ll n; cin >> n;
    string x; cin >> x;

    vector<ll> f(10000000, 0);
    for (ll i = 1; i < 10000000; ++i) {
        ll popcount = __builtin_popcountll(i);

        if (i % popcount == 0) {
            f[i] = 1;
        } else {
            f[i] += f[i % popcount] + 1;
        }
    }

    ll popcount = 0;
    for (ll i = 0; i < n; ++i) {
        if (x[i] == '1') {
            popcount++;
        }
    }

    // 1回目のmod計算
    ll n_mod_plus = 0;
    ll n_mod_minus = 0;
    for (int i = 0; i < n; ++i) {
        if (x[n - i - 1] == '1') {
            n_mod_plus += mod_pow(2, i, popcount + 1);
            n_mod_plus %= popcount + 1;
            if (popcount >= 2) {
                n_mod_minus += mod_pow(2, i, popcount - 1);
                n_mod_minus %= popcount - 1;
            }
        }
    }

    vector<ll> ans;
    for (ll i = 0; i < n; ++i) {
        ll n_mod_plus_tmp = n_mod_plus;
        ll n_mod_minus_tmp = n_mod_minus;
        if (x[n - i - 1] == '0') {
            n_mod_plus_tmp += popcount + 1;
            n_mod_plus_tmp += mod_pow(2, i, popcount + 1);
            n_mod_plus_tmp %= popcount + 1;
            ans.push_back(f[n_mod_plus_tmp] + 1);
        } else {
            if (popcount == 1) {
                ans.push_back(0);
            } else {
                n_mod_minus_tmp += popcount - 1;
                n_mod_minus_tmp -= mod_pow(2, i, popcount - 1);
                n_mod_minus_tmp %= popcount - 1;
                ans.push_back(f[n_mod_minus_tmp] + 1);
            }
        }
    }

    reverse(ans.begin(), ans.end());

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

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a >= 13) cout << b << endl;
    else if(5 >= a) cout << 0 << endl;
    else cout << b/2 << endl;
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<int> A(N); REP(i, N) cin >> A[i];
  int left = 0, prev_r = 0, right = 0, now = 0;
  ll ans = 0;
  while (left < N) {
    while(right < N and (A[right] ^ now) == A[right] + now) {
      now ^= A[right];
      right++;
    }
    //cout << left << ' ' << right << ' ' << (ll)(right - left) * (ll)(right - left - 1) / 2 << endl;
    ans += (ll)(right - left) * (ll)(right - left - 1) / 2 - (ll)max(0, prev_r - left) * (ll)max(0, prev_r - left - 1) / 2;
    prev_r = right;
    if (right == N) break;
    while ((A[right] ^ now) != A[right] + now) {
      now ^= A[left];
      left++;
    }
  }
  cout << ans + N << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  cout<<max({(n-1)/a,(n-1)/b,(n-1)/c,(n-1)/d,(n-1)/e})+5;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

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


int main()
{
    int N;
    cin >> N;
    vector<int> vt[N];
    vector<P> pairs;
    vector<bool> ok(N, false);
    for(int i=0; i<N-1; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        pairs.push_back(P(a,b));
        vt[a].push_back(b);
        vt[b].push_back(a);
    }
    queue<int> que;
    map<P,int> cls;
    vector<int> pre_color(N, 0);
    que.push(0);
    ok[0]=1;
    int K=0;
    while(que.size()>0){
        int now=que.front(); que.pop();
        K=max(K, (int)vt[now].size());
        int color=1;
        for(auto nx: vt[now]){
            if(ok[nx]) continue;
            if(pre_color[now]==color) color++;
            cls[P(now, nx)]=color;
            cls[P(nx, now)]=color;
            pre_color[nx]=color;
            color++;
            que.push(nx);
            ok[nx]=1;
        }
    }

    cout << K << endl;
    for(auto p: pairs){
        cout << cls[p] << endl;
    }



    return 0;
}

Measured memory_bytes: 19700
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,k;cin>>n>>k;
	vector<double> p(n+1);
	p[0] = 0.0;
	rep(i, n){
		double tmp;cin>>tmp;
		p[i+1] = p[i]+(tmp+1)/2;
		debug("%d %d\n", i+1, p[i+1]);
	}
	double ans = 0;
	rep(i, n-k+1){
		chmax(ans, p[k-1+i+1]-p[i]);
		debug("%d %d\n", i, p[k-1+i+1]-p[i]);
	}
	printf("%.8f\n", ans);
	return 0;
}


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

int main() {
    string s1, s2, s3;
    int shift = 'A' - 'a';
    char c1, c2, c3;    
    cin >> s1 >> s2 >> s3;

    c1 = s1[0] + shift;
    c2 = s2[0] + shift;
    c3 = s3[0] + shift;
    cout << c1 << c2 << c3 << endl;

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

#define UNK 1000000
#define CAL 1000001
#define IMP 1000002

int memo[2][101];
int kabe[2][101];
int n;

int solve(int a, int b){
  if(b >= n - 1){
    if(kabe[a][b] == 2)
      return IMP;
    else
      return 0;
  }

  if(memo[a][b] <  UNK) return memo[a][b];
  if(memo[a][b] == IMP) return IMP;
  if(memo[a][b] == CAL) return IMP;
  
  //printf("%d,%d\n", a, b);

  int ret = IMP;
  memo[a][b] = CAL;

  if(kabe[a][b] == 0 || (kabe[a][b] == 1 && kabe[a][b+1] != 1)){
    int next = (a ^ 1);
    ret = min(ret, 1 + solve(next, b));
    ret = min(ret, 1 + solve(next, b + 1));
    ret = min(ret, 1 + solve(next, b + 2));
  }else if(kabe[a][b] == 1){
    ret = min(ret, solve(a, b + 1));
  }else{
    ret = min(ret, solve(a, b - 1));
  }

  //printf("solve(%d,%d): %d\n", a, b, ret);

  return memo[a][b] = ret;
}

int main(){
  while(n = getInt()){
    REP(i,n) kabe[0][i] = getInt();
    REP(i,n) kabe[1][i] = getInt();

    REP(i,2) REP(j,n) memo[i][j] = UNK;

    int ans = min(solve(0,0), solve(1,0));

    if(ans == IMP) puts("NA");
    else print(ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
// #define int long long
#define Matrix vector<vector<int> >
// #define Matrix vector<vector<int> >
#define double long double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9+7;
const long long INF = 5e18;
const double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
 
inline long long mod(long long n, long long m){
    long long ret = n%m;
    if(ret < 0) ret += m;
    return ret;
}
 
double rad(double x){
    return x*pi/180.0;
}
 
bool isleft(pair<int,int> a, pair<int,int> b, pair<int,int> c){
    int det = (b.first-a.first)*(c.second-a.second) - (c.first-a.first)*(b.second-a.second);
    if(det>=0) return true;
    if(det<0) return false;
    return false;
}
 
int exp(int a, int b){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = mod(result*a,MOD);
 
        b >>= 1;
        a = mod(a*a,MOD);
    }
    return result;
}

void solve(){
	int n,k;
	cin>>n>>k;
	vector<bool> ans(k+1,false);
	vector<int>v(n);
	for(int &i : v){
		cin>>i;
	}
	for(int i=1;i<=k;i++){
		bool ok=false;
		for(int &j : v){
			if(i-j<0) continue;
			if(!ans[i-j]){
				ok=true;
			}
		}
		ans[i]=ok;
	}
	cout<<(ans[k] ? "First" : "Second")<<endl;
}

signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n,p;
ll a[111];
ll dp[111][3];

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>p;
  rep(i,n){
    cin>>a[i];
    a[i]%=2;
  }
  dp[0][0]=1;
  rep(i,n)rep(j,2){
    if(a[i]){
      dp[i+1][j]=(dp[i+1][j]+dp[i][j]);
      dp[i+1][1-j]=(dp[i+1][1-j]+dp[i][j]);
    }else{
      dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2);
    }
  }
  cout<<dp[n][p]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll W, H, N;
    cin >> W >> H >> N;

    ll left = 0;
    ll right = W;
    ll up = H;
    ll down = 0;

    FOR(i, 0, N){
        ll x, y, a;
        cin >> x >> y >> a;

        if(a==1){
            if(left < x){
                left = x;
            }
        }
        else if(a==2){
            if(x < right){
                right = x;
            }
        }
        else if(a==3){
            if(down < y){
                down = y;
            }
        }
        else if(a==4){
            if(up > y){
                up = y;
            }
        }
    }

    ll diff_x = right - left;
    ll diff_y = up - down;

    if(diff_x <= 0 || diff_y <= 0){
        p(0);
    }
    else{
        p(diff_x * diff_y);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll A, B, K;
  cin >> A >> B >> K;
  if(A >= K) {
    A -= K;
  }
  else {
    B -= (K-A);
    A = 0;
  }
  if(A >= 0 && B >= 0) {
    cout << A << " " << B << endl;
  }
  else {
    cout << 0 << " " << 0;
  }
}

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

using namespace std;

#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define ff first
#define ss second

void solve()
{
    int n;cin>>n;
    int s = 0 , b[n-1];
    for(int i = 0 ; i < n-1 ; i++) cin>>b[i];

    for(int i = 1 ; i < n-1 ; i++)
        s+=  min(b[i] , b[i-1]);

    cout<<s + b[0] + b[n-2]<<endl;
    return;
}


int32_t main()
{
    tie();
    int t = 1;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n=sc.nextInt();
        int a[]=sc.readArray(n);
        int max=a[0];
        long sum=0;
        for (int i=1;i<n;i++){
            max=Math.max(a[i],max);
            sum+=max-a[i];


        }
        System.out.println(sum);

        out.flush();

    }









    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sortReverse(long[] a) {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
//        Collections.sort.(l);
        Collections.sort(l,Collections.reverseOrder());
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long[] readArrayLong(long n) {
            long[] a=new long[(int)n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }


}


Measured memory_bytes: 55396
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int a; cin >> a;
  cout << a + a*a + a*a*a << endl;
  

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3628
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int k=Integer.parseInt(line[1]);

        String[] line1 = sc.nextLine().split(" ");
    
        int[] num=new int[n];
        for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        }

        List<Integer> list=new ArrayList<Integer>();

        for(int i=0;i<k;i++){
          list.add(num[i]);
        } 
        for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        }
        int sum=0;

        for(int value:list){
          sum=sum+value;
        }

          System.out.println(sum);
    }
  
}




Measured memory_bytes: 37136
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100005],b[100005];
int v[100005];
int main()
{
    int n,ans1=0,ans11=0,ans2=0,ans22=0,t1=0,t2=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&v[i]);
    for(int i=1; i<=n; i++)
    {
        if(i&1)
        {
            a[v[i]]++;
            if(a[v[i]]>ans1)
                ans1=a[v[i]],t1=v[i];
        }
        else
        {
            b[v[i]]++;
            if(b[v[i]]>ans2)
                ans2=b[v[i]],t2=v[i];
        }
    }
    int ans;
    if(t2==t1)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=1; i<=n; i++)
        {
            if(v[i]==t2)
                continue;
            if(i&1)
            {
                a[v[i]]++;
                if(a[v[i]]>ans11)
                    ans11=a[v[i]];
            }
            else
            {
                b[v[i]]++;
                if(b[v[i]]>ans22)
                    ans22=b[v[i]];
            }
        }
        ans=max(ans1+ans22,ans2+ans11);
        ans=n-ans;
    }
    else
        ans=n-ans1-ans2;
    printf("%d\n",ans);
    return 0;
}


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

#define rep(i,a,b) for (auto i = (a); i < (b); i++)
typedef long long ll;
const ll INF = 1000000000000000000;

int h[100100];
ll mn[100100];
int n, k;

ll dp(int at) {
    if (at == n-1) {
        return 0;
    }
    if (mn[at] != -1) {
        return mn[at];
    }

    mn[at] = INF;
    rep(i,1,k+1) {
        if (at + i <= n-1) {
            mn[at] = min(mn[at], abs(h[at] - h[at+i]) + dp(at+i));
        } else {
            break;
        }
    }
    return mn[at];
}

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

    rep(i,0,n) {
        cin >> h[i];
    }

    memset(mn, -1, sizeof(mn));
    cout << dp(0) << endl;

    return 0;
}


Measured memory_bytes: 6144
#include <stdio.h>
#include <stdlib.h>

int main(){
    int a,b,c,d,diff1,diff2,diff3;
    
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    diff1=abs(a-b);
    diff2=abs(b-c);
    diff3=abs(a-c);
    
    if(diff1<=d && diff2<=d){
        printf("Yes\n");
    }
    else if(diff3<=d){
        printf("Yes\n");
    }
    
    else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

inf=10**9
n, m=map(int,input().split())
g1=np.ones((n,n),dtype=int) * inf

bridge=[]
for _ in range(m):
    a,b=map(int,input().split())
    bridge.append((a-1, b-1))
    g1[a-1][b-1]=1
    g1[b-1][a-1]=1

ans=0
for a,b in bridge:
    graph=np.copy(g1)
    graph[a][b]=inf
    graph[b][a]=inf
    graph=floyd_warshall(graph)
    if inf in graph:
        ans+=1

print(ans)

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

long long gcd(long long a, long long b)
{
    return (b == 0) ? a : gcd(b, a % b);
}

int main()
{
    long long n, ans = 0;
    std::cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            long long d = gcd(i, j);
            for (int k = 1; k <= n; k++) {
                ans += gcd(k, d);
            }
        }
    }

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


Measured memory_bytes: 3636
import bisect

n = int(input())
l = list(map(int,input().split()))
l.sort()

ans = 0

#a<b+c, a>b-c, a>c-b
for a in range(n-2):
	for b in range(a+1,n-1):
		index = bisect.bisect_left(l,l[a]+l[b])
		ans += index - (b+1)
print(ans)

Measured memory_bytes: 3188
import itertools
import math
answer = 0
N,D = map(int,input().split())
X_list=[]
for i in range(N):
  X_list.append(list(map(int,input().split())))
for v in itertools.combinations(range(N),2):
  sum_2 = 0
  for j in range(D):
    sum_2 += (X_list[v[0]][j] - X_list[v[1]][j])**2
  if math.sqrt(sum_2).is_integer():
    answer += 1
print (answer)

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

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

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

int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    ll mx1 = max(a,b);
    ll mn1 = min(a,b);
    ll mx2 = max(c,d);
    ll mn2 = min(c,d);
    cout << max({mx1*mx2, mn1*mn2, mx1*mn2, mn1*mx2})<< endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    int n;
    cin>>n;
    ll m,ans=0;
    cin>>m;
    for(ll i=1;i<n;i++){
        ll x;
        cin>>x;
        if(x<m)
            ans+=(m-x);
        else
            m=x;
    }
    cout<<ans;
}
int main()
{
    solve();
    return 0;
}


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

using namespace std;

int main() {
    string a, b;
    int a_len, b_len;

    cin >> a >> b;

    a_len = a.length();
    b_len = b.length();
    if (a_len == b_len) {
        for (int i = 0; i < a_len; i++) {
            if (a[i] > b[i]) {
                cout << "GREATER" << endl;
                return 0;
            } else if (a[i] < b[i]) {
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    } else if (a_len > b_len) {
        cout << "GREATER" << endl;
    } else {
        cout << "LESS" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def readinput():
    n=int(input())
    w=[]
    for _ in range(n):
        w.append(input())
    return n,w

def main(n,w):
    #print(w)
    words={}
    word=w[0]
    words[w[0]] = 1 
    for i in range(1,n):
        #print(w[i])
        if w[i][0]!=word[-1]:
            return 'No'
        else:
            if w[i] not in words:
                words[w[i]] = 1
            else:
                return 'No'
        word = w[i]
    return 'Yes'

if __name__=='__main__':
    n,w=readinput()
    ans=main(n,w)
    print(ans)


Measured memory_bytes: 9212
#include<iostream>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    int num = 100*r + 10*g + b;
    if(num%4==0){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main (){
  int N,d,e,i,x,y,z,a,b;
  x=0;
  y=0;
  cin>>N;
  for(i=0;i<N;i++){
    cin>>d;
    e=d*d;
    x+=d;
    y+=e;
  }
  b=x*x;
  z=b-y;
  a=z/2;
  cout<<a<<endl;
  return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i <= k; i++)
#define SZ 110000
#define PB push_back
#define MEM(n, val) memset((n), val, sizeof(n))
#define INF 1000000000
#define F first
#define S second
#define MP make_pair
#define LL long long

int n;
LL ara[100010];

bool vis[100010][2];
LL dp[100010][2];

LL func(int pos, bool chk)  {
    LL cur = ara[pos];
    if(chk)    {
        cur = -1LL * cur;
    }

    if(pos == n - 1)    {
        return cur;
    }
    if(vis[pos][chk])    {
        return dp[pos][chk];
    }

    LL ans = -2000000000000000000LL;

    ///etar sign change kore
    ans = max(ans, (-1LL * cur) + func(pos + 1, 1));

    ///etar sign change na kore
    ans = max(ans, cur + func(pos + 1, 0));

    vis[pos][chk] = 1;
    return dp[pos][chk] = ans;
}

int main()  {
//    freopen("in.txt", "r", stdin);

    cin >> n;
    FOR(i, 0, n - 1)    {
        cin >> ara[i];
    }

    cout << func(0, 0);
    return 0;
}
/**
*/


Measured memory_bytes: 9088
use std::io;

fn main() {
    let mut buf: String = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let iter = buf.trim().split_whitespace();
    let mut nums: Vec<i64>  = Vec::new();
    for i in iter {
        nums.push(i.parse::<i64>().unwrap());
    }
    nums.reverse();
    let mut n_max = 2;
    let mut n_min = 2;
    for n in nums {
        if n_max % n != 0 {
            n_max -= n_max % n;
        }
        if n_min % n != 0 {
            n_min += n - n_min % n;
        }
        if n_max < n_min { println!("-1"); return; }
        n_max += n - 1;
    }
    println!("{} {}", n_min, n_max);
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(void){
    // Your code here!
    int n;
    string s;
    cin >> n >> s;
    
    vector<map<string, int>> count = vector<map<string, int>>(n, map<string, int>());
    count[n - 1][s.substr(n - 1, 1)]++;
    
    for (int i = n - 1; i > 0; i--){
        count[i - 1] = count[i];
        count[i - 1][s.substr(i - 1, 1)]++;
    }

    long long ans = 0;
    for (int i = 0; i < n - 2; i++){
        for (int j = i + 1; j < n - 1; j++){
            if(s[i] == s[j]) continue;
            
            string key;
            if(s[i] != 'R' && s[j] != 'R'){
                key = "R";
            }
            else if(s[i] != 'G' && s[j] != 'G'){
                key = "G";
            }
            else{
                key = "B";
            }
            ans += count[j + 1][key];
            if (j * 2 - i < n && s.substr(j * 2 - i, 1) == key){
                ans--;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4504
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#define PI acos(-1.0)
using namespace std;
int main(){
	char c[4];
	for(int i = 0;i < 4;i++) scanf("%c",&c[i]);
	int a,b;
	a = (c[0]-'0')*10 + (c[1] - '0');
	b = (c[2]-'0')*10 + (c[3] - '0');
//	cout << a << endl << b << endl;
	bool flag1 = 0,flag2 = 0;
	if(a >= 1 && a <= 12 ){
		flag1 = 1;
	}
	if(b >= 1 && b <= 12){
		flag2 = 1;
	}
	if(flag1 && flag2){
		cout << "AMBIGUOUS" << endl;
	}
	else if(flag1){
		cout << "MMYY" << endl;
	}else if(flag2){
		cout << "YYMM" << endl;
	}else{
		cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}

use std::collections::VecDeque;

fn main() {
    input! {
        k:u64,
    }
    let mut q: VecDeque<u64> = (1..10).collect();
    let mut count = 0;

    let mut res = 0;
    loop {
        let n = q.pop_front().unwrap();
        count += 1;
        if count == k {
            res = n;
            break;
        };

        if n % 10 != 0 {
            q.push_back(n * 10 + n % 10 - 1);
        }

        q.push_back(n * 10 + n % 10);

        if n % 10 != 9 {
            q.push_back(n * 10 + n % 10 + 1);
        }
    }

    println!("{}", res);
}


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

ll kaijou( int n ){
    ll ret = 0 ;
    for(int i = 1 ; i <= n ; i++ ){
        ret += i ;
    }
    return ret ;
}

int main(){
    int N , K ;
    cin >> N >> K ;
    vector<int> A(N) ;
    vector<double>  B(N) ;
    rep(i,N) cin >> A.at(i) ;
    rep(i,N) B.at(i) = (double) kaijou(A.at(i) )/ A.at(i) ;
    //rep(i,N) cout << B.at(i) << endl ; 
    double sum = 0 ;
    rep(i,K) sum += B.at(i) ;
    double ans = sum ;
    for(int i = 0 ; i < N - K ; i++ ){
        // cout << sum << endl ;
        sum = sum + B.at(K+i) - B.at(i) ;
        ans = max(ans,sum) ;
    }
    printf("%.10f",ans) ;
    //cout << ans << endl;
}


Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    while(cnt < s.size() && s != t){
        char x = s[0];
        s.erase(s.begin());
        s+=x;
        cnt++;
    }
    if(s == t) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool pt(int n) {
	return (n&(-n)) == n;
}
void eg(int a, int b) {
	cout << a << " " << b << '\n';
}
int lso(int n) {
	return n&(-n);
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	if(pt(n)) {
		cout << "No\n";return 0;
	}
	if(n%4 != 3 && n <= 4) {
		cout << "No\n";return 0;
	}
	cout << "Yes\n";
	for(int i=0;i<2;i++) {
		eg(i+1,i+2);
	}
	eg(3,n+1);
	for(int i=0;i<2;i++) {
		eg(n+i+1,n+i+2);
	}
	for(int i=4;i<n;i+=2) {
		eg(i,i+1);
		eg(i+1,1);
		eg(1,i+n);
		eg(i+n,i+n+1);
	}
	if(n%2 == 0) {
		int a = lso(n),b = (n-lso(n))+1;
		eg(n,a+n);
		eg(b,n+n);
	}
}


Measured memory_bytes: 2304
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//

int32_t main()
{
    io;
    int n, m;
    cin>>n>>m;
    vi val(n), cnt(n);
    for(auto& x: val) cin>>x;

    vector<bool> vis(n);
    vi adj[n];

    while(m--)
    {
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    queue<int> q;

    for(int i = 0; i < n;i++)
    {
        if(vis[i])
            continue;
        q.push(i);
        vis[i] = 1;
        while(!q.empty())
        {
            int nod = q.front();
            q.pop();
            for(auto x: adj[nod])
            {
                if(val[x] == val[nod])
                    {
                        //cout<<"a\n";
                        cnt[x]++;
                        cnt[nod]++;
                    }
                    else if(val[x] > val[nod])
                    {
                        cnt[nod]++;
                        //cout<<"b\n";
                    }
                    else
                    {
                        cnt[x]++;
                        //cout<<"c\n";
                    }

                if(!vis[x])
                {
                    vis[x] = 1;
                    //cout<<"cntn " << cnt[nod] <<" cntx: " << cnt[x]<<"\n";
                    q.push(x);
                }
            }
        }
    }

    int ans = 0;
    for(int i =0 ;i < n; i++)
        if(!cnt[i])
            ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 9340
#!/usr/bin/env python3
import sys
import numpy as np


def solve(H: int, W: int, S: "List[List[str]]"):
    arr_s = np.array(S)
    arr_s = np.where(arr_s == ".", 1, 0)
    arr_v = np.zeros((H, W), dtype=int)
    arr_h = np.zeros((H, W), dtype=int)
    arr_v[0, :] = arr_s[0, :]
    arr_h[:, 0] = arr_s[:, 0]

    for i in range(H-1):
        arr_v[i+1, :] = (arr_v[i, :] + 1) * arr_s[i+1, :]
    
    for i in range(H-2, -1, -1):
        arr_v[i, :] = np.where(arr_v[i, :] > 0, np.maximum(arr_v[i+1, :], arr_v[i, :]), 0)

    for i in range(W-1):
        arr_h[:, i+1] = (arr_h[:, i] + 1) * arr_s[:, i+1]
    
    for i in range(W-2, -1, -1):
        arr_h[:, i] = np.where(arr_h[:, i] > 0, np.maximum(arr_h[:, i+1], arr_h[:, i]), 0)
    
    print(np.max(arr_v + arr_h) - 1)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ [c for c in next(tokens)] for _ in range(H) ]  # type: "List[List[str]]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 169660
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

bool h[1000001];
const int a[3] = {2,3,5};

int main(){
	h[0] = h[1] = true;
	for(int i=1;i<=1000000;i++){
		if(!h[i]) continue;
		for(int j=0;j<3;j++) if(i*a[j]<=1000000) h[i*a[j]] = true;
	}
	int M,N;
	while(cin>>M,M){
		cin>>N;
		int ans = 0;
		for(int i=M;i<=N;i++) ans += h[i];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1824
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn next_perm<T: Ord>(xs: &mut [T]) -> bool {
    // `xs[i + 1..]` : desc but
    // `xs[i..]` : not desc.
    let i = match (0..xs.len())
        .rev()
        .filter(|&i| i + 1 < xs.len() && xs[i] < xs[i + 1])
        .next()
    {
        None => return false,
        Some(i) => i,
    };

    // `xs[k]` : The next greater elem in `xs[i..]`.
    let k = (i + 1..xs.len())
        .rev()
        .filter(|&k| xs[i] < xs[k])
        .next()
        .unwrap();

    // E.g. 2431 -> 3421 -> 3124 (where i = 0, k = 2).
    xs.swap(i, k);
    xs[i + 1..].reverse();

    true
}

fn sq(x: f64) -> f64 {
    x * x
}

fn dist(p: (f64, f64), q: (f64, f64)) -> f64 {
    let (px, py) = p;
    let (qx, qy) = q;

    (sq(px - qx) + sq(py - qy)).sqrt()
}

fn main() {
    let N = read!(usize);
    let T = read![f64, f64; N];
    let mut order = (0..N).collect::<Vec<_>>();

    let mut total = 0.0;
    let mut count = 0;

    loop {
        total += order
            .windows(2)
            .map(|w| dist(T[w[0]], T[w[1]]))
            .sum::<f64>();
        count += 1;

        if !next_perm(&mut order) {
            break;
        }
    }

    println!("{}", total / count as f64)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back  
#define INF 10000000000

 

 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll i,f,ss,th,ans = 0,k,t,j;
   string s;
   cin>>s>>k;
  
   ll n = s.length();
    f = n+5;
   ss= n+5;th = n+5;
   t = 0;
   for(i=0;i<n;i++){
   	if(s[i] != '0' && t == 0){
   		f = i;
   		t++;
   		continue;
	   }
	   if(s[i] != '0' && t == 1){
   		ss = i;
   		t++;
   		continue;
	   }
	   if(s[i] != '0' && t == 2){
   		th = i;
   		t++;
   		continue;
	   }
   }
   
   if(k == 1){
   	for(i=0;i<n;i++){
   		
   		if(i == f){
   			ans += s[i] - '0';
		   }else if(i > f){
		   	ans+=9;
		   }
	   }
   }else if( k == 2){
	   	 for(i=0;i<n;i++){
		   	for(j=i+1;j<n;j++){
		   		if(i < f)	continue;
		   		if(i == f){
		   			if(j < ss)	ans += (s[f] - '0' -1)*9;
		   			if(j == ss )	ans+=(s[f]-'0'-1)*9 + s[ss] - '0';
		   			if(j > ss)	ans+=(s[f]-'0')*9 ;
				   }
				   if(i > f){
				   	ans += 9*9;
				   }
			   }
	   }
   }
   else{
   		for(i=0;i<n;i++){
		   	for(j=i+1;j<n;j++){
		   		for(k=j+1;k<n;k++){
		   				if(i < f)	continue;
				   		if(i == f){
				   			if(j < ss)	ans += (s[f]-'0'-1) * 9*9;
				   			if(j == ss){
				   				if(k < th)	ans += (s[f]-'0'-1)*9*9 + (s[ss]-'0'-1)*9;
				   				if(k == th)	ans += (s[f]-'0'-1)*9*9 + (s[ss]-'0'-1)*9 + s[th]-'0';
				   				if(k > th)	ans += (s[f]-'0'-1)*9*9 + (s[ss]-'0')*9;
							   }
							   if(j > ss){
							   	ans += (s[f]-'0')*9*9 ;
							   }
						   }
						   if(i > f){
						   	ans += 9*9*9;
						   }
				   }
			   }
   }
   }
   
   cout<<ans;
   
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b, c, d, e, f, g, h, i, j = 0;
	cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
	if (a - d == b - e && b - e == c - f) {
		if (d - g == e - h && e - h == f - i) {
			cout << "Yes" << endl;
			j++;
		}
	}
	if (j == 0) {
		cout << "No" << endl;
	}
	cin >> e;
}

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

int main(){
int n, k;
  cin >> n >> k;
  int ans=0;
  vector<int> ball(n);
  rep(i,n){cin >> ball.at(i);}
  rep(i,n)ans += min(ball.at(i),abs(ball.at(i)-k));
  cout << ans*2 << endl;

	return 0;
}


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

int main() {
    int before_high = 0;
    int now_high = 0;
    int N;
    cin >> N;
    cin >> before_high;
    before_high -= 1;
    if (N == 1) {
        cout << "Yes" << endl;
    }
    for (int i = 1; i < N; i++) {
        cin >> now_high;
        if (now_high > before_high) {
            before_high = now_high - 1;
            if (i == N - 1) {
                cout << "Yes" << endl;
            }
        }
        if (now_high == before_high) {
            if (i == N - 1) {
                cout << "Yes" << endl;
            }
        }
        if (now_high < before_high) {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(void)
{
	string p, a[100];
	int n;
	cin >> p;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	int q = 0;
	q = p.size();
	int o[100];
	int co = 0;
	for (int i = 0; i < n; i++)
	{
		o[i] = 0;
		o[i] = a[i].size();
		
		a[i] += a[i].substr(0, q);
		for (int j = 0; j < o[i]; j++)
		{
			if (a[i].substr(j, q) == p)
			{
				co++;
				break;
			}
		}
	}

	cout << co << endl;
}




Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int a[212345];
int b[212345];
int c[212345];
//int ha[212345];
//int hb[212345];
vector<int>t;
int n;
int f(int x) {
	for (int i = 0; i < n; ++i) {
		if (a[i] != c[x] && a[x] != c[i]) {
			swap(c[i], c[x]);
			return 1;
		}
	}
	return -1;
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i)cin >> a[i];
	for (int i = 0; i < n; ++i)cin >> b[i];
	/*for (int i = 0; i < n; ++i)++ha[a[i]];
	for (int i = 0; i < n; ++i)++hb[b[i]];*/
	int cnt1 = 0, cnt2 = n - 1;
	for (int i = 0; i < n; ++i) {
		if (a[i] != b[cnt1]) {
			c[i] = b[cnt1++];
		}
		else if (a[i] != b[cnt2]) {
			c[i] = b[cnt2--];
		}
		else {
			c[i] = b[cnt1++];
			t.push_back(i);
		}
	}
	for (auto& x : t) {
		int y = f(x);
		if (y == -1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	for (int i = 0; i < n; ++i)cout << c[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 6308