akhauriyash/Code-Regression huggingface dataset:
//#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    char a, b;
    cin >> a >> b;
    if(a=='H'&&b=='H') P("H");
    else if(a=='H'&&b=='D') P("D");
    else if(a=='D'&&b=='H') P('D');
    else P('H');
    return 0;
}



Measured memory_bytes: 256
<?php

$lines = explode(" ", fgets(STDIN));
$a = array();
for ($i = 0; $i < count($lines); $i++) {
    $tmp = trim($lines[$i]);
    $c = count($a);
    if (ctype_digit($tmp)) {
        $a[$c] = $tmp;
    } else {
        if ($tmp == "+") {
            $a[$c - 2] = $a[$c - 2] + $a[$c - 1];
        } elseif ($tmp == "*") {
            $a[$c - 2] = $a[$c - 2] * $a[$c - 1];
        } elseif ($tmp == "-") {
            $a[$c - 2] = $a[$c - 2] - $a[$c - 1];
        } elseif ($tmp == "/") {
            $a[$c - 2] = $a[$c - 2] / $a[$c - 1];
        }
        unset($a[$c - 1]);
    }
}
echo $a[0];
?>

Measured memory_bytes: 15540
main :: IO ()
main = do
  [w,h,n] <- map read . words <$> getLine :: IO [Int]
  pta <- getInfo n
  let (s,e) = overwrite pta ((0,0), (w,h))
  print $ area s e

type Pos = (Int, Int)
type Pta = [Int]

getInfo :: Int -> IO [Pta]
getInfo n = sequenceA (replicate n (map read . words <$> getLine))

overwrite :: [Pta] -> (Pos, Pos) -> (Pos, Pos)
overwrite [] (start, end) = (start,end)
overwrite (x:xs) (start,end) 
  |a == 1 = if fst start < xi then 
                              overwrite xs ((xi, snd start), end) 
                              else 
                              overwrite xs (start, end) 
  |a == 2 = if fst end > xi then 
                              overwrite xs (start, (xi, snd end)) 
                              else 
                              overwrite xs (start, end) 
  |a == 3 = if snd start < yi then 
                              overwrite xs ((fst start, yi), end) 
                              else 
                              overwrite xs (start, end) 
  |otherwise = if snd end > yi then 
                              overwrite xs (start, (fst end, yi))
                              else 
                              overwrite xs (start, end) 
  where a = last x
        xi = head x
        yi = x !! 1


area :: Pos -> Pos -> Int
area (sx,sy) (ex,ey) = 
  if ex > sx && ey > sy then a else 0
    where a = (ex-sx) * (ey-sy)


Measured memory_bytes: 1020
from heapq import heappush, heappop
import queue
import re
import math
import functools

def s_raw():
    return input().rstrip("\r")

def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return list(map(int, ss_raw()))


INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    

def main():
    N,M = ints_raw()
    As = ints_raw()
    As = [-a for a in As]
    As.sort()
    for i in range(M):
        a = heappop(As)
        heappush(As,-((-a)//2))
    return -sum(As)

    


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 64616
#!/usr/bin/env python3
S = input()
Q = int(input())

count = True
ans = S

ireru_mae = ''
ireru_usiro = ''
for i in range(Q):
    T = input().split()
    if len(T)==1:
        count = not(count)
        continue

    if count:
        if T[1] == '1': ireru_mae = T[2] + ireru_mae
        else: ireru_usiro += T[2]
    else:
        if T[1] == '1': ireru_usiro += T[2]
        else: ireru_mae = T[2] + ireru_mae

ans = ireru_mae + ans + ireru_usiro
if count:
    print(ans)
else:
    print(ans[::-1])


Measured memory_bytes: 4576
import sys
#input = sys.stdin.readline

def main():
    n,k=map(int,input().split())
    s=input()
    g=1
    for a,b in zip(s,s[1:]):
        if a!=b:
            g+=1
    print(n-max(1,g-2*k))

if __name__ == '__main__':
    main()

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int W, H, x, y;
    cin >> W >> H >> x >> y;

    if( W % 2 == 0 && H % 2 == 0 ){
        cout << (double)W * H / 2 << " ";
        if( x == W / 2 && y == H / 2 ){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        cout << (double)W * H / 2 << " ";
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
int main() {
  string a,s,c;
  cin >> a >> s >> c;
  cout << "A" << s[0] << "C" << endl;
}
  


Measured memory_bytes: 256
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,
        k: usize,
        v: [usize; n]
    }
    let mut w = v;
    w.sort();
    if w[0] >= k {
        println!("0");
        return;
    }
    {
        let mut ps: Vec<bool> = vec![false;k];
        ps[0] = true;
        for i in 1..n {
            let mut psn = ps.clone();
            for j in 0..k {
                if j + w[i] >= k {
                    break;
                }
                if ps[j] == true {
                    psn[j + w[i]] = true;
                }
            }
            ps = psn;
        }
        if ps[k-w[0]..].iter().any(|&x| x) {
            println!("0");
            return;
        }
    }
    let mut l = 0;
    let mut r = n;
    while l + 1 < r {
        let m = (l + r) / 2;
        if w[m] >= k {
            r = m;
            continue;
        }
        let mut ps: Vec<bool> = vec![false;k];
        ps[0] = true;
        for i in 0..n {
            if i == m {
                continue;
            }
            let mut psn = ps.clone();
            for j in 0..k {
                if j + w[i] >= k {
                    break;
                }
                if ps[j] == true {
                    psn[j + w[i]] = true;
                }
            }
            ps = psn;
        }
        if ps[k-w[m]..].iter().any(|&x| x) {
            r = m;
        } else {
            l = m;
        }
    }
    println!("{}",r);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	double a, b, c, d; cin >> a >> b >> c >> d;
	cout << a * b / 2 << ' ' << (c * 2 == a && d * 2 == b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 0x7FFFFFFF

int main()
{
    ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
    string ch;
    cin >> ch;
    int i;
    bool zero = 1;
    for (i = 0; i < ch.size(); i++)
    {
        if (ch[i] == ch[i + 1])
        {
            cout << i + 1 << ' ' << i + 2 << endl;
            zero = 0;
            break;
        }
        else if (ch[i] == ch[i + 2])
        {
            cout << i + 1 << ' ' << i + 3 << endl;
            zero = 0;
            break;
        }
    }
    if (zero)
    {
        cout << -1 << ' ' << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3728
from collections import deque
import bisect
n = int(input())
L = deque([int(input())])
for i in range(1,n):
    t = int(input())
    k = bisect.bisect_left(L, t)
    if k == 0:
        L.appendleft(t)
    else:
        L[k-1] = t
print(len(L))


Measured memory_bytes: 7412
require 'set'

def calc_d(n)
  i = 1
  d = Set.new
  while i ** 2 <= n
    if n % i == 0
      d << i
      d << n / i    
    end
    i += 1
  end
  d.size
end

n = gets.to_i

ans = 0

1.upto(n) do |i|
  next if i % 2 == 0
  ans += 1 if calc_d(i) == 8
end

puts ans


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

fill :: (IORef Int) -> (IOUArray (Int, Int) Char) -> (Int, Int) -> IO ()
fill ref arr p = do
    c <- readArray arr p
    when (c=='1') $ do
        modifyIORef ref (+1)
        fill' arr p

fill' :: (IOUArray (Int, Int) Char) -> (Int, Int) -> IO ()
fill' arr p@(x,y) = do
    c <- readArray arr p
    when (c=='1') $ do
        writeArray arr p '0'
        mapM_ (fill' arr) $ [(x+dx, y) | dx <- [1,-1]] ++ [(x,y+dy) | dy <- [1,-1]]


main = do
    d <- map (((replicate 14 '0':) . (++[replicate 14 '0'])) . map (('0':) . (++"0"))) . splitWhen (=="") . lines <$> getContents
    forM_ d $ \f -> do 
        ref <- newIORef 0
        arr <- newListArray ((0,0),(13,13)) $ concat f
        mapM_ (fill ref arr) [(x,y) | x <- [1..12], y <- [1..12]]
        readIORef ref >>= print

Measured memory_bytes: 4236
N = int(input())
A = [int(input()) for _ in range(N)] + [0]
ans = 0

for i in range(N):
    ans += A[i] // 2
    if A[i] % 2 == 1 and A[i+1] > 0:
        ans += 1
        A[i+1] -= 1

print(ans)


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

int main()
{
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for (int x=0;x<K+1;x++)
    {
        for (int y=0;y<x+1;y++)
        {
            for (int z=0;z<y+1;z++)
            {
                if(x+y+z == S)
                {
                    if (x==y && y==z)
                    {
                        ans += 1;
                    } 
                    else if (x != y && y != z && z != x)
                    {
                        ans += 6;
                    }
                    else
                    {
                        ans +=3;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))


def is_approve(a:list):
  ans = False
  for num in a:
    if num % 2 == 1 :
      ans = True
    elif num % 3 == 0 or num % 5 == 0:
      ans = True
    else:
      ans = False
      break
  return ans

if is_approve(a):
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 9080
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
for i in range(N):
    if A[i]+A[i+1]>=B[i]:
        ans+=B[i]
        if B[i]-A[i]>=0:
            A[i+1]=A[i+1]-(B[i]-A[i])
            A[i]=0
    else:
        ans+=A[i]+A[i+1]
        A[i]=0
        A[i+1]=0
print(ans)

Measured memory_bytes: 18624
import numpy as np
n = int(input())
arr = []

for i in range(n):
    x,y = map(int, input().split(' '))
    arr.append([x,y])

l=0
for i in range(n-1):
    for j in range(i+1, n):
        x_i,y_i = arr[i][0],arr[i][1]
        x_j,y_j = arr[j][0],arr[j][1]
        l += ((x_i-x_j)**2 + (y_i-y_j)**2)**0.5

print((2*l)/n)

Measured memory_bytes: 13288
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int aa,n;
long long ans=1LL,cur=0LL,MOD=1000000007;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	while(n--){
		cin>>aa;
		cur=0LL;
		if(aa==a)
			cur++;
		if(aa==b)
			cur++;
		if(aa==c)
			cur++;
		ans*=cur;
		ans%=MOD;
		if(aa==a){
			a++;
			continue;
		}
		if(aa==b){
			b++;
			continue;
		}
		if(aa==c){
			c++;
			continue;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
abc_list = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
            'n','o','p','q','r','s','t','u','v','w','x','y','z']
abc = ''
while(N>26):
    n = N%26
    N = N//26
    if n==0:
        abc+=abc_list[25]
        N = N-1
    else:
        abc+=abc_list[n-1]
abc+=abc_list[N-1]
print(abc[::-1])

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

int main() {

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

  int n, w;
  cin >> n >> w;

  long long val[w + 5], ans = 0;
  memset(val, 0, sizeof val);

  val[0] = 0;
  for (int i = 0; i < n; ++i) { 
    int wi, v;
    cin >> wi >> v;

    for (int j = w-wi; j >= 0; --j) {
      val[j+wi] = max(val[j+wi], val[j] + v);
      ans = max(ans, val[j+wi]);
    }

  }
  cout << ans << '\n';
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){
  

  int n;
  cin>>n;
  map<vi,ll>  bigdata;
  
  rep(i,n){
    string tmp;
    cin>>tmp;
    vi data(26,0);
    
    rep(j,10){
      data.at(tmp.at(j)-'a')++;
    }
    
    if (bigdata.count(data)){
      bigdata.at(data)++;
    }
    else {
      bigdata[data]=1;
    }
  }
  
  ll answer=0;
  
  for (auto mypair:bigdata){  
    answer+=((mypair.second*(mypair.second-1))/2);
  }
  
  cout<<answer<<endl;
    

  
}






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


int main()
{
   int k,a,b;
   cin>>k>>a>>b;
   for(int i=a;i<=b;i++)
   {
       if(i%k==0)
       {
            cout<<"OK";
            return 0;
       }
   }
   cout<<"NG";



}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
using namespace std;
 
struct st {int from, to;};
vector<st> v;

int main() {
    int m, n, x, y;
    cin >> m >> n;
 
    int c[21] = {};
    for (int i=0; i<n; ++i) {
        cin >> x >> y;
        v.push_back((st){x, y});
        c[y] ++;
    }
 
    for (int i=0; i<m; ++i) {
        for (int j=1; j<=m; ++j) {
            if (c[j] == 0) {
                cout << j << endl;
            	c[j] = (1 << 10);
                for (int k=0; k<n; ++k) {
                    c[v[k].to] -= (v[k].from == j);
                }
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3152
#include <iostream>
    using namespace std;
     
    int main(){
    int a,b;
    cin >>a >>b;
    if(a>=13) cout <<b <<endl;
    else if(a>=6 and a<=12) cout <<b/2 <<endl;
    else cout <<'0' <<endl;
     
    return 0;
    }

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

int main() {
  long long int N,D;
  cin >> N  >> D;
  int count =0;
  for(int i=0; i<N; i++){
    long long int a,b;
    cin >> a >> b;
    if(a*a+b*b<=D*D){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextIntArray(N);

        System.out.println(solve());
    }

    static int solve() {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            map.put(A[i], i);
        }

        int[] B = Arrays.copyOf(A, N);
        Arrays.sort(B);

        int odd = 0;
        for (int bi = 0; bi < N; bi++) {
            int ai = map.get(B[bi]);
            if( (Math.abs(ai - bi)) % 2 == 1 ) odd++;
        }
        if( odd % 2 == 0 ) {
            return odd / 2;
        } else {
            throw new RuntimeException("wtf");
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

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

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

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

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

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


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


// 最大曼哈顿距离
int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        a[i] = x+y;
        b[i] = x-y;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int ans = max(a[n-1]-a[0], b[n-1]-b[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4816
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(){ 
	int count[26] = {0},c,zero = 'a',i,num;
	while((c=getchar()) != EOF){
		if('A' <= c && c <= 'Z'){
			c += 32;
		}
		num = c-zero;
		count[num]++;
	}
	for(i = 'a';i <='z';i++){
		num = i-zero;
		printf("%c : %d\n",i,count[num]);
	}
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int y,x,n;
	while(cin>>x>>y){
	if(x==0&&y==0) break;
	if(x>y){
		n=x;
		x=y;
		y=n;
	}
	cout<<x<<" "<<y<<endl;
	} 
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  double t,x;
  cin >> t >> x;

  cout << t/x << endl;
  return 0;
}

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

typedef long long ll;

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

    int a,b;
    cin >> a >> b;
    int ans,num;
    if(a<b){
        ans = a;
        num = b;
    }else{
        ans = b;
        num = a;
    }
    for(int i=0;i<num;i++) cout << ans;
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int n,x[1005],y[1005],i,j,m=31,a[35];
int main(){
	for(i=0;i<=30;++i)a[31-i]=1<<i;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d%d",x+i,y+i);
	if((x[1]+y[1])%2==0)a[++m]=1;
	for(i=2;i<=n;++i)if(((x[i]+y[i])&1)!=((x[1]+y[1])&1))break;if(i<=n){puts("-1");return 0;}
	printf("%d\n",m);for(i=1;i<=m;++i)printf("%d%c",a[i],i==m?'\n':' ');
	for(i=1;i<=n;++i){
		for(j=1;j<=m;++j)if(abs(x[i])>=abs(y[i]))putchar(x[i]>0?x[i]-=a[j],'R':(x[i]+=a[j],'L'));
			else putchar(y[i]>0?y[i]-=a[j],'U':(y[i]+=a[j],'D'));
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 200003;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define fr(s,n) for (int i=(int)(s);i<(int)(n);i++)
#define lc cout<<"\n"
//double pi=2*acos(0.0);
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    int a[n]={0};
    fr(0,k){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int x;
            cin>>x;
            a[x-1]=1;
        }
    }
    int ans=0;
    fr(0,n){
        ans+=!a[i];
    }
    cout<<ans;
}



Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;
int main()
{
	ll N,f=0;
	vector<ll> A;
	cin >> N;

	fore(i, 0, N) {
		ll t;
		cin >> t;
		A.push_back(t);
	}
	sort(A.begin(), A.end());
	fore(i, 0, A.size()-1) {
		if (A[i] == A[i + 1])f = 1;
	}
	if (f != 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


}


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

using namespace std;

typedef long long ll;

const int Maxn = 100010;
ll x[Maxn];

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

    ll ans = numeric_limits<ll>::max();
    for (int i = 0; i <= n - k; ++i) {
        ll len = x[i + k - 1] - x[i];
        len += min(abs(x[i + k - 1]), abs(x[i]));
        ans = min(ans, len);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import numpy as np
n = int(input())
A = []
for _ in range(n):
  j = int(input())
  tmp = []
  for _ in range(j):
    x, y = map(int, input().split())
    tmp.append([x, y])
  A.append(tmp)
A = np.array(A)
# print(A)

ans = 0
for i in range(1, pow(2, n)):
  person = [-1 for _ in range(n)]

  b = [int(j) for j in list(format(i, 'b').zfill(n))]
  # print('b', b)
  indices = [i for i, x in enumerate(b) if x == 1]
  state = A[indices]
  # print(state)
  flag_contradiction = False
  for d in state:
    for e in d:
      x, y = e
      # print(b, x-1, y)
      if b[x-1] != y:
        # print('flag')
        flag_contradiction = True
        break
    if flag_contradiction:
      break
  if not flag_contradiction:
    ans = max(ans, sum(b))
  # print(ans)
print(ans)
  
        

Measured memory_bytes: 12444
number = gets.to_i


if number<=100
    
    puts 0
    exit
end

string = number.to_s.split("").map(&:to_s)
ll = string.length

arr = [0,0,0,0,0,0,0,0,0]

i = 1
9.times{
    arr[i-1] = 3**i-3-3*(2**i-2)
    
    i+=1
}

 

count = arr[0...ll-1].inject(:+)


k = 0
(3**ll).times{
    three = k.to_s(3).split("").map(&:to_i)
    
    three = Array.new(ll-three.length,0)+three
    
    key = 0
    
    unless three.include?(2) && three.include?(1) && three.include?(0) 
    k+=1
    next
    end
    
    j = 0
    ll.times{
        
        if three[j] == 2
            key+=7*(10**(ll-j-1))
        end
        
        if three[j] == 1
            key+=5*(10**(ll-j-1))
            
        end
        
        if three[j] == 0
            key+=3*(10**(ll-j-1))
        end
    
        
        j+=1
    }
    

    if key<=number
        count+=1
    end

    k+=1
}



puts count


Measured memory_bytes: 2044
#include<iostream>
using namespace std;
int dp[50];
int fibonacci(int x){
  if(x==0 || x==1) return 1;
  if(dp[x]!=0) return dp[x];
  return dp[x]=fibonacci(x-1)+fibonacci(x-2);
}
int main(){
  int n;
  cin>>n;
  cout<<fibonacci(n)<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long l[87]={2,1};
    int n;
    cin >> n;
    for(int i=2;i<=n;i++){
        l[i]=l[i-1]+l[i-2];
    }
    cout << l[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 1000005;
string a;
int ans, n, dp[N][2];

int f(int i, int carry) {
    int digit = ((a[i] - '0')) + carry;
    if (i == 0) return digit;
    if (dp[i][carry]) return dp[i][carry];
    return dp[i][carry] = (min(f(i-1, 1) + (10-digit), f(i-1, 0) + digit));
}

pls give {
    AC;
    cin >> a;
    n = a.length();
    a = '0' + a;
    cout << f(n, 0) << nl;
}

Measured memory_bytes: 63816
s=gets.chomp
cnt=Hash.new(0)
s.each_char do |c|
  cnt[c] += 1
end
flag = true
# cnt.keys.each do |key|
#   if cnt[key] != 2
#     flag = false
#     break
#   end
# end
puts (cnt.keys.size == 2 && flag) ? 'Yes' : 'No'

Measured memory_bytes: 1788
// https://atcoder.jp/contests/abc091/tasks/abc091_a
#include <stdio.h>

int main(int argc, char **argv) {
  int a, b, c;

  while (scanf("%d %d %d", &a, &b, &c) != EOF) {
    if (a + b >= c) {
      puts("Yes");
    } else {
      puts("No");
    }
  }

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		sc.close();

		int d = a / b;
		int r = a % b;
		double f = 1.0 * a / b;

		System.out.println(d + " " + r + " " + String.format("%.6f", f));

	}

}


Measured memory_bytes: 26444
#include<stdio.h>
char a[100010];
long long int c;
int main(){
    int i;
    scanf("%s",a);
    for(i=0;a[i]!='\0';i++){
        if(a[i]=='g') c++;
    }
    if(i%2==1){
        c=c-i/2-1;
    }else{
        c=c-i/2;
    }
    printf("%lld",c);
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;


int mem[100][100];
int sg(int x,int y)
{
	if(x<y)swap(x,y);
	if(mem[x][y]!=-1)return mem[x][y];
	set<int> s;
	FOR(i,1,x)
	{
		if(x-2*i<0)break;
		s.insert(sg(x-2*i,y+i));
	}

	FOR(i,0,10000)if(!s.count(i))return mem[x][y] = i;
	throw;
}
int main()
{
	//freopen("in.txt", "r", stdin);

	LL x,y;
	cin>>x>>y;
	if(abs(x-y)>1)
	{
		cout<<"Alice";
	}else
	{
		cout<<"Brown";
	}
	return 0;
	FILL(mem,-1);

	FOR(x,0,20)
	{
		FOR(y,0,x+1)
		{
			cout<<sg(x,y)<<" ";
		}
		cout<<endl;
	}
}


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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define pb push_back


// string size = str.size()

// stack <int> s; 
// queue <int> gquiz; 
// __gcd(m, n) 

// ll arr[10e5 + 5];
// char arr[10e5 + 5];

// printf ("%.9f\n",x);

bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}


int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    ll fh = n/500;
    n = n - fh * 500;
    ll five = n/5;
    // cout << fh << endl;
    // cout << five << endl;
    cout << fh * 1000 + five * 5 << endl;
    return 0;
}   

Measured memory_bytes: 256
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N, D;
    cin >> N >> D;

    ll ans = 0;
    REP(i, N)
    {
        ll X, Y;
        cin >> X >> Y;

        double distance = sqrt(X * X + Y * Y);
        if (distance <= D)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


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

int main () {
  bool nul[4][13] ={};
  int N ;
  cin >> N ;
  for(int i = 0 ; i < N ;i++){
    char a ;
    int b ;
    cin >> a >> b ;
    if(a=='S') nul[0][b-1] = true ;
    if(a=='H') nul[1][b-1] = true ;
    if(a=='C') nul[2][b-1] = true ;
    if(a=='D') nul[3][b-1] = true ;
  }
  for(int i = 0 ; i < 52 ; i++){
    if(nul[i/13][i%13]==true) {
      continue ;
    } else {
      if(i/13==0) cout << "S " <<i%13+1 << endl;
      else if (i/13==1) cout << "H " <<i%13+1 << endl;
      else if (i/13==2) cout << "C " <<i%13+1 << endl;
      else if (i/13==3) cout << "D " <<i%13+1 << endl;
    }
  }
}


Measured memory_bytes: 3084
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(void){
    int ac, wa, tle, re;
    ac = wa = tle = re = 0;
    int N; cin >> N;
    while (N--){
        string S; cin >> S;
        if (S == "AC") ++ac;
        else if (S == "WA") ++wa;
        else if (S == "TLE") ++tle;
        else ++re;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3616
while True:
    h,w = map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for j in range(w):
            if (i+j)%2 == 0 :
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()


Measured memory_bytes: 7004
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int m = sc.nextInt()-1;
			int[] a = new int[m];
			int[] b = new int[m+1];
			int x = sc.nextInt();
			int y = sc.nextInt();
			int p, q;
			for(int i=0;i<m;i++){
				p = sc.nextInt();
				q = sc.nextInt();
				a[i] = p-x + q-y;
				if(i!=0){
					if(a[i-1]*a[i]>0) b[i] = 1;
					else b[i] = -1;
				}
				if(q==y) b[i] = -b[i];
				x = p;
				y = q;
			}

			boolean flag;
			for(int i=1;i<=n;i++){
				int r = sc.nextInt()-1;
				int[] c = new int[r];
				int[] d = new int[r+1];
				x = sc.nextInt();
				y = sc.nextInt();
				for(int j=0;j<r;j++){
					p = sc.nextInt();
					q = sc.nextInt();
					c[j] = p-x + q-y;
					if(j!=0){
						if(c[j-1]*c[j]>0) d[j] = 1;
						else d[j] = -1;
					}
					if(q==y) d[j] = -d[j];
					x = p;
					y = q;
				}
				if(r!=m) continue;
				
				flag = false;
				for(int j=0;j<m;j++){
					if(Math.abs(a[j])==Math.abs(c[j]) && b[j]==d[j]);
					else{
						flag = true;
						break;
					}
				}
				if(flag==false){
					System.out.println(i);
					continue;
				}
				
				flag = false;
				for(int j=0;j<m;j++){
					if(Math.abs(a[j])==Math.abs(c[m-1-j]) && b[j]==-d[m-j]);
					else{
						flag = true;
						break;
					}
				}
				if(flag==false)System.out.println(i);
			}
			System.out.println("+++++");
		}	
	}	
}

Measured memory_bytes: 29324
#include <iostream>
#include <algorithm>
#include <iomanip>


const int MAXN = 3000;

double proba[MAXN];


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

	int coins; std::cin >> coins;
	proba[0] = 1;

	for (int iCoin = 0; iCoin < coins; iCoin++)
	{
		double probHead; std::cin >> probHead;
		for (int iHeads = coins; iHeads > 0; iHeads--)
				proba[iHeads] = proba[iHeads - 1] * probHead + proba[iHeads] * (1 - probHead);
		proba[0] *= 1 - probHead;
	}

	double probMore = 0;
	for (int iHeads = coins; iHeads > coins / 2; iHeads--)
			probMore += proba[iHeads];
	std::cout << std::setprecision(9) << probMore << '\n';

	return 0;
}


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

using namespace std;

int main() {
  string S;
  int K;
  cin >> S >> K;

  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'a') continue;
    int countToA = 'z' - S[i] + 1;
    if (countToA <= K) {
      S[i] = 'a';
      K -= countToA;
    }
  }

  int alphabet = S.back() - 'a' + K;
  alphabet = alphabet % 26;
  S.back() = 'a' + alphabet;

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rep3(k,n) for(int k = 0; k < (n); ++k)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; j < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int X,Y,Z,K;
  cin >> X >> Y >> Z >> K;
  v(ll) A(X),B(X),C(X);
  rep(i,X) cin >> A[i];
  rep(i,Y) cin >> B[i];
  rep(i,Z) cin >> C[i];
  v(ll) AB;
  rep(i,X) {
    rep2(j,Y) {
      AB.push_back(A[i] + B[j]);
    }
  }
  sort(rng(AB));
  reverse(rng(AB));
  v(ll) ABC;
  rep(i,min(K,sz(AB))) {
    rep2(j,Z) {
      ABC.push_back(AB[i] + C[j]);
    }
  }
  sort(rng(ABC));
  reverse(rng(ABC));
  rep(i,K) {
    cout << ABC[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 43240
#include<iostream>
#include<set>
#include<vector>
#include<unordered_map>
#include<algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++){
        cin >> p.at(i);
    }
    unordered_map<int, int> pm;
    for (int i = 0; i < N; i++){
        pm[p.at(i)] = i;
    }
    set<long> ps;
    ps.insert(-1);
    ps.insert(pm[N]);
    ps.insert(N);
    long long r = 0;
    for (int i = N-1; i > 0; i--){
        auto x = ps.upper_bound(pm[i]);
        set<long>::iterator xm(x);
        xm--;
        auto xp = ps.upper_bound(*x);
        if(xp != ps.end()){
            r += i * ((pm[i] - *xm) * (*xp - *x));
        }
        if(xm != ps.begin()){
            set<long>::iterator xmm(xm);
            xmm--;
            r += i * ((*xm - *xmm) * (*x - pm[i]));
        }
        ps.insert(pm[i]);
    }
    cout << r << endl;
}



Measured memory_bytes: 9380
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define int long long

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define pb emplace_back
#define mp make_pair

using namespace std;

const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

typedef pair<ll, ll> P;

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll R, C, N, M, K, Q;

vector<ll> v[300000];
vector<ll> cost(300000,0);
vector<ll> res(300000,-1);

void dfs(ll node, ll lastCost = 0){
    PRINT(node)
    PRINT(res[node])
    if(res[node]!=-1){
        PRINT("FINISH")
        return;
    }
    lastCost+=cost[node];
    res[node] = lastCost;
    irep(itr,v[node]){
        PRINT(*itr)
        dfs(*itr, lastCost);
    }
    return;
}

signed main() {
    //cout << fixed << setprecision(10);
    cin >> N >> Q;

    rep(i, N-1){
        ll from,to; cin >> from >> to;
        from --;
        to --;
        v[from].pb(to);
        v[to].pb(from);
    } 
    rep(i,Q){
        ll node, val; cin >> node >> val;
        cost[--node] += val;
    }

    dfs(0);

    rep(i, N){
        cout << res[i] << endl;
    }

    //cout << max << endl;
}


Measured memory_bytes: 26624
#include <bits/stdc++.h>  // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int a,b;
  cin >> a >> b;
  if(a+b==15) cout << '+' << endl;
  else if(a*b==15) cout << '*' << endl;
  else cout << 'x' << endl;
  return 0;
}


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

using namespace std;

int main() {
    vector<long long int> cnt(5, 0);
    int N;
    cin >> N;
    for(int n=0; n<N; n++) {
        string str;
        cin >> str;
        if(str[0]=='M') {
            cnt[0]++;
        } else if(str[0]=='A') {
            cnt[1]++;
        } else if(str[0]=='R') {
            cnt[2]++;
        } else if(str[0]=='C') {
            cnt[3]++;
        } else if(str[0]=='H') {
            cnt[4]++;
        }
    }

    long long int ans=0;
    for(int i=0; i<5; i++) {
        for(int j=i+1; j<5; j++) {
            for(int k=j+1; k<5; k++) {
                ans += cnt[i]*cnt[j]*cnt[k];
            }
        }
    }
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
while data =gets
x=1
y=1
z=1
gcd=[]
gcda=[]
gcdb=[]

lcma=[]
lcmb=[]

	a,b=data.split(" ").map{|num| num.to_i}
	i=2
	while i <= a || i <= b
		if a%i==0 && b%i==0
#		p "a=#{a} b=#{b} i=#{i}  ab??????"
			gcd << i
			a = a/i
			b = b/i
			redo
		elsif a%i==0
#		p "a=#{a} b=#{b} i=#{i}  a??????"
			gcda << i
			a = a/i
			redo
		elsif b%i==0
#		p "a=#{a} b=#{b} i=#{i}  b??????"
			gcdb << i
			b = b/i
			redo
		end
		i+=1
#		p "#{a} #{b}"
	end

	gcda.each do |i|
		x=x*i 
	end

	gcdb.each do |i|
		y=y*i 
	end

	gcd.each do |i|
		z=z*i 
	end

	#puts "#{gcd} #{x} #{y} #{z} #{x*y*z}"
	puts "#{z} #{x*y*z}"

end

Measured memory_bytes: 8520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2001,INF=1<<30;
 
int main(){
    
    int N;cin>>N;
    vector<vector<char>> S(N,vector<char>(N));

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

    int cnt=0;

    for(int k=0;k<N;k++){
        bool flag=true;
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                int x=(i+k)%N,y=(j+k)%N;
                if(S[x][j]!=S[y][i]) flag=false;
            }
        }
        if(flag) cnt++;
    }

    cout<<cnt*N<<endl;
}


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

int main(){
	int M, D; cin >> M >>D;

    int ans=0;
    for(int m=1; m<=M; m++){
        for(int d10=2; d10<=9; d10++){
            for(int d1=2; d1<=9; d1++){
                if(10*d10+d1>D) goto OUT;
                if(m==d1*d10) ans++;
            }
        }
        OUT: ;
    }

	cout << ans << endl;
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

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

    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }

    rep2(i,k,n-1){
        if(a[i-k]<a[i])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

}


Measured memory_bytes: 4832
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

char ALPHA[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

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

    rep(i, s.size()) {
        rep(j, 26) {
            if(s[i] == ALPHA[j]) {
                s[i] = ALPHA[(j+n)%26];
                break;
            }
        }
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256