akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

void solve() {
	ll n, k;
	cin >> n >> k;
	ll k2 = k;
	vector<ll> pos, neg;
	int zero = 0;
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		if (a < 0)
			neg.push_back(a);
		else if (a > 0)
			pos.push_back(a);
		else
			zero++;
	}

	sort(pos.rbegin(), pos.rend());
	sort(neg.begin(), neg.end());

	if (pos.size() + neg.size() < k) {
		cout << 0;
		return;
	}

	ll ans = 1;
	int c = 0;

	for (int i = 1; i < neg.size(); i += 2) {
		int cnt = k - 1 - c;
		if (cnt <= 0)
			break;

		if (cnt >= pos.size()) {
			c += 2;
			ans *= neg[i];
			if (ans < 0)
				ans += mod * mod;
			ans %= mod;

			ans *= neg[i - 1];
			if (ans < 0)
				ans += mod * mod;
			ans %= mod;
		}
		else if (neg[i] * neg[i - 1] > pos[cnt] * pos[cnt - 1]) {
			c += 2;
			ans *= neg[i];
			if (ans < 0)
				ans += mod * mod;
			ans %= mod;

			ans *= neg[i - 1];
			if (ans < 0)
				ans += mod * mod;
			ans %= mod;
		}
	}


	int i = 0;
	k -= c;
	while (k && i < pos.size()) {
		ans *= pos[i++];
		ans %= mod;
		k--;
	}

	if (k != 0 && zero != 0) {
		cout << 0;
		return;
	}
	else if (k) {
		k = k2;
		int pos1 = neg.size() - 1, pos2 = 0;
		ans = 1;
		while (k) {
			if (pos1 >= 0 && pos2 < pos.size() && pos[pos2] <= neg[pos1]) {
				ans *= pos[pos2];
				if (ans < 0)
					ans += mod * mod;
				ans %= mod;
				pos2++;
			}
			else if (pos1 >= 0 && pos2 < pos.size() && pos[pos2] > neg[pos1]) {
				ans *= neg[pos1];
				if (ans < 0)
					ans += mod * mod;
				ans %= mod;
				pos1--;
			}
			else if (pos1 >= 0) {
				ans *= neg[pos1];
				if (ans < 0)
					ans += mod * mod;
				ans %= mod;
				pos1--;
			}
			else if (pos2 < pos.size()) {
				ans *= pos[pos2];
				if (ans < 0)
					ans += mod * mod;
				ans %= mod;
				pos2++;
			}
			k--;
		}
	}

	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, std::vector<long long> A){
    vector<i64> ans(N, 0);
    rep(i, N - 1) ans[A[i] - 1]++;
    rep(i, N) cout << ans[i] << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 6432
import sys
import numpy as np
#import math
#import itertools
#import re
#from functools import lru_cache
from collections import deque

input = sys.stdin.readline
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    n, m = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(m)]
    graph = [[] for _ in range(n)]
    for a, b in AB:
        graph[a-1].append(b)
        graph[b-1].append(a)
    dist = np.ones(n)
    dist *= -1
    dist[0] = 0
    queue = deque([1])
    while queue:
        p = queue.popleft()
        for next in graph[p-1]:
            if dist[next-1] == -1:
                dist[next-1] = p
                queue.append(next)

    if np.count_nonzero(dist == -1) > 0:
        print('No')
    else:
        print('Yes')
        for d in dist[1:]:
            print(int(d))


if __name__ == '__main__':
    main()


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

int main() {
    int m, f, r, end_i = 0;
    char result[50];
    for (int i = 0; i < 50; i++) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) {
            end_i = i - 1;
            break;
        }
        if (m == -1 || f == -1) {
            result[i] = 'F';
            continue;
        }
        if ((m + f) >= 80) {
            result[i] = 'A';
            continue;
        } else if ((m + f) >= 65) {
            result[i] = 'B';
            continue;
        } else if ((m + f) >= 50) {
            result[i] = 'C';
            continue;
        } else if ((m + f) >= 30) {
            result[i] = 'D';
            if (r >= 50) result[i] = 'C';
            continue;
        } else {
            result[i] = 'F';
        }
    }
    for (int i = 0; i <= end_i; i++) {
        cout << result[i] << endl;
    }

    return 0;

}


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

using namespace std;

int main() {
  int x;
  cin >> x;
  int a = x / 100;
  int remain = x - (a * 100);
  if (remain > a * 5) {
    puts("0");
  } else {
    puts("1");
  }
  
  return 0;
}



Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    N=[]
    for _ in range(3):
        a,b=map(int,input().split())
        N.append(a)
        N.append(b)
    N=Counter(N)
    NN=N.most_common(1)
    if NN[0][1]==3:
        print("NO")
    else:
        print("YES")


if __name__=='__main__':
    main()

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

int main(){
	string N;
	cin >> N;
	bool is_seven = false;

	for(int i = 0; i < 3; i++){
		if(N.at(i) == '7'){
			is_seven = true;
		}
	}

	if(is_seven){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

ll pow(int a,int b){
  if(b == 0) return 1;
  else return a*pow(a,b-1);
}

int main(){
  
  ll n;
  cin >>n;
  if(n%2 == 1){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for(int i=1;pow(5,i)<=n;i++){
    ans += n/(pow(5,i))/2;
  }
  cout << ans << endl;
}

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

int main(){
    int n,x,i,j,k,ans;
    while(true){
        cin>>n>>x;
        ans=0;
        if(n==0&&x==0)break;
        for(i=1;i<=n-2;i++){
            for(j=i+1;j<=n-1;j++){
                for(k=j+1;k<=n;k++){
                    if(i+j+k==x)ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;
    cout << powint(2, m)*(1900*m+100*(n-m)) << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  if (N/10%111 == 0){
    cout << "Yes" << endl;
  }else if(N%1000%111 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
ll INF = 1e12+10;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
vector<pair<ll, ll> > pairs;
#define print1(x) cerr << "x = " << x << endl;
#define print2(x, y) cerr<< "x,y = "  << x << "," << y << endl;
#define print3(x, y, z) cerr << "x,y,z = " << x << "," << y << "," << z << endl;
#define print4(x, y, z, w) cerr << "x,y,z,w = " << x << "," << y << "," << z << "," << w << endl;

ll N, M;
ll get_num(ll target, vector<ll> A, vector<ll> B, vector<ll> C, ll *sum){
    ll cnt = 0;
    *sum = 0;
    //fprintf(stderr, "=----  target = %d\n", (int)target);
    rep(i, N){
        // �\�[�g���ꂽB�̓��Atarget - A[i] ��菬�������̂̌���cnt0�ɏo��
        //ll cnt0 = lower_bound(B.begin(), B.end(), target - A[i]) - B.begin();
        //cnt += N - cnt0;  // A�z��̒��ŁAtarget - A[i] �ȏ�̌�
        // *sum += (ll)A[i] * (N - cnt0) + (ll)C[N - cnt0 - 1];        
        // B�z��̒��ŁAtarget - A[i] �ȏ�̌�
        ll cnt0 = B.end() - lower_bound(B.begin(), B.end(), target - (ll)A[i]);
        if (cnt0 > 0){
            cnt += cnt0;  
            *sum += (ll)A[i] * cnt0 + (ll)C[cnt0 - 1];
            //fprintf(stderr, "i = %d, %d, %d + %d\n", i, (int)cnt0, (int)A[i] * cnt0, (int)C[cnt0 - 1]);
        }
    }
    return cnt;
}

int main()
{
 
    cin >> N >> M;
    vector<ll> A(N), B(N), C(N);
    
    rep(i, N){
            cin >> A[i];
            B[i] = A[i];
    }
    
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end());
    C[0] = A[0];
    reps(i, 1, N)
        C[i] = C[i - 1] + A[i];
    
    ll upper = A[0] * 2 + 1;
    ll lower = A[N-1] * 2 - 1;
    ll sum;
    while (upper - lower > 1){
        ll target = (upper + lower) /2;
        //fprintf(stderr, "target ===== %d\n", i);
        ll res = get_num(target, A, B, C, &sum);
        //fprintf(stderr, "  res = %d, sum = %d, M = %d, target = %d (%d, %d)\n", 
        //            res, sum, M, i, lower, upper);
        if (res >= M){
            lower = target;
        } else {
            upper = target;
        }
    }
    ll sum1, sum2, ans;
    ll res1 = get_num(upper, A, B, C, &sum1); // res1 < M
    ll res2 = get_num(lower, A, B, C, &sum2); // res2 >= M
    //fprintf(stderr, "%d, %d\n", lower, upper);
    if (res2 > M){
        ans = sum1 + (M - res1) * lower;
        //fprintf(stderr, "%d, %d, %d\n", sum1, (M - res1), lower);
    } else {
        ans = sum2;
    }
    cout << ans << endl;
    return 0;    
#if 0
    rep(i, N){
        rep(j, N){
            B[i * N + j] = A[i] + A[j];
        }
    }
    sort(B.begin(), B.end(), greater<int>());
    
    ll ans = 0;
    rep(i, M){
        ans += B[i];
    }
    cout << ans << endl;
#endif
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    int n;cin >>n;
    cout << n*n*n;
}



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

#define int long long

int N;
vector<int> a;
vector<int> b;

int solve(){
  a.resize(N);
  b.resize(N - 1);
  rep(i,0,N - 1) cin >> a[i];
  rep(i,0,N - 2) cin >> b[i];
  int sum = 0;
  for(int x : a) sum += x;
  for(int x : b) sum += x;
  int ans = sum;
  sort(b.begin(),b.end());
  int cou = 1;
  for(int x : b){
    sum -= x;
    cou++;
    ans = max(ans , sum * cou);
  }

  return ans;
}

signed main(){
  while(cin >> N , N){
    cout << solve() << endl;
  }
}



Measured memory_bytes: 3784
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = [deque(list(map(int, input().split()))) for _ in range(n)]

    que = deque()
    for i in range(n):
        que.append(i)

    res = 0
    while True:
        tmp = deque()
        used = set()
        while que:
            idx = que.popleft()
            if A[idx]:
                a = A[idx][0] - 1
                if idx in used or a in used:
                    continue
                if A[a][0] - 1 == idx:
                    A[idx].popleft()
                    A[a].popleft()
                    used.add(idx)
                    used.add(a)
                    tmp.append(idx)
                    tmp.append(a)
        if tmp:
            res += 1
            que = tmp
        else:
            break

    for a in A:
        if a:
            print(-1)
            break
    else:
        print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 41816
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        a_vec: [i32; n]
    }
    let mut a_vec = a_vec;
    let mut cnt: i32 = 0;
    let mut loop_flag: bool = true;
    loop {
        for i in 0..a_vec.len() {
            if a_vec[i] % 2 == 0 {
                a_vec[i] = a_vec[i] / 2;
            } else {
                loop_flag = false;
                break;
            }
        }
        match loop_flag {
            true => {
                cnt = cnt + 1;
                continue;
            },
            false => {
                break;
            }
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
int A, B, C;

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%d %d %d", &A, &B, &C);
    if (C >= A && C <= B) { printf("Yes\n"); }
    else { printf("No\n"); }
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lol long long
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b;
  cin >>n>>a>>b;
  int m[3]={};
  while(n--){
    int p;cin >>p;
    if(p<=a) m[0]++;
    else if(p<=b) m[1]++;
    else m[2]++;
  }
  cout <<min({m[0],m[1],m[2]})<<'\n';
  return (0);
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <utility>
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
const lli inf = 1e18;

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i=0; i<n; i++){
		cin >> v[i];
	}

	int ans = 0;
	for(int i=0; i<=n; i++){
		for(int j=i; j<=n; j++){
			int total = i +n-j;
			if(total > k) continue;
			vector<int> w(total);
			for(int k=0; k<i; k++){
				w.push_back(v[k]);
			}
			for(int k=j; k<n; k++){
				w.push_back(v[k]);
			}
			int rem = k -total;
			sort(w.begin(), w.end());
			int sub = 0;
			for(int k: w){
				if(k < 0 and rem > 0){
					rem--;
					continue;
				}
				sub += k;
			}			
			ans = max(ans, sub);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int W,H,N;
  cin>>W>>H>>N;
  int xMin,xMax,yMin,yMax;
  xMin=0;
  xMax=W;
  yMin=0;
  yMax=H;
  int x,y,a;
  int i=0;
  for(i=0;i<N;i++){
    cin>>x>>y>>a;
    if(a==1){
      if(xMin<x){
	xMin=x;
      }
    }
    if(a==2){
      if(xMax>x){
	xMax=x;
      }
    }
    if(a==3){
      if(yMin<y){
	yMin=y;
      }
    }
    if(a==4){
      if(yMax>y){
	yMax=y;
      }
    }
  }
  int xlen = xMax-xMin;
  int ylen = yMax-yMin;
  if(xlen<0){xlen=0;}
  if(ylen<0){ylen=0;}
  int area = xlen*ylen;
  cout<<area<<endl;
  return 0;
  
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n) , b(n);
    int cnt = 0, ans = 0;

    for (int i = 0; i < n; i++) cin >> a.at(i);
    for (int i = 0; i < n; i++) {
        if (a.at(i) % 2 == 0) {
            cnt++;
            if (a.at(i) % 3 == 0 || a.at(i) % 5 == 0) {
                ans++;
            }
            else {
               cout << "DENIED" << endl;
               break; 
            }
        }
    }
    if (cnt == ans) {
        cout << "APPROVED" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, x;
  cin >> N >> A;
  x = N % 500;
    
  if (x > A) {
    cout <<  "No" << endl;
  }
  
  else {
    cout << "Yes" << endl;
  }  
}  

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


int main() {
	
	int N,cnt=0;
	cin >> N;
	vector<int> h(N);
	for(int i=0; i<N; i++){
		cin >> h.at(i);
		bool flag = 1;
		for(int j=0; j<i; j++){
			if(h.at(j)>h.at(i)) flag = 0;
		}
		if(flag) cnt++;
	}
	cout << cnt << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
from copy import deepcopy
def solve():
    N,A,B,C,D = map(lambda x:int(x)-1, input().split())
    field_orig = list(input())
    field = deepcopy(field_orig)

    if C < D:
        if existsContinuousRocks(field,A,B,C,D):
            print('No')
        else:
            print('Yes')
    else:
        if not existsContinuousRocks(field,A,B,C,D) \
            and existsContinuousDots(field,A,B,C,D):
            print('Yes')
        else:
            print('No')

def existsContinuousRocks(field, A, B, C, D):
    for i in range(A, min(max(C,D), len(field)-1)):
        if field[i] == '#' and field[i+1] == '#':
            return True
    return False

def existsContinuousDots(field,A,B,C,D):
    for i in range(B-1,min(D, len(field)-2)):
        if field[i] == '.' and field[i+1] == '.' and field[i+2] == '.':
            return True
    return False


if __name__ == '__main__':
    solve()

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

#define int long long

int32_t main(){
	int n;
	cin >> n ;
	int cnt = 0 ;
	bool found = false ;
	for(int i = 0 ; i < n ; i++){
		int x , y ;
		cin >> x >> y ;
		x-- , y-- ;
		if(x == y){
			cnt++ ;
		} else {
			cnt = 0 ;
		}
		if(cnt > 2) found = true ;
	}
	if(found){
		cout << "Yes" ;
	} else {
		cout << "No" ;
	}
	return 0 ;
}



Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
 char a[9];
  rep(i, 0, 9){
    cin >> a[i];
  }
  cout << a[0] << a[4] << a[8] << "\n";
}

Measured memory_bytes: 3624
#include <stdio.h>
#define N 100

int main()
{
  int i, j, n, u, k, v, output[N][N];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      output[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u, &k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      output[u-1][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",output[i][j]);
     if(j<n-1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MX = 50;

int h, w;
int white;

int grid[MX][MX];
int d[MX][MX];
bool used[MX][MX];

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

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c; cin >> c;
            grid[i][j] = (c == '#');
            white += (c == '.');
        }
    }
    
    queue<pair<int, int>> q;
    q.push({0, 0});
    used[0][0] = true;
    while(!q.empty()) {
        pair<int, int> v = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            int a = v.first + dx[i], b = v.second + dy[i];
            if (a < 0 || a >= h || b < 0 || b >= w) continue;
            if (used[a][b] || grid[a][b]) continue;
            used[a][b] = true;
            d[a][b] = d[v.first][v.second] + 1;
            q.push({a, b});
        }
    }
    if (d[h - 1][w - 1]) cout << white - d[h - 1][w - 1] - 1;
    else cout << -1;
}


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

#define rep(i, a, b) for(lli i  = (lli)(a); i < (lli)(b);i++)
#define REP(i,n) for(lli(i)=0;(i)<(lli)(n);(i)++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define trace(x) cerr << #x << ": " << x << endl;

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

int main(){
	fastio;
	int a,b,t; cin>>a>>b>>t;
	int cont=0;
	for(int i=1;i*a<=t;i++){
		cont++;
	}
	cout<<cont*b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio {
  int it, len;
  char s[LEN + 5];
  fastio() {
    it = len = 0;
  }
  char get() {
    if(it < len) return s[it++];
    it = 0, len = fread(s, 1, LEN, stdin);
    return len ? s[it++] : EOF;
  }
  bool notend() {
    char c;
    for (c = get();c == ' ' || c == '\n' || c == '\r';c = get());
    if (it) it--;
    return c != EOF;
  }
  void put(char c) {
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush() {
    fwrite(s, 1, it, stdout);
  }
}buff, bufo;
inline int getint() {
  char c; int res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if(c == '-') sig = -1;
  for (;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll() {
  char c; ll res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if (c == '-') sig = -1;
  for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
#define maxn 100005
int n, a[maxn];
ll l[maxn], r[maxn];
int main() {
  n = getint();
  for (int i = 0; i <= n; i++) a[i] = getint();
  l[n] = a[n], r[n] = a[n];
  for (int i = n - 1; i >= 0; i--) {
    l[i] = l[i + 1] - l[i + 1] / 2 + a[i], 
    r[i] = r[i + 1] + a[i];
  }
  l[0] = max(l[0], 1ll), r[0] = min(r[0], 1ll);
  for (int i = 1; i <= n; i++) {
    l[i] = max(l[i - 1] - a[i - 1], l[i]), 
    r[i] = min((r[i - 1] - a[i - 1]) * 2, r[i]);
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    if (l[i] > r[i]) {
      puts("-1");
      return 0;
    }
    ans += r[i];
  }
  printf("%lld\n", ans); 
  return 0;
}


Measured memory_bytes: 5820
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main()
{int n;
	cin >> n;
	int ans=0;
	vector<char>c(n);
for(int i=0;i<n;i++){
    cin>>c[i];
}
vector<char>d=c;
sort(c.begin(),c.end());
for(int i=0;i<n;i++){
    if(c[i]!=d[i]){
        ans++;
    }
}
if(ans%2==0){
	   cout<<ans/2;
	}else{
	cout<<(ans+1)/2;
	}
	return 0;
}


Measured memory_bytes: 3784
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;



int main(void)
{
	//変数の宣言
	ll int n;
	ll int s[10];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	ll int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	int dummy;



	//データの読み込み


	scanf("%lld",&n);
//	scanf_s("%lld",&n);

	for(i=0;i<5;i++){
		scanf("%lld",&s[i]);
//		scanf_s("%lld",&s[i]);
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	temp=s[0];
	for(i=1;i<5;i++){
		temp=min(temp,s[i]);
	}



	//	printf("計算部分終了\n");

	//出力
	printf("%lld",(n+temp-1)/temp+4);


/*	for(i=0;i<b+w;i++){
		printf("%lld %lld\n",black[i],white[i]);
	}*/


	//	printf("結果の出力終了\n");

	return 0;
}



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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a==1&&b==9&&c==7&&d==4){
		cout<<"YES"<<endl;
	}
	else if(a==1&&b==9&&c==4&&d==7){
		cout<<"YES"<<endl;
	}
	else if(a==1&&b==7&&c==9&&d==4){
		cout<<"YES"<<endl;
	}
	else if(a==1&&b==7&&c==4&&d==9){
		cout<<"YES"<<endl;
	}
	else if(a==1&&b==4&&c==9&&d==7){
		cout<<"YES"<<endl;
	}
	else if(a==1&&b==4&&c==7&&d==9){
		cout<<"YES"<<endl;
	}
	else if(a==9&&b==1&&c==7&&d==4){
		cout<<"YES"<<endl;
	}
	else if(a==9&&b==1&&c==4&&d==7){
		cout<<"YES"<<endl;
	}
	else if(a==9&&b==7&&c==1&&d==4){
		cout<<"YES"<<endl;
	}
	else if(a==9&&b==7&&c==4&&d==1){
		cout<<"YES"<<endl;
	}
	else if(a==9&&b==4&&c==1&&d==7){
		cout<<"YES"<<endl;
	}
	else if(a==9&&b==4&&c==7&&d==1){
		cout<<"YES"<<endl;
	}
	else if(a==7&&b==1&&c==9&&d==4){
		cout<<"YES"<<endl;
	}
	else if(a==7&&b==1&&c==4&&d==9){
		cout<<"YES"<<endl;
	}
	else if(a==7&&b==9&&c==1&&d==4){
		cout<<"YES"<<endl;
	}
	else if(a==7&&b==9&&c==4&&d==1){
		cout<<"YES"<<endl;
	}
	else if(a==7&&b==4&&c==1&&d==9){
		cout<<"YES"<<endl;
	}
	else if(a==7&&b==4&&c==9&&d==1){
		cout<<"YES"<<endl;
	}
	else if(a==4&&b==1&&c==9&&d==7){
		cout<<"YES"<<endl;
	}
	else if(a==4&&b==1&&c==7&&d==9){
		cout<<"YES"<<endl;
	}
	else if(a==4&&b==9&&c==1&&d==7){
		cout<<"YES"<<endl;
	}
	else if(a==4&&b==9&&c==7&&d==1){
		cout<<"YES"<<endl;
	}
	else if(a==4&&b==7&&c==1&&d==9){
		cout<<"YES"<<endl;
	}
	else if(a==4&&b==7&&c==9&&d==1){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
char M[6][6]={
	"abcde",
	"fghij",
	"klmno",
	"pqrst",
	"uvwxy",
	"z.?! "
};
string s;
main()
{
	while(cin>>s)
	{
		if(s.size()%2)
		{
			cout<<"NA"<<endl;
			continue;
		}
		bool f=1;
		for(int i=1;i<s.size();i+=2)if(!(s[i]>='1'&&s[i]<='5'))f=0;
		for(int i=0;i<s.size();i+=2)if(!(s[i]>='1'&&s[i]<='6'))f=0;
		if(!f)
		{
			cout<<"NA"<<endl;
			continue;
		}
		for(int i=0;i<s.size();i+=2)
		{
			cout<<M[s[i]-'1'][s[i+1]-'1'];
		}
		cout<<endl;
	}
}



Measured memory_bytes: 3156
n = int(input())

all_list=[]
for i in range(n):
  a,b = map(int, input().split())
  all_list.append([a+b,a,b])

#print(all_list)  
all_list.sort()
all_list.reverse()
#print(all_list)

ans=0
for i in range(n):
  if i%2==0:
    ans+=all_list[i][1]
  else:
    ans-=all_list[i][2]
print(ans)

Measured memory_bytes: 25260
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,m=mii()
chk=[0]*(n+1)
ans=[0]*n
ahk1=[0]*(n+1)
s=[]
c=[]

for i in range(m):
    a,b=mii()
    s.append(a)
    c.append(b)
    
    if (a==1 and b==0 and n!=1):
        print(-1)
        exit()
    
    if chk[a]==0 or ahk1[a]==b or ahk1[a]==0:
        chk[a]+=1
        ans[a-1]=b
        ahk1[a]=b
    else:
        print(-1)
        exit()

if ans[0]==0 and n!=1:
    ans[0]=1

print("".join(list(map(str,ans))))


Measured memory_bytes: 65388
package main

import "fmt"

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

	var scoreA, scoreB int
	for i := 0; i < n; i++ {
		idx, max := maxInt(a)
		a = delete(a, idx)
		if i%2 == 0 {
			scoreA += max
		} else {
			scoreB += max
		}
	}
	fmt.Println(scoreA - scoreB)
}

func maxInt(a []int) (int, int) {
	max := a[0]
	var idx int
	for i, e := range a {
		if e > max {
			max = e
			idx = i
		}
	}
	return idx, max
}

func delete(s []int, i int) []int {
	s = append(s[:i], s[i+1:]...)
	//新しいスライスを用意することがポイント
	n := make([]int, len(s))
	copy(n, s)
	return n
}

Measured memory_bytes: 640
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    if not n&1:
        dp = a[:2]
        for i in range(2,n)[::2]:
            nd = [-float("inf")]*2
            nd[0] = dp[0]+a[i]
            nd[1] = max(dp)+a[i+1]
            dp = [j for j in nd]
        print(max(dp))
        return
    dp = a[:3]
    dp[0] = a[0]
    dp[1] = a[1]
    dp[2] = a[2]
    for i in range(2,n-1)[::2]:
        nd = [-float("inf")]*3
        nd[0] = dp[0]+a[i]
        nd[1] = max(dp[0],dp[1])+a[i+1]
        nd[2] = max(dp)+a[i+2]
        dp = [j for j in nd]
    print(max(dp))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 91708
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == "?":
        break
    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)




Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
//const int mod = 1000000007;
ll gcd(ll x, ll y){
    if(y==0)return x;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
    return (x/gcd(x,y))*y;
}
int main(void){
    // Your code here!
    ll n,m;cin>>n>>m;
    vector<ll> a(n);
    ll two=-1;
    rep(i,n){
        cin>>a[i];a[i]/=2;
        if(two==-1){
            ll x=a[i];
            while(x>0){
                if(x%2==1){
                    two=a[i]/x;
                    break;
                }
                x/=2;
            }
        }else{
            if((a[i]/two)%2!=1){
                //a[i]を2で割り切れる数が他と違う場合
                cout<<0<<endl;
                return 0;
            }
        }
    }
    ll L=a[0];
    rep(i,n){
        L=lcm(L,a[i]);
    }
    m/=L;
    ll res=(m+1)/2;
    cout<<res<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int dx[] ={ 0,1,0,-1};
const int dy[] ={-1,0,1, 0};

int main(){
	int n,cnt = 0;
	while(cin >> n , n ){
		cout << "Case " << ++cnt << ":" << endl;
		int dt[10][10] = {0};

		if(n == 0){
			continue;
		}else if(n == 1){
			printf("%3d\n",1);
			continue;
		}
		int x = 0, y = 0 , num = 1, I = 0;
		do{
			I++;
			dt[y][x] = num++;
			if(x != n-1)x++;
			else y++;
			rep(i,x-y)dt[y+i][x-i] = num++;
			
			swap(x,y);
			dt[y][x] = num++;
			
			if(y != n-1) y++;
			else x++;
			
			rep(i,y-x)dt[y-i][x+i] = num++;
			
			swap(x,y);
		}while(x != n-1 || y != n-1);
		dt[y][x] = num;
		rep(i,n){
			rep(j,n)printf("%3d",dt[i][j]);
			cout << endl;
		}
	}
}
	

Measured memory_bytes: 0
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

constexpr int INF = 1000000000;

using Pair = std::pair<int, int>;

int n, m;
std::vector<Pair> cost[101];
std::vector<Pair> time_[101];

int d[101];
int dijkstra(int st, int gl, std::vector<Pair>* elm) {
    std::fill(d, d + 101, INF);

    d[st] = 0;

    std::priority_queue<Pair, std::vector<Pair>, std::greater<Pair>> queue;

    queue.push({0, st});

    while(!queue.empty()) {
        auto p = queue.top();queue.pop();

        if(p.first > d[p.second]) {
            continue;
        }

        for(int i = 0; i < elm[p.second].size(); ++i) {
            auto e = elm[p.second][i];

            //To, cost

            if (d[e.first] > d[p.second] + e.second) {
                d[e.first] = d[p.second] + e.second;

                queue.push({d[e.first], e.first});
            }
        }
    }

    return d[gl];
}

int main() {
    while(std::cin >> n >> m, n + m) {
        int a, b, c, t;

        for(int i = 0; i < m; ++i) {
            cost[i].clear();
            time_[i].clear();
        }

        for(int i = 0; i < n; ++i) {
            std::cin >> a >> b >> c >> t;

            --a, --b;

            cost[a].push_back({b, c});
            cost[b].push_back({a, c});
            time_[a].push_back({b, t});
            time_[b].push_back({a, t});
        }

        int k;
        std::cin >> k;
        for(int i = 0; i < k; ++i) {
            int p, q, r;

            std::cin >> p >> q >> r;

            if(r == 0) {
                std::cout << dijkstra(p - 1, q - 1, cost) << std::endl;
            }else {
                std::cout << dijkstra(p - 1, q - 1, time_) << std::endl;
            }

        }
    }
}

Measured memory_bytes: 3116
s = input()
t = input()
n = len(s)
m = len(t)

ans = 10000

for i in range(n-m+1):
    rem = 0
    for j in range(m):
        if(s[i+j] != t[j]):
            rem += 1
    ans = min(rem, ans)
print(ans)


Measured memory_bytes: 9024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt()%10;
		if(n == 3){
			System.out.println("bon");
		} else if(n < 2 || n == 6 || n == 8){
			System.out.println("pon");
		} else {
			System.out.println("hon");
		}
	}
}


Measured memory_bytes: 35792
n, a, b = map(int, input().split())
S =input()

x = 1
y = 1
for i in range(len(S)):
    if S[i] == "a":
        if x <= a + b:
            print("Yes")
            x += 1
        else:
            print("No")
    elif S[i] == "b":
        if (x <= a + b) and (y <= b):
            print("Yes")
            x += 1
            y += 1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4016
N, L = [int(i) for i in input().split()]

plus = []
minus = []
for i in range(N):
    taste = L + i
    if taste >= 0:
        plus.append(taste)
    else:
        minus.append(taste)

if plus and minus:
    ans = sum(plus) + sum(minus)  
elif plus:
    ans = sum(plus) - plus[0]
else:
    ans = sum(minus) - minus[-1]

print(ans)

Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  
        static void Main(string[] args)
        {
          //入力を受け取る
          int N = int.Parse(Console.ReadLine());
          int[] d = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          long sum = 0;
          for(int i = 0; i < N ;i++){
            for(int j = i+1; j < N ;j++){
              sum += d[i]*d[j];
            }
          }
          Console.Write(sum);
        }
  
 }

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int P[100100];
int PP[100100];
int L1[100100];
int L2[100100];
int R1[100100];
int R2[100100];

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> P[i];
        PP[P[i]] = i;
    }

    set<int> set1;
    for (int i = N; i >= 1; --i) {
        if (i != N) {
            set1.insert(PP[i + 1]);
        }
        auto ite = set1.upper_bound(PP[i]);
        if (ite != set1.end()) {
            R1[PP[i]] = *ite;
            ite++;
            if (ite != set1.end()) {
                R2[PP[i]] = *ite;
            } else {
                R2[PP[i]] = N;
            }
        } else {
            R1[PP[i]] = N;
            R2[PP[i]] = N;
        }
        ite = set1.upper_bound(PP[i]);
        if (ite == set1.begin()) {
            L1[PP[i]] = -1;
            L2[PP[i]] = -1;
            continue;
        }
        ite--;
        L1[PP[i]] = *ite;
        if (ite != set1.begin()) {
            ite--;
            L2[PP[i]] = *ite;
        } else {
            L2[PP[i]] = -1;
        }
    }
    int ans = 0;
    rep(i, N) {
        //(L2,L1] ,R1)
        ans += P[i] * (L1[i] - L2[i]) * (R1[i] - i);
        //(L1, [R1,R2)
        ans += P[i] * (R2[i] - R1[i]) * (i - L1[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  string s;
  cin >> s;
  bool ok = false;
  for (int i = 0; i < s.size(); i += 2) {
    if (s[i] == 'h' && s[i + 1] == 'i') {
      ok = true;
    } else {
      ok = false;
      break;
    }
  }
  print(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

    int K, X;

    cin >> K >> X;

    for(int i = X - (K - 1); i <= X + (K - 1); i++){
        if(i < -1000000 || i > 1000000) {

        } else {
            cout << i << " ";
        }
    }

    
}

Measured memory_bytes: 256
//=================================
// Created on: 2018/07/03 04:20:37
//=================================
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
int main()
{
    using P = pair<ld, string>;
    for (int N;;) {
        cin >> N;
        if (N == 0) { break; }
        vector<P> p(N);
        for (int i = 0; i < N; i++) {
            cin >> p[i].second;
            int P, A, B, C, D, E, F, S, M;
            cin >> P >> A >> B >> C >> D >> E >> F >> S >> M;
            const int T = (A + B + C) + (D + E) * M;
            const int X = F * S * M - P;
            p[i].first = (ld)X / T;
        }
        sort(p.begin(), p.end(), [](const P& p1, const P& p2) { return p1.first != p2.first ? p1.first > p2.first : p1.second < p2.second; });
        for (int i = 0; i < N; i++) { cout << p[i].second << endl; }
        cout << "#" << endl;
    }
    return 0;
}



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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  cout<<n/3<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200010],f[200010];
int main(){
	int n;ll k;scanf("%d%lld",&n,&k);
	for(int i=0;i<n;++i){
		scanf("%lld",a+i);
	}
	for(int i=0;i<n;++i)scanf("%lld",f+i);
	sort(a,a+n);
	sort(f,f+n);
	ll L=0,R=1e12+2;
	while(L<=R){
		ll m=L+R>>1,p=k;
		for(int i=0;i<n;++i){
			ll x=a[i],y=f[n-i-1];
			ll t=m/y;
			if(t<x){
				p-=x-t;
			}
		}
		if(p>=0)R=m-1;
		else L=m+1;
		//printf("m = %lld\n",m);
	}
	printf("%lld\n",L);

	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>


using namespace std;

long long modexp(long long x, long long n, long long mod)
{
    if (n == 0) {
        return 1;
    }

    if (n % 2 == 0) {
        return (modexp(x, n / 2, mod) * modexp(x, n / 2, mod)) % mod;
    }
    return (modexp(x, n / 2, mod) * modexp(x, n / 2, mod) * x) % mod;
}



int main()
{
    string s;
    cin >> s;
    int i;
    for (i = 0; i < s.length(); ++i) {
        if (s[i] == ',') {
            s[i] = ' ';
        }
    }
    cout << s;


    
    

}

    


Measured memory_bytes: 384
from sys import stdin


def answer(x, y, C):
    if x < C < y:
        print("Yes")
    else:
        print("No")


def main():
    A, B, C = [int(x) for x in stdin.readline().split()]
    if A < B:
        answer(A, B, C)
    else:
        answer(B, A, C)


if __name__ == "__main__":
    main()


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

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

//4,7,8,11,12,14,15,16,18,19,20,21,22,23,24,25,26,27,28

  int a[9] = {1,2,3,5,6,9,10,13,17};
  bool ans = true;
  for(int i=0;i<9;i++){
    if(a[i]==b){
      cout << "No" << endl;
      ans = false;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(b % a == 0) {
			System.out.println(a + b);
		}else {
			System.out.println(b - a);
		}
	}
}



Measured memory_bytes: 23380
#include <stdio.h>
#include <math.h>
int main(){
    int l, r, d, count = 0;
    scanf("%d%d%d", &l, &r, &d);
    while(l <= r){
        if(fmod((double)l, (double)d) == 0)count++;
        l++;
    }
    printf("%d", count);
}

Measured memory_bytes: 2240
// AOJ 2423 Code Art Online
// 2018.4.8 bal4u

#include <stdio.h>
#include <string.h>
#include <math.h>

#define MAX 210
short hi[MAX], to[MAX][MAX];
char seen[MAX];
int  match[MAX];

int bpm(int u);
int bipartiteMatching(int m, int n)
{
	int u, max;

	memset(match, -1, (m+n)*sizeof(int));
	max = 0;
	for (u = 0; u < m; u++) {
		memset(seen, 0, m+n);
		if (bpm(u)) max++;
	}
	return max;
}

int bpm(int u)
{
	int i, v;

	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		if (seen[v]) continue;
		seen[v] = 1;
		if (match[v] < 0 || bpm(match[v])) {
			match[u] = v, match[v] = u;
			return 1;
		}
	}
	return 0;
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	if (c == '-') {	c = getchar_unlocked();
		do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int    rn[102];
double rm[102];
char   rel[102][102];
char   assign[102], f[102];

typedef struct { double x, y; } PP;
PP p[102];

#define EPS 1e-2
#define EQ(a,b)  (fabs((a)-(b))<EPS)

double smallestCircle(int n)
{
	int  k, i, t;
	PP a = { 50, 50 };
	double move, max, d;

	move = 0.5;
	while (move > 1e-4) {
		for (t = 0; t < 50; t++) {
			max = 0;
			for (i = 0; i < n; i++) {
				if ((d = hypot(a.x-p[i].x, a.y-p[i].y)) > max) max = d, k = i;
			}
			a.x += (p[k].x - a.x)*move;
			a.y += (p[k].y - a.y)*move;
		}
		move /= 2;
	}
	return max;
}

int main()
{
	int n, m, i, j, k, l;

	n = in(), m = in();
	for (i = 0; i < n; i++) rn[i] = in();
	for (i = 0; i < m; i++) {
		k = in();
		for (j = 0; j < k; j++) p[j].x = in(), p[j].y = in();
		rm[i] = smallestCircle(k);
	}

	for (i = 0; i < m; i++) for (j = 0; j < n; j++) {
		if (EQ(rm[i], rn[j]) || rm[i] <= rn[j]) {
			rel[i][j] = 1;
			to[i][hi[i]++] = m+j;
		}
	}

	if (bipartiteMatching(m, n) != m) puts("NG");
	else {
		for (i = 0; i < m; i++) {
			for (j = 0; j < n; j++) if (!f[j] && rel[i][j]) {
				for (k = i+1; k < m; k++) hi[k] = 0;
				f[j] = 1;
				hi[i] = 1, to[i][0] = m+j;
				for (k = i+1; k < m; k++) {
					for (l = 0; l < n; l++) if (!f[l]) {
						if (rel[k][l]) to[k][hi[k]++] = m+l;
					}
					if (hi[k] == 0) { f[j] = 0; continue; }
				}

				if (bipartiteMatching(m, n) == m) {
					assign[i] = 1+j;
					break;
				}
				f[j] = 0;
			}
		}
		for (i = 0; i < m; i++) printf("%d\n", assign[i]);
	}
	return 0;
}


Measured memory_bytes: 2136