akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

vi lh, rh, lm(1, 1e9), rm(1, 1e9);

void push(int x) {
    lh.pb(x);
    int z = lm.back();
    lm.pb(min(x, z));
}

int get_min() {
    return min(lm.back(), rm.back());
}

void pop() {
    if (rh.empty()) {
        while (!lh.empty()) {
            int x = lh.back();
            lh.pop_back();
            lm.pop_back();
            rh.pb(x);
            int z = rm.back();
            rm.pb(min(x, z));
        }
    }
    rh.pop_back();
    rm.pop_back();
}

void init() {
    lh.clear(); rh.clear();
    lm.assign(1, 1e9); rm.assign(1, 1e9);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n, x;
    cin >> n >> x;
    vi a(n);
    forn(i, n) cin >> a[i];
    i64 ans = 1e18;
    forn(k, n) {
        init();
        forn(i, k + 1) push(a[i]);
        int j = (k + 1) % n;
        i64 res = 0;
        forn(i, n) {
            res += get_min();
            pop();
            push(a[j]);
            ++j;
            if (j == n) j = 0;
        }
        uin(ans, res + 1LL * k * x);
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pp pair<pair<ll, ll>, pair<ll, ll>>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define ERASE(v) v.erase(unique(v.begin(), v.end()), v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


template <class T>
struct SegmentTree {
    ll n;
    vector<T> data;
    T def;
    function<T(T, T)> operation;
    function<T(T, T)> update;

    SegmentTree(ll _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
        : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }

    void change(ll i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    T _query(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a || b <= l)
            return def;
        if (a <= l && r <= b) {
            return data[k];
        } else {
            T vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
            return operation(vr, vl);
        }
    }

    T query(ll a, ll b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](ll i) {
        return data[i + n - 1];
    }
};


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    ll q;
    cin>>n>>q;
    SegmentTree<ll> sg(n,0,[](ll a,ll b){return a+b;},[](ll a,ll b){return a+b;});
    rep(i,q){
        ll c,x,y;
        cin>>c>>x>>y;
        if(c==0){
            sg.change(x-1,y);
        }
        else{
            cout<<sg.query(x-1,y)<<endl;
        }
    }
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    set<char> allowed = {'A','C','G','T'};
    int ans = 0;
    for(int i=0;i<s.length();i++)
    {
        bool ok = true;
        for(int len=1;i+len-1<s.length();len++)
        {
           
            string curr;
            curr+= s.substr(i,len);
            
            for(int k=0;k<curr.length();k++)
            {
            
                if(allowed.count(curr[k])==0)
                {
                    ok = false;
                    break;
                }
                
            }
            //cout << curr << " ";
            if(ok)
            {
                ans = max(ans,(int)curr.length());
            }
            else
            {
                break;
            }
            
        }
    }


 cout << ans;
}

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

#define MAX_V 100005

using namespace std;

struct Edge {
  int dst, cost;
  Edge() {}
  Edge(int b, int c) : dst(b), cost(c) {}
};

vector<Edge> tree[MAX_V];
int ans[MAX_V];

void dfs(int cur_v, int par_v, int color) {
  ans[cur_v] = color;
  for (int i = 0; i < tree[cur_v].size(); i++) {
    Edge e = tree[cur_v][i];
    if ( e.dst == par_v ) { continue; }
    if ( e.cost & 1 ) {
      dfs(e.dst, cur_v, 1-color);
    } else {
      dfs(e.dst, cur_v, color);
    }
  }
}

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

  for (int i = 0; i < n-1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    tree[u].push_back( Edge(v, w) );
    tree[v].push_back( Edge(u, w) );
  }
  
  dfs(0, -1, 0);

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int, int> > v;
    rep (i, n) {
      int a, b;
      cin >> a >> b;
      v.push_back(make_pair(b, a));
    }
    sort(v.begin(), v.end());
    ll t = 0;
    rep (i, n) {
      t += v[i].second;
      if (t > v[i].first) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
int main(){
	ll N;
	cin >> N;
	ll ans = 1;
	for(int i=1;i<=N;i++){
		ans = ans%1000000007*i;
	}
	cout << ans%1000000007 << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))

Measured memory_bytes: 62612
import java.util.Scanner;

class Main{
    final static int LEN = 105;
    public static void main(String args[]){
	int[][] graph = new int[LEN][LEN];
	int[] minCost = new int[LEN];
	int count=0;
	int v;
	boolean[] used = new boolean[LEN];

	Scanner in = new Scanner(System.in);

	//read
	int n = in.nextInt();
	int nodeNumber;
	int k;
	for(int i=0; i<n; i++){
	    for(int j=0; j<n; j++){
		graph[i][j]=2000000;
	    }
	}
	for(int i=0; i<n; i++){
	    nodeNumber = in.nextInt();
	    k = in.nextInt();
	    for(int j=0; j<k; j++){
		graph[nodeNumber][in.nextInt()]=in.nextInt();
	    }
	}

	//make prim
	for(int i=0; i<n; i++){
	    minCost[i]=999999;
	    used[i]=false;
	}

	minCost[0]=0;

	while(true){
	    v = -1;
	    for(int i=0; i<n; i++){
		if(!used[i] && (v==-1 || minCost[i] < minCost[v]))v=i;
	    }

	    if(v==-1)break;
	    used[v]=true;
	    count+=minCost[v];

	    for(int i=0; i<n; i++){
		minCost[i]=Math.min(minCost[i], graph[v][i]+minCost[v]);
	    }
	}

	//print
	for(int i=0; i<n; i++)System.out.println(i+" "+minCost[i]);
    }
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while (s.hasNextDouble()) {
			int[] n = new int[6];
			for (int i = 0; i < 6; ++i) {
				n[i] = s.nextInt();
			}
			double d = n[0] * n[4] - n[1] * n[3];
			System.out.printf("%.3f %.3f\n", (double)Math.round((n[2] * n[4] - n[1] * n[5]) * 1000 / d) / 1000, (double)Math.round((n[0] * n[5] - n[2] * n[3]) * 1000 / d) / 1000);
		}
	}
}

Measured memory_bytes: 18448
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define fi first 
#define se second 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);
#define mem(a,v) memset(a,v,sizeof(a))
const ll INF=1e18;
const int mod=1e9+7;
const int iinf=1e9+10;
const int xd[4]={1,0,-1,0},yd[4]={0,1,0,-1};
int main()
{
	faster
	int n;
	cin>>n;
	int mm1=-mod,mm3=mod,mm2=mod,mm4=-mod;
	for(int i=0,a,b;i<n;i++){
		cin>>a>>b;
		mm1=max(mm1,a+b);
		mm2=min(mm2,a-b);
		mm3=min(mm3,a+b);
		mm4=max(mm4,a-b);
		//cout<<mm1<<" "<<mm2<<" "<<mm3<<" "<<mm4<<"\n";
	}
	cout<<max(mm4-mm2,mm1-mm3);
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int S = sc.nextInt();
		for (int i = 0; i < S; ++i) {
			System.out.println(Long.toString(solve(), 16).toLowerCase());
		}
	}

	static long solve() {
		long[] input = new long[9];
		for (int i = 0; i < 9; ++i) {
			input[i] = Long.parseLong(sc.next(), 16);
		}
		long key = 0;
		for (int i = 0; i < 32; ++i) {
			if (!match(input, key, (1L << (i + 1)) - 1)) {
				key |= (1L << i);
			}
		}
		return key;
	}

	static boolean match(long[] input, long key, long mask) {
		long sum = 0;
		for (int i = 0; i < 8; ++i) {
			sum += input[i] ^ key;
		}
		return (sum & mask) == ((input[8] ^ key) & mask);
	}

}

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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n,greater<int>());
    int alice,bob;
    alice=bob=0;
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        alice+=arr[i];
        else
        bob+=arr[i];
    }
    cout<<alice-bob<<"\n";
}

Measured memory_bytes: 3596
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

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; }
void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class A {
	int a, b, c;
public:
	A()
	{
		cin >> a >> b >> c;
	}
	void solve()
	{
		cout << (a ^ b ^ c) << endl;
	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin >> s >> t;
    int n=s.size();
    int m=t.size();
    s="$"+s;
    t="$"+t;
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    vector<vector<array<int,2>>> p(n+1,vector<array<int,2>>(m+1,{0,0}));
    for(int o=1;o<=n;o++)
    {
        for(int i=1;i<=m;i++)
        {
            if(s[o]==t[i])
            {
                dp[o][i]=dp[o-1][i-1]+1;
                p[o][i]={o-1,i-1};
            }
            else if(dp[o-1][i]>=dp[o][i-1])
            {
                dp[o][i]=dp[o-1][i];
                p[o][i]={o-1,i};
            }
            else
            {
                dp[o][i]=dp[o][i-1];
                p[o][i]={o,i-1};
            }
        }
    }
    string res;
    array<int,2> now={n,m};
    while(min(now[0],now[1])>0)
    {
        if(p[now[0]][now[1]]==array<int,2>({now[0]-1,now[1]-1})) res+=s[now[0]];
        now=p[now[0]][now[1]];
    }
    reverse(res.begin(),res.end());
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 105984
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    int n;
    cin>>n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        string s = std::to_string(i);
        int len = s.size();
        if(len % 2 == 1){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3704
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long


int main(){
    int n; string s; cin >> n >> s; int res = 0;
    rep(i, n-2){
        if(s.substr(i, 3) == "ABC") res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const ll mod = 1e9 + 7;
int n, k;
ll ans;
int main() {
	scanf("%d%d", &n, &k);
	for (int i = k; i <= n + 1; i++) {
		ll L = 1ll*(i - 1)*i / 2;
		ll R = 1ll*(2 * n - i + 1)*i / 2;
		ans = (ans + (R - L) + 1) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;

    if (n % 2 != 0) cout << "No" << endl;
    else {
        bool ok = true;
        rep(i,n/2) {
            if (s[i] != s[n/2+i]) ok = false;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;
#define int long long
const int MOD = 998244353;
int dp[301][301][301][2];
void add(int &a, const int &b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	int K;
	cin >> S >> K;
	K = min(K, (int)300);
	int N = S.size();
	int res = 0;
	dp[0][0][0][0] = 1;
	for (int i = 1; i <= N; i++) {
		if (S[i - 1] == '0') {
			for (int j = 0; j <= K; j++) {
				for (int k = 0; k <= j; k++) {
					if (j > k) add(dp[i][j][k][0], dp[i][j - 1][k][0]);
					add(dp[i][j][k][0], dp[i - 1][j][k][0]);
				}
			}
			for (int j = 0; j <= K; j++) {
				for (int k = 0; k <= j; k++) {
					add(dp[i][j][k][0], dp[i - 1][j][k][1]);
				}
			}
		} else {
			for (int j = 0; j <= K; j++) {
				for (int k = 0; k <= j; k++) {
					if (k > 0) add(dp[i][j][k][1], dp[i - 1][j][k - 1][0]);
					if (k > 0) add(dp[i][j][k][1], dp[i - 1][j][k - 1][1]);

					//add(dp[i][j][k][1], dp[i - 1][j][k][1]);
					add(dp[i][j][k][0], dp[i - 1][j][k][0]);
				}
			}
		}
	}
	
	for (int i = 0; i <= K; i++) {
		//cerr << i << " " << dp[N][i][i][0] << " " << dp[N][i][i][1] << endl;
		add(res, dp[N][i][i][0]);
		add(res, dp[N][i][i][1]);
	}
	cout << res << endl;
}

Measured memory_bytes: 421964
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstring>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

int main() {
    double A = 0 , B = 0 , C = 0 , D = 0, E = 0, F = 0;
    double sumt = 1, sugart = -1, sum = 0, sugar = 0;
    cin >> A >> B >> C >> D >> E >> F;
    for (double i = 0; i*100*A <= F; i++) {
        for (double j = 0; j*100*B <= F-i*100*A; j++) {
            for (double k = 0; k*C <= F-i*100*A-j*100*B; k++) {
                for (double l = 0; l*D <= F-i*100*A-j*100*B-k*C; l++) {
                    sugar = k*C + l*D;
                    sum = i*100*A + j*100*B + sugar;
                    int judge = A*E*i + B*E*j;
                    if (sugar > judge || sum > F) continue;
                    if (sum != 0 && sugar / sum > sugart / sumt) {
                        sugart = sugar;
                        sumt = sum;
                    }
                }
            }
        }
    }
    cout << int(sumt) << ' ' << int(sugart) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main() {
    ll n,k; cin >> n >> k;
    vl a(n),f(n);
    ll s = 0;
    rep(i,n){
        cin >> a[i];
        s += a[i];
    }
    rep(i,n) cin >> f[i];
    sort(all(a));
    sort(rall(f));
    if(s-k<=0){
        puts("0");
        return 0;
    }
    ll left = 0;
    ll right = 1e12 + 1;
    while(right - left > 1){
        ll mid = (left + right) / 2;
        ll cnt = 0;
        rep(i,n){
            cnt += max(0LL,(a[i]*f[i]-mid+f[i]-1)/f[i]);
        }
        if(cnt > k){
            left = mid;
        }else {
            right = mid;
        }
    }
    cout << right << endl;
}


Measured memory_bytes: 3328
s = input()

tag = 0
i = 1
num = []

while tag == 0:
    if i > 1000000:
        break
    num.append(int(s))
    if int(s)%2 == 0:
        s = int(s)/2
    else:
        s = 3*int(s) + 1
    i += 1
    for j in range(int(i)-1):
        if int(s) == int(num[j]):
            tag = 1
            print (i)
            break
        else:
            continue



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

int main () {
	string s;
	cin >> s;
	int ug = 1;
	for (int i = 1; i < s.length(); i++) {
		if (s[i] != s[i-1]) {
			ug++;
		}
	}
	cout << ug-1 << "\n";
	return 0;
}

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

int main(){
    int N,X;
    int D,ans = 0;
    int sum = 0;
    cin >> N;
    vector<int> A(N+2);
    A[0] = 0;
    A[N+1] = 0;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
        sum += abs(A[i]- A[i-1]);
    }
    sum += abs(A[N+1] - A[N]);

    for(int i = 1; i <= N; i++){
        ans = sum - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]) + abs(A[i+1]-A[i-1]);
        cout << ans << endl;  
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;

int main(){
    int64_t N,K;
    int64_t ans=1;
    cin >> N >> K;
    ans=K;
    for(int n=1;n<N;n++){
        ans*=(K-1);
    }
    cout << ans << endl;
    
    return 0;
}


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

#define all(x) x.begin(),x.end()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;
int ctoi(char c) {return c-'0';}

const int mxn=105;
const int mxw=1e5+5;
vector<pair<int,int>> a(mxn);
ll dp[mxn][mxw];

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

int N,W;
cin>>N>>W;
forn(i,N) {
  cin>>a[i].first>>a[i].second;
}
sort(a.begin(),a.begin()+N);
forn(i,N+1) {
  if(i==0) {
    forn(j,W+1) {
      dp[0][j]=0;
    }
    continue;
  }
  forn(j,W+1) {
    if(j==0) {
      dp[i][0]=0;
      continue;
    }
    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    if(j>=a[i-1].first) {
      dp[i][j]=max(dp[i][j],dp[i-1][j-a[i-1].first]+a[i-1].second);
    }
  }
}
cout<<dp[N][W]<<endl;
return 0;
}


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

int main(){
	int n,m;
	cin>>n>>m;
	vector<int> arr(n);
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		arr[x-1]++;
		arr[y-1]++;
	}

	for(int i=0;i<n;i++) cout<<arr[i]<<"\n";


}

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

using namespace std;

int gcd (int a, int b){
	int D, d, res;
	D = max(a, b);
	d = min(a, b);
	res = D % d;
	while(res !=0){
		D = d;
		d = res;
		res = D % d;
	}
	return d;
}

int main(){
	int n; cin >> n;
	int res=0;
	int g;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			for(int k=1; k<=n; k++){
				g = gcd(i, gcd(j, k));
				res += g;
			}
		}
	}
	cout << res ;
	return 0;
}


Measured memory_bytes: 3612
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
	return 0;
}


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


bool tryDiv(const std::vector<int> &A, std::vector<int> &B)
{
    for(int i = 0; i < A.size(); ++i)
    {
        if(A[i] % 2 == 0)
        {
            B[i] = A[i] / 2;
        }
        else
        {
            return false;
        }
    }
    return true;
}

template<class T>
int print(const T &t)
{
    for(auto i : t)
    {
         std::cout << i << " ";
    }
    std::cout << std::endl;
}

int main()
{
    int N;
    std::cin >> N;
    
    std::vector<int> A(N);
    std::vector<int> B(N);
    for(int i = 0; i < N; ++i)
    {
        std::cin >> A[i];
    }
    
    int ans = 0;
    while(tryDiv(A, B))
    {
        A = B;
        ++ans;
    }
    std::cout << ans;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
#define LLD "%lld"
#define ll long long
#define vi vector <ll>
#define pii pair <int, int>
#define forall(x,c) for (auto x : c)
#define rep(i,n) for (int i = 0; i < int(n); ++ i)
using namespace std;

inline
int getint() {
	int a = 0, b = 1, c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') b = -b;
	for (; isdigit(c); c = getchar()) a = (a<<3) + (a<<1) + (c^48);
	return a * b;
}

#define Sgn(x) ((x) > 0 ? 1 : -1)
#define Abs(x) ((x) > 0 ? (x) : -(x))
#define Min(x,y) ((x) < (y) ? (x) : (y))
#define Max(x,y) ((x) > (y) ? (x) : (y))

int N, K, A[1 << 17];

int main() {
	N = getint(), K = getint();
	rep(i, N) A[i] = getint();
	int Ans = 1 << 30;
	rep(i, N - K + 1) {
		int X = A[i], Y = A[i + K - 1];
		int cur;
		if (Sgn(X) == Sgn(Y)) {
			cur = Max(Abs(X), Abs(Y));
		}
		else {
			cur = Min(Abs(X), Abs(Y)) + Abs(X) + Abs(Y);
		}
		Ans = Min(Ans, cur);
	}
	printf("%d\n", Ans);
	return 0;
}


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

int main() {
  long h,w,a,b;
  cin >> h >> w >> a >> b;
  for(long i=0;i<b;i++) {
    for(long j=0;j<a;j++) cout << 1;
    for(long j=0;j<w-a;j++) cout << 0;
    cout << endl;
  }
  for(long i=0;i<h-b;i++) {
    for(long j=0;j<a;j++) cout << 0;
    for(long j=0;j<w-a;j++) cout << 1;
    cout << endl;
  }
}

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

signed main(void)
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int diff_x = x2 - x1, diff_y = y2 - y1;
	cout <<  x2 - diff_y << " " << y2 + diff_x << " " << x1 - diff_y << " " << y1 + diff_x << endl;
	return 0;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    string s;
    cin >> s;
    int n = s.size();

    /* xxを探す */
    REP(i, n-1) {
        if(s[i] == s[i+1]) {
            cout << i+1 << " " << i+2;
            return 0;
        }
    }

    /* xyxを探す */
    REP(i, n-2) {
        if(s[i] == s[i+2]) {
            cout << i + 1 << " " << i + 3;
            return 0;
        }
    }

    cout << "-1 -1" << endl;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top = 0, S[1000];

void push(int x) {
	S[++top] = x;
}
/* S[top++] = x ??£??\????????????top????¢???????
   S[++top] = x top????¢??????????????????£??\ */

int pop() {
	top--;
	/* printf("top: %d\n",top);  ?£??¶? */
	return S[top+1];
}

int main(void) {
	int a,b;
	char s[100];

	while(scanf("%s",s) != EOF) {
		if(s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		} else if(s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		} else if(s[0] == '*') {
			b = pop();
			a = pop();
			push(a * b);
		} else {
			push(atoi(s));
		}
	}
	
	printf("%d\n",pop());
	
	return 0;
}

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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N); for (auto &x : A) cin >> x;
    vector<bool> memo(K+1, false);
    for (int i = 0; i < K; i++) {
        if (!memo[i]) {
            for (int j = 0; j < N; j++) {
                if (i+A[j] <= K) memo[i+A[j]] = true;
            }
        }
    }
    if (memo[K]) cout << "First" << endl;
    else cout << "Second" << endl;
}


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

int main() {
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    for(int i=0;i<T;i++) cin >> a[i];
    sort(a.begin(), a.end());
    for(int i=0;i<T-1;i++) a[T-1]-=a[i];
    cout << (a[T-1]>1?a[T-1]-1:0) << endl;
    return 0;
}

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


int main(){
    int a,b,c;
    cin >> a >>b >> c;
    if(a==b){
        printf("%d\n",c);
    }
    else if(b==c){
        printf("%d\n",a);
    }
    else printf("%d\n",b);
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
  char s[3];
  scanf("%s", s);
  int c = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o') c++;
  }
  printf("%d\n", 700+100*c);
  
  return 0;
}


Measured memory_bytes: 128
s = input()
odd = "RUD"  
even = "LUD"
frag = True
for i in range(len(s)): 
    if i%2 == 0 and s[i] not in odd:
        frag = False
        break 
    elif i%2 != 0 and s[i] not in even:
        frag = False

if frag:
    print("Yes")
else:
    print("No")

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

void solve()
{
   ll a,b,c,d,x,y,z,w;
   cin>>a>>b>>c>>d;
   x=b*c, y=b*d;
   z=a*c, w=a*d;
   cout<<max({x,y,z,w})<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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


Measured memory_bytes: 3656
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        long[] a = sc.nextLongArray(n);
        long d = lcm(a);
        long m = 0;
        for(long v : a){
            m += d/v;
        }
        System.out.println((double)d/(double)m);
    }
    
    private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }

    private static long gcd(long[] input){
        long result = input[0];
        for(int i = 1; i < input.length; i++)
        {
            result = gcd(result, input[i]);
        }
        return result;
    }
    
    private static long lcm(long a, long b){
        return a * (b / gcd(a, b));
    }
    
    private static long lcm(long[] input){
        long result = input[0];
        for(int i = 1; i < input.length; i++)
        {
            result = lcm(result, input[i]);
        }
        return result;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        UL Q; cin >> Q;
        vector<int> A;
        rep(i, Q) {
            UL c; cin >> c;
            if (c == 0) {
                UL x; cin >> x; A.push_back(x);
            }
            if (c == 1) {
                UL p; cin >> p; cout << A[p] << endl;
            }
            if (c == 2) {
                A.pop_back();
            }
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3872
#!/usr/bin/env python3
import sys


def solve(S: str):
    l = ['Sunny', 'Cloudy', 'Rainy']
    print(l[l.index(S) + 1] if S != 'Rainy' else 'Sunny')
    return


# Generated by 1.1.6 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()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

def b_ser(bot, top, a, target, u_r_f = nil, mm = nil)
  mid = (bot + top)/2
  if(a[mid] == target)
    if(u_r_f == nil)
      return mid
    else
      return mid if(bot == mid)
      return b_ser(bot, mid, a, target, u_r_f, mid)
    end
  end
  if(bot == mid)
    return nil if(u_r_f == nil)
    return mid + ((a[mid] < target)? 1 : 0)
  end
  return (a[mid] > target)? b_ser(bot, mid, a, target, u_r_f, mm) : b_ser(mid, top, a, target, u_r_f, mm)
end

n = inp[0]
a = inp.sort
b = inp.sort
c = inp.sort
abt = []
a.size.times do |i|
  abt[i] = b_ser(0,n,b,a[i]+1,true)
end
bct = []
b.size.times do |i|
  bct[i] = b_ser(0,n,c,b[i]+1,true)
end

bcs = na(n,0)
sum = 0
n.times do |i|
  i = n-i-1
  sum += n - bct[i]
  bcs[i] = sum
end
ans = 0
abt.each do |d|
  break if d >= n
  ans += bcs[d]
end
p ans

Measured memory_bytes: 27288
def find(A):
    temp=[]
    ##split into R..RL..L
    left=1
    
    count1=0
    count2=0
    for i in range(len(A)):
        if left==1:
            if A[i]=="R":
                count1+=1
            else:
                
                count2=1
                left=0
        else:
            if A[i]=="L":
                count2+=1
            else:
                temp+=[(count1,count2)]
                count2=0
                count1=1
                left=1
    temp+=[(count1,count2)]
    return temp

def findout(x,y):
    org=x
    left=0
    right=0
    if x%2==0:
        left+=x//2
        right+=x//2
    else:
        left+=(x-1)//2+1
        right+=x-((x-1)//2+1)
    
    x=y
    if x%2==0:
        right+=x//2
        left+=x//2
    else:
        right+=(x-1)//2+1
        left+=x-((x-1)//2+1)
    
    return [0]*(org-1)+[left]+[right]+[0]*(y-1)


def findans(A):
    temp=find(A)
    ans=[]
    #print(temp)
    for (x,y) in temp:
        #print(findout(x,y))
        ans+=findout(x,y)
    return ans
s=input()
print(*findans(s))

Measured memory_bytes: 53400
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> A(N);
	for (Int i = 0; i < N; i++) {
		cin >> A[i];
	}

	sort(A.begin(), A.end());

	Int temp = A[0];
	Int cnt = 0;
	Int num = 0;
	Int diff = 0;
	//vector<Int> card(N);
	for (Int i = 0; i < N; i++) {
		if (A[i] == temp) {
			cnt++;
		}
		if(A[i]!=temp){
			//card[num] = cnt;
			diff += cnt - 1;
			temp = A[i];
			num++;
			cnt = 1;
		}
		if (i == N - 1) {
			//card[num] = cnt;
			diff += cnt - 1;
		}
	}

	/*Int diff = 0;
	for (Int i = 0; i <= num; i++) {
		diff += card[i] - 1;
	}*/

	cout << (diff % 2 ? num : num + 1) << "\n";

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> s(H + 1, vector<char>(W + 1, '.'));
    rep(0, i, H)
    {
        rep(0, j, W)
        {
            cin >> s[i][j];
        }
    }
    vector<int> dx(4), dy(4);
    dx = {1, 0, -1, 0};
    dy = {0, 1, 0, -1};
    rep(1, i, H + 1)
    {
        rep(1, j, W + 1)
        {
            bool flag = false;
            if (s[i][j] == '#')
            {
                rep(0, k, 4)
                {
                    if (s[i + dx[k]][j + dy[k]] == '#')
                    {
                        flag = true;
                    }
                }
                if (!flag)
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
//fizzbuzz
#include "iostream"
#define ll long long int
using namespace std;
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
  
int main()
{

    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                sum+= gcd(i,gcd(j,k));
                
            }
            
        }
    }

    cout<<sum<<endl;

}


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

template<typename M>
struct segment_tree{
	typedef function<M(M, M)> F;
	int size;//2冪
	vector<M> val;//1-indexed
	F f;//結合関数
	M e;//単位元

	segment_tree(int N, vector<M> &data, F f, M e) : f(f), e(e){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, e);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = N; i < size; i++) val[size + i] = e;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	//k番目の要素をxに変更する
	void update(int k, M x){
		k += size;
		val[k] = x;
		while(k /= 2) val[k] = f(val[2 * k], val[2 * k + 1]);
	}

	//[l, r)の演算の結果を返す
	M query(int l, int r){
		M L = e, R = e;
		for(l += size, r += size; l < r; l /= 2, r /= 2){
			if(l & 1) L = f(L, val[l++]);
			if(r & 1) R = f(val[--r], R);
		}
		return f(L, R);
	}
};




//(int, sum, 0)
int sum(int x, int y){
	return x + y;
}

signed main(){
	int N, i;
	scanf("%lld", &N);
	vector<int> P(N + 2), Pinv(N + 2);
	for(i = 1; i <= N; i++){
		scanf("%lld", &P[i]);
		Pinv[P[i]] = i;
	}
	vector<int> data(N + 2, 0);
	data[0] = 2;
	data[N + 1] = 2;
	segment_tree<int> t(N + 2, data, sum, 0);
	int ans = 0;
	for(i = N; i > 0; i--){
		int j = Pinv[i];
//		printf("(i, j) = (%lld, %lld)\n", i, j);
		int l, h, r;
		int a, b, c;

		l = 0;
		r = j;
		while(r - l > 1){
			h = (l + r) / 2;
			if(t.query(h, j) >= 2){
				l = h;
			}
			else{
				r = h;
			}
		}
		a = l;

		l = 0;
		r = j;
		while(r - l > 1){
			h = (l + r) / 2;
			if(t.query(h, j) >= 1){
				l = h;
			}
			else{
				r = h;
			}
		}
		b = l;

		l = j;
		r = N + 1;
		while(r - l > 1){
			h = (l + r) / 2;
			if(t.query(j + 1, h + 1) >= 1){
				r = h;
			}
			else{
				l = h;
			}
		}
		c = r;
//		printf("(a, b, c) = (%lld, %lld, %lld)\n", a, b, c);

		ans += i * (b - a) * (c - j);


		l = 0;
		r = j;
		while(r - l > 1){
			h = (l + r) / 2;
			if(t.query(h, j) >= 1){
				l = h;
			}
			else{
				r = h;
			}
		}
		a = l;

		l = j;
		r = N + 1;
		while(r - l > 1){
			h = (l + r) / 2;
			if(t.query(j + 1, h + 1) >= 1){
				r = h;
			}
			else{
				l = h;
			}
		}
		b = r;

		l = j;
		r = N + 1;
		while(r - l > 1){
			h = (l + r) / 2;
			if(t.query(j + 1, h + 1) >= 2){
				r = h;
			}
			else{
				l = h;
			}
		}
		c = r;
//		printf("(a, b, c) = (%lld, %lld, %lld)\n", a, b, c);

		ans += i * (j - a) * (c - b);


		t.update(j, 1);
//		printf("ans = %lld\n", ans);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,c,d,e;
   string s,t;
   while(cin>>s>>t)
   {
       a=0;
       if(s[0]==t[0])a++;
       if(s[1]==t[1])a++;
       if(s[2]==t[2])a++;
       cout<<a<<endl;

   }




    return 0;
}


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

const int vmax=10010;
const int inf=1<<29;
struct edge{int to,cap,rev;};
vector<edge> graph[vmax];
int level[vmax],iter[vmax];

int max_flow(int s,int t){
	auto bfs=[&](int s,int t){
		rep(i,vmax) level[i]=-1;
		queue<int> q;
		level[s]=0,q.push(s);
		while(!q.empty()){
			int v=q.front();q.pop();
			for(auto &e:graph[v]){
				if(e.cap>0 && level[e.to]<0){
					level[e.to]=level[v]+1;
					q.push(e.to);
				}
			}
		}
		return level[t]>=0;
	};
	function<int(int,int,int)> dfs=[&dfs](int v,int t,int f){
		if(v==t) return f;
		for(int &i=iter[v];i<graph[v].size();i++){
			edge &e=graph[v][i];
			if(e.cap>0 && level[v]<level[e.to]){
				int d=dfs(e.to,t,min(f,e.cap));
				if(d>0){
					e.cap-=d;
					graph[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	};
	int flow=0;
	while(bfs(s,t)){
		rep(i,vmax) iter[i]=0;
		while(1){
			int f=dfs(s,t,inf);
			if(f==0) break;
			flow+=f;
		}
	}
	return flow;
}

int main(void){
	int N,M;
	cin >> N >> M;
	rep(i,M){
		int a,b,c;
		cin >> a >> b >> c;
		graph[a].push_back({b,c,(int)graph[b].size()});
		graph[b].push_back({a,0,(int)graph[a].size()-1});
	}
	cout << max_flow(0,N-1) << endl;
	return 0;
}

Measured memory_bytes: 1580
#include <iostream>
#include <deque>

using namespace std;

int main()
{
    long long n,q;
    cin>>n>>q;
    deque < deque<int> > a(n);
    while(q--)
    {
        int b;
        cin>>b;
        if(b==0)
        {
           long long t,x;
           cin>>t>>x;
           a[t].push_back(x);
        }
        else if(b==1)
        {
            long long t;
            cin>>t;
            if(!a[t].empty())
            {
                cout<<a[t][0]<<endl;
            }
        }
        else
        {
            long long t;
            cin>>t;
            if(!a[t].empty())
            {
                a[t].pop_front();
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4392
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    
    cin>>a>>b;
    
    if(a==1&&b!=1)cout<<"Alice"<<endl;
    else if(b==1&&a!=1)cout<<"Bob"<<endl;
    else if(a>b)cout<<"Alice"<<endl;
    else if(a<b)cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int s[3][3];
int check()
{
    if(s[0][1] - s[0][0] != s[1][1] - s[1][0] || s[0][1] - s[0][0] != s[2][1] - s[2][0])return 0;
    if(s[0][2] - s[0][0] != s[1][2] - s[1][0] || s[0][2] - s[0][0] != s[2][2] - s[2][0])return 0;
    if(s[0][1] - s[0][2] != s[1][1] - s[1][2] || s[0][1] - s[0][2] != s[2][1] - s[2][2])return 0;
    if(s[0][0] - s[1][0] != s[0][1] - s[1][1] || s[0][0] - s[1][0] != s[0][2] - s[1][2])return 0;
    if(s[0][0] - s[2][0] != s[0][1] - s[2][1] || s[0][0] - s[2][0] != s[0][2] - s[2][2])return 0;
    if(s[2][0] - s[1][0] != s[2][1] - s[1][1] || s[2][0] - s[1][0] != s[2][2] - s[1][2])return 0;
    return 1;
}
int main()
{
    for(int i = 0;i < 3;i ++)
    {
        for(int j = 0;j < 3;j ++)
        {
            cin>>s[i][j];
        }
    }
    if(check())cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}//#########################################

bool isPrime(ll n){
    for(ll i = 2; i <= n / i; ++i)
        if(n % i == 0)
            return 0;
    return n > 1;
}


vector<ll> getDivisors(ll n){
    vector<ll> ret;
    for(int i = 1; i <= n / i; ++i){
        if(n % i == 0){
            ret.push_back(i);
            if(n / i != i)
                ret.push_back(n / i);
        }
    }
    return ret;
}



ll GCD(ll a, ll b){
    return b ? GCD(b, a % b) : a;
}

ll LCM(ll a, ll b){
    return a / GCD(a, b) * b;
}

vector<ll> ret;

vector<ll> getFactors(ll n){
    // vector<ll> ret;
    for(ll i = 2; i <= n / i; ++i)
        while(n % i == 0){
            ret.push_back(i);
            n /= i;
        }

    if(n != 1){
        ret.push_back(n);
    }
    return ret;
}
const int N = 1e6 + 5;
int vst[N], cnt[N];
vector<int> primes;
void seive(){
    for(int i = 2; i < N; ++i){
        if(vst[i])
            continue;
        primes.push_back(i);
        for(ll j = 1LL * i * i; j < N; j +=i)
            vst[j] = 1;
    }
}

// Modified sieve for number of divisors
int cnt1[N];
void modSeive(){
    for(int i = 1; i < N; ++i){
        for(int j = i; j < N; j += i)
            ++cnt1[j];
    }
}

// Modified sieve for number of prime factors
int cnt2[N];
void mod2Sieve(){
    for(int i = 2; i < N; ++i){
        if(vst[i])
            continue;
        for(ll j = i; j < N; j +=i){
            vst[j] = 1;
            int cntP = 0;// calculate the power of i exists in j
            int curr = j;
            while (curr % i == 0) {
                ++cntP;
                curr /= i;
            }
            cnt2[j] += cntP;
        }
    }
}
//####################################################################################################

int main() {
    //  freopen("", "r", stdin);
    // freopen(" ","w",stdout);
char a[3][3];
for(int i=0;i<3;i++)
    for(int j=0;j<3;j++){
        cin>>a[i][j];
        if(i==j) cout<<a[i][j];
    }
}



Measured memory_bytes: 2304