akhauriyash/Code-Regression huggingface dataset:
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;
const ll inf = 1e15 + 42;

int main() {
	fast_cin();
	int n; cin >> n;
	vector<ll> a(n + 1);
	for (auto& i : a) {
		cin >> i;
	}
	if (n == 0) {
		if (a[0] == 1) {
			cout << 1 << endl;
		} else {
			cout << -1 << endl;
		}
		return 0;
	}
	vector<ll> lo(n + 1), hi(n + 1);
	lo[0] = hi[0] = 1;
	bool ok = (a[0] == 0);
	for (int i = 1; i <= n; ++i) {
		ok &= (2 * hi[i - 1] >= a[i]);
		lo[i] = max(0ll, lo[i - 1] - a[i]);
		hi[i] = min(inf, max(0ll, 2 * hi[i - 1] - a[i]));
	}
	ok &= (lo[n] <= 0);
	if (!ok) {
		cout << -1 << endl;
		return 0;
	}
	ll ans = a[n], cur = a[n];
	for (int i = n - 1; i >= 0; --i) {
		cur = min(hi[i] + a[i], a[i] + cur);
		ans += cur;
	}
	cout << ans << endl;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    cout << n*(n-1)/2 << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;
use std::collections::VecDeque;

struct Node {
    to: Vec<usize>,
    from: Vec<usize>,
}

impl Node {
    fn new() -> Self
    {
        Node {
            to: Vec::new(),
            from: Vec::new(),
        }
    }
}

fn main() {
    input! {
    n:usize,
    m:usize,
    edge:[(Usize1,Usize1);n+m-1],
    }

    let mut node = (0..n).map(|_| Node::new()).collect::<Vec<Node>>();
    for (a, b) in edge {
        node[a].to.push(b);
        node[b].from.push(a);
    }

    let mut cnt = vec![0; n];
    let mut ans = vec![0; n];

    let mut q = VecDeque::new();
    let root = node.iter().position(|n| n.from.len() == 0).unwrap();
    q.push_back(root);

    while let Some(idx) = q.pop_front() {
        for i in 0..node[idx].to.len() {
            let nxt = node[idx].to[i];
            cnt[nxt] += 1;
            if cnt[nxt] == node[nxt].from.len() {
                ans[nxt] = idx + 1;
                q.push_back(nxt);
            }
        }
    }

    for i in ans {
        println!("{}", i);
    }
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var M = input[1];
            var A = ReadArrayInt();
            var pq = new PriorityQueue<int>((a, b) => b - a);
            for (int i = 0; i < N; i++) pq.Enqueue(A[i]);
            for (int i = 0; i < M; i++) pq.Enqueue(pq.Dequeue() / 2);
            var sum = 0L;
            while (pq.Any()) sum += pq.Dequeue();

            Console.WriteLine(sum);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }

    class PriorityQueue<T>
    {
        readonly List<T> heap;
        readonly Comparison<T> compare;
        int size;
        public PriorityQueue(Comparison<T> compare)
        {
            heap = new List<T>();
            this.compare = compare;
        }
        public void Enqueue(T val)
        {
            heap.Add(val);
            int i = size++;
            while (i > 0)
            {
                int p = (i - 1) >> 1;
                if (compare(heap[p], val) <= 0) break;
                heap[i] = heap[p];
                i = p;
            }
            heap[i] = val;
        }
        public T Dequeue()
        {
            T ret = heap[0];
            T x = heap[--size];
            int i = 0;
            while ((i << 1) + 1 < size)
            {
                int a = (i << 1) + 1;
                int b = (i << 1) + 2;
                if (b < size && compare(heap[b], heap[a]) < 0) a = b;
                if (compare(heap[a], x) >= 0) break;
                heap[i] = heap[a];
                i = a;
            }
            heap[i] = x;
            heap.RemoveAt(size);
            return ret;
        }
        public T Peek() { return heap[0]; }
        public int Count { get { return size; } }
        public bool Any() { return size > 0; }
    }
}

Measured memory_bytes: 29404
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

int dp[101][100001];
int we[101],val[101];

signed main()
{
    fasino
    int n,w;
    cin >> n >> w;
    for(int i=0;i<n;i++) cin>>we[i]>>val[i];
    memset(dp,0,sizeof dp);
    for(int i=1;i<n+1;i++){
        for(int j=1;j<w+1;j++){
            if(we[i-1]<=j){
                dp[i][j] = max(val[i-1]+dp[i-1][j-we[i-1]],dp[i-1][j]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w];
    return 0;
}


Measured memory_bytes: 79232
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

typedef tuple<int, int> point;
typedef tuple<point, int> circle;
typedef tuple<double, int> pass;
typedef tuple<double, int> state;

int N;
circle C[1010];
vector<pass> V[1010];

double distance(point x, point y) {
  double a = get<0>(x);
  double b = get<1>(x);
  double c = get<0>(y);
  double d = get<1>(y);
  // cerr << a << " " << b << " " << c << " " << d << " " << endl;
  return sqrt((a - c) * (a - c) + (b - d) * (b - d));
}

int main () {
  int x, y;
  cin >> x >> y;
  C[0] = make_tuple(make_tuple(x, y), 0);
  cin >> x >> y;
  cin >> N;
  C[N+1] = make_tuple(make_tuple(x, y), 0);
  int r;
  for (auto i = 1; i <= N; i++) {
    cin >> x >> y >> r;
    C[i] = make_tuple(make_tuple(x, y), r);
  }
  for (auto i = 0; i <= N+1; i++) {
    point src = get<0>(C[i]);
    int src_r = get<1>(C[i]);
    for (auto j = 0; j <= N+1; j++) {
      if (i == j) continue;
      point dst = get<0>(C[j]);
      int dst_r = get<1>(C[j]);
      // cerr << distance(src, dst) << endl;
      double dist = max(0.0, distance(src, dst) - src_r - dst_r);
      // cerr << "i = " << i << ", j = " << j << ", dist = " << dist << endl;
      V[i].push_back(make_tuple(dist, j));
    }
  }
  bool visited[1010];
  fill(visited, visited+1010, false);
  priority_queue<state, vector<state>, greater<state> > Q;
  Q.push(make_tuple(0.0, 0));
  while (!Q.empty()) {
    double cost = get<0>(Q.top());
    int src = get<1>(Q.top());
    Q.pop();
    if (src == N+1){
      cout << fixed << setprecision(12) << cost << endl;
      return 0;
    } else if (!visited[src]) {
      visited[src] = true;
      for (auto p : V[src]) {
        double newcost = get<0>(p);
        int dst = get<1>(p);
        if (!visited[dst]) {
          Q.push(make_tuple(cost + newcost, dst));
        }
      }
    }
  }
}


Measured memory_bytes: 24704
#include <stdio.h>
 
 
int main()
{
    int sum=0,l[10],v1,v2,i;
    double t,r;
 
    while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
                 l,l+1,l+2,l+3,l+4,l+5,l+6,l+7,l+8,l+9,&v1,&v2)!=EOF)
    {
        for(i=0;i<10;i++) sum+=l[i];
        t=(double)sum/(v1+v2);
        r=v1*t;
 
        for(i=0;i<10;i++){
            r-=l[i];
            if(r<=0.0){
                printf("%d\n",i+1);
                break;
            }
        }
        sum=0;
    }
 
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  if (N == 0)
  {
    cout << 0 << endl;
    return 0;
  }

  string result = "";
  bool plus = true;
  while (N != 0)
  {
    if (N % 2 != 0)
    {
      result = "1" + result;
      if (plus)
      {
        N--;
      }
      else
      {
        N++;
      }
    }
    else
    {
      result = "0" + result;
    }

    N /= 2;

    plus = !plus;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[1000000];
int sum[1000000];
int n;
int main(){
 for (int i=2;i<1000000;i++){
  if (!a[i])
   for (int j=i*2;j<1000000;j+=i)
    a[j]=1;
 }
 for (int i=2;i<1000000;i++) sum[i]=sum[i-1]+(a[i]==0?1:0);
 while (cin>>n)
  cout<<sum[n]<<endl;
 return 0;
}


Measured memory_bytes: 10820
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-02 22:31:43
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.length();

    s = s + s;

    string ans = "No";
    for (int i = 0; i < n; i++) {
        string u = s.substr(i, n);
        if (t == u) ans = "Yes";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n;
	ll h,a,sum=0;
	cin>>h>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		sum+=a;
	}
	if(h<=sum)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	ll n, m, k;
	cin >> n >> m >> k;
	
	vector<ll> sumA(n + 1, 0), sumB(m + 1, 0);
	for(int i = 0; i < n; ++i) {
		ll a;
		cin >> a;
		sumA[i + 1] = sumA[i] + a;
	}
	
	for(int i = 0; i < m; ++i) {
		ll b;
		cin >> b;
		sumB[i + 1] = sumB[i] + b;
	}
	
	ll ans = 0LL, j = m;
	for(int i = 0; i <= n; ++i) {
		
		if( sumA[i] > k ) continue;
	
		while( sumA[i] + sumB[j] > k ) {
			j--;
		}

		ans = max(ans, (ll)(i) + j);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define INF (1<<18)


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

    vector<pair<int, int>> ab(n);
    rep(i,n) ab[i] = make_pair(a[i], b[i]);

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

    ll ans = 0;
    rep(i,n){
        int buy = min(m, ab[i].second);
        m -= buy;
        ans += (ll)buy*ab[i].first;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main() {
  int n,x,minv=1001;
  int m[1001];
  cin >> n >> x;
  for (int i=0; i<n; i++){
    cin >> m[i];
    x -= m[i];
    if(minv > m[i]) {
      minv = m[i];
    }
  }
  cout << x/minv + n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int s[100000][10];
int main()
{
	int N;
	ll ss[100000];
	
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		char c[10+1];
		scanf("%s", c);
		for(int j = 0; j < 10; j++){
			s[i][j] = (int)c[j] - 97;
		}
		sort(s[i], s[i]+10);
		
		ss[i] = 0;
		for(int j = 0; j < 10; j++){
			ll sss = s[i][j];
			ss[i] = ss[i] | (sss << 5*j);
		}
	}
	sort(ss, ss+N);
	
	ll count = 0;
	for(int i = 0; i < N-1; i++){
		for(int j = i + 1; j < N; j++){
			if(ss[i] != ss[j]){
				count += mySigma(j-i-1);
				i += j-i-1;
				break;
			}
			else if(j == N-1){
				count += mySigma(j-i);
				i = N;
				break;
			}
		}
	}
	
	printf("%lld\n", count);
	
	return 0;
}

Measured memory_bytes: 4864
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.List (foldl')
import Text.Printf
import Debug.Trace

main = do
  [n,a,b] <- getInts
  xs <- getInts
  print $ fst $ foldl' (\(acc,px) x -> (acc + min ((x-px)*a) b, x)) (0,head xs) xs

-- util
getInts :: IO [Integer]
getInts = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine

substr :: Int -> Int -> B.ByteString -> B.ByteString
substr b l s = B.take l $ B.drop b s


Measured memory_bytes: 29052
import sys

class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def inorderTreeWalk(node):
    global In
    if node:
        inorderTreeWalk(node.left)
        In.append(str(node.key))
        inorderTreeWalk(node.right)

def preorderTreeWalk(node):
    global Pre
    if node:
        Pre.append(str(node.key))
        preorderTreeWalk(node.left)
        preorderTreeWalk(node.right)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    root = None
    for line in lines:
        if line[0] == "i":
            insert(Node(int(line.split()[1])))
        else:
            In = []
            Pre = []
            inorderTreeWalk(root)
            print " " + " ".join(map(str, In))
            preorderTreeWalk(root)
            print " " + " ".join(map(str, Pre))

Measured memory_bytes: 290916
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	H, W := getInt(), getInt()
	if H == 1 || W == 1 {
		out(1)
		return
	}
	if H%2 == 0 || W%2 == 0 {
		out(H * W / 2)
		return
	}
	out(H*(W-1)/2 + H/2 + 1)
}


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

int main()
{
    string S;
    cin >> S;
    if (S[0] == 'A')
    {
        int count = 0;
        int idx;
        for (int i = 2; i < S.size() - 1; i++)
        {
            if (S[i] == 'C')
            {
                count++;
                idx = i;
            }
        }
        if (count == 1)
        {
            bool flag = true;
            for (int i = 1; i < S.size(); i++)
            {
                if (i != idx)
                {
                    if (S[i] < 'a')
                    {
                        flag = false;
                    }
                }
            }
            if (flag)
            {
                cout << "AC" << endl;
                return 0;
            }
        }
    }
    cout << "WA" << endl;
}


Measured memory_bytes: 256
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def sol():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    B = A.copy()
    ans = sum(B)
    for magic in range(1, N):
        for i in range(N):
            B[i] = min(B[i], A[i - magic])
        ans = min(ans, sum(B) + X * magic)

    print(ans)

sol()



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n; cin >> n;
    long long ans = 1e12+5;
    for(long long i = 1; i * i <= n; i++) {
        if(n % i == 0) ans = min(ans, i - 1 + n / i - 1);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int n;
long long f[50];
int main() {
	cin >> n;
	f[0] = 2;
	for (int i = 1; i <= n; i++) {
		f[i] = f[i - 1] * 2 + 2;
	}
	cout << f[n] << endl;
	
	return 0;
}

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

#define ll long long
ll dp[100005], hgt[100005], n;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> hgt[i];
	}
	dp[0] = 0; dp[1] = abs(hgt[1] - hgt[0]);
	for (ll i = 2; i < n; i++) {
		dp[i] = min (dp[i - 1] + abs(hgt[i] - hgt[i - 1]), dp[i - 2] + abs(hgt[i] - hgt[i - 2]));
	}
	cout << dp[n - 1] << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define strep(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<int>
#define rs resize
ll modexp(ll a,ll b){ ll res = 1;  while(b>0){  if(b&1)  res = (res*a)%mod;  a = (a*a)%mod;  b/=2;  }  return res; }
const ll N = 100009;
ll f[N],cnt,n,i,a;
int main()
{
   std::ios::sync_with_stdio(false);
   bool flag = true;
   cin>>n;
   rep(i,0,n) cin>>a,f[a]++;
   if(n&1)
   {  if(f[0] != 1)
        flag = false;
   }
   else
   {
       if(f[0] != 0)
         flag = false;
   }
   if(flag){
     rep(i,1,N){
      if(f[i] != 2 and f[i] != 0)
      {
        flag = false;
        break;
      }
      if(f[i] == 2) cnt++;
     }
   }
   cout<<(flag ? modexp(2,cnt) : 0);
   return 0;
}


Measured memory_bytes: 1024
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(s[k-1])

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

map<string,long long> mp;
int main() {

    ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    long long n;
    cin>>n;

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

    long long max = 0;
    for(auto i=mp.begin();i!=mp.end();i++){
        if(i->second>max){
            max = i->second;
        }
    }

    for(auto i=mp.begin();i!=mp.end();i++){
        if(i->second==max){
            cout<<i->first<<"\n";
        }
    }




    return 0;
}

Measured memory_bytes: 19252
//author: clorf
//Think twice,Code once.
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=100010;
const double Pi=acos(-1.0);
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}
long long k,n,ans=INF;
long long gcd(long long a,long long b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
long long phi(long long x)
{
	long long ans=x;
	for(int i=2;i*i<=x;i++)
		if(x%i==0)
		{
			ans=ans/i*(i-1);
			while(x%i==0)
				x/=i;
		}
	if(x>1)
		ans=ans/x*(x-1);
	return ans;
}
long long power(long long a,long long b,long long p)
{
	long long ans=1%p;
	for(;b;b>>=1)
	{
		if(b&1)
			ans=ans*a%p;
		a=a*a%p;
	}
	return ans%p;
}
int main()
{
	scanf("%lld",&k);
	long long d=gcd(k,(long long)7);
	long long n=9*k/d;
	long long m=phi(n);
	for(long long i=1;i*i<=m;i++)
		if(m%i==0)
		{
			if(power(10,i,n)==1)
				ans=min(ans,i);
			if(i*i==m)
				continue;
			if(power(10,m/i,n)==1)
				ans=min(ans,m/i);
		}
	if(ans==INF)
		ans=-1;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1736
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
    int w = abs(sx - tx), h = abs(sy - ty);
    string ans;
    rep(i, 0, w) ans += "R";
    rep(i, 0, h) ans += "U";
    rep(i, 0, w)ans += "L";
    rep(i, 0, h)ans += "D";
    ans += "D";
    ans += "R";
    rep(i, 0, w)ans += "R";
    ans += "U";
    rep(i, 0, h)ans += "U";
    ans += "L";
    ans += "U";
    ans += "L";
    rep(i, 0, w)ans += "L";
    ans += "D";
    rep(i, 0, h)ans += "D";
    ans += "R";
    cout << ans << endl;
}


Measured memory_bytes: 256
# input
N = int(input())
A = list(map(int, input().split()))

sum_A = sum(A)
temp = 2 * A[0] - sum_A
ans = abs(temp)

for i in range(1, N - 1):
    temp = temp + 2 * A[i]
    if abs(temp) < ans:
        ans = abs(temp)

print(ans)


Measured memory_bytes: 24832
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 1;
const int MOD = 1e9 + 7;
vector<ll> factors[N];

void sieve(){
	for(int i = 1; i < N; ++i)
		for(int j = i; j < N; j += i)
			factors[j].push_back(i);
}

int main(){
	fast;
	ll n, ans = 0;
	cin >> n;
	sieve();
	for(int i = 1; i < n; ++i){
		ll x = n - i;
		ans += factors[x].size();
	}
	cout << ans;
  	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}


Measured memory_bytes: 184364
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn solve(n: usize, a: &mut Vec<usize>) -> bool {
  a.sort();
  let low = *a.first().unwrap();
  let high = *a.last().unwrap();
  if high - low > 1 {
    return false;
  }
  if high == low {
    return high == n - 1 || high * 2 <= n;
  }
  let count_high = a.iter().filter(|&x| *x == high).count();
  let count_low = n - count_high;
  count_low + 1 <= high && high <= count_high / 2 + count_low
}

fn main() {
  input! {
    n: usize,
    a: [usize; n],
  }
  let mut a: Vec<_> = a;
  let ans = if solve(n, &mut a) { "Yes" } else { "No" };
  println!("{}", ans);
}


Measured memory_bytes: 6396
#include <iostream>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define rrep(i, s, n) for (int i = (s); i > (n); i--)

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

    x = N / 1.08;
    if(x * 1.08 < N)
    {   
        int i = (x+1)*1.08;
        if(i != N)
            cout << ":(" << endl; 
        else
            cout << x+1 << endl;
    } else
    {
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  if(k == 1) cout << 0 << endl;
  else cout << (n - k) << endl;
  return 0;
}


Measured memory_bytes: 256
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    /////////////////////
    // Write code below /
    /////////////////////
    int numberOfMochi;
    cin >> numberOfMochi;
    vector<int> diametersOfMochi(numberOfMochi);
    
    for (int mochi_i = 0; mochi_i < numberOfMochi; mochi_i++) {
        cin >> diametersOfMochi.at(mochi_i);
    }
    
    sort(diametersOfMochi.begin(), diametersOfMochi.end(), greater<int>());
    
    int X = 1;
    for (int mochi_i = 1; mochi_i < numberOfMochi; mochi_i++) {
        if (diametersOfMochi.at(mochi_i - 1) == diametersOfMochi.at(mochi_i)) {
            continue;
        }
        X++;
    }
    
    cout << X << endl;
    
    return 0;
}


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

using namespace std;
typedef long long ll;

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

    int ans = INT_MIN;
    int min_value = INT_MAX;

    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;

        if (a - min_value > ans) ans = a - min_value;
        if (a < min_value) min_value = a;
    }
    
    cout << ans << endl;    

}


Measured memory_bytes: 3088
# -*- coding: utf-8 -*-
import math

###
# main
if(__name__ == '__main__'):
    # input
    n, m = map(int, input().split(" "))
    a = list(map(int, input().split(" ")))

    sum = 0
    for elem in a:
        sum += elem

    ans = -1
    if sum <= n:
        ans = n - sum

    print(ans)

# else:
    # do nothing


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

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


Measured memory_bytes: 3576
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <stack>
#include <map>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

const int M = 1000000007;
 
long power(long x, long n)
{
    long res;
    if (n == 0)
        return 1;
 
    res = power(x*x%M, n / 2);
    if ((n & 1) != 0)
    {
        res = res*x%M;
    }
    return res;
}
int main(){
    int m,n;
    cin >> m >> n;
    cout << power(m,n) << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_SIZE = 1001;
const int N = 100;

main(){
  int n, m, sizeH, sizeR;
  int dp[MAX_SIZE+1][MAX_SIZE+1];
  int dataH[2][N];
  int dataR[2][N];
  while(cin >> n && n){
    sizeH = sizeR = 0;
    for(int i=0;i<n;++i){
      cin >> dataH[0][i] >> dataR[0][i];
      sizeH = max(sizeH, dataH[0][i]);
      sizeR = max(sizeR, dataR[0][i]);
    }
    cin >> m;
    for(int i=0;i<m;++i){
      cin >> dataH[1][i] >> dataR[1][i];
      sizeH = max(sizeH, dataH[1][i]);
      sizeR = max(sizeR, dataR[1][i]);
    }
    fill(dp[0], dp[MAX_SIZE], -1);
    dp[0][0] = 0;
    for(int i=0;i<=sizeH;++i){
      for(int j=0;j<=sizeR;++j){
	if(dp[i][j] == -1) continue;
	for(int k=0;k<n;++k){
	  if(dataH[0][k] > i && dataR[0][k] > j) 
	    dp[dataH[0][k]][dataR[0][k]] = max(dp[dataH[0][k]][dataR[0][k]], dp[i][j] + 1);
	}
	for(int k=0;k<m;++k){
	  if(dataH[1][k] > i && dataR[1][k] > j) 
	    dp[dataH[1][k]][dataR[1][k]] = max(dp[dataH[1][k]][dataR[1][k]], dp[i][j] + 1);
	}
      }
    }
    int ans = 0;
    for(int i=0;i<=sizeH;++i){
      for(int j=0;j<=sizeR;++j){
	ans = max(ans, dp[i][j]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> L(M), R(M);
    rep(i, M) {
        cin >> L[i] >> R[i];
        L[i]--, R[i]--;
    }

    vector<int> p(Q), q(Q);
    rep(i, Q) {
        cin >> p[i] >> q[i];
        p[i]--;
    }

    vector<vector<int>> v(N, vector<int>(N));
    rep(i, M) {
        v[L[i]][R[i]]++;
    }

    vector<vector<int>> sum(N+1, vector<int>(N+1));
    rep(i, N)rep(j, N) {
        sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + v[i][j];
    }

    rep(i, Q) {
        int ans = sum[q[i]][q[i]] - sum[p[i]][q[i]] - sum[q[i]][p[i]] + sum[p[i]][p[i]];
        cout << ans << endl;
    }
}

Measured memory_bytes: 7716
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::*;
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
use std::cmp::min;
 
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    
    // i < j, a[i] + i = j - a[j] <= j < n
    let mut ans: i64 = 0;
    let mut map  = std::collections::BTreeMap::new();
    for i in 0..n {
        let ind = i as i64 - a[i];
        ans += map.get(&ind).map_or(0, |a| *a);
        *map.entry(a[i] + i as i64).or_insert(0) += 1;
    }
    
    println!("{}", ans);
}

Measured memory_bytes: 11860
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val p = in.readLine.split(" ").map(_.toInt)

  val table = Array.ofDim[Int](n+1)
  for(i <- 0 until n - 2) {
    val v = Seq(p(i), p(i+1), p(i+2)).sorted
    if(v(1) == p(i+1)) {
      table(p(i+1)) += 1
    }
  }

  val ans = table.count(_ > 0)
  println(ans)
}

Measured memory_bytes: 27328
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


int main() {
  IOS;
  ll a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22){
    cout<<"bust"<<endl;
  }else{
    cout<<"win"<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int x,y,z,m,e;
	while(1){
	scanf("%d",&e);
	if(e==0){
		break;
	}
	m=e;
	for(z=0;z*z*z<=e;z++){
		for(y=0;y*y+z*z*z<=e;y++){
			x=e-z*z*z-y*y;
			if(m>x+y+z){
				m=x+y+z;
			}
		}
	}
	printf("%d\n",m);
	}
	return 0;
}

Measured memory_bytes: 600
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations
from itertools import accumulate
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def rinsetsudic(lst):
    dic=defaultdict(list)
    for a,b in lst:
        dic[a].append(b)
        dic[b].append(a)
    return dic
mod=10**9+7

n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]

F,S="First","Second"

dic=rinsetsudic(ab)
# print(dic)
last=0
for i in range(n):
    if len(dic[i+1])==1:
        itta=[0]*(n+1)
        d=deque([i+1])
        while d:
            now=d.popleft()
            if itta[now]==1:
                continue
            itta[now]=1
            last=now
            for j in dic[now]:
                d.append(j)
        break
itta=[0]*(n+1)
cnt=0
d=deque([(last,0)])
while d:
    now=d.popleft()
    if itta[now[0]]==1:
        continue
    itta[now[0]]=1
    cnt=now[1]
    for j in dic[now[0]]:
        d.append((j,now[1]+1))
# print(cnt)
if cnt%3==1:
    print(S)
else:
    print(F)

Measured memory_bytes: 159884
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

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

  rep(i, 3) cout << s[i];
  return 0;
}


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

class MainClass
{
    static void Main()
    {
        var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int a = ab[0], b = ab[1];
        string S = Console.ReadLine();
        if (S.Length == a + b + 1)
        {
            if(S[a]=='-'&&int.TryParse(S.Substring(0,a),out int n)&&int.TryParse(S.Substring(a+1),out int m))
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }
}

Measured memory_bytes: 28196
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		PriorityQueue<Integer> queue = new PriorityQueue<Integer>(new Comparator<Integer>() {
		public int compare(Integer i1, Integer i2) {
			return i2.intValue() - i1.intValue();
		}
		});
		for (int i = 0; i < n; i++) {
			queue.add(sc.nextInt());
		}
		for (int i = 0; i < m; i++) {
			int x = queue.poll();
			queue.add(x / 2);
		}
		long total = 0;
		while (queue.size() > 0) {
			total += queue.poll();
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 61364
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
 
	while(kbd.hasNext()) {
	    int n = kbd.nextInt();
	    int a = kbd.nextInt();
	    int b = kbd.nextInt();
	    int c = kbd.nextInt();
	    int x = kbd.nextInt();
	    if(!(n==0 && a==0 && b==0 && c==0 && x==0)){
		solve(n, a, b, c, x);
	    }
	}
    }
 
    static void solve(int n, int a, int b, int c, int x){
	int f=0;//かかったフレーム数
	int[] r = new int[n];  //リール乱数の配列
	int i;   //作業用
	for(i=0; i<n; i++){      //乱数放り込む
	    r[i] = kbd.nextInt();
	}
 
	i=0;
	while(f<=10000 && i<n){
	    if(r[i]==x){
		i++;
	    }
	    x = (a*x+b)%c;
	    f++;
	}
	
	if(i==n){
	    System.out.println(f-1);
	}
	else{
	    System.out.println("-1");
	}
    }
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		String str = "APPROVED";

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] % 2 == 0) {
				if (A[i] % 3 != 0 && A[i] % 5 != 0) {
					str = "DENIED";
				}
			}
		}
		sc.close();
		System.out.println(str);
	}

}


Measured memory_bytes: 23252
#include <iostream>

using namespace std;

string s_string;
char s[100000];
int a[100000];

int main() {
    cin >> s_string;
    int n = s_string.size();
    s_string.copy(s, n);
    for (int i = 0; i < n; ++i) a[i] = 0;
    int count = 0;
    int lp = 0;

    for (int k = 0; k < n; ++k) {
        if (k == 0 || s[k] == s[k - 1]) {
            count++;
        } else {
            if (s[k] == 'L') {
                a[k] += count / 2;
                a[k - 1] += (count + 1) / 2;
                lp = k;
                count = 1;
            } else if (s[k] == 'R') {
                a[lp] += (count + 1) / 2;
                a[lp - 1] += count / 2;
                count = 1;
            }
        }
    }
    a[lp] += (count + 1) / 2;
    a[lp - 1] += count / 2;

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


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, j, n) for(size_t i = (j); i < (n); ++i)
int main() {
	int n, p; cin >> n;

	vector<int> target(n + 1);
	rep(i, 1, n + 1) {
		cin >> p;
		target[p] = i;
	}
	rep(i, 1, n + 1) cout << n * i << " \n"[i == n];
	rep(i, 1, n + 1) cout << n * (n - i) + target[i] << " \n"[i == n];
	return 0;
}


Measured memory_bytes: 3676
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<string.h>
#include<iomanip>
using namespace std;
int main()
{
	string a;
	char b[10000];
	int m[100];
	int n,k,sum=0;//??£??¨???????????????,string?±????????¬???????????????§?°??°±???????????????
	while(cin>>a)
	{
	
		
		m[0]=0;
		if(a=="-")//?????????????????¨?????????????????????????????????????¬????,???????°?????????¨???????¬??????????????????¶??¶??????????¬????
			break;
		
		sum++;
		m[sum]=a.length();
		cin>>n;

	
	for(int i=0;i<n;i++)
	{
		cin>>k;
	for(int j=0;j<k;j++)
	{
		a.push_back(a[j]);
		
		
	/*a.pop_back();*/
		/*a[i]=' ';*/
	}
	a.erase(0,k);//??¨???????????????????§?????????????????°??°±???????°?,????°±??????????????¨???????????????,??¨???sum???????????????
	

	}
	m[sum]=m[sum]+m[sum-1];

	
	for(int p=m[sum-1];p<m[sum];p++)//??????????????\??¨????¬????????????¶
		b[p]=a[p-m[sum-1]];

	
	
	
	
	}
	
	for(int q=1;q<=sum;q++)
		{
			for(int j=m[q-1];j<m[q];j++)
			cout<<b[j];
			cout<<endl;

	
	
	}
}

Measured memory_bytes: 3168
#include <iostream>
//#include <math.h>
#include <set>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
    
    int n;
    ll ans =0;
    vector<pll> v(maxn);
    multiset<ll> ms;
    
    cin >> n;
    rep(i,n){
        cin >> v[i].first;
        v[i].second = i;
        ms.insert(i);
    }
    
    sort(v.begin(),v.begin()+n);
    //cout << v[0].first<<endl;
    
    ms.insert(-1);ms.insert(-1);ms.insert(n);ms.insert(n);
    
    rep(i,n){
//        ll add = 0;
        ll arg = v[i].first;ll idx = v[i].second;
        auto c = ms.find(idx);
        auto r = next(c,1); auto l = prev(c,1);
        ll r_1 = *r;ll l_1 = *l;
        r = next(r,1);l = prev(l,1);
        ll r_2 = *r;ll l_2 = *l;
        
        ans += arg *((l_1-l_2)*(r_1-idx)+(idx-l_1)*(r_2-r_1));
//        cout <<"idx"<<space<< l_2<<space<<l_1<<space<<idx<<space<<r_1<<space<<r_2<<endl;
//        cout <<"arg"<<space<<arg<<space<<"add"<<space<<add<<endl;
//        ans += add;
        ms.erase(idx);
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 6528
N, M = map(int, input().split())
V = [[] for _ in range(N)]
lst = []
for _ in range(M):
    a, b = map(int, input().split())
    V[a - 1].append(b - 1)
    V[b - 1].append(a - 1)
    lst.append([a - 1, b - 1])

def dfs(v, prohibited):
    global visited
    visited[v] = True
    for adj in V[v]:
        if {v, adj} == {lst[prohibited][0], lst[prohibited][1]}: continue
        if visited[adj]: continue
        dfs(adj, prohibited)

ans = 0

# 1本かけた状態で連結しているか否かを判定する
for i in range(M):
    Q = []
    visited = [False] * N
    dfs(0, i)
    if not all(visited): ans += 1 

print(ans)

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

using namespace std;

#ifdef ACMTUYO
struct RTC{~RTC(){cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC <<" seconds\n";}} runtimecount;
#define DBG(X) cerr << #X << " = " << X << '\n';
#else
struct RTC{};
#define DBG(X)
#endif

#define fast_io() ios_base::sync_with_stdio(false)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(c) (c).begin(),(c).end()
#define forn(i, n) for (int i = 0; i < (n); i++)
typedef long long int number;
const int maxn = 1000010;
int n;
int a[maxn];
int f[maxn];
bool vis[maxn];
vector<int> fact(int x) {
  set<int> fcs;
  while (x > 1) {
    fcs.insert(f[x]);
    x /= f[x];
  }
  return vector<int>(all(fcs));
}
int main() {
  for (int i = 2; i < maxn; i += 2) {
    f[i] = 2;
  }
  for (int i = 3; i < maxn; i += 2) {
    if (!f[i]) {
      for (int j = i; j < maxn; j += i) {
        f[j] = i;
      }
    }
  }
  scanf("%d", &n);
  forn (i, n) {
    scanf("%d", a + i);
  }

  bool ok = true;
  for (int i = n - 1; i >= 0 and ok; i--) {
    int x = a[i];
    vector<int> facts = fact(x);
    for (int fac: facts) {
      if (vis[fac]) {
        ok = false;
        break;
      }
      vis[fac] = true;
    }
  }
  if (ok) {
    puts("pairwise coprime");
    return 0;
  }
  int gcd = a[0];
  for (int i = 1; i < n; i++) {
    gcd = __gcd(gcd, a[i]);
  }
  puts(gcd == 1?"setwise coprime": "not coprime");

  return 0;
}

Measured memory_bytes: 11444
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

double t, x;

int main() {
	cin >> t >> x;
	
	printf("%.6f\n", t / x);
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n, x, sum;
	while(1){
		x=getchar();
		if(x=='0'){
			break;
		} else {
			sum=x-'0';
			while(1){
				n=getchar();
				if(n=='\n'){
					printf("%d\n", sum);
					sum=0;
					break;
				} else {
					sum+=n-'0';
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 524
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return(a)

a,b,c,d=map(int,input().split())
cn1=0
cn2=0
cn3=0
an1=0
an2=0
an3=0
cnt=0
ans=0
lm=(c*d)//gcd(c,d)

#bまで
cn1=b//c
cn2=b//d
cn3=b//lm
#aまで
an1=(a-1)//c
an2=(a-1)//d
an3=(a-1)//lm
#aからbまで
cn1=cn1-an1
cn2=cn2-an2
cn3=cn3-an3

cnt=cn1+cn2-cn3
ans=b-a-cnt+1

print(ans)


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

int main(){
	string s;
  	int ans=0;
  	cin>>s;
  	
	for(int i=0;i<s.size();++i)ans+=(int)(s[i]-'0');
  	int n=stoi(s);
  	if(n%ans==0)cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
  	return 0;
}

Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

D = lines[0][0]

class Array
  def max_id
    max = - 10000000000
    tmp = -1
    for i in 1..self.length do
      if self[i-1] > max then
        tmp = i-1
        max = self[i-1]
      end
    end
    return tmp
  end
end

last_date = []
for i in 1..26 do
  last_date.push(0)
end

satis = 0
for i in 1..D do
  contest = lines[D+i+1][0]
  satis += lines[i+1][contest-1]
  last_date[contest-1] = i
  for j in 1..26 do
    satis -= (i - last_date[j-1]) * lines[1][j-1]
  end
  puts satis
end

Measured memory_bytes: 14328
while True:
    m, f, r = map(int, input().split())
    if m+f+r==-3:
        break

    if m==-1 or f==-1:
        print('F')

    else:
        score=m+f
        if score>=80:
            print('A')
        elif 80> score>=65:
            print('B')
        elif 65> score>=50:
            print('C')
        elif 50>score>=30:
            if r>=50:
                print('C')
            else:
                print('D')
        else:
            print('F')


Measured memory_bytes: 5596