akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> a(M);
  std::vector<long long> b(M);
  vector<int> graph[10];
  for (int i = 0; i < M; i++)
  {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
    a[i]--;
    b[i]--;
    graph[a[i]].push_back(b[i]);
    graph[b[i]].push_back(a[i]);
  }
  vector<int> v(N);
  iota(v.begin(), v.end(), 0);
  int cnt = 0;
  do
  {
    if (v[0] != 0)
      continue;
    bool flag = true;
    for (int i = 1; i < N; ++i)
    {
      bool t = false;
      for (int j = 0; j < graph[v[i - 1]].size(); ++j)
      {
        if (graph[v[i - 1]][j] == v[i])
        {
          t = true;
          break;
        }
      }
      if (!t)
      {
        flag = false;
        break;
      }
    }
    if (flag)
    {
      cnt++;
    }
  } while (next_permutation(v.begin(), v.end()));

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
 
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;
 
using namespace std;
 
int main (void) {
    ll N, ans;
    scanf("%lld", &N);
    vector<ll> d(N);
    ans = 0;
    REP(ll,i,0,N) scanf("%lld",&d.at(i));
    REP(ll,i,0,N-2){
        if ( d.at(i) < d.at(i+1) && d.at(i+1) < d.at(i+2) ) ans++;
        else if ( d.at(i+2) < d.at(i+1) && d.at(i+1) < d.at(i) ) ans++;
    }
    printf("%lld\n", ans);
    return 0;
}

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

if n <= 1:
  n_even = 0
else:
  n_even = n * (n-1) / 2
if m <= 1:
  m_even = 0
else:
  m_even = m * (m-1) / 2

even = n_even + m_even
print(int(even))


Measured memory_bytes: 2940
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete




main = replicateM 10 getInt >>= print . sum


Measured memory_bytes: 3692
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
LR_list = [list(map(int, input().split())) for i in range(M)]

L = 1
R = N

for LR in LR_list:
    if LR[0] > L:
        L = LR[0]
    if LR[1] < R:
        R = LR[1]

output = 0
if L <= R:
    output = R - L + 1

print (output)

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

using namespace std;

int n;
int arr[105];

int main()
{
	double ans=0;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		ans+=1.0/arr[i];
	}
	cout << fixed << setprecision(12) << 1.0/ans << endl;
}

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

diff_count = 0
for i in range(N):
    if i+1 != p_input_lst[i]:
        diff_count += 1

if diff_count == 2 or diff_count == 0:
    print("YES")
else:
    print("NO")






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

typedef long long ll;

const int N = 2e5+1;

int a[N];
int main(){
	int n, b;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		a[i] -= i;
	}
	sort(a+1, a+n+1);
	if(n%2)
		b = a[(n+1)/2];
	else b = (a[n/2] + a[n/2 + 1])/2;
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ans += abs(a[i]-b);
	}
	cout << ans << endl;
	return 0;
}


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

const int N=1000100,mod=998244353;
typedef long long ll;
int ksm(ll a,int b,int c=1){
	for(;b;b/=2,a=a*a%mod)
		if(b&1)c=c*a%mod;
	return c;
}
int jc[N],jc2[N],ans,n,m;
void init(){
	jc[0]=1;
	for(int i=1;i<N;++i)jc[i]=(ll)jc[i-1]*i%mod;
	jc2[N-1]=ksm(jc[N-1],mod-2);
	for(int i=N-1;i;--i)jc2[i-1]=(ll)jc2[i]*i%mod;
}
int C(int n,int k){return (ll)jc[n]*jc2[k]%mod*jc2[n-k]%mod;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;if(n<m)swap(n,m);init();
	for(int i=1;i<=m;++i)
		ans=(ans+(ll)C(2*i,i)*C(n+m-2*i,n-i))%mod;
	ans=ksm(2*C(n+m,n)%mod,mod-2,ans);
	cout<<(ans+n)%mod<<'\n';
	return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <stdlib.h>

int main(){
  int x = 0, top = 0, stack[100];
  char s[100];
 
  while( scanf("%s",s) != EOF){
    if ( s[0] == '+'){
      stack[top - 2] = stack[top - 2] + stack[top - 1];
      top -= 1;
    }

    else if (s[0] == '-'){
      stack[top - 2] = stack[top - 2] - stack[top - 1];
      top -= 1;
    }

    else if (s[0] == '*'){
      stack[top - 2] = stack[top - 2] * stack[top - 1];
      top -= 1;
    }

    else {
      stack[top] = atoi(s);
      top += 1;
    }
  }
 
  printf("%d\n",stack[top - 1]);
 
  return 0;
}

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

int main() {
	int g = 0, p = 0, ans = 0, pos;
	string s;
	cin >> s;
	for (int i=0; i<s.length(); i++) {
		if (s[i] == 'g') g++;
		else p++;
	}
	pos = s.length() - 1;
	while (p < g - 1) {
		if (s[pos--] == 'g') {
			g--; p++;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

bool visited[50];
bool connect[50][50];
int a[50],b[50];
int N,M;

void dfs(int pre){
    visited[pre] = true;
    for(int u=0; u<N; u++){
        if(u == pre) continue;
        if(visited[u]) continue;
        if(!connect[pre][u]) continue;
        dfs(u);
    }
}

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

    for(int i=0; i<M; i++){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
        connect[a[i]][b[i]] = connect[b[i]][a[i]] = true;
    }

    int ans = 0;

    for(int i=0; i<M; i++){
        connect[a[i]][b[i]] = connect[b[i]][a[i]] = false;

        for(int j=0; j<N; j++) visited[j] = false;

        bool check = false;

        dfs(0);
        for(int j=0; j<N; j++) if(!visited[j]) check = true;
        if(check) ans++;

        connect[a[i]][b[i]] = connect[b[i]][a[i]] = true;
    }

    cout<<ans<<endl;

    return 0;
}

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

ll n,num[N],x,ans;
string str[5]={"dream","dreamer","erase","eraser"},a;

int main()
{
	ll i,j,p,q;
	cin>>n>>x;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&num[i]);
	}
	for(i=1;i<=n;i++)
	{
		if(num[i]+num[i-1]>x)
		{
			ans+=(num[i]+num[i-1])-x;
			num[i]-=(num[i]+num[i-1])-x;
		}
		if(num[i]>x)
		{
			ans+=(num[i]-x);
			num[i]=x;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1024
s=int(input())
dic={str(s):1}
count=0
while True:
        if s%2==0:
                if str(s//2) not in dic:
                        dic[str(s//2)]=1
                        count+=1
                        s=s//2
                else:
                        break
        else:
                if str(s*3+1) not in dic:
                        dic[str(s*3+1)]=1
                        count+=1
                        s=s*3+1
                else:
                        break
print(count+2)
         

Measured memory_bytes: 3060
#include <iostream>

using namespace std;
#define ll long long
int main()
{
   ll a[5];
   for(int i=0;i<5;i++)
   {
       cin>>a[i];
       if(a[i]==0)
       {
           cout<<i+1<<endl;
           break;
       }
   }
   
   
   return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<int> cnt(1e5+1);
    rep(i, n) {
        int a;
        cin >> a;
        ++cnt[a];
        ++cnt[a+1];
        if (a-1>=0) ++cnt[a-1];
    }
    int max_num = 0;
    int ans = 0;
    rep(i, 1e5+1) {
        if (cnt[i] > max_num) {
            ans = i;
            max_num = cnt[i];
        }
    }
    cout << max_num << endl;
    return 0;
}


Measured memory_bytes: 3732
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int h, m, hh, mm, k,ans;
    cin >> h >> m >> hh >> mm >> k;
    ans = (hh * 60 + mm) - (h * 60 + m);
    ans -= k;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int N, M, ans[300009], b[300009];
long long T;
pair < pair < int, int >, int > a[300009];

int main ()
{
scanf ("%d %d %I64d", &N, &M, &T);
long long rot = 0;
for (int i=0; i<N; i++)
{
    int c;
    scanf ("%d %d", &a[i].first.first, &c), a[i].second = i;
    if (c == 2) a[i].first.second = -1;
    else a[i].first.second = +1;
    int finPos = ((long long) a[i].first.first + 1LL * a[i].first.second * T) % M;
    if (finPos < 0) finPos += M;
    b[i] = finPos;
    if (a[i].first.second == -1)
    {
        long long times = T - a[i].first.first - 1;
        if (times >= 0)
        {
            times /= M, times ++;
            rot = (rot - times) % N;
        }
    }
    else
    {
        long long times = T - (M - 1 - a[i].first.first) - 1;
        if (times >= 0)
        {
            times /= M, times ++;
            rot = (rot + times) % N;
        }
    }
}
if (rot < 0) rot += N;
rot = (N - rot) % N;
sort (a, a + N);
sort (b, b + N);
for (int i=0; i<N; i++)
    ans[a[(i + rot) % N].second] = b[i];
for (int i=0; i<N; i++)
    printf ("%d\n", ans[i]);
return 0;
}


Measured memory_bytes: 4864
x1, y1, x2, y2 = [int(i) for i in input().split()]
dx = x2 - x1
dy = y2 - y1

x3, y3 = x2 - dy, y2 + dx
x4, y4 = x1 - dy, y1 + dx
print(x3, y3, x4, y4)

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

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

using vi = vector<int>;

int main() {
  int n; cin >> n;
  vi h(n);
  rep(i, n) {
    cin >> h.at(i);
  }
  
  vi head(2); int next;
  head.at(0) = 0;
  head.at(1) = abs(h.at(1) - h.at(0));
  //cout << ": " << head.at(0) << ", " << head.at(1) << endl;

  for (int i = 2; i < n; i++) {
    next = min(
      head.at(1) + abs(h.at(i-1) - h.at(i)),
      head.at(0) + abs(h.at(i-2) - h.at(i))
    );
    head.at(0) = head.at(1);
    head.at(1) = next;
    //cout << i << ": " << head.at(0) << ", " << head.at(1) << endl;
  }
  
  cout << head.at(1) << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  ll l,r,i,j,ans=2019;
  
  cin >> l >> r;
  
  if (r-l>=2018 || l%2019>=r%2019){
    cout << 0 << endl;
    return 0;
  }
  
  for (i=l;i<r;i++) for (j=i+1;j<=r;j++){
    ans=min(ans,i*j%2019);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
n, k, c = map(int, input().split())
s = input()
L = [0]
R = [0]
i = 1
while i <= n:
    if s[i-1] == 'o':
        L.append(i)
        i += c+1
    else:
        i += 1
i = n
while i >= 1:
    if s[i-1] == 'o':
        R.append(i)
        i -= c+1
    else:
        i -= 1
# print(L)
# print(R)
for i in range(1, min(len(L), len(R))):
    if L[i] == R[k-i+1]:
        print(L[i])

Measured memory_bytes: 58352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] T = new int[N];
		int sum = 0;
		for (int i = 0; i < T.length; i++) {
			T[i] = sc.nextInt();
			sum += T[i];
		}
		int M = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < M; i++) {
			ans = sum;
			ans -= T[sc.nextInt() - 1];
			ans += sc.nextInt();
			System.out.println(ans);
		}

		sc.close();
	}
}

Measured memory_bytes: 23764
///
// File:  b.cpp
// Author: ymiyamoto
//
// Created on Sun Dec 31 17:25:47 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  uint32_t N, M;
  cin >> N >> M;
  string str;
  cin >> str;

  for (uint32_t i = 0; i < N; i++) {
    if (!('0' <= str[i] && str[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }

  if (!(str[N] == '-')) {
    cout << "No" << endl;
    return 0;
  }

  for (uint32_t i = N + 1; i < str.size(); i++) {
    if (!('0' <= str[i] && str[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
s = int(input())
a = [s]
cnt = 1
while True:
    cnt += 1 
    if a[-1] % 2 == 0:
        tmp = a[-1] / 2
    else:
        tmp = 3 * a[-1] + 1
    if tmp in a:
        break
    a.append(tmp)
print(cnt)

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

const long long INF = 1LL << 60;
int main()
{
	int n;
	cin >> n;
	int x[n];
	for (int i = 0; i < n; i++) cin >> x[i];
	long long ans = INF;
	int idx;
	for (int i = 1; i < 101; i++){
		long long tmp = 0;
		for (int j = 0; j < n; j++){
			tmp += pow(i-x[j], 2);
		}
		if (tmp < ans){
			ans = tmp;
		}

	}
	cout << ans << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

vector<long> yakusuu(long X) {
    vector<long> rec_vec;

    long i = 2;
    while (i * i <= X) {
        if (X % i == 0) {
            rec_vec.emplace_back(i);
            rec_vec.emplace_back(X / i);
        }
        i++;
    }
    if (X != 1) {
        rec_vec.emplace_back(X);
    }

    return rec_vec;
}

bool is_sosuu(long X) {
    bool sosuu = true;

    long i = 2;
    while (i * i <= X) {
        if (X % i == 0) {
            sosuu = false;
        }
        i++;
    }

    return sosuu;
}

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

    long A, B;

    cin >> A >> B;

    long C = min(A, B);
    long D = max(A, B);

    vector<long> yakusuu_C = yakusuu(C);

    long count = 0;
    for (auto i : yakusuu_C) {
        if ((D % i == 0) && (is_sosuu(i))) {
            count++;
        }
    }

    cout << count + 1 << "\n";

    return 0;
}


Measured memory_bytes: 384
let read_lines () =
  let rec iter xs =
    try read_line() :: xs |> iter
    with End_of_file -> xs
  in iter [] |> List.rev

let split_nums str =
  Str.split (Str.regexp " ") str
  |> List.map int_of_string

let read_ints () =
  read_line () |> split_nums |> Array.of_list


let init n = Array.init n (fun x -> x)

let rec find i a =
  if a.(i) = i then i
  else compress a.(i) a
and compress i a =
  a.(i) <- find i a;
  a.(i)

let same x y a =
  find x a = find y a

let void _ = ()

let unite x y a =
  let i = find x a
  and j = find y a in
  if i = j then ()
  else a.(i) <- j

let () =
  let first_line = read_ints () in
  let tree = init first_line.(0) in
  let answer com x y =
    match com with
    | 0 -> unite x y tree;
    | 1 ->
       Printf.printf "%d\n" (if same x y tree then 1 else 0);
    | _ -> raise Not_found in

  for i = 1 to first_line.(1) do
    let xs = read_ints () in
    answer xs.(0) xs.(1) xs.(2)
  done

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

using namespace std;

using Int = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  Int N;
  cin >> N;
  Int ans = (N - 1) * N / 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc120/tasks/abc120_c

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

int main() {
    string S; cin >> S;
    
    int N = S.length();
    int count0 = 0, count1 = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '0') {
            count0++;
        }

        if (S[i] == '1') {
            count1++;
        }
    }

    int diff = abs(count0 - count1);
    int ans = N - diff;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

#define N 100

int main(){

  int n,i,j,u,k;
  int h[N];
  int v[N][N];
  int m[N][N];
  
  scanf("%d",&n);

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



Measured memory_bytes: 2056
#include <stdio.h>
int main(void){
    int x, i, n;
    scanf("%d", &x);
    i=1;
    
    while(i <= x){
        n=i;
        if(n%3 == 0){
            printf(" %d", i);
        }
        else{
            do{
                if(n%10 == 3){
                    printf(" %d", i);
                    break;
                }
                n /= 10;
            }while(n);
        }
        i++;
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2128
import math
import numpy as np
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
oreder_time = np.array([a,b,c,d,e])
next_oreder_time = np.ceil(oreder_time/10)*10

print(int(np.sum(next_oreder_time)-np.max(next_oreder_time-oreder_time)))

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


struct Doubling {
    const int LOG;
    vector<vector<int> > table;

    Doubling(int sz, int64_t lim_t) : LOG(64 - __builtin_clzll(lim_t)) {
        table.assign(LOG, vector<int>(sz, -1));
    }

    void set_next(int k, int x) {
        table[0][k] = x;
    }

    void build() {
        for (int k = 0; k + 1 < LOG; k++) {
            for (int i = 0; i < table[k].size(); i++) {
                if (table[k][i] == -1) table[k + 1][i] = -1;
                else table[k + 1][i] = table[k][table[k][i]];
            }
        }
    }

    int query(int k, int64_t t) {
        for (int i = LOG - 1; i >= 0; i--) {
            if ((t >> i) & 1) k = table[i][k];
        }
        return k;
    }
};


vector<int> amida_simulator(vector<int> &horizontal, int width) {
    vector<int> currents(width);
    vector<int> current_indexes(width);
    rep(i, width) currents[i] = i;
    rep(i, width) current_indexes[i] = i;

    for (int h : horizontal) {
        int h1 = currents[h];
        int h2 = currents[h + 1];

        swap(current_indexes[h1], current_indexes[h2]);
        currents[h] = h2;
        currents[h + 1] = h1;

    }
    return current_indexes;
}

int main() {
    int n;
    ll k;
    cin >> n >> k;
    Doubling doubling(n, k);
    rep(i, n) {
        int to;
        cin >> to;
        to--;
        doubling.set_next(i, to);
    }
    doubling.build();

    cout << doubling.query(0, k) + 1 << endl;


}


Measured memory_bytes: 50996
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
   cin >> n;
  int ans=0;
  for(int i=1;i<=n;i++){
    int count=0;
    int x=i;
    while(1){
      if(x%2==0) {
        ++count;
      	x/=2;
      }
      else break;
    }
    ans=max(ans, count);
  }

  int S=1;
  for(int i=0;i<ans;i++) S*=2;
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long N,A,B,C,D,E;
  scanf("%ld",&N);
  scanf("%ld",&A);
  scanf("%ld",&B);
  scanf("%ld",&C);
  scanf("%ld",&D);
  scanf("%ld",&E);

  long min = A;
  if (min>B) {
    min = B;
  }
  if (min>C) {
    min = C;
  }
  if (min>D) {
    min = D;
  }
  if (min>E) {
    min = E;
  }
  long ans = 4+ (N+min-1)/min;
  printf("%ld\n",ans);
  return 0;
}


Measured memory_bytes: 128
import sys
import numpy as np


def main():
    n = int(input())
    prime = [0 for _ in range(n + 1)]
    for i in range(1, n + 1):
        num = i
        for j in range(2, i + 1):
            while num % j == 0:
                num /= j
                prime[j] += 1
    ans = 0
    for i in range(2, n + 1):
        if prime[i] >= 74:
            ans += 1
        for j in range(i + 1, n + 1):
            if prime[i] >= 24 and prime[j] >= 2:
                ans += 1
            if prime[i] >= 14 and prime[j] >= 4:
                ans += 1
            if prime[i] >= 4 and prime[j] >= 14:
                ans += 1
            if prime[i] >= 2 and prime[j] >= 24:
                ans += 1
            for k in range(j + 1, n + 1):
                if prime[i] >= 2 and prime[j] >= 4 and prime[k] >= 4:
                    ans += 1
                if prime[i] >= 4 and prime[j] >= 2 and prime[k] >= 4:
                    ans += 1
                if prime[i] >= 4 and prime[j] >= 4 and prime[k] >= 2:
                    ans += 1
    print(ans)


main()


Measured memory_bytes: 13496
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y>>z;
if (x+y==z||x+z==y||z+y==x) {
  std::cout << "Yes" << '\n';
}else std::cout << "No" << '\n';
}


Measured memory_bytes: 256
# _*_ coding:utf-8 _*_
#  Atcoder_YahooMinnanoProcon_Contest-B
#  TODO https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_b

def solveProblem(positionList):
	dictPosition = {"1":0,"2":0,"3":0,"4":0}
	for position in positionList:
		dictPosition[position] = dictPosition[position]+1
	oneBridgePosition = 0
	twoBridgePosition = 0
	for eachPosition in dictPosition:
		countBridge = dictPosition[eachPosition]
		if countBridge == 1:
			oneBridgePosition = oneBridgePosition + 1
		elif countBridge == 2:
			twoBridgePosition = twoBridgePosition + 1
	if oneBridgePosition == 2 and twoBridgePosition == 2:
		answer="YES"
	else :
		answer="NO"
	return answer


if __name__ == '__main__':
	positionList = list()
	a1,b1 = map(str,input().strip().split(' '))
	positionList.append(a1)
	positionList.append(b1)
	a2, b2 = map(str, input().strip().split(' '))
	positionList.append(a2)
	positionList.append(b2)
	a3, b3 = map(str, input().strip().split(' '))
	positionList.append(a3)
	positionList.append(b3)
	solution = solveProblem(positionList)
	print("{}".format(solution))


Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
		int a,b,c;
		int i;
		int count=0;
		scanf("%d %d %d",&a,&b,&c);
		for(i=a;i<=b;i++){
				if((c % i)==0)
						count+=1;
		}
		printf("%d\n",count);
		return 0;
}


Measured memory_bytes: 2060
import numpy as np
N,M = map(int,input().split())
A_s = []
for _ in range(N):
  A_s.append(list(map(int,input().split())))
## Aiの順にsortする
A_s = sorted(A_s,key=lambda x:x[0])
money = 0
num = 0
pre_num = 0
for a_s in A_s:
  num += a_s[1]
  if num <= M:
    money += a_s[1] * a_s[0]
    pre_num += a_s[1]
  else:
    money += (M-pre_num) * a_s[0]
    break
  #print(money)
print(money)

Measured memory_bytes: 38856
n = int(input())
p_array_tmp = [int(x) for x in input().split()]
for i in range(n):
    for j in range(i, n):
        if i == j:
            continue
        p_array = list(p_array_tmp)
        if p_array[i] > p_array[j]:
            tmp = p_array[i]
            p_array[i] = p_array[j]
            p_array[j] = tmp
        now = p_array[0]
        for p in p_array[1:]:
            if p > now:
                now = p
            else:
                break
        else:
            print("YES")
            exit()
print("NO")


Measured memory_bytes: 3064
/**
     *   created: 03 June 2019  00:25:23
    **/
    #include<bits/stdc++.h>
    using namespace std;
     
    typedef vector<int> vi;
    typedef pair<int , int> pii;
    typedef vector< pair<int , int> > vii;
    typedef long long ll;
    typedef vector<long long> vl;
    typedef pair<long long , long long> pll;
    typedef vector< pair<long long , long long> > vll;
     
    #define PB push_back
    #define PPB pop_back
    #define all(c) c.begin(),c.end()
    #define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
    #define INFLL 2000000000000000007
    #define INF 2000000007
    #define MOD 1000000007
     
     
    #define TRACE
     
    #ifdef TRACE
    #define trace1(x)                cerr << #x << ": " << x << endl;
    #define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
    #define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
    #define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
    #define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
    #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
     
    #else
     
    #define trace1(x)
    #define trace2(x, y)
    #define trace3(x, y, z)
    #define trace4(a, b, c, d)
    #define trace5(a, b, c, d, e)
    #define trace6(a, b, c, d, e, f)
     
    #endif
     
     
    void optimizeIO()
    {
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    }
     
    //                                        //AUTHOR: Kaushalesh Shukla
     
    //=========================================================================================================
     
    int main()
    {
    	optimizeIO();
    	int tt=1;
    	//cin>>tt;
    	while(tt--){
    		ll n,k;
    		cin>>n>>k;
    		vl v(n);
    		rep(i,0,n)
    			cin>>v[i];
    		ll lb=-1;
    		rep(i,0,60){
    			ll temp = (ll)((ll)1<<(ll)i);
    			// trace1(temp);
    			if((k&temp))
    				lb = i;
    		}
    		// cout<<lb<<endl;
    		ll num=0;
    		rrep(i,50,0){
    			ll cnt0=0,cnt1=0;
    			rep(j,0,n){
    				if((v[j]&(1ll<<i)))
    					cnt1++;
    				else
    					cnt0++;
    			}
    			// trace3(cnt0,cnt1,i);
    			if(cnt0>cnt1)
    				if((num|(1ll<<i))<=k)
    					num = (num|(1ll<<i));
    		}
    		// cout<<num<<endl;
    		ll sum=0;
    		rep(i,0,n){
    			sum += (v[i]^num);
    		}
    		cout<<sum;
    	}
    	return 0;
    }

Measured memory_bytes: 1024
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func divFloor(a, b int) int {
	return (a + (b - 1)) / b
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	s := nextInt()
	giga := 1000000000

	y := divFloor(s, giga)
	x := giga*y - s

	puts(0, 0, giga, 1, x, y)
}


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

int main(){
	int N, ans = 0, temp = 0;
	cin >> N;
	int V[N], C[N], dis[N];
	for(int i = 0; i < N; i++){
		cin >> V[i];
	}
	for(int i = 0; i < N; i++){
		cin >> C[i];
	}
	for(int i = 0; i < N; i++){
		dis[i] = V[i] - C[i];
	}
	for(int i = 0; i < N; i++){
		if(dis[i] >= 0){
			ans += dis[i];
		}
	}
	if(ans >= 0){
		cout << ans << endl;
	}else{
		cout << 0 << endl;
	}
	return 0;
}


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

typedef long long int ll;

int main()
{
    string s;
    cin >> s;
    ll size = s.length(), ma = 0;
    vector<ll> a(size + 1), b(size + 1);

    for(ll i = 0;i < size;i++){
        if(s[i] == '<'){
            a[i + 1] = a[i] + 1;
        }
        else{
            a[i + 1] = 0;
        }
    }
    for(ll i = size - 1;i >= 0;i--){
        if(s[i] == '>'){
            b[i] = b[i + 1] + 1; 
        }
        else{
            b[i] = 0;
        }
    }


    ll ans= 0;
    for(ll i = 0;i < size + 1;i++){
        if(a[i] > b[i]){
            ans += a[i];
        }
        else{
            ans += b[i];
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 8708
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define int long long
#define sz(x) (int)x.size()
#define mp make_pair
#define fi first
#define se second
#define io ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#define INF 1e7

signed main()
{
	io;
	int n;
	cin >> n;
	int a=1;

	for(int i=0;i<n;i++)
	{
		a = (a*10)%hell;
	}
	//cout << a  <<endl;
	int b = 1;
	for(int i=0;i<n;i++)
	{
		b=(b*9)%hell;
	}
	//cout << b <<endl;
	b = (b*2)%hell;
	int c = 1;
	for(int i=0;i<n;i++)
	{
		c = (c*8)%hell;
	}
	//cout <<a << " "<<b << " "<<c <<endl;
	int ans =  (a%hell-b%hell+c%hell+hell)%hell;
	cout << ans <<endl;
}
 
	
		



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
vector<int>color;
vector<vector<pii>>v;
vector<bool>visited;
void c(int node, int distance){
	if(distance%2==0)color[node] = 1;
	for(pii a: v[node]){
		int n = a.first;
		int w = a.second;
		if(!visited[n]){
			visited[n] = true;
			c(n, distance+w);
		}
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	color = vector<int>(n);
	v = vector<vector<pii>>(n,vector<pii>());
	visited = vector<bool>(n);
	int v1,v2,w;
	for(int i =0; i <n-1; i++){
		cin>>v1>>v2>>w;
		v1--;
		v2--;
		v[v1].pb(make_pair(v2,w));
		v[v2].pb(make_pair(v1,w));
	}
	c(0, 0);
	for(int i =0 ;i < color.size(); i++){
		cout<<color[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 10900
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	cin>>n>>x;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int sum=0;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		sum+=a[i];
		if(sum<=x)
		{
			ans++;
		}
	}
	ans+=1;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i,ans=0;
  for(i=0;i<4;i++){
    if(s.at(i)=='+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n, a[100];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    sort(a, a + n);
    int res = a[n - 1] - a[0];
    cout << res << endl;
}


Measured memory_bytes: 256
function main(input) {
  input=input.trim();
  const a = parseInt(input.split(" ")[0], 10);
  const op = input.split(" ")[1];
  const b = parseInt(input.split(" ")[2], 10);
  if(op=="+"){
    console.log(a+b);
  }else{
    console.log(a-b);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
//
//$$$$$$$$$$$$$$$$$$$$$$
//$$                  $$
//$$   gyoubu_oniwa   $$
//$$                  $$
//$$$$$$$$$$$$$$$$$$$$$$
//
#include<bits/stdc++.h>
using namespace std;
#define DBG(a) if(DBGDO) cout<<#a<<':'<<a<<endl;
#define PB push_back
#define EB emplace_back
#define btoe(v) (v).begin(),(v).end()
#define etob(v) (v).rbegin(),(v).rend()
#define F first
#define S second
#define SZ size()
#define pow(a,b) (pow(a,b)+0.5)

typedef unsigned long long int ulli;
typedef long long int lli;
typedef long double ldbl;
#define f(i,a,b) for(int i=(a); i<(b); ++i)
#define fr(i,a,b) for(int i=(a); i>(b); --i)
#define fl(i,a,b) for(lli i=(a); i<(b); ++i)
#define flr(i,a,b) for(lli i=(a); i>(b); --i)
#define w(x) lli x; cin>>x; while(x--) 
#define inpn(n,v,T) T n; cin>>n; vector<T> v(n); fl(i,0,n) cin>>v[i];
#define inp(n,v,T) vector<T> v(n); fl(i,0,n) cin>>v[i];

typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<vector<pii>> vvpii;typedef pair<lli,lli> plli;typedef vector<lli> vlli;typedef vector<vlli> vvlli;typedef vector<plli> vplli;typedef vector<vector<plli>> vvplli;typedef vector<bool> vb;typedef vector<string> vs;typedef vector<vector<string>> vvs;

#define unmp unordered_map

#define PRIME ((lli)(1e9+7ll))
#define PRIME2 (998244353ll)
const lli TEN_18 = 1e18;
const lli TEN_9 = 1e9;
const lli TEN_5 = 1e5;

inline void debugORfast(int a=1,int b=1){
    if(a){
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
        #endif
    }
    if(b){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}}

template<typename T>
void print(const T &v, int begin=-1, int end=-1, int w=2)
{
	if(begin<=end){
		if(begin==-1) fl(i,0,v.SZ) cout<<setw(w)<<v[i]<<' ';
		else if(end==-1) fl(i,begin,v.SZ) cout<<setw(w)<<v[i]<<' ';
		else fl(i,begin,end) cout<<setw(w)<<v[i]<<' ';
		cout<<endl;}
	else{
		if(begin==-1) flr(i,v.SZ-1,-1) cout<<setw(w)<<v[i]<<' ';
		else if(end==-1) flr(i,begin,-1) cout<<setw(w)<<v[i]<<' ';
		else flr(i,begin,end) cout<<setw(w)<<v[i]<<' ';
		cout<<endl;
	}
}

void pans(char v){
	switch(v){
		case 'y' : cout<<"yes"<<endl; break;
		case 'n' : cout<<"no"<<endl; break;
		case 'Y' : cout<<"Yes"<<endl; break;
		case 'N' : cout<<"No"<<endl; break;
		case 'B' : cout<<"YES"<<endl; break;
		case 'S' : cout<<"NO"<<endl; break;
	}
}

int DBGDO=0;

lli brute(){
	return 0;
}

lli solve(){
    return 0;
}

int main()
{
	debugORfast(0,1);
	//w(ttt)
	{
		int n,k; cin>>n>>k;
		inp(n,p,int);
		sort(btoe(p));
		int minsum=0;
		f(i,0,k) minsum+=p[i];
		cout<<minsum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <limits>
#include <string>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

bool is_ok(const string & s){
    if ((uint)s.size()%2==1)return false; else {
        for (auto &&i: irange(0U, (uint)s.size()/2)){
            if (s.at(i)!=s.at((uint)s.size()/2+i))return false;
        }
    }
    return true;
}


int main() {
    string s;
    cin >> s;
    s.pop_back();
    while (!s.empty()){
        if (is_ok(s)){cout << (uint)s.size();return 0;} else s.pop_back();
    }
    return 0;
}

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

int main() {
  int L,R,i,j,m=2018;
  cin >> L >> R;

  if(R-L>=2018)
    cout << 0 << endl;
  else {
    R %= 2019;
    L %= 2019;
    for(i=L; i<R; i++)
      for(j=i+1; j<=R; j++)
        m = min((i*j)%2019, m);
        if(m == 0) {
          cout << 0 << endl;
          return 0;
        }
    cout << m << endl;
  }
}

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

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

  if (x <= 599) cout << '8' << endl;
  else if (x <= 799) cout << '7' << endl;
  else if (x <= 999) cout << '6' << endl;
  else if (x <= 1199) cout << '5' << endl;
  else if (x <= 1399) cout << '4' << endl;
  else if (x <= 1599) cout << '3' << endl;
  else if (x <= 1799) cout << '2' << endl;
  else if (x <= 1999) cout << '1' << endl;

}

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

int N;
vector<int> L;

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int l;
        cin >> l;
        L.push_back(l);
    }

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

    ll ans = 0;
    for (int s = 0; s < N-2; s++) {
        for (int m = s+1; m < N-1; m++) {
            auto itr = lower_bound(L.begin(), L.end(), L[s] + L[m]);
            ll dis = distance(itr, L.end());
            ans += (N - 1 - m) - dis;
        }
    }
    
    cout << ans << endl;

    return 0;
}


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

int main() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    for (auto& e : l) cin >> e;

    int ans = 1e9;
    stack<tuple<int, int, int, int, int>> s;
    s.emplace(0, 0, 0, 0, 0);
    while(!s.empty()) {
        auto t = s.top();
        s.pop();
        int ta = get<0>(t), tb = get<1>(t), tc = get<2>(t), join = get<3>(t), depth = get<4>(t);
        if(depth == n) {
            if (ta != 0 && tb != 0 && tc != 0) ans = min(ans, join * 10 + abs(a - ta) + abs(b - tb) + abs(c - tc));
        } else {
            s.emplace(ta + l[depth], tb, tc, join + (ta != 0), depth + 1);
            s.emplace(ta, tb + l[depth], tc, join + (tb != 0), depth + 1);
            s.emplace(ta, tb, tc + l[depth], join + (tc != 0), depth + 1);
            s.emplace(ta, tb, tc, join, depth + 1);
        }
    }

    cout << ans << endl;
}

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

int main(void)
{
    int A;
    int B;
    int C;
    int K;
    int c;
    int ans;
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &C);
    scanf("%d", &K);
    if (K <= A)
    {
        ans = K;
    }
    else if (A < K && K <= A + B)
    {
        ans = A;
    }
    else
    {
        ans = A - (K - A - B);
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
int n, c, f, i, j, a[200000], vis[1000001], spf[1000001];
int main()
{
    ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    cin >> n;
    for (i = 0; i < n; i++)
        cin >> a[i], vis[a[i]]++;
    if (vis[1])
    {
        if (vis[1] == 1)
            cout << 1 << '\n';
        else
            cout << 0 << '\n';
        return 0;
    }
    for (i = 2; i <= 1e6; i += 2)
        spf[i] = 2;
    for (i = 3; i < 1e6; i += 2)
        spf[i] = i;
    for (i = 3; i < 998; i += 2)
        if (spf[i] == i)
            for (j = i * i; j < 1e6; j += i)
                if (spf[j] == j)
                    spf[j] = i;
    for (i = 0; i < n; i++)
        if (vis[a[i]] == 1)
        {
            if (a[i] != spf[a[i]])
                for (j = spf[a[i]]; j * j <= a[i]; j++)
                    if (a[i] % j == 0 && (vis[a[i] / j] || vis[j]))
                    {
                        c++;
                        break;
                    }
        }
        else c++;
    cout << n - c << '\n';
}

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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> vec (N);
    for(int i = 0;i < N;i++){
    	cin >> vec.at(i);
    }
    SORT(vec);
    REV(vec);
    vec.at(0) /= 2;
    int ans = 0;
    for(int i = 0;i < N;i++){
    	ans += vec.at(i);
    }
    cout << ans << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:

const int limit=1<<18;
int ans[limit];
bool used[limit];
		
int main(void){
	int n,x;
	cin >> n >> x;
	n=2*n-1;

	if(x==1 or x==n){
		puts("No");
	}else{
		puts("Yes");
		const int mid=n/2;
		ans[mid]=x,used[x]=true;
		if(x-2>=1){
			ans[mid-1]=x-1,used[x-1]=true;	
			ans[mid+1]=x+1,used[x+1]=true;
			ans[mid+2]=x-2,used[x-2]=true;		
		}else{
			ans[mid-1]=x+1,used[x+1]=true;	
			ans[mid+1]=x-1,used[x-1]=true;
			ans[mid+2]=x+2,used[x+2]=true;
		}
		int idx=1;
		rep(i,n) if(ans[i]==0){
			while(used[idx]) idx++;
			ans[i]=idx,used[idx]=true;
		}
		rep(i,n) cout << ans[i] << endl;
	}	
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

ll mpow(ll x, ll n){
  if(n==0)return 1;

  ll y = mpow(x, n/2);
  y *= y;

  if(n%2==1) y *=x;
  return y;
}

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


  FOR(i,1,20){
    ll x = mpow(26,i);
    if(n <= x){
      string ans = "";
      n--;
      REP(j,i){
        ans += 'a' + (n%26);
        n /= 26;
      }
      reverse(ALL(ans));
      PRINT(ans);
      break;
    }else{
      n -= x;
    }
  }
}



Measured memory_bytes: 3604
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int func(long long n) {
	if (n < 10)return 1;
	return func(n/10)+1;
}
string S, T;
int sLen, tLen;
bool match(int k) {
	REP(i, tLen) {
		if (T[i] != S[i + k] && S[i + k] != '?')return false;
	}
	return true;
}
string construct(int k){
	string ans = S;
	REP(i, tLen) {
		ans[k + i] = T[i];
	}
	replace(ans.begin(), ans.end(), '?', 'a');
	return ans;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> S >> T;
	sLen = S.length();
	tLen = T.length();
	string ans;

	int k = 0;
	for (k = sLen - tLen; k >= 0;k--) {
		if (match(k))break;
	}

	if(k>=0)cout << construct(k) << endl;
	else cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 888
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

A_B = []
B_C = []
total = 0

for b in B:
    k = bisect.bisect_left(A,b)
    l = bisect.bisect_right(C,b)
    total += k * (N-l)

print(total)


Measured memory_bytes: 23092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){

char s[4];
int i,j;
scanf("%s",s);
for(i=0;i<3;i++){
  if(s[i]==s[i+1]){
    printf("Bad");
    return 0;
  }
}
printf("Good");
return 0;

}


Measured memory_bytes: 128