akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
BC = [[int(i) for i in input().split()] for j in range(M)]
BC.sort(key = lambda x:x[1],reverse = True)
replist = [0]*N
ans = [0]*N
t = 0

for times,rep in BC:
    for i in range(times):
        if t<N:
            replist[t]=rep
            t += 1
        else:
            break
    else:
        continue
    break

s=0
t=0

for i in range(N):
    if A[s]>replist[t]:
        ans[i]=A[s]
        s += 1
    else:
        ans[i]=replist[t]
        t+=1
print(sum(ans))

Measured memory_bytes: 26964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  int N;
  cin >> N;
  vi a(4);
  for (ll i = 0; i < N; i++) {
    string s;
    cin >> s;
    if (s == "AC")
      a[0]++;
    else if (s == "WA")
      a[1]++;
    else if (s == "TLE")
      a[2]++;
    else if (s == "RE")
      a[3]++;
  }
  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL X[210012];
LL dp[210012];

int main() {
    
    // 1. 入力情報取得.
    int N;
    LL A, B;
    scanf("%d %llu %llu", &N, &A, &B);
    for(int i = 0; i < N; i++) scanf("%llu", &X[i]);
    
    // 2. 疲労度の上昇値の合計の最小値を求める.
    for(int i = 1; i < N; i++){
        dp[i] = dp[i - 1];
        LL d = X[i] - X[i - 1];
        dp[i] += min(A * d, B);
    }
    
    // 3. 出力 ～ 後処理.
    printf("%llu", dp[N - 1]);
    return 0;
    
}

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


int main() {
long A,B,C,K;
cin>>A>>B>>C>>K;
long ans=0;
if(A>K){
  cout<<K<<endl;
  return 0;
}
else{
  ans+=A;
  K-=A;
}

if(B>K){
  cout<<ans<<endl;
  return 0;
}
else{
  K-=B;
}

ans-=K;
cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	double dp[100001] = {};
	for (int i = 1;i <= min(K, N);++ i) dp[i] += 1.0 / N;
	dp[K] += (double)max(0, N - K) / N;
	for (int i = 1;i < K;++ i) dp[min(K, 2 * i)] += dp[i] / 2;
	cout << setprecision(10) << fixed << dp[K] << endl;
	return 0;
}

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

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;}

int main(){
  ll ans=0;
  ll n;
  cin >>n;
  ll k=n;
  queue<int> p;
  for(ll i = 2; i*i<=k; i++){
    int g=0,top=1;
    while(n%i==0){
      n/=i;
      g++;
      if(g==top){ans++;top++;g=0;}
      }
  }
  if(n!=1)ans++;
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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;
}

template <class T> T gcd(T x, T y) {
    // 最小公倍数を求める
    if (y == 0)
        return x;
    gcd(y, x % y);
}

template <class T> T lcm(T x, T y) {
    // 最大公約数を求める
    T GCD = gcd(x, y);
    T ans = x / GCD * y;
    return ans;
}

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

    int N, M;
    cin >> N >> M;

    int ans = 0;
    if (N == 1) {
        std::cout << M << '\n';
        return 0;
    }
    REP(i, M / N) {
        if (M % (i + 1) == 0) {
            ans = i + 1;
        }
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        String S = sc.next();

        int NUM = 100001;
        int[] one = new int[NUM];
        int[] zero = new int[NUM];

        int oneIndex = 0;
        int zeroIndex = 0;

        if (S.charAt(0) != '0') {
            zero[zeroIndex++] = 0;
        }

        int i = 0;
        while (i < S.length()) {
            if (S.charAt(i) == '0') {
                int cnt = 0;
                while (i < S.length() && S.charAt(i) == '0') {
                    cnt++;
                    i++;
                }
                zero[zeroIndex++] = cnt;
            } else {
                int cnt = 0;
                while (i < S.length() && S.charAt(i) == '1') {
                    cnt++;
                    i++;
                }
                one[oneIndex++] = cnt;
            }
        }

        int index = 0;
        int tmpK = K;
        long ans = 0;
        while (tmpK-- > 0) {
            ans += one[index];
            ans += zero[index];
            index++;
        }

        long tmp = ans;
        while (index < NUM) {
            if(index - K - 1 >= 0) {
                tmp -= one[index - K - 1];
            }
            tmp -= zero[index - K];
            tmp += one[index] + zero[index];

            ans = Math.max(ans, tmp);
            index++;
        }

        out.print(ans);
    }
}

Measured memory_bytes: 26504
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong();
        long cnt = 0;
        sc.close();
        if (l % 2 == 1) {
            System.out.println(0);
            return;
        } else {
            long five = 10;
            while (five <= l) {
                cnt += (l / five);
                five *= 5;
            }
        }
        System.out.println(cnt);

    }
}


Measured memory_bytes: 22740
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

int main() {
	int H, A;
	cin >> H >> A;
	if (H % A == 0)cout << H / A << endl;
	else cout << H / A + 1 << endl;
	return 0;
}


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

int main() {
	
	string s;
	cin >> s;
	
	sort(s.begin(), s.end());
	if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) puts("Yes");
	else puts("No");
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 55;

vector<vector<ll>> DP(MAX,vector<ll>(MAX*MAX,0));

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

	int N,A;
	cin >> N >> A;

	DP[0][0] = 1;

	vector<int> V(N);
	for(auto &x : V) cin >> x;

	for(int i = 0; i < N; i++){
		for(int j = i; j >= 0; j--){
			for(int k = 0; k < MAX*MAX; k++){
				if(k + V[i] < MAX*MAX)
					DP[j+1][k+V[i]] += DP[j][k];
			}
		}
	}

	ll ans = 0;
	for(int i = 1; i <= N; i++) ans += DP[i][i*A];

	cout << ans << endl;	

	return 0;
}


Measured memory_bytes: 4920
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    s = input()
    if s == 'AC':
        AC += 1
    elif s == 'WA':
        WA += 1
    elif s == 'TLE':
        TLE += 1
    else:
        RE += 1
print ('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))

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

#pragma warning(disable : 4996)

using namespace std;

int M, N, dp[2001][2001][2]; string S, T;

int main()
{
	scanf("%d", &M);
	scanf("%d", &N);

	cin >> S >> T;

	for (int i = 0; i <= M; i++)
	{
		for (int j = 0; j <= N; j++)
		{
			if (i != 0)
			{
				char c = S[i - 1];

				if (c == 'I')
				{
					dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][1] + 1);
				}
				else
				{
					dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][0]);
				}
			}

			if (j != 0)
			{
				char c = T[j - 1];

				if (c == 'I')
				{
					dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][1] + 1);
				}
				else
				{
					dp[i][j][1] = max(dp[i][j][1], dp[i][j - 1][0]);
				}
			}
		}
	}

	int ret = 0;

	for (int i = 0; i <= M; i++)
	{
		for (int j = 0; j <= N; j++)
		{
			for (int k = 0; k < 2; k++)
			{
				ret = max(ret, dp[i][j][k]);
			}
		}
	}

	printf("%d\n", ret != 0 ? ret * 2 - 1 : 0);

	return 0;
}

Measured memory_bytes: 34580
class Operation():
    def __init__(self, num_list):
        self.num_list = num_list
        
    def ope(self, queries):
        q = queries[0]
        # print(queries, self.num_list)
        if q == 0:
            self.pushBack(queries[1])
        elif q == 1:
            self.randomAccess(queries[1])
        elif q == 2:
            self.popBack()
    
    def pushBack(self, x):
        # print("pushBack")
        self.num_list.append(x)
    def randomAccess(self, p):
        # print(len(self.num_list), p + 1)
        if len(self.num_list) >= p + 1:
            print(self.num_list[p])
    def popBack(self):
        if len(self.num_list) > 0:
            self.num_list.pop(-1)
    

x = int(input())
op = Operation(list())
for i in range(x):
    op.ope(list(map(int,input().split())))


Measured memory_bytes: 13372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
   int a,b;cin>>a>>b;
   if(1<=a && a<=9 && 1<=b && b<=9)cout<<a*b<<endl;
   else cout<<-1<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var H = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            int count = 1;
            for(int i = 1; i < N; i++)
            {
                int[] x = H.Take(i).ToArray();
                if (x.Max() <= H[i])
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x1:i64 = read();
    let y1:i64 = read();
    let x2:i64 = read();
    let y2:i64 = read();
    let x3 = x2 - x1;
    let y3 = y2 - y1;
    println!("{} {} {} {}", x2 - y3, y2 + x3, x1 - y3, y1 + x3);
}

Measured memory_bytes: 2168
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

int main() {
	int N;
	cin >> N;
	vector<priority_queue<char, vector<char>, std::greater<char>>> vec(N);
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		for (size_t t = 0; t < s.length(); ++t) {
			vec[i].push(s[t]);
		}
	}

	map<int, int> mp;
	for (int ascii = (int)'a'; ascii <= (int)'z'; ++ascii) {
		int minCount = INT_MAX;
		for (int i = 0; i < N; ++i) {
			int count = 0;
			while (!vec[i].empty() && (int)vec[i].top() == ascii) {
				++count;
				vec[i].pop();
			}
			minCount = min(minCount, count);
		}

		mp[ascii] = minCount;
	}

	string s = "";
	for (auto iter = mp.begin(); iter != mp.end(); ++iter) {
		for (int i = 0; i < iter->second; ++i) {
			s += char(iter->first);
		}
	}

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

Measured memory_bytes: 3616
k=int(input())
q=[7]
Q=[0]

for i in range(k) :
    q.append((q[i]*10)%k)
    if (q[i]+Q[i])%k==0 :
        print(i+1)
        exit()
    Q.append((q[i]+Q[i])%k)
    
else :
    print(-1)


Measured memory_bytes: 88048
#include <bits/stdc++.h>
#define inf (1<<29)
#define sq(n) ((n)*(n))
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define MEMSET(a) memset(a,0,sizeof(a))
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
using ll = long long;

#define MAX 100005
#define NIL -1

struct node{int p,l,r;};
node t[MAX];
int n,d[MAX];

void print(int u){
	cout<<"node "<<u<<": ";
	cout<<"parent = "<<t[u].p<<", ";
	cout<<"depth = "<<d[u]<<", ";
	if(t[u].p==NIL)cout<<"root, ";
	else if(t[u].l==NIL)cout<<"leaf, ";
	else cout<<"internal node, ";
	cout<<"[";
	int i,c;
	for(i=0,c=t[u].l;c!=NIL;i++,c=t[c].r){
		if(i)cout<<", ";
		cout<<c;
	}
	cout<<"]"<<endl;
}

void dep(int u,int p){
	d[u]=p;
	if(t[u].r!=NIL)dep(t[u].r,p);
	if(t[u].l!=NIL)dep(t[u].l,p+1);
}

signed main(){
	cin>>n;
	rep(i,n)t[i].p=t[i].l=t[i].r=NIL;
	rep(i,n){
		int id,k,c;
		cin>>id>>k;
		int l;
		rep(j,k){
			cin>>c;
			if(j)t[l].r=c;
			else t[id].l=c;
			t[c].p=id;
			l=c;
		}
	}
    int r;
	rep(i,n)if(t[i].p==NIL)r=i;
	dep(r,0);
	rep(i,n)print(i);
	return 0;
}


Measured memory_bytes: 9252
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	// find m such that n/m*(1+m)==n;
	// means m+1 should be factor of n obviosly .
	int m;
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++)
	{
		if (n % i == 0)
		{
			int x = i;
			int y = n / i;
			int ans1 = 0, ans2 = 0, ans = 0;
			//m+1=x or m+1=y;
			m = x - 1;
			if (m > 0 && (n / m) * (m + 1) == n)
				ans++, ans1 = m;
			m = y - 1;
			if (m > 0 && (n / m) * (m + 1) == n)
				ans++, ans2 = m;
			if (ans == 2 && x == y)
			{
				//ans--;
				ans2 = 0;
			}
			cnt += ans1 + ans2;
		}
	}
	cout << cnt << en;



	return 0;
}



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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 4e5 +11;
int n,m,cnt,d,b[N],ans[N];;
struct uzi{int s,t,x,i;}p[N];
struct faker{int x,i; bool operator <(const faker & t)const{return x<t.x;} }a[N];
int cmp(uzi a,uzi b){return a.x<b.x;}
map<int,int>pos;
bool operator < ( pair<int,int>A,pair<int,int>B ){return A.fi<B.fi;}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	memset(ans,-1,sizeof ans);
	for(int i=1;i<=n;i++){
		cin>>p[i].s>>p[i].t>>p[i].x;
		p[i].s-=p[i].x;p[i].t-=p[i].x;p[i].i=i;
		p[i].s=max(p[i].s,0);
		p[i].t=max(p[i].t,0);
	}
	sort(p+1,p+1+n,cmp);
	for(int i=1;i<=m;i++)cin>>a[i].x,a[i].i=i,pos[a[i].x]=i;
	set<int>s;
	for(int i=1;i<=m;i++)s.insert(a[i].x);
	for(int i=1;i<=n;i++){//当前这个区间选择一些可以满足的数[p[i].s,p[i].t),左闭右开
		auto l=s.lower_bound(p[i].s);
		auto k=s.lower_bound(p[i].t);
		vector<int>q;
		for(auto j=l;j!=k;j++){
			ans[pos[*j]]=p[i].x;
			q.pb(*j);
		}
		for(auto j:q)s.erase(j);
	}
	for(int i=1;i<=m;i++)cout<<ans[i]<<'\n';cout<<endl;
	return 0;
}
// 找最小的位置，使得该位置的时间包含d
// 可以找每个障碍点控制的范围（指人



Measured memory_bytes: 32512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,a,b = LI()
    if abs(a-b) % 2 == 1:
        return 'Borys'

    return 'Alice'

print(main())




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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 1;

int n, k;
int h[maxN];

int dp[maxN];

int ABS(int x)
{
    return x > 0 ? x : -x;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for1(i, n)
    {
        cin >> h[i];
    }
    dp[1] = 0;
    fore(i, 2, min(n, k))
    {
        dp[i] = dp[i - 1] + ABS(h[i] - h[i - 1]);
        for1(j, i - 2)
        {
            dp[i] = min(dp[i], dp[j] + ABS(h[i] - h[j]));
        }
    }
    fore(i, k + 1, n)
    {
        dp[i] = dp[i - 1] + ABS(h[i] - h[i - 1]);
        fore(j, i - k, i - 2)
        {
            dp[i] = min(dp[i], dp[j] + ABS(h[i] - h[j]));
        }
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var res int
	for i := 1; i <= n; i++ {
		if i%3 == 0 || i%5 == 0 {
			continue
		}
		res += i
	}
	fmt.Println(res)
}


Measured memory_bytes: 1752
#include<bits/stdc++.h>
using namespace std;
const int N=262144;
int tree[N*2-1];
int func(int a,int b,int k,int l,int r);
int main(void){
	int n;
	int box[200001];
	int n_2;
	int i,k;
	int x;
	int ans;
	cin>>n;
	n_2=1;
	while(n_2<n)	n_2*=2;
	for(i=0;i<2*n_2-1;i++)	tree[i]=INT_MIN;
	for(i=0;i<n;i++){
		cin>>box[i];
		k=i+n_2-1;
		tree[k]=box[i];
		while(k>0){
			k=(k-1)/2;
			tree[k]=max(tree[2*k+1],tree[2*k+2]);
		}
	}
	for(i=0;i<n;i++){
		k=i+n_2-1;
		tree[k]=0;
		while(k>0){
			k=(k-1)/2;
			tree[k]=max(tree[2*k+1],tree[2*k+2]);
		}
		ans=func(0,n,0,0,n_2);
		cout<<ans<<endl;
		k=i+n_2-1;
		tree[k]=box[i];
		while(k>0){
			k=(k-1)/2;
			tree[k]=max(tree[2*k+1],tree[2*k+2]);
		}
	}
	return 0;
}
int func(int a,int b,int k,int l,int r){
	int chl,chr;
	if(b<=l||r<=a)	return INT_MIN;
	if(a<=l&&r<=b)	return tree[k];
	else{
		chl=func(a,b,2*k+1,l,(l+r)/2);
		chr=func(a,b,2*k+2,(l+r)/2,r);
		return max(chl,chr);
	}
}
	

Measured memory_bytes: 4480
def main():
    c = [list(map(int, input().split())) for _ in range(3)]
    N = 100
    for i in range(-N, N+1):
        for j in range(-N, N+1):
            for k in range(-N, N+1):
                if c[0][0] - i == c[0][1] - j == c[0][2] - k:
                    if c[1][0] - i == c[1][1] - j == c[1][2] - k:
                        if c[2][0] - i == c[2][1] - j == c[2][2] - k:
                            print('Yes')
                            return
    print('No')
main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int N = Integer.parseInt(reader.readLine());
        String line = reader.readLine();
        String[] inputs = line.split(" ");

        int[] as = Arrays.stream(inputs).mapToInt(Integer::parseInt).toArray();

        Arrays.sort(as);

        int max = 1000000;
        int[] tmp = new int[max+1];


        for (int i = 0; i < N; i++) {
            tmp[as[i]] += 1;
        }

        int answer = 0;
        for (int i = 1; i < max; i++) {
            answer = Math.max(answer, tmp[i - 1] + tmp[i] + tmp[i + 1]);
        }


        System.out.println(answer);
    }
}


Measured memory_bytes: 50624
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
asum=0
bsum=0
pointer=0
while pointer<m and bsum+b[pointer]<=k:
	bsum+=b[pointer]
	pointer+=1
ans=pointer
for i in range(n):
	asum+=a[i]
	while asum+bsum>k and pointer>=0:
		pointer-=1
		bsum-=b[pointer]
	if asum+bsum>k:
		break
	ans=max(ans,(i+1)+pointer)
print(ans)

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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i = 0;i < N;i++) cin >> l[i];
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int ans = 0;
  for(int i = 0;i < K;i++) ans += l[i];
  cout << ans << endl;
}

Measured memory_bytes: 3580
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};


ll dbit(ll N,ll d){
    N=N>>d;
    return N&1;
}
long pow_mod(long a,long n,long mod){
    long res=1;
    while(n>0){
        if(n&1){
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        n=(n>>1);
    }
    return res;
}

int main(){
    ll N;
    cin>>N;
    ll bit[63][2]={0};
    for(ll i=0;i<N;i++){
        ll a;
        cin>>a;
        for(ll i=0;i<63;i++){
            bit[i][dbit(a,i)]++;
        }
    }
    mint res=0;
    for(ll i=0;i<63;i++){
        ll zero_num = bit[i][0];
        ll one_num = bit[i][1];
        // cout<<"i:"<<i<<", zero:"<<zero_num<<", one:"<<one_num<<endl;
        res += pow_mod(2,i,mod)*zero_num%mod*one_num%mod;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
N = int(input())
ls = [int(s) for s in input().split(" ")]

fwd_tall = ls[0]
sum_e = 0
for i in range(N):
    tall = ls[i]
    e = 0
    if fwd_tall > tall:
        e = fwd_tall - tall
        ls[i] += e
    sum_e += e
    #print(e)
    fwd_tall = ls[i]
print(sum_e)

Measured memory_bytes: 32252
class DisjointSet:
    def __init__(self,n):
        self.rank = [0]*n
        self.parent = [i for i in range(n)]
        self.siz = [1]*n

    def same(self,x,y): 
        return self.findSet(x) == self.findSet(y)

    def unite(self,x,y): 
        return self.link(self.findSet(x), self.findSet(y))

    def link(self,x,y):
        if self.rank[x] > self.rank[y]: 
            self.parent[y] = x
            self.siz[x] += self.siz[y]
        else:
            self.parent[x] = y
            self.siz[y] += self.siz[x]
            if self.rank[x] == self.rank[y]: self.rank[y] += 1

    def findSet(self,x):
        if x != self.parent[x]: 
            self.parent[x] = self.findSet(self.parent[x])
        return self.parent[x]

    def size(self,x):
        return self.siz[self.parent[self.findSet(x)]]

n,m = map(int,input().split())
brg = [[int(i)-1 for i in input().split()] for _ in range(m)]
cnt = n*(n-1)//2
ans = [0]*m
ds = DisjointSet(n)
for i in range(m)[::-1]:
    ans[i] = cnt
    a,b = brg[i]
    if not ds.same(a,b):
        cnt -= ds.size(a)*ds.size(b)
        ds.unite(a,b)
print("\n".join(map(str,ans)))

Measured memory_bytes: 36740
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector<int> s(n);
		for (int i = 0; i < n; i++) cin >> s[i];
		sort(s.begin(), s.end());
		int sum = 0;
		for (int i = 1; i < n - 1; i++) sum += s[i];
		cout << sum / (n - 2) << endl;
	}
}

Measured memory_bytes: 1216
N=int(input())
A=[int(input()) for _ in range(N)]

import bisect
B=[A[N-1]]
for i in range(N-2,-1,-1):
    if A[i]>=B[-1]:
        B.append(A[i])
    else:
        B[bisect.bisect_right(B,A[i])]=A[i]

print(len(B))

Measured memory_bytes: 56280
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && a!=c)
    cout<<"Yes"<<endl;
  else if(c==b && b!=a)
        cout<<"Yes"<<endl;
  else if(c==a && a!=b)
        cout<<"Yes"<<endl;
  
  
  else
         cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>
// #define rep(i,a,b) for(int i=a;i<b;i++)
// #define rrep(i,b,a) for(int i=b;i>=a;i--)
// #define fori(a) for(auto i : a )
// #define all(a) begin(a), end(a)
// #define set(a,b) memset(a,b,sizeof(a))
// #define sz(a) a.size()
// #define pi 3.14159
// #define ll long long
// #define ull unsigned long long
// #define pb push_back
// #define PF push_front //deque
// #define mp make_pair
// #define pq priority_queue
// #define mod 1000000007
// #define f first
// #define s second
// #define pii pair< int, int >
// #define vi vector<int>
// #define vpii vector<pii>
// #define debug(v) for(auto i:v) cout<<i<<" ";
// #define tc int t; cin >> t; while(t--)
// const int INF=1e9;
// using namespace std;
// string repeat(string s, int n) {
//     string s1 = "";
//     for (int i=0; i<n;i++)
//         s1+=s;
//     return s1;
// }
// string getString(char x) {
//     string s(1, x);
//     return s;
// }
//
// void optimizeIO(){
//     ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
//     cout.tie(NULL);
// }
// int gcd(int a, int b){
//     if (a == 0)  return b;
//     return gcd(b % a, a);
// }
// vector<int> h(101);
// int solve1(int st,int en,int curr){
//   if(st>en) return 0;
//   int idx=min_element(h.begin()+st,h.begin()+en)-h.begin();
//   vector<int> v;
//   rep(i,st,en+1) if(h[i]==h[idx]) v.pb(i);
//   int ans=solve1(st,v[0]-1,h[idx])+h[idx]-curr;
//   rep(i,1,v.size()) ans+= solve1(v[i-1]+1,v[i]-1,h[idx]);
//   ans+= solve1(v[v.size()-1]+1,en,h[idx]);
//   return ans;
// }
// void  solve(){
//   int n;
//   cin>>n;
//   rep(i,0,n) cin>>h[i];
//   int last=h[0],ans=0;
//   rep(i,1,n){
//     if(h[i]>=last){
//       ans+= (h[i]-last)*i;
//       last=h[i];
//     }
//     else{
//
//     }
//   }
//   cout<<ans<<endl;
// }
// int main(){
//   // int idx=min_element(h.begin(),h.begin()+n)-h.begin();
//   // vector<int> v;
//   // rep(i,0,n) if(h[i]==h[idx]) v.pb(i);
//   // int ans=solve1(0,v[0]-1,h[idx])+h[idx];
//   // rep(i,1,v.size()) ans+= solve1(v[i-1]+1,v[i]-1,h[idx]);
//   // ans+= solve1(v[v.size()-1]+1,n-1,h[idx]);
//   // cout<<ans<<endl;
//     optimizeIO();
//     // tc
//     { solve();
//     }
// }

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

int main(){

  int N, i, j, cnt = 0; cin >> N;
  vector<int> h(N);
  for(i=0; i<N; i++) cin >> h[i];

  while(true){

    j = 0;
    while(h[j] == 0) j++;

    for(i = j; i < N; i++){

      if(h[i] == 0){
        cnt++;
        break;
      }
      h[i]--;
      if(i == N - 1) cnt++;
    }

    bool flag = true;
    for(i = 0; i < N; i++){
      if(h[i] != 0) flag = false;
    }
    if(flag){
      cout << cnt << endl;
      return 0;
    }
  }
  return -1;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod=1000000007;
ll dp[100][100005],w[100],v[100],n;
ll call(int i,int wt)
{
//	cout<<w[i]<<" "<<wt<<" "<<dp[i][wt]<<endl;
	if(i==n || wt==0) return 0;
//	if(wt==0) return dp[i][wt]=0;
	if(dp[i][wt]!=-1) return dp[i][wt];
	if(w[i]<=wt) return dp[i][wt]=max(call(i+1,wt-w[i])+v[i],call(i+1,wt));
	return dp[i][wt]=call(i+1,wt);
}
int main()
{
	int i,wt,j;
	cin>>n>>wt;
	for(i=0;i<n;i++)
	{
	cin>>w[i]>>v[i];
	for(j=0;j<=wt;j++) dp[i][j]=-1;
	}
	cout<<call(0,wt);
}

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

int main(void) {
  int a,b,c,x;
  cin >> a >>b >> c;
  if(a >= b && a >= c) {
    cout << a*10 + b +c << endl;
  } else if(b >= a && b >= c) {
    cout << b*10 + a + c << endl;
  } else if(c >= a && c >= b) {
    cout << c*10 + a +b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
H,W,A,B=map(int,input().split())

ans=[]
for b in range(B):
    ans.append(["1"]*A+["0"]*(W-A))
for b in range(H-B):
    ans.append(["0"]*A+["1"]*(W-A))

for item in ans:
    print("".join(item))

Measured memory_bytes: 11892
from collections import Counter
N = int(input())
A = [int(v) for v in input().split()]

m = max(A)
l = [1 for i in range(m+1)]
for v in sorted(A):
    for j in range(2*v, m+1, v):
        l[j] = 0

ans = 0
c = Counter(A)
for a in A:
    if c[a] > 1:continue
    ans += l[a]
print(ans)

Measured memory_bytes: 44660
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int prime[101000];
bool is_prime[101000];
void sieve(int n){
	// n以下の素数を求める
	int p = 0;
	for(int i=0;i<=n;i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <=n ; i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j <=n;j+=i) is_prime[j] = false;
		}
	}
}
int main(){
	cout << fixed << setprecision(10);
	sieve(100010);
	vector<int> sum(100011,0);
	rep(i,100010){
		if( i%2!=0 && is_prime[i] && is_prime[(i+1)/2]){
			sum[i+1] = sum[i] + 1;
		}else sum[i+1] = sum[i]; 
	}
	int q;
	cin >> q;
	rep(i,q){
		int l,r;
		cin >> l >> r;
		cout << sum[r+1] - sum[l] << endl; 
	}
	return 0;
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

def main():
    S = input()

    if S[-1] == 's':
        print(S + 'es')
    else:
        print(S + 's')


if __name__ == '__main__':
    main()


Measured memory_bytes: 65224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N;
    cin >> N;
    for (ll h = 1; h <= 3500; h++) {
        for (ll n = 1; n <= 3500; n++) {
            if((4 * h * n - n * N - h * N) >= 1 && (N*h*n) % (4 * h * n - n * N - h * N) == 0){
                printf("%lld %lld %lld\n", h, n, (N*h*n) / (4 * h * n - n * N - h * N));
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3748
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N =get_int
P = get_ints

first = nil
second = nil
i = 1
while i <= N-1
  if P[i] < P[i-1]
    if first.nil?
      first = i-1
    else
      second = i
      break
    end
  end
  i += 1
end

px = P.dup

if first && second
  px[first] = P[second]
  px[second] = P[first]
elsif first
  px[first] = P[first+1]
  px[first+1] = P[first]
end

puts px.each_cons(2).all? { |a, b| b >= a } ? 'YES' : 'NO'


Measured memory_bytes: 14380
#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)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

//プロトタイプ宣言
void faster(void);
ll gcd(auto , auto);
ll get_digent(auto);
ll POW(auto , auto);
ll vec_max(auto & , string);
ll vec_min(auto & , string);

int main(){
  faster();
  ll n,k;
  cin >> n >> k;
  vl a(n),cnt(n,0);
  rep(i,n) cin >> a[i];
  rep(i,n) cnt[a[i]]++;
  sort(cnt.rbegin(),cnt.rend());
  ll tmp=0;
  rep(i,k) tmp += cnt[i];
  cout << n - tmp << endl;
}


























//以下、ライブラリ

//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
ll gcd(auto a, auto b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
ll get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
ll POW(auto x, auto y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//配列内の最大要素の添え字取得or要素取得
ll vec_max(auto &v, string s){
  auto itr = max_element(v.begin(),v.end());
  ll element = *itr;
  ll place = itr - v.begin();
  if(s == "element") return element;
  else if(s == "place") return place;
  else return -1;
}

//配列内の最小要素の添え字取得or要素取得
ll vec_min(auto &v, string s){
  auto itr = min_element(v.begin(),v.end());
  ll element = *itr;
  ll place = itr - v.begin();
  if(s == "element") return element;
  else if(s == "place") return place;
  else return -1;
}

Measured memory_bytes: 3456
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>a>>b;
    cout<<a*b<<endl;

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int D, N;
    cin >> D >> N;
    
    int base;
    if(D == 0){
        int cnt = 0;
        for(int i = 0; i <= 1010000; i++){
            int temp = i;
            if(temp % 100 != 0){
                cnt++;
            }
            
            if(cnt == N){
                cout << i << endl;
                return 0;
            }
        }
    }
    
    if(D == 1){
        base = 100;
    }
    else{
        base = 10000;
    }
    
    int cnt = 0;
    for(int i = base; i <= 1010000; i++){
        int temp = i;
        if(temp % base == 0){
            temp /= base;
            if(temp % 100 != 0){
                cnt++;
            }
        }
        
        if(cnt == N){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import Data.Bits
import Data.List
import Data.Maybe (fromJust)
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

type Ans = Int

solve :: Int -> [Int] -> Ans
solve n as =  max case1 case2
  where
    pos = V.fromList $ sort $ filter (0 <=) as
    neg = V.fromList $ sort $ filter (0 >) as
    lpos = V.length pos
    lneg = V.length neg
    case1 = if (lneg `mod` 2) == 0 then (V.sum pos) - (V.sum neg)
      else (V.sum pos) - (V.sum $ V.take (lneg-1) neg) + (V.last neg)
    case2 = if (lneg `mod` 2) == 0 then (V.sum pos) - (V.sum neg)
      else if pos == (V.fromList []) then (V.head neg) - (V.sum $ V.tail neg)
        else (V.sum $ V.tail pos) - (V.head pos) - (V.sum $ neg)

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read.words <$> getLine
  print $ solve n as


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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
// vll x(n); x[i]=a;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;
typedef vector<vector<ll>> vvll;
// vvll x(m,vi(n)); x[i][j]=a;

#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll a, b, ans;
    cin >> a >> b;
    if(b==1) ans=0;
    else if((b-1)%(a-1) == 0) ans=(b-1)/(a-1);
    else ans = (b-1)/(a-1)+1;
    cout << ans << endl;
    return 0;
}


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


void solve(long long N, std::vector<long long> X){
    sort(X.begin(),X.end());
    long long ans = INT_MAX;
    for(int p=0;p<=100;++p)
    {
        long long result = 0;
        for(int i=0;i<N;++i)result += (X[i]-p)*(X[i]-p);
        ans = min(ans,result);
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void merge(lld brr[], lld arr[], lld l, lld m, lld r){
    lld i , j ,  k;
    lld n1 = m-l+1; 
    lld n2 = r - m;
    lld L1[n1], L2[n1];
    lld R1[n2], R2[n2];
    for (i = 0; i < n1; i++){
        L1[i] = arr[l + i];
        L2[i] = brr[l + i];
    }
    for (j = 0; j < n2; j++){
        R1[j] = arr[m+1+j];
        R2[j] = brr[m+1+j];
    }
    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L1[i] <= R1[j]){
            arr[k] = L1[i];
            brr[k] = L2[i];
            i++;
        }
        else{
            arr[k] = R1[j];
            brr[k] = R2[j];
            j++;
        }
        k++;
    }
        while (i   <   n1){
            arr[k] = L1[i];
            brr[k] = L2[i];
            i++;
            k++;
        }
        while (j   <   n2){
            arr[k] = R1[j];
            brr[k] = R2[j];
            j++;
            k++;
        }
}
void mergeSort(lld brr[], lld arr[], lld l, lld r){
    if (l < r)
    {
        lld m = l+(r-l)/2;
        mergeSort(brr, arr,l , m);
        mergeSort(brr,arr,m+1 ,r);
        merge(brr, arr, l, m , r);
    } 
}
int main ()
{
      FastIO
      lld n, i;
      cin >> n;
      lld A[n];
      lld B[n];
      foi(i, n)
      {
      	cin >> A[i];
      	B[i] = i+ 1;
      }
      	set<lld>seq;
      mergeSort(B, A, 0, n-1);
      lld count = 0;
      for(i = 0; i < n; i+=1)
      {
      	seq.insert (B[i]);
      	set <lld> :: iterator p = seq.begin();
      	if ((*p) == B[i])
      	{
      		count += 1;
      	}
      }
      cout << count <<  "\n";
      return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    bool flag = 1;
    for(int i=0; i<s.size(); i++)
    {
        if(i%2 == 1)
        {
            if((s[i]=='L' || s[i] =='U' || s[i] =='D'))
                continue;
            else
                flag = 0;
        }
        else
        {
            if((s[i]=='R' || s[i] =='U' || s[i] =='D'))
                continue;
            else
                flag = 0;
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))


int main()
{
	string s;
	cin >> s;
	int a[4];
	rep(i, 0, 3)a[i] = s[i] - '0';
	rep(i, 0, 7)
	{
		int res = a[0];
		char b[3] = { '-', '-', '-' };
		rep(j, 0, 2)
		{
			if ((i >> j) & 1 == 1)
			{
				b[j]= '+';
				res += a[j + 1];
			}
			else
			{
				res -= a[j + 1];
			}
		}
		if (res == 7)
		{
			s.insert(s.begin() + 1, b[0]);
			s.insert(s.begin() + 3, b[1]);
			s.insert(s.begin() + 5, b[2]);
			cout << s;
			cout << "=7" << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 256
from sys import stdin

input = stdin.readline
from itertools import accumulate


def solve():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    pa = [0] + list(accumulate(a))
    pb = [0] + list(accumulate(b))
    la = len(a)
    lb = len(b)
    left = 0
    right = la + lb

    def ok(cur):
        for i in range(max(0, cur - lb), min(cur,la) + 1):
            j = cur - i
            if pa[i] + pb[j] <= k:
                return True
        return False

    while left < right:

        mid = (left + right + 1) // 2
        if ok(mid):
            left = mid
        else:
            right = mid - 1
    print(left)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 134952
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}
vector<int> inv;
vector<int> cmp;
void init (int n) {
  inv.resize(n + 1, 0);
  cmp.resize(n + 1, 1);
  inv[1] = 1;
  cmp[1] = 0;
  for (int i = 2; i <= n; i++) {
    int q = md % i;
    int r = md / i;
    sub(inv[i], mul(inv[q], r));
    sub(cmp[i], inv[i]);
  }
}
int main() {
  int n, X;
  cin >> n >> X;
  init(n);
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end(), greater<int>());
  vector<int> dp(X + 1, 0);
  dp[X] = 1;
  for (int i = 0; i < n; i++) {
    for (int x = 0; x <= X; x++) {
      int d = dp[x];
      dp[x] = 0;
      add(dp[x % s[i]], mul(d, inv[n - i]));
      add(dp[x], mul(d, cmp[n - i]));
    }
  }
  int ret = 0;
  for (int x = 0; x <= X; x++) {
    add(ret, mul(x, dp[x]));
  }
  for (int i = 1; i <= n; i++) {
    ret = mul(ret, i);
  }
  cout << ret << '\n';
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

typedef pair<int,int> P;

vector<P> v; 

bool comp(const P& pfirst,const P& psecond){
    return pfirst.second<psecond.second;
}

int main(){
    int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        v.push_back(pair<int,int>(a,b));
    }
    sort(v.begin(),v.end(),comp);

    int cnt=0,t=1;

    for(int i=0;i<M;i++){
        if(t<=v[i].first){
            cnt++;
            t=v[i].second;
        }
        
    }
    cout<<cnt<<endl;


    
}

Measured memory_bytes: 1400