akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

const int MAX_N = 51;
const int MAX_M = 21;

struct edge {
    int to, id;
    edge(const int _to, const int _id) : to(_to), id(_id){}
};

vector<edge> G[MAX_N];
unsigned long long cv[MAX_M], two[MAX_N];

bool dfs(const int u, const int p, const int t, unsigned long long& bs){
    if(u == t) return true;
    for(const edge& e : G[u]){
        if(e.to != p){
            bs |= (1ULL << e.id);
            if(dfs(e.to, u, t, bs)){
                return true;
            }else{
                bs ^= (1ULL << e.id);
            }
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n-1; ++i){
        int a, b;
        cin >> a >> b;
        G[a-1].emplace_back(b-1, i), G[b-1].emplace_back(a-1, i);
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        dfs(a, -1, b, cv[i]);
    }
    two[0] = 1;
    for(int i = 0; i < n; ++i) two[i+1] = two[i] * 2;
    long long ans = 0;
    for(int i = 0; i < (1 << m); ++i){
        unsigned long long st = 0;
        for(int j = 0; j < m; ++j){
            if(i >> j & 1) st |= cv[j];
        }
        if(__builtin_popcount(i) & 1) ans -= two[n - 1 - __builtin_popcountll(st)];
        else ans += two[n - 1 - __builtin_popcountll(st)];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
/*
*/

//#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 510031;

long long a,b;

string st;
long long ans;

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	cin>>st;
	ans=st.size();
	for (int i=0;i+1<st.size();i++){
		if (st[i]!=st[i+1]){
			int d1=i+1;
			int d2=st.size()-d1;
			ans=min(ans,0ll+max(d1,d2));
		}
	}
	cout<<ans<<endl;

	cin.get(); cin.get();
	return 0;
}


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

int main() {
  int ntree;
  while(cin >> ntree, ntree) {
    int fieldw, fieldh;
    cin >> fieldw >> fieldh;
    vector<vector<bool> > treeField(fieldw, vector<bool>(fieldh, false));
    for(int i = 0; i < ntree; ++i) {
      int x, y;
      cin >> x >> y;
      treeField[x - 1][y - 1] = true;
    }
    // for(auto i = treeField.begin(); i != treeField.end(); ++i) {
    //   for(auto j = (*i).begin(); j != (*i).end(); ++j) cout << *j;
    //   cout << endl;
    // }
    int qw, qh;
    cin >> qw >> qh;
    vector<int> candidits;
    for(int x = 0; x < fieldw - qw + 1; ++x) for(int y = 0; y < fieldh - qh + 1; ++y) {
      vector<int> rows;
      for(int i = x; i < x + qw; ++i) rows.push_back(accumulate(treeField[i].begin() + y, treeField[i].begin() + y + qh, 0));
      candidits.push_back(accumulate(rows.begin(), rows.end(), 0));
      // cout << accumulate(rows.begin(), rows.end(), 0);
    }
    cout << *max_element(candidits.begin(), candidits.end()) << endl;
  }
  return 0;
}

Measured memory_bytes: 1288
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const int MAX = 4;

ll M[200][200];
vector<ll> v;
void wf(int n) {
	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				if (M[k][j] == INF) continue;
				if (M[i][k] == INF) continue;
				M[i][j] = min(M[i][j], M[i][k] + M[k][j]);
			}
		}
	}
	//rep(i, 0, n) {
	//	rep(j, 0, n) {
	//		//if (M[i][k] == INF) continue;
	//		rep(k, 0, n) {
	//			//if (M[k][j] == INF) continue;
	//			M[i][j] = min(M[i][j], M[i][k] + M[k][j]);
	//		}
	//	}
	//}
}
int main() {
	ll n, m, r; cin >> n >> m >> r;

	rep(i, 0, r) {
		ll R; cin >> R;
		v.push_back(--R);
	}

	rep(i, 0, n) {
		rep(j, 0, n) {
			M[i][j] = INF;
		}
	}

	//wf;
	rep(i, 0, m) {
		ll a, b, c; cin >> a >> b >> c;
		a--, b--;
		M[a][b] = c;
		M[b][a] = c;
	}
	wf(n);

	ll minV = INF;

	sort(v.begin(), v.end());
	do {
		ll distance = 0;
		rep(i, 0, r - 1) {
			distance += M[v[i]][v[i + 1]];
		}
		minV = min(minV, distance);
	} while (next_permutation(v.begin(), v.end()));

	cout << minV << endl;
	return 0;
}

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

whole = 0
right = 0

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            whole += 1
            if i < j:
                right += 1

mod = 10 ** 9 + 7
ans = right * K
ans += whole * (K - 1) * K // 2

print(ans % mod)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
#define int long long
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;

int h,w;
char s[444][444];
int used[444][444];
int used2[444][444];
int cnt_w[444][444];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void rec2(int x,int y,int k){
  if(used2[x][y])return;
  used2[x][y]=1;
  cnt_w[x][y]=k;
  for(int i=0;i<4;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(nx<0||h<=nx||ny<0||w<=ny)continue;
    if(s[x][y]==s[nx][ny])continue;
    rec2(nx,ny,k);
  }
}

int rec(int x,int y){
  if(used[x][y])return 0;
  used[x][y]=1;
  int sum=(s[x][y]=='.');
  for(int i=0;i<4;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(nx<0||h<=nx||ny<0||w<=ny)continue;
    if(s[x][y]==s[nx][ny])continue;
    sum+=rec(nx,ny);
  }
  return sum;
}

signed main(){
  cin>>h>>w;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
	 cin>>s[i][j];

  int ans=0;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
	 if(used[i][j]){
	   if(s[i][j]=='#')ans+=cnt_w[i][j];
	   continue;
	 }
	 int k=rec(i,j);
	 //	 DBG(k);
	 rec2(i,j,k);
	 if(s[i][j]=='#')ans+=cnt_w[i][j];
	 //	 DBG(ans);
    }
  }

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


Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  sort(l.begin(), l.end());
  ll ans = 0;
  rep(i,n-2) {
    for (int j = i+1; j < n-1; j++)
    {
      int k = l[i] + l[j];
      auto iter = lower_bound(l.begin(), l.end(), k) - l.begin();
      if (iter > j) ans += (iter-j-1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
N,K = map(int,input().split())
H = [int(x) for x in input().split()]

def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)

Measured memory_bytes: 13980
n = int(input())
L = list(map(int,input().split()))
ans, cnt, tmp = 0, 0, L[0]

for i in range(1,n):
  if tmp >= L[i]:
    tmp = L[i]
    cnt += 1
    ans = max(ans, cnt)
  else:
    cnt = 0
    tmp = L[i]
print(ans)

Measured memory_bytes: 20384
# coding: utf-8
# Your code here!

n,m = map(int,input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = True

for i in range(m):
  if a[i] < sum(a) / (4*m):
    ans = False

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


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

int main(){
  ull n;
  cin >> n;
  set<ull> S;
  rep(i,n){
    ull num;
    cin >> num;
    if( S.count(num) ){
      S.erase(num);
    }else{
      S.insert(num);
    }
  }
  cout << S.size() << endl;
  return 0;
}


Measured memory_bytes: 4864
package main

import (
	"fmt"
)

func main() {
	var A, B, N int
	countA := 0
	countB := 0

	fmt.Scanf("%d %d %d", &N, &A, &B)

	var S string
	fmt.Scanf("%s", &S)
	// fmt.Println(S)

	for i := 0; i < N; i++ {
		if S[i] == 'a' {
			if countA+countB < A+B {
				countA++
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}

		} else if S[i] == 'b' {
			if countA+countB < A+B && countB < B {
				countB++
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		} else {
			fmt.Println("No")
		}
	}

}


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

int h, w;
string field[51];

int dp[51][51];

int main () {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> field[i];
	}
	memset(dp, 0x7f, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int x = dp[i][j];
			if (j > 0) {
				x = min(x, dp[i][j - 1]);
			}
			if (i > 0) {
				x = min(x, dp[i - 1][j]);
			}
			dp[i][j] = x + field[i][j] - '0';
		}
	}
	
	cout << dp[h - 1][w - 1] << endl;
	
	return 0;
}

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

int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;

  if (A*B==C*D){
    cout << A*B << endl;
  }
    else{
      if(A*B>C*D){
        cout << A*B << endl;
      }
      else{
        cout << C*D << endl;
      }
    }
}


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

int main(void)
{
    int a, b;

    cin >> a >> b;

    if (a < b){
        cout << "a < b" << "\n";
    }
    else if (a > b){
        cout << "a > b" << "\n";
    }
    else {
        cout << "a == b" << "\n";
    }

    return (0);
}



Measured memory_bytes: 3068
from statistics import median
R,G,B,N = map(int,input().split())
count = 0
n_max = max(R,G,B)
n_mid = median([R,G,B])
n_min = min(R,G,B)
for i in range(N//n_max + 1):
  x = N - i*n_max
  for j in range(x//n_mid + 1):
    y = x - j*n_mid
    if y % n_min == 0:
      count += 1
print(count)

Measured memory_bytes: 5404
n = int(input())
a = list(map(int,input().split()))
def calc(t):
	global a
	ans = 0
	s = 0
	for i in a:
		s += i
		if s * t <= 0:
			ans += abs(s-t)
			s = t
		t *= -1
	return ans
print(min(calc(1),calc(-1)))


Measured memory_bytes: 14332
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

LL k,a,b,c=1;

int main()
{
    cin>>k>>a>>b;
    if(a!=c){
        k = k - a + c;
        c+=a-c;
    }
    // cout<<"k: "<<k<<endl;
    // cout << "c: "<<c << endl;
    while(k>0){ 
        // cout<<"k: "<<k<<endl;
        // cout << "c: "<<c << endl;
        if(c+1<b-a+c&&k>=2){
            k--;
            c=b-a+c;
        }else{
            c++;
        }
        k--;
        // cout<<k<<endl;
    }
    cout<<c<<endl;
    
}

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

using namespace std;

int main()
{
    int A, B, K;
    cin >> A >> B >> K;

    if (A > B) {
        swap(A, B);
    }

    vector<int> v;

    for (int i = 1; i <= A; ++i) {
        if (A % i == 0 && B % i == 0) {
            v.emplace_back(i);
        }
    }

    std::cout << v[v.size() - K] << std::endl;

    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

class KMP {
  int m;
  string pattern;
  vector<int> fail;

public:
  KMP(const string &pattern) : m(pattern.size()), pattern(pattern), fail(m + 1) {
    int j = fail[0] = -1;
    for (int i = 1; i <= m; ++i) {
      while (j >= 0 && pattern[j] != pattern[i - 1]) j = fail[j];
      fail[i] = ++j;
    }
  }

  vector<int> findAll(const string &target) { // matched substrs positions (0-indexed)
    int n = target.size();
    vector<int> indices;
    for (int i = 0, j = 0; i < n;) {
      if (target[i] == pattern[j]) {
        i++, j++;
      } else if (j == 0) {
        i++;
      } else {
        j = fail[j];
      }
      if (j == m) {
        indices.emplace_back(i - m);
        j = fail[j];
      }
    }
    return indices;
  }
};

main {
  string t, p;
  cin >> t >> p;
  KMP kmp(p);
  for (auto i : kmp.findAll(t)) cout << i << endl;
}



Measured memory_bytes: 3200
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
    int u, minv;
    int d[MAX], p[MAX], color[MAX];

    for (int i=0; i<n; i++) {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    d[0] = 0;

    while(1) {
        minv = INFTY;
        u = -1;
        for (int i=0; i<n; i++) {
            if (minv>d[i] && color[i]!=BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u==-1) break;
        color[u] = BLACK;
        for (int v=0; v<n; v++) {
            if (color[v]!=BLACK && M[u][v]!=INFTY) {
                if (d[v] > M[u][v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum=0;
    for (int i=0; i<n; i++) {
        if (p[i]!=-1) sum += M[i][p[i]];
    }

    return sum;
}

int main() {
    cin >> n;

    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            int e; cin >> e;
            M[i][j] = (e==-1) ? INFTY : e;
        }
    }

    cout << prim() << endl;

    return 0;
}


Measured memory_bytes: 3096
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        a: i32
    }

    println!("{}", a + a * a + a * a * a);
}


Measured memory_bytes: 2140
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;
 
void solve(){
	int N;
	LL K;
	cin >> N >> K;
	vector< pair<int,int> > v(N);
	for(int i=0;i<N;++i){
		cin >> v[i].first >> v[i].second;
	}
	sort( v.begin(), v.end() );
	LL sum = 0;
	for(int i=0;i<N;++i){
		sum += v[i].second;
		if( K <= sum ){
			cout << v[i].first << endl;
			return;
		}
	}
	
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


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

using namespace std;
using ll = long long;

ll solve(ll val) {
	ll lo = 0, hi = 1000;
	while(lo <= hi) {
		ll mid = lo + (hi - lo) / 2;
		ll tmp = mid * mid * mid * mid * mid;
		if(tmp == val) return mid;
		if(tmp < val) lo = mid + 1;
		else hi = mid - 1;
	}
	return -1;
}

int main() {
	int x;
	scanf("%d", &x);

	for(ll a = 0; ; a++) {
		ll val = a * a * a * a * a - x;
		ll tmp = solve(abs(val));
		if(tmp == -1) continue;
		if(val < 0) tmp *= -1;
		printf("%lld %lld\n", a, tmp);
		break;
	}
}


Measured memory_bytes: 3824
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;
*/

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define debug(aa, a) fprintf(stderr, aa, a)

using ll =long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	string s;
	scans(s);
	int ans = 0;
	rep(i, n - 2) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')++ans;
	}
	printf("%d\n", ans);

	Please AC;
}


Measured memory_bytes: 888
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

   int x, a; cin>>x>>a;

   if(x < a)cout<<0<<"\n";
   else cout<<10<<"\n";

    







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 256
X, Y = map(int, input().split())


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7
N = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

if X == Y // 2 or Y == X//2:
    print(1)
    exit(0)

X, Y = max(X, Y), min(X, Y)

diff = X - Y
x = X - 2*diff

if x % 3 != 0:
    print(0)
    exit(0)
else:
    k = x // 3
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    ans = cmb(2*k+diff, k, mod)
    print(ans)


Measured memory_bytes: 122032
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
//Binary Indexed Tree
struct BIT{
private:
	int n;
	vector<int> node;
public:
	BIT(int N){
		node.resize(N+1,0);
		n=N;
	}
	int sum(int i){
		if(!i)
			return 0;
		return node[i]+sum(i-(i&-i));
	}
	void add(int i,int x){
		if(i>n)
			return;
		node[i]+=x;
		add(i+(i&-i),x);
	}
};
//Binary Indexed Tree
int main(){
	int N;
	cin>>N;
	vint A;
	A.pb(0);
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
	}
	//二分探索
	//medianのmedianがmid以下であれば、high=mid
	int low=0,high=MOD;
	while(high-low>1){
		int mid=(high+low)/2;
		//二値化
		ll B[SIZE]={};
		for(int i=1;i<=N;i++){
			if(A[i]<=mid)
				B[i]=-1;
			else
				B[i]=1;
		}
		//累積和
		for(int i=1;i<=N;i++)
			B[i]+=B[i-1];
		//offsetを足しておく
		for(int i=0;i<=N;i++)
			B[i]+=SIZE;
		//転倒数
		ll temp=0;
		BIT T(N+SIZE+100);
		for(int i=0;i<=N;i++){
			//B[i]より大きいものの和
			temp+=T.sum(N+SIZE+99)-T.sum(B[i]);
			//B[i]に++
			T.add(B[i],1);
		}
		if(temp>=(ll)N*(N+1)/2/2+1LL)
			high=mid;
		else
			low=mid;
	}
	cout<<high<<endl;
	return 0;
}

Measured memory_bytes: 2296
N=int(input())
w_list=list(map(int,input().split()))
s=sum(w_list)
sa_list=[]
for i in range(N):
    w=sum(w_list[:i+1])
    nokori=s-w
    sa=abs(w-nokori)
    sa_list.append(sa)
print(min(sa_list))
    
    

Measured memory_bytes: 2940
// Problem : A - 500 Yen Coins
// Contest : AtCoder - AtCoder Beginner Contest 150
// URL : https://atcoder.jp/contests/abc150/tasks/abc150_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int k,x;
    cin>>k>>x;
    if(500*k >= x) cout<<"Yes";
    else cout<<"No";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

const int MAX = 2e5 + 111;

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    if (x % y == 0)
        cout << -1;
    else
        cout << x;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rpt(n) for(register int ttxyc=0;ttxyc<n;++ttxyc)//宏定义
using namespace std;
int n,a,ans;map<int,int>m;
main()
{
    scanf("%d",&n);
    rpt(n)scanf("%d",&a),++m[a];
	for(map<int,int>::iterator i=m.begin();i!=m.end();++i)
	{
		pair<int,int>now=*i;
		if(now.first>now.second)ans+=now.second;
		else ans+=now.second-now.first;
	}
	printf("%d\n",ans);
}/**/

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

string str1,str2;
int main(){
int i=0,a=0,b=0;
cin>>i;
for(int i2=0;i2<i;i2++)
	{cin>>str1>>str2;
	if(str1>str2) a+=3;
	else if(str1<str2) b+=3;
	else {a++; b++;}
	}
cout<<a<<" "<<b<<endl;
return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <iomanip>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define MOD 1000000007
using namespace std;
 
int main(){
  long long N, K, Q;
  cin >> N >> K >> Q;
  long A[Q], S[N];
  REP(i,N){
    S[i] = K-Q;
  }
  REP(i,Q){
    cin >> A[i];
    A[i]--;
    S[A[i]]++;
  }
  REP(i,N-1){
    if (S[i] > 0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  if (S[N-1] > 0){
      cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 2176
N = int(input())
s = input()
s = list(s)
s.append(s[0])
SW01 = [[0, 0],[0, 1],[1, 0],[1, 1]]


for i in range(4):
	SW = []
	SW.append(SW01[i][0])
	SW.append(SW01[i][1])
	for loc in range(1, N + 1):
		if s[loc] == "o":
			SW.append(SW[loc-1]^SW[loc])
		else:
			SW.append(SW[loc - 1] ^ (SW[loc]^1))
	if SW[0] == SW[-2] and SW[1] == SW[-1]:
		SW2 = []
		for i in range(N):
			if SW[i] == 0:
				SW2.append('S')
			else:
				SW2.append('W')
		print("".join(SW2))
		exit()


print(-1)

Measured memory_bytes: 62972
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll inf = 3e5+9;
ll n,m,k,col[inf],ans;
vector<ll> row[inf];
set<pair<ll,ll> > s;
int main(){

    cin>>n>>m>>k;
    for(ll i=1;i<=k;i++){
            ll a,b;
        cin>>a>>b;
        row[a].push_back(b);
        col[b]++;
    }
    for(ll i=1;i<=m;i++)
        s.insert(make_pair(-col[i],i));

    for(ll i=1;i<=n;i++){
        for(auto o:row[i]){
            s.erase(make_pair(-col[o],o));
            col[o]--;
            s.insert(make_pair(-col[o],o));
        }
        ans = max(ans,(ll)row[i].size()- (*s.begin()).first );
        for(auto o:row[i]){
            s.erase(make_pair(-col[o],o));
            col[o]++;
            s.insert(make_pair(-col[o],o));
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 41132
#include<bits/stdc++.h>
using namespace std;
int main(){
    double x1, x2, y1, y2;
    cin >> x1 >> x2 >> y1 >> y2;
    //double ans=0;
    cout <<fixed << setprecision(8) <<sqrt(pow(x1-y1, 2)+pow(x2-y2, 2))<< endl;
    return 0;
}


Measured memory_bytes: 3288
n = int,input()
a = list(map(int, input().split()))
total = []
ans = 0
dic = {0:1}
for i in range(0,len(a)):
    if(i == 0):
        total.append(a[0])
    else:
        total.append(total[i-1] + a[i])
    ans += dic.get(total[i],0)
    if total[i] in dic:
        dic[total[i]] += 1
    else:
        dic[total[i]] = 1
print(ans)


Measured memory_bytes: 38652
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define INFI LLONG_MAX
int main(){
	 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];
}
int ans=0;
for(int i=0;i<n;i++){
	if(arr[i]%2==0){
		if(arr[i]%3==0||arr[i]%5==0){
continue;}
else{
	ans=1;
	break;

}
		
	}
}
	if(ans==0){
		cout<<"APPROVED";
	}
	else{
		cout<<"DENIED";
	}
}




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

using namespace std;

int main() {
	int n; cin >> n;
	int dp[500] = {0};
	for (int i = 0; i < n; ++i) {
		int s, l, p; cin >> s >> l >> p;
		for (int w = s; w <= l; ++w) {
			for (int from = 0; from < 500; ++from) {
				if (from + w < 500) {
					dp[from+w] = max(dp[from+w], dp[from]+p);
				}
			}
		}
	}
	int m; cin >> m;
	vector<int> v;
	bool f = true;
	for (int t = 0; t < m; ++t) {
		int w; cin >> w;
		if (dp[w] > 0) v.push_back(dp[w]);
		else f = false;
	}
	if (f) {
		for (int i = 0; i < v.size(); ++i) {
			cout << v[i] << endl;
		}
	}
	else {
		cout << -1 << endl;
	}
}

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

using namespace std;

namespace mod {

const int mod = 1000000007;

class MInt;
MInt Pow(const MInt &base, long long exp);
MInt Inv(const MInt &n);

class MInt {
  long long n_;
public:
  MInt() : n_(0) {}
  MInt(long long n) : n_((n % mod + mod) % mod) {}

  MInt& operator+=(const MInt &rhs) {
    n_ += rhs.n_;
    if (n_ >= mod) {
      n_ -= mod;
    }

    return *this;
  }
  
  MInt& operator-=(const MInt &rhs) {
    n_ += mod - rhs.n_;
    if (n_ >= mod) {
      n_ -= mod;
    }

    return *this;
  }

  MInt& operator*=(const MInt &rhs) {
    n_ = n_ * rhs.n_ % mod;
    return *this;
  }

  MInt& operator/=(const MInt &rhs) {
    return (*this) *= Inv(rhs);
  }

  long long Get() {
    return n_;
  }
};

MInt operator-(const MInt &lhs, const MInt &rhs) {
  MInt res(lhs);
  return res -= rhs;
}

MInt operator+(const MInt &lhs, const MInt &rhs) {
  MInt res(lhs);
  return res += rhs;
}

MInt operator*(const MInt &lhs, const MInt &rhs) {
  MInt res(lhs);
  return res *= rhs;
}

MInt operator/(const MInt &lhs, const MInt &rhs) {
  MInt res(lhs);
  return res /= rhs;
}

MInt Pow(const MInt &base, long long exp) {
  if (exp == 0) {
    return 1;
  }
  
  auto a = Pow(base, exp / 2);
  a *= a;
  if (exp % 2 == 1) {
    a *= base;
  }
  
  return a;
}

MInt Inv(const MInt &n) {
  return Pow(n, mod - 2);
}
}

int factorial(int n) {
  return n <= 1 ? 1 : factorial(n - 1) * n;
}

class BinCoef {
  vector<mod::MInt> f;
  vector<mod::MInt> f_inv;
public:
  BinCoef(int n): f(n + 1), f_inv(n + 1) {
    f[0] = f[1] = 1;
    for (int i = 2; i <= n; i++) {
      f[i] = i * f[i - 1];
    }
  }

  mod::MInt NCM(int n, int m) {
    return f[n] * mod::Inv(f[m] * f[n - m]);
  }
};

int main(int argc, const char *argv[])
{
  int n, k;
  cin >> n >> k;
  k = min(k, n - 1);

  BinCoef bc(n);

  mod::MInt ans(0);
  for (int i = 0; i <= k; i++) {
    ans += bc.NCM(n, i) * bc.NCM(n - 1, i);
  }

  cout << ans.Get() << "\n";
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int MAX;
int search_max(vector<int> a) {
    int max_num = a[0];
    int flag = 0;
    for(int i = 0;i < a.size();i++) {
        if(max_num<a[i]) {
            max_num = a[i];
            flag = i;
        }
    }
    MAX = max_num;
    return flag;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) {
        cin >> a[i];
    }
    int flag = search_max(a);
    for(int i = 0;i < n;i++) {
        if(flag!=i) {
            cout << MAX << endl;
        } else {
            int max_num = -1;
            for(int i = 0;i < a.size();i++) {
                if(i!=flag) {
                    if(max_num<a[i]) {
                        max_num = a[i];
                    }
                }
            }
            cout << max_num << endl;
        }
    }
}

Measured memory_bytes: 2416
if __name__=="__main__":
    count = 0
    idx = int(input())
    n = list(map(int,input().split(" ")))
    while True:
        for i in range(idx):
            if n[i]|1==n[i]:
                print(count)
                exit()
            else:
                n[i]=n[i]>>1
        count+=1

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>

int main(void)
{
  int i;
  char s[11], t[11];
  
  scanf("%s", s);
   scanf("%s", t);
  
  for( i = 0; i < 12; i++ ){
      if( s[i] == '\0'){
          printf("Yes\n");
          return 0;
      }
      
      if( s[i] != t[i] ){
          printf("No\n");
          return 0;
      }
      
  }
  

}

Measured memory_bytes: 1608
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll a, b;
  cin>>a>>b;
  cout<<(a*b)/__gcd(a,b);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int N,Q;
vector<int> v;
vector<int> e[200005];

void dfs(int now_v,int parent_v = -1){
  if(now_v != 0)v[now_v] += v[parent_v];

  for(int i : e[now_v]){
    if(i != parent_v){
      dfs(i,now_v);
    }
  }

  return ;
}


int main(){
  cin >> N >> Q;

  v.resize(N,0);

  for(int i = 0;i < N-1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }


  for(int i = 0;i < Q;i++){
    int p,x;
    cin >> p >> x;
    p--;
    v[p] += x;
  }

  dfs(0);

  for(int i = 0;i < N;i++)cout << v[i] << ' ';
}


Measured memory_bytes: 23424
unittest
{
	assert( [ "5 7 4" ].parse.expand.solve == 2 );
	assert( [ "11 10 9" ].parse.expand.solve == 9 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abn = input.front.split.to!( long[] );
	return tuple( abn[ 0 ], abn[ 1 ], abn[ 2 ] );
}

auto solve( long a, long b, long n )
{
	auto x = min( n, b - 1 );
	return ( a * x / b ) - a * ( x / b );
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    ll N;
    cin >> N;

    vector<pair<ll,ll>> pos;
    for (ll i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        pos.push_back({x, y});
    }

    map<pair<ll,ll>,ll> freq;
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            if (i != j) {
                freq[make_pair(pos[i].first-pos[j].first, pos[i].second- pos[j].second)]++;
            }
        }
    }

    ll maxval = 0;
    for (auto itr = freq.begin(); itr != freq.end(); itr++) {
        if (maxval < itr->second) {
            maxval = itr->second;
        }
    }

    cout << N - maxval << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 384
d = [0] * 100
for i in range(int(input()) + 1):
	s = str(i)
	d[int(s[0]) * 10 + int(s[-1])] += 1
r = range(1, 10)
print(sum(d[i * 10 + j] * d[j * 10 + i] for i in r for j in r))


Measured memory_bytes: 3060
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

judge c s = any (all ((==c) . (s!!))) $ [[t..t+2] | t <- [0,3,6]] ++ [[t,t+3,t+6] | t <- [0..2]] ++ [[0,4,8], [2,4,6]]
f s = cond "o" (cond "x" "d" $ judge 'x' s) $ judge 'o' s

main = map f . lines <$> getContents >>= mapM_ putStrLn

Measured memory_bytes: 3568
n,m = gets.chomp.split.map(&:to_i)
lumps = []
m.times do |i|
  lump = gets.chomp.split.map(&:to_i)
  lumps.push(lump)
end
p = gets.chomp.split.map(&:to_i)
len=n
out_put=0
[0, 1].repeated_permutation(len) do |pat| # スイッチの状態
  cnt=0
  lumps.each_with_index do |lump,i|
    on=0
    lump[1..-1].each do |s|
      if pat[s-1]==1
        on+=1
      end
    end
    if on%2==p[i] #この場合はi+1 light is on
      cnt+=1
    end
  end
  if cnt == m
    out_put+=1
  end
end
puts out_put

Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 1000000007;
/*
2000000011 is prime
2000000033 is prime
*/

ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
ll fact[800005],rfact[800005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];
ll res;
char s[500005];

int main(){
    cin >> n;
    multiset<ll> v;
    v.insert(-1);
    v.insert(-1);
    v.insert(n);
    v.insert(n);
    for(i=0;i<n;i++){
    	cin >> x[i];
    }
    for(i=0;i<n;i++){
    	y[x[i]] = i;
    }
    ll place[50];
    ll distance[40];
    for(i=n;i>=1;i--){
    	v.insert(y[i]);
    	auto it = v.find(y[i]);
    	it--;
    	it--;
    	for(j=-2;j<=2;j++){
    		place[j+2] = *it;
    		//pe(place[j+2]);
    		it++;
    	}
    	//el;
    	for(j=0;j<4;j++){
    		distance[j] = place[j+1] - place[j];
    		if(distance[j] >= INF / 5){
    			distance[j] = 0;
    		}
    	}
    	ll res1 = distance[1] * distance[3];
    	ll res2 = distance[0] * distance[2];
    	ans += (res1 + res2) * i;
    	//p(ans);
    }
    p(ans);
    return 0;
}






Measured memory_bytes: 23936
//
// Created by rajshah9914 on 29/03/20.
//

#include <bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
int main() {
    long n,k,h[100000];
    cin>>n>>k;
    vector<long>dp(n,INF);
    for(long i=0;i<n;i++)
        cin>>h[i];
    dp[0]=0;
    for(long i=0;i<n;i++)
    {
        for(long j=i+1;j<=i+k;j++)
        {
            if(j<n)
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 10007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

bool getGcdList(llong x,llong y,vector<llong>& gcd_list){
    int N = min(x,y);
    FOR(i,1,N+1){
        if( ((x%i)==0 && (y%i)==0) ){
            gcd_list.push_back(i);
        }
    }
    return 0;
}

int main(){
    llong A,B,K;
    cin >> A >> B >>K;
    vector<llong> gcd_list;
    getGcdList(A,B,gcd_list);
    sort(gcd_list.begin(),gcd_list.end(),greater<llong>());
    llong ans=gcd_list[K-1];
    cout << ans << endl;
    
    
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int H,W;
int main(){
	while(cin >> H >> W && H>0){
		string s;
		for(int i=0;i<W;i++){
			s += '#';
		}
		for(int i=0;i<H;i++){
			cout << s << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3224
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := []int{}
	for i := 0; i < n; i++ {
		var aa int
		fmt.Scan(&aa)

		a = append(a, aa)
	}

	c := 0
	for i := 0; i < n; i++ {
		minj := i
		for j := i+1; j < n; j++ {
			if a[j] < a[minj] {
				minj = j
			}
		}
		if i != minj {
			a[i], a[minj] = a[minj], a[i]
			c++
		}
	}

	fmt.Print(a[0])
	for i := 1; i < n; i++ {
		fmt.Print(" ")
		fmt.Print(a[i])
	}
	fmt.Println()
	fmt.Println(c)
}



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

ll LCS(string s, string t, ll i, ll j){
    if(i < 0 || j < 0){
        return 0;
    }
    if(s[i] == t[j]){
        return 1 + LCS(s, t, i - 1, j -1);
    } else {
        return max(LCS(s, t, i, j - 1), LCS(s, t, i - 1, j));
    }
}

int main(){
    string s, t;
    cin >> s >> t;

    // cout << LCS(s, t, s.size() - 1, t.size() - 1) << endl;
    ll dp[s.size() + 1][t.size() + 1];
    for(ll i = 0; i < s.size() + 1; i++){
        for(ll j = 0; j < t.size() + 1; j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            } else if(s[i - 1] == t[j - 1]){
                dp[i][j] = 1 + dp[i - 1][j - 1];
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    stack<char> st;
    ll i= s.size();
    ll j = t.size();
    while(dp[i][j] != 0){
        if(s[i - 1] == t[j - 1]){
            st.push(s[i - 1]);
            i--;
            j--;
        } else {
            if(dp[i - 1][j] > dp[i][j - 1]){
                i--;
            } else {
                j--;
            }
        }
    }
    while(!st.empty()){
        cout << st.top();
        st.pop();
    }
    cout << endl;
    // for(ll i = 0; i <= s.size(); i++){
    //     for(ll j = 0; j <= t.size(); j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
}

Measured memory_bytes: 70656
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	String string = scanner.next();
    	if (string.indexOf("A") >= 0 && string.indexOf("B") >= 0) {
    		System.out.println("Yes");
    	}else {
    		System.out.println("No");
    	}
    }
    }


Measured memory_bytes: 22996
L,R = map(int,input().split())
ans = 4*(10**18)
mod = 2019
if R-L >= mod:
  print(0)
  exit()
else:
  for i in range(L,R):
    for j in range(L+1,R+1):
      ans = min(ans,(i*j)%mod)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	string S = res();
	int c = 0;
	for(int i=0;i<3;i++){
		if(S[i] == 'A'){
			c++;
		}
	}
	if(c == 0 || c == 3){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    double r;
    cin >> r;
    cout << fixed << setprecision(3);
    cout << 2 * acos(-1) * r;
    return 0;
}


Measured memory_bytes: 3784
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int A = sc.nextInt();
        if(H%A==0) System.out.println(H/A);
        else System.out.println(H/A+1);
    }
}


Measured memory_bytes: 23252
#include<iostream>

typedef long long ll;
using namespace std;

int main()
{ll A,B,C,X,Y; cin >> A >> B >> C >> X >> Y;

 ll min_sum = 1e10;
 for(ll m = 0; m <= 100000; m++)
 { ll sum = max((X-m),(ll)0)*A + max((Y-m),(ll)0)*B + 2*m*C;
  min_sum = min(min_sum, sum);}
 
 cout << min_sum << endl;
 
 return 0;
}

Measured memory_bytes: 256
o=->a,n{n<1?1:a**n[0]*o[a,n/2]**2%M}
eval'N,A,B='+`dd`.split*?,
a=o[A*=t=o[A+B,-2+M=10**9+7],N]
b=o[B*=t,N]
f=f=1,*(1..2*N).map{|i|f=f*i%M}
N.times{|i|$.=($.+(N+i)*f[N+i-1]*o[f[N-1]*f[i],M-2]*(a+b)*100*t)%M
a=a*B%M
b=b*A%M}
p$.

Measured memory_bytes: 7044