akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int Len;
long long Num[11];
long long Sum;

void DFS(int d, long long s, long long n);

int main(void)
{
    char tmp[11] = { 0 };

    scanf("%s", tmp);
    for (Len = 0; tmp[Len]; Len++)
    {
        Num[Len] = (long long)(tmp[Len] - '0');
    }

    DFS(1, 0, Num[0]);

    printf("%lld\n", Sum);

    return 0;
}

void DFS(int d, long long s, long long n)
{
    if (d == Len) 
    {
        s += n;
        Sum += s;
        return;
    }

    // 이자리에 +를 쓴다.
    DFS(d + 1, s + n, Num[d]);

    // 안쓴다.
    DFS(d + 1, s, (n * 10) + Num[d]);
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	ar := make([]int, n)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	sort.Ints(ar)
	var a, b, t int
	for i := n - 1; i >= 0; i-- {
		if t%2 == 0 {
			a += ar[i]
		} else {
			b += ar[i]
		}
		t++
	}
	fmt.Println(a - b)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
typedef long long ll;
const ll mod = 1000 * 1000 * 1000 + 7;

vector<ll> v, suf;

int main() {
	int n; cin >> n; v.resize(n); suf.resize(n);
	for (auto &x : v) { cin >> x; }
	suf.back() = v.back(); for (int i = n - 2; i >= 0; i--) suf[i] = (suf[i + 1] + v[i]) % mod;
	ll res = 0; for (int i = 0; i < n - 1; i++) {
		ll x = (v[i] * suf[i + 1]) % mod;
		res = (res + x) % mod;
	}
	cout << res << '\n';
	cin.ignore(2); return 0;
}

Measured memory_bytes: 6328
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int getLength(int x){
	if(x<10)
		return 1;
	if(x<100)
		return 2;
	if(x==100)
		return 3;
		
}
int main(){
	
	int a,b,c;
	bool ans = false;
	
	scanf("%d%d",&a,&b);
	
	c = a*pow(10,getLength(b))+b;
	
	for(int i=1;i<=400;i++)
		if(pow(i,2) == c){
			ans = true;
			break;
		}
	
	
	if(ans)
		printf("Yes");
	else
		printf("No");
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
      cin >> L[i];
  }
  int max_L = *std::max_element(L.begin(), L.end());
  if(max_L < (std::accumulate(L.begin(), L.end(), 0)-max_L)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	sort(A.begin(),A.end(),greater<int>());
	ll a = A[0];
	ll b = a/2;
	ll mini = 1e18;
	ll c;
	
	for(int i=1; i<N; i++) {
		if(abs(b-A[i]) < mini) {
			mini = abs(b-A[i]);
			c = A[i];
		}
	}
	cout << A[0] << " " <<  c << endl;

  return 0;
}


Measured memory_bytes: 768
n, m = map(int, input().split())
requests = []
for _ in range(m):
    requests.append(tuple(map(int, input().split())))
requests.sort(key=lambda x: x[1])
cutcount = 0
lastcut = 0
for request in requests:
    if request[0] >= lastcut:
        lastcut = request[1]
        cutcount += 1
print(cutcount)

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

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long int ll;
using graph = vector<vector<int>>;
using edgedp = vector<vector<pair<int,ll>>>;
constexpr int INF=1000000;
//constexpr int MOD=998244353;
constexpr int MOD=1e9+7;

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

    int x;
    cin >> x;
    if (x < 30){
        cout << "No" << "\n";
    }else{
        cout << "Yes" << "\n";
    }

}   




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

int main()
{
    string s;
    cin >> s;
    if (s.at(0) == s.at(1) && s.at(1) == s.at(2))
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}


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

int main() {
	int N;
	cin >> N;
	vector<int> vec1 (N);
	vector<int> vec2 (N);
	int total = 0;
	for(int i = 0;i < N;i++){
		cin >> vec1.at(i);
		total += vec1.at(i);
	}
	for(int i = 0;i < N;i++){
		cin >> vec2.at(i);
		total += vec2.at(i);
	}
	
	vector<int> vec (N);
	for(int i = 0;i < N;i++){
		for(int j = 0;j < i;j++){
			vec.at(i) += vec2.at(j);
		}
		for(int j = N - 1;j > i;j--){
			vec.at(i) += vec1.at(j);
		}
	}
	sort(vec.begin(),vec.end());
	cout << total - vec.at(0) << endl;
}

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

t = math.ceil(sum(a)/(4*m))
ans = 0
for i in a:
  if t <= i:
    ans += 1
    
if m <= ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
int mod = 1e9+7;

vector<vector<P> > vec2(31), vec(31);
int sum[1000000];
signed main(){
	int n, m;
	scanf("%lld%lld", &n, &m);
	rep(i,n){
		int s, t, c;
		scanf("%lld%lld%lld",&s, &t, &c);
		vec2[c].push_back(P(s, t));
	}
	
	rrep(i,m){
		sort(all(vec2[i]));
		int s = vec2[i].size(), l, r;
		if(s > 0)l = vec2[i][0].fi;
		rep(j,s){
			P p1 = vec2[i][j];
			if(j+1 == s){
				vec[i].pb(P(l, p1.se));
				break;
			}
			if(p1.se == vec2[i][j+1].fi)continue;
			vec[i].pb(P(l, p1.se));
			l = vec2[i][j+1].fi;
		}
	}
	
	rrep(i,m){
		int s = vec[i].size();
		rep(j,s){
			P p = vec[i][j];
			sum[p.fi*2-1]++;sum[p.se*2]--;
		}
	}
	
	int ans = 0;
	repi(i,1,500000){
		sum[i] += sum[i-1];
		ans = max(ans, sum[i]);
	}
	printf("%lld\n", ans);
	
	/*printf("\n");
	rrep(i,m){
		//printf("%lld\n", (int)vec[i].size());
		rep(j,vec[i].size()){
			P p = vec[i][j];
			printf("%lld %lld %lld\n", i, p.fi, p.se);
		}
	}*/
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair <int, int> pp;
#define MAXN 2005
#define MP make_pair
#define PB push_back
#define A first
#define B second
const ll INF = 2e9;
const ll MOD = 1e9+7;
int N, K, Q;
int V[MAXN];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> K >> Q;
	for(int i=1; i<=N; i++) cin >> V[i];
	if(N == 1) {
		cout << 0 << endl;
		return 0;
	}
	int ret = 1e9;
	for(int i=1; i<=N; i++) {
		//
		int minV = V[i];
		vector <int> vi;
		vector <int> cand;
		for(int j=1; j<=N; j++) {
			if(V[j] >= minV) vi.PB(V[j]);
			else {
				sort(vi.begin(), vi.end());
				for(int k=0; k+K-1<vi.size(); k++) cand.PB(vi[k]);
				vi.clear();
			}
		}
		sort(vi.begin(), vi.end());
		for(int k=0; k+K-1<vi.size(); k++) cand.PB(vi[k]);
		vi.clear();

		// Q'th smallest element
		sort(cand.begin(), cand.end());
		int upper = minV;
		if(cand.empty()) continue;
		if(cand.size() < Q) continue;
		for(int j=0; j<min((int)cand.size(), Q); j++) upper = max(upper, cand[j]);
		//cout << i << ' ' << upper << endl;
		ret = min(ret, upper-minV);
	}
	cout << ret << endl;
}

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

int main() {
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'C') {
			for (int j = i + 1; j < s.size(); j++) {
				if (s[j] == 'F') {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc089/tasks/abc089_c
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from itertools import product, permutations, combinations

N = read_a_int()
cnt = defaultdict(lambda: 0)
march = {'M', 'A', 'R', 'C', 'H'}
for _ in range(N):
    s = read()[0]
    if s in march:
        cnt[s] += 1
ans = 0
for a, b, c in combinations(cnt.values(), r=3):
    ans += a * b * c
print(ans)


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

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

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp115
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var min = int.MaxValue;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (i != j && j != k && k != i)
                        {
                            min = Math.Min(min,
                                Math.Abs(a[j] - a[i]) + Math.Abs(a[k] - a[j]));
                        }
                    }
                }
            }

            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>

int itchi(unsigned int mask, int x) {
    int t = 0;
    for(int i=0; i< (x-1); i++) {
        t += (mask & 0x1);
        mask >>= 1;
    }
    return t+1;
}
int bitcount(unsigned int mask){
    int total = 0;
    while(mask > 0 ) {
      if ( mask & 0x1 ) total++;
      mask >>= 1;
    }
    return total;
}
int kai(int x) {
   int total = 1;
   for(int i=1; i<=x; i++) {
      total = total*i;
   }
   return total;
}

int main(){
  int N; 
  scanf("%d\n", &N);
  int A[8];
  int B[8];
  unsigned int mask_a;
  unsigned int mask_b;

  mask_a = (0x1<<N) - 1;
  int t1=1;
  for(int i=0; i<N; i++) {
     scanf("%d\n", &A[i]);
     //printf("mask: %x, %d => %d, %d\n", mask_a, A[i], itchi(mask_a, A[i]), (itchi(mask_a, A[i]) -1) * kai(N-i-1) ); 
     t1 += (itchi(mask_a, A[i]) -1) * kai(N-i-1) ;
     mask_a &= ~(0x1 << (A[i]-1));
  }
  int t2=1;
  mask_b = (0x1<<N) - 1;
  for(int i=0; i<N; i++) {
     scanf("%d\n", &B[i]);
     //printf("mask: %x, %d => %d, %d\n", mask_b, B[i], itchi(mask_b, B[i]), (itchi(mask_b, B[i]) -1) * kai(N-i-1)); 
     t2 += (itchi(mask_b, B[i]) -1) * kai(N-i-1);
     mask_b &= ~(0x1 << (B[i]-1));
  }
  printf("%d\n", t1 - t2 > 0 ? t1-t2: (t1  -t2)*-1);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main() {
    /* brute force !
    Method 1: BFS
        for each book, split into Buy and Not Buy
    Method 2: Subsets
        no. of subsets = 2^n where n: number of books
        Buy: 1, Not Buy: 0
        Make subset using 0 and 1
        each bit represents a book
            e.g. when 3 books are available, 000, 001, 010, 011, 100, 101, 110, 111
        looping through all the subsets (represented in binary) can be done by
        looping from 0 to 2^n (but in binary)
    */ 
    
    // numBooks, numAlgo, targetMastery
    int n, m, x;
    cin >> n >> m >> x;
    // prices
    vector<int> c(n);
    // masteryUp for each algo in each book
    int a[12][12];
    
    int maxPrice{1};
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        maxPrice += c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }

    int minPrice{maxPrice};
    // << : left shift (bitwise operator)
    // 1<<n = 2^n
    for (int s = 0; s < 1<<n; ++s) { // loop through all possible subsets
        int cost{0};
        vector<int> mastery(m);
        for (int i = 0; i < n; ++i) { // loop through each bit in s
            // check if the ith bit (in s) is one = to buy
            // shift s to the right by i bit
            if (s>>i&1) {
                cost += c[i];
                for (int j = 0; j < m; ++j) mastery[j] += a[i][j];
            }
        }
        bool allMastered{true};
        for (int j = 0; j < m; ++j) {
            if (mastery[j] < x) {
                allMastered = false;
                break;
            }
        }
        if (allMastered) minPrice = min(minPrice, cost);
    }
    
    if (minPrice == maxPrice) cout << -1 << endl;
    else cout << minPrice << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int main() {
  int a;
  cin >> a;
  long long int b[a];
  int long long sum = 0;
  long long int ans = 0;
  for(int i=0;i<a;i++){
  cin >> b[i];
  sum += b[i];
  sum %= MOD;
  }
  for(int i=0;i<a;i++){
      sum -= b[i];
      if (sum < 0) sum += MOD;
      ans += sum*b[i];
      ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5188
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  
  int n,k,a=1;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    if(a>k)a+=k;
    else a+=a;
  }
  cout << a <<endl;
      
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N;
    cin >> N;
    vec a(N);
    loop(i, N) cin >> a[i];
    ll ans = 0;
    loop(i, N)
    {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
            ans++;
    }
    putout(ans);
    return 0;
}


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

int main() {
  string s;
  cin>>s;
  int n;
  cin >>n;
  for(int i=0;i<s.size();i+=n){
    if(i<s.size())cout<<s[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0233
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                Stack<string> res = new Stack<string>();
                while (n != 0)
                {
                    int q = n / -10;
                    int r = n - (q * -10);

                    if (r < 0)
                    {
                        r += 10;
                        q += 1;
                    }

                    res.Push(r.ToString());
                    n = q;
                }
                Console.WriteLine(WAr(res, string.Empty));
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 14588
#include <iostream>
using namespace std;
typedef long long ll;
ll ans, res, sub;
string str;
int main(void){
    // Your code here!
    cin >> str;
    for (ll i = 0; i < 26; i++) {
        ans = 0, res = 0;
        for (ll j = 0; j < str.length(); j++) {
            if (str[j] - 'a' != i) {
                ans++;
            } else {
                res = max(res, ans);
                ans = 0;
            }
        }
        res = max(res, ans);
        sub = (i ? min(sub, res) : res);
    }
    cout << sub << endl;
}


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

int N;
void dfs(char c, vector<char> &S){
  if( S.size() == N ){
    for( int i = 0; i < N; i++ ) cout << S.at(i);
    cout << endl;
    return;
  }else{
    for( char h = 'a'; h <= c+1; h++ ){
      S.push_back(h);
      dfs(max(c, h), S);
      S.pop_back();
    }
  }
}
signed main() {
  cin >> N;
  vector<char> S;
  S.push_back('a');
  dfs('a', S);
}

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

using namespace std;

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  if( B > A && B <= ( X + A ) )
    cout << "safe" << endl;
  else if ( B <= A )
    cout << "delicious" << endl;
  else if ( B > ( A + X ) )
    cout << "dangerous" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;

void optimize_cpp_stdio() {
	std::ios::sync_with_stdio(false);
	std::cout.tie(NULL);
	std::cin.tie(NULL);
}
int main()
{
	optimize_cpp_stdio();
	ll x, y;
	cin >> x >> y;
	if(y < x) swap(x, y);
	if((y - x) > 1) cout << "Alice\n";
	else cout << "Brown\n";
	return 0;
}

Measured memory_bytes: 256
nums = list(input())
A = [0, 1]
B = [0, 1]
C = [0, 1]
ops = {
  0: "+",
  1: "-"
}
total = 0
res = ''
for a in range(2):
    for b in range(2):
        for c in range(2):
            if a == 0:
                total = int(nums[0]) + int(nums[1])
            else:
                total = int(nums[0]) - int(nums[1])
            if b == 0:
                total = total + int(nums[2])
            else:
                total = total - int(nums[2])
            if c == 0:
                total = total + int(nums[3])
            else:
                total = total - int(nums[3])
            if total == 7:
                res = nums[0] + ops[a] + nums[1] + ops[b] + nums[2] + ops[c] + nums[3] + "=7"
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  int res=0;
  rep(i,n)
  {
    int a;
    cin>>a;
    a--;
    res+=a;
  }
  cout<<res<<endl;
  return 0;

}


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

using namespace std;
int N;
string In[10000], Out[10000];
int main() {
  while (cin >> N && N > 0) {
    for (int i=0; i<N; ++i) {
      cin >> Out[i] >> In[i];
      //    for (int i=0; i<N; ++i)
      //      cout << Out[i] << ' ' << In[i] << endl;
    }
      sort(In, In+N);
      sort(Out, Out+N);
    int p=0, taiki=0, train=0;
    for (int i=0; i<N; ++i) {
      while (p<N && In[p] <=Out[i]) {
	taiki++;
	p = p+1;
      }
      if (taiki > 0) taiki = taiki - 1;
      else train = train + 1;
    }
    cout << train << endl;
  }
}
 

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

int main(){
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    vector<string> st;
    st.push_back("AC");
    st.push_back("WA");
    st.push_back("TLE");
    st.push_back("RE");
    rep(i,st.size()){
        cout << st[i] << " x " << mp[st[i]] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int M = scn.nextInt();
		int l = 1;
		int r = N;
		for(int i = 0;i < M;i++) {
			int ll = scn.nextInt();
			int rr = scn.nextInt();
			l = Math.max(ll, l);
			r = Math.min(r, rr);
		}
		System.out.println((l > r)?0:r-l+1);
	}

}


Measured memory_bytes: 64572
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N; cin >> N;
    int ans=1;
    int vec=0;
    vector<long long> v(N);
    for(int i=0;i<N;i++){
        cin >>v[i];
        if(i==0) continue;
        if(vec==1){
            if(v[i]<v[i-1]) {vec=0; ans++;}
        }
        else if(vec==0){
            if(v[i]>v[i-1]) vec=1;
            if(v[i]<v[i-1]) vec=-1;
        }
        else if(vec==-1){
            if(v[i]>v[i-1]) {vec=0;ans++;}
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
const ll MOD = 1e9 + 7;

ll aaa(vector<vector<ll>> cake, ll m){
	priority_queue<ll> q;

	rep(i,cake.size()){
		q.push(cake[i][0] + cake[i][1] + cake[i][2]);
	}
	
	ll res = 0;
	rep(i,m){
		res += q.top();
		q.pop();
	}
	return res;
}
void mainsolve(){

	ll n,m;
	cin >> n >> m;

	vector<vector<ll>> cake(n,vector<ll>(3));
	rep(i,n){
		cin >> cake[i][0] >> cake[i][1] >> cake[i][2];
	}

	ll res = 0;
	rep(i,2){
		vector<vector<ll>> tmp = cake;
		if(i==1) rep(x,n) tmp[x][0] *= -1;

		rep(j,2){
			if(j==1) rep(x,n) tmp[x][1] *= -1;

			rep(k,2){
				if(k==1) rep(x,n) tmp[x][2] *= -1;

				res = max(res, aaa(tmp, m));
			}
		}
	}

	cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 384
const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const solve = (n) => {
  // ...
  // let current = undefined
  let max = 0
  let z = []
  n.map((r, i) => {
    // if (current === undefined) {
    if (i == 0) {
      z[i] = 0
      // current = r
      return
    }
    // let before = n[i - 1]
    const current = n[i - 1]
    if (r > current) {
      z[i] = 0
    } else {
      z[i] = z[i - 1] + 1
      max = Math.max(z[i], max)
    }
    // current = r
  })
  // console.log(z)
  return max
}
const main = (input) => {
  const [h, r] = input.split("\n")
  return solve(r.split(" ").map(Number))
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}

if (process.env.NODE_ENV === "test") {
  // module.exports = (input) => solve(input.trim())
  // main(``)
  // solve(1, [2, 3, 4])
}


Measured memory_bytes: 29804
N = int(input())
p = list(int(x) for x in input().split())
a = 0
for k in range(N):
    k = k + 1
    if k != p[k - 1]:
        a = a + 1
    if a == 3:
        print("NO")
        break
if k == N:
    print("YES")

Measured memory_bytes: 3060
from bisect import bisect_left

n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]

count = 0
for t in T:
    index = bisect_left(S, t)
    if index < len(S) and S[index] == t:
        count += 1

print(count)


Measured memory_bytes: 16924
import sys
import math

n = int(sys.stdin.readline())

for i in range(n):
    n1 = int(sys.stdin.readline())
    n2 = int(sys.stdin.readline())
    if n1+n2<100000000000000000000000000000000000000000000000000000000000000000000000000000000 :
        print(n1+n2)
    else:
        print("overflow")

Measured memory_bytes: 6316
N=int(input())
if N==0:
  print(0)
  exit()
X=1
P=''
for i in range(32):
  if N&X:
    if i&1:
      N+=X
    else:
      N-=X
    P+='1'
  else:
    P+='0'
  X<<=1
while P[-1]=='0':
  P=P[:-1]
print(P[::-1])

Measured memory_bytes: 61308
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)
#define ll LL
#define st f
#define nd s
#define pb PB
#define mp MP
#define eb emplace_back
#define siz(c) SIZ(c)
const int inf = 1e9+7;
const ll INF = 1e18L+7;

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int main()
{
  string s;
  cin >> s;
  if(s == "ABC")cout << "ARC" << endl;
  else cout << "ABC" << endl;
}


Measured memory_bytes: 3580
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int b[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  int c[n-1];
  for (int i = 0; i < n-1; i++) {
    scanf("%d", &c[i]);
  }

  int answer = 0;
  for (int i = 0; i < n; i++) {
    answer += b[i];
    if (i != 0 && a[i] == a[i-1]+1) {
      answer += c[a[i-1]-1];
    }
  }

  printf("%d\n", answer);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)
using namespace std;

typedef long long ll;
const int inf=1000000000;
const int np=1000000007;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main() {
	int n;
	cin>>n;
	int p[100]={};
	rep(i,n)cin>>p[i];
	sort(p,p+n);
	int r=0;
	rep(i,n){
		if((n-i)<=p[i])r=max(r,n-i);
	}
	cout<<r<<endl;
	return 0;
}



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


int main() {
    int N;
    cin >> N;
    int ans = 0;
    xrep(n1, 1, N+1) {
        int cnt = 0;
        xrep(n2, 1, N+1) {
            if(n1%n2==0 && n1%2==1) {
                ++cnt;
            }
        }
        if(cnt==8) ++ans;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3576
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
    int n, k, s;
    cin >> n >> k >> s;
    rep(i, k) printf("%d ", s);
    rep(i, n-k) {
        if (s == 1e9) printf("1 ");
        else printf("%d ", s+1);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(){
	int n, m;
	int tmp;
	int i, j=0;
	int a[100]={};
	while(1){
		scanf("%d", &n);
		if(n==0){
			break;
		}
		m=0;
		for(i=0;i<n/4;i++){
			scanf("%d", &tmp);
			m+=tmp;
		}
		a[j]=m;
		j++;
	}
	for(i=0;i<j;i++){
		printf("%d\n", a[i]);
	}
	return 0;
}

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

// Template START
#define endl "\n"
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
const int mod = (int)1e9 + 7 ;
template<class T>
auto matrix( int r, int c, T v ){
    return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
template<class T>
auto matrix( int o1, int o2, int o3, T v ){ 
    return vector<vector<vector<T>>>( o1, vector<vector<T>>( o2, vector<T>( o3, v ) ) ) ;
}
#define v vector
// Template END

int power( int x, int n ){
    if( n == 0 ) return 1 ;
    else if( n & 1 ) return ( x * power( (x*x) % mod, n / 2 ) ) % mod ;
    return power( (x*x) % mod, n / 2 ) % mod ;
}


signed main(){
    int n, k ; cin >> n >> k ;
    vector<int> p(n) ;
    for( int i = 0 ; i < n ; i++ ) cin >> p[i] ;
    sort( all(p) ) ;
    int res = 0 ;
    for( int i = 0 ; i < k ; i++ ) res += p[i] ;
    cout << res ;
    return 0 ;   
}          

Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
    int i,n,max,min,x;
    int a[200000];
    scanf("%d", &n);
    for(i=0;i<n;i++) {
        scanf("%d",&a[i]);
    }
 
    for(i=1;i<n;i++){
        if(i==1){
            max = a[1]-a[0];
            min = a[0];
        }
        x = a[i]-min;
        if(x>max)max = x;
        if(a[i]<min)min=a[i];
    }
    printf("%d\n", max);
    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    // 素因数分解
    auto pf = prime_factorize(M);

    ll ans=1;
    for(auto pn:pf){
        mulM(ans,nCk(pn.second+N-1,pn.second,MOD));
    }
    
    pl(ans)

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M_PI       3.14159265358979323846
#define Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define 	pb	push_back 
#define 	ff	first 
#define 	ss	second 
#define sz(x) (int)x.size()
#warning Remeber to change t
using namespace std;
typedef long long ll;
inline void setIO(string name="") {
	#ifndef ONLINE_JUDGE 
	freopen((name+".in").c_str(), "r", stdin); 
	freopen((name+".out").c_str(), "w", stdout);
	#endif
	}
  ll const mx=2e5+7;
  vector<ll>adj[mx];
  ll vis[mx],n,m,nodes;

  void dfs(ll u){
    if(vis[u]){
      return ;
    }
    vis[u]=1;
      nodes++;
      for(auto i:adj[u])
        dfs(i);
    }
    
int main(){
	Speed_UP
	ll t;
	t=1;
	while(t--){
    cin>>n>>m;
    for(int i=0;i<m;i++){
      ll u,v;
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
      if(vis[i]==0){
        nodes=0;
        dfs(i);
        ans=max(nodes,ans);
      }
    }
    cout<<ans;
		
		
		
	}





}


Measured memory_bytes: 22216
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template<typename Monoid, typename OperatorMonoid>
struct LazySegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    using G = function<Monoid(Monoid, OperatorMonoid)>;
    using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
    const F f;
    const G g;
    const H h;
    const Monoid M1;
    const OperatorMonoid OM0;
    int sz, height;
    vector<Monoid> data;
    vector<OperatorMonoid> lazy;
    LazySegmentTree(int n, const F f, const G g, const H h,
                    const Monoid &M1, const OperatorMonoid &OM0)
        : f(f), g(g), h(h), M1(M1), OM0(OM0), sz(1), height(0)
    {
        while (sz < n) sz <<= 1, height++;
        data.assign(sz * 2, M1);
        lazy.assign(sz * 2, OM0);
    }
    void set(int k, const Monoid &x) { data[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            data[k] = f(data[k << 1 | 0], data[k << 1 | 1]);
        }
    }
    inline Monoid reflect(int k) {
        return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]);
    }
    inline void propagate(int k) {
        if (lazy[k] == OM0) return ;
        lazy[k << 1 | 0] = h(lazy[k << 1 | 0], lazy[k]);
        lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]);
        data[k] = reflect(k);
        lazy[k] = OM0;
    }
    inline void thrust(int k) {
        for (int i = height; i > 0; i--) propagate(k >> i);
    }
    inline void recalc(int k) {
        while (k >>= 1) data[k] = f(reflect(k << 1 | 0), reflect(k << 1 | 1));
    }
    void update(int a, int b, const OperatorMonoid &x) {
        thrust(a += sz);
        thrust(b += sz - 1);
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) lazy[l] = h(lazy[l], x), ++l;
            if (r & 1) --r, lazy[r] = h(lazy[r], x);
        }
        recalc(a);
        recalc(b);
    }
    Monoid get(int a, int b) {
        thrust(a += sz);
        thrust(b += sz - 1);
        Monoid L = M1, R = M1;
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) L = f(L, reflect(l++));
            if (r & 1) R = f(reflect(--r), R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) { return get(k, k + 1); }
};

int main() {
    int n, q; cin >> n >> q;
    struct T {
        long long sum; int num;
        T(long long sum, int num) : sum(sum), num(num) { }
    };
    using E = long long;
    auto f = [](T a, T b) { return T(a.sum + b.sum, a.num + b.num); };
    auto g = [](T a, E b) { return T(a.sum + a.num * b, a.num); };
    auto h = [](E a, E b) { return E(a + b); };
    LazySegmentTree<T, E> seg(n, f, g, h, T(0, 1), E(0));
    seg.build();
    while (q--) {
        int op; cin >> op;
        int s, t; cin >> s >> t; s--;
        if (op == 0) {
            int x; cin >> x;
            seg.update(s, t, x);
        }
        if (op == 1) {
            cout << seg.get(s, t).sum << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 8904
#include<bits/stdc++.h>
using namespace std;
string S;
bool reach(int start,int goal){
   for(int i=start;i<goal;i++){
      if(S[i]=='#'&&S[i+1]=='#') return false;
   }
   return true;
}
int main(void){
   int N,A,B,C,D;
   cin>>N>>A>>B>>C>>D;
   cin>>S;
   S="#"+S+"#";
   if(!reach(A,C)||!reach(B,D)){
      cout<<"No"<<endl;
      return 0;
   }
   if(C>D){
      bool judge=false;
      for(int i=B;i<=D;i++){
         if(S[i-1]=='.'&&S[i]=='.'&&S[i+1]=='.'){
            judge=true;
         }
      }
      if(!judge){
         cout<<"No"<<endl;
         return 0;
      }
   }
   cout<<"Yes"<<endl;
   return 0;
}


Measured memory_bytes: 3884
import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int rec=0,rho=0;
		int a,b,d;
		String str;
		try{
		while((str=br.readLine())!=null&&!str.isEmpty()){
			String[] s=str.split(",");
			a=Integer.parseInt(s[0]);
			b=Integer.parseInt(s[1]);
			d=Integer.parseInt(s[2]);
			if(a*a+b*b==d*d) rec++;
			else if(a==b) rho++;
		}
		System.out.println(rec+"\n"+rho);
		}catch(Exception e){}
	}
}

Measured memory_bytes: 16904
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m,0);
    rep(i,m)cin >> a[i];
    sort(a.begin(),a.end());
    vector<ll> diff;
    rep(i,m-1)diff.push_back(a[i+1] - a[i]);
    sort(diff.begin(),diff.end(),greater<ll>());
    ll res = a.back() - a.front();
    for (ll i = 0; i < min((ll)diff.size(), n-1); ++i) res -= diff[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2168
# _*_ coding:utf-8 _*_
#  Atcoder_Beginner_Contest091-B
#  TODO https://atcoder.jp/contests/abc091/tasks/abc091_b

def solveProblem(wordDic,blueCards,redCards):
	maxMoney = 0
	for eachWord in wordDic:
		getMoney = blueCards.count(eachWord)-redCards.count(eachWord)
		if maxMoney < getMoney:
 			maxMoney = getMoney
	answer = maxMoney
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	wordDic = []
	blueCards = []
	blueCardRange = range(0,N,+1)
	for _ in blueCardRange:
		eachWord = str(input().strip())
		blueCards.append(eachWord)
		if eachWord not in wordDic:
			wordDic.append(eachWord)
	M = int(input().strip())
	redCardRange = range(0,M,+1)
	redCards = []
	for _ in redCardRange:
		redCards.append(str(input().strip()))
	solution = solveProblem(wordDic,blueCards,redCards)
	print("{}".format(solution))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

int N;
string S[200010];
int ans;
//string T[200010];

int main() {
    cin >> N;
    rep(i, N) cin >> S[i];
    sort(S, S + N);
    ans = 1;
    //T[0] = S[0];
    REP(i, 1, N) {
        if (S[i] != S[i - 1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9900
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

char s[20],a[20];
int n;
LL pw,ans;
char ord[20];

LL conv(char *s)
{
	LL ret=0;
	for(int i=0;i<n;i++)ret=ret*10+s[i]-'0';
	return ret;
}
int main()
{
	scanf("%s",s);
	n=strlen(s);pw=1;for(int i=1;i<=n;i++)pw*=10;
	for(int i=0;i<10;i++)ord[i]=i+'0';
	LL t1=conv(s);
//	printendl(t1);
	do
	{
		LL t2=abs(t1-conv(ord));
		t2=min(t2,pw-t2);
		if(t2>ans)
		{
			ans=t2;
			for(int i=0;i<n;i++)a[i]=ord[i];
		}
	}while(next_permutation(ord,ord+10));
//	printendl(ans);
	for(int i=0;i<n;i++)putchar(a[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 3124
import sys
import copy
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

a = LI()
k = I()

m = pow(3,k)
result = False
for i in range(m):
    val = copy.copy(a)
    for _ in range(k):
        tmp = i % 3
        i = i // 3
        val[tmp] = val[tmp]*2
    
    if(val[1] > val[0] and val[2] > val[1]):
        result = True

if(result):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 74456
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    int n; cin >> n;
    vector<int> V(n);
    vector<int> C(n);

    rep(i,n) cin >> V[i];
    rep(i,n) cin >> C[i];

    int value = 0;
    int cost = 0;

    rep(i,n){
        if(V[i] > C[i]){
            value += V[i];
            cost += C[i];
        }
    }

    cout << value - cost << endl;

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int calcDpTable(int i, int j, const int ** dpTable, const int *p) {
	int minValue = INT_MAX; 
	for (int k = i; k < j; ++k) {
		minValue = min(dpTable[i][k - i] + dpTable[k + 1][j - k - 1] + p[i] * p[k + 1] * p[j + 1], minValue);
	}
	return minValue;
}

int minNumOfMultiplications(const int *p, int n) {
	int **dpTable = new int*[n];
	for (int i = 0; i < n; ++i) {
		dpTable[i] = new int[n - i];
		dpTable[i][0] = 0;
	}

	int d = 1;
	for (int to = n - 2; to >= 0; --to) {
		for (int i = 0; i <= to; ++i) {
			int j = i + d;
			dpTable[i][j - i] = calcDpTable(i, j, const_cast<const int**>(dpTable), p);
		}
		++d;
	}
	int ret = dpTable[0][n - 1];
	
	for (int i = 0; i < n; ++i) {
		delete[] dpTable[i];
	}
	delete[] dpTable;

	return ret;
}

int main() {
	int n;
	cin >> n;
	int *p = new int[n + 1];
	for (int i = 0; i < n; ++i) {
		cin >> p[i] >> p[i + 1];
	}
	cout << minNumOfMultiplications(p, n) << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int start = max(a, c), end = min(b, d);
  if (end - start > 0) cout << end - start << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

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

int main() {
  int H, W; cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string r; cin >> r;
    cout << r << endl;
    cout << r << endl;
  }
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n,i,j,tmp;
  scanf("%d",&n );
  float set=0.0;
  int v[n];
  for(i=0;i<n;i++){
      scanf("%d",&v[i] );
  }
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      if(v[j] > v[j+1]){
        tmp = v[j];
        v[j] = v[j+1];
        v[j+1] = tmp;
      }
    }
  }
set = v[0];
for(i=1;i<n;i++){
  set += v[i];
  set /= 2;
}
printf("%f\n",set );

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
//long long mo = 1e9 + 7;
typedef long long ll;

int main(){
    double H,A;
    cin >> H >> A;
    cout << int(ceil(H/A)) << endl;
}


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

const int N=1e5+5;
int n,cnt[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		cnt[x]++;
	}
	int res=0,two=0;
	for(int i=1;i<N;++i){
		if(!cnt[i]) continue;
		if(cnt[i]>=3)
			cnt[i]=(cnt[i]&1)?1:2;
		if(cnt[i]==2) two++;
		else res++;
	}
	res+=two;
	if(two&1) res--;
	cout<<res<<'\n';
}



Measured memory_bytes: 4000