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

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        
        if (rx == ry) return false;
        if(r[rx] > r[ry]) swap(rx, ry);
        r[rx] += r[ry];
        r[ry] = rx;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

    bool same(int x, int y) {
        return root(x) == root(y); 
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind UF(N);
    int A, B;
    for(int i = 0; i < M; i++) {
        cin >> A >> B;
        A -= 1;
        B -= 1;
        UF.unite(A, B);
    }
    
    int ans = 0;
    for(int i = 0; i < N; i++) {
        //cout << i << ": " << UF.r[i] << endl;
        ans = max(UF.size(i), ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
const int MN=10000+2;
using namespace std;
typedef long long ll;
template<typename T>T IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	in*=f;return in;
}
ll n;
int a[MN],L=100,R=L-1;
void input(){
	IN(n);n++;
	int p=40;
	while(!((1ll<<p)&n))p--;p--;
	while(p>=0){
		a[++R]=++a[0];
		if((1ll<<p)&n)a[--L]=++a[0];
		p--;
	}
	n=a[0];printf("%lld\n",n*2);
	for(int i=1;i<=n;++i)a[i]=a[i+L-1];
	for(int i=n+1;i<=n*2;++i)a[i]=i-n;
	for(int i=1;i<=n*2;++i)printf("%d ",a[i]);
}
int main(){
	
	input();
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a[2005],f[3005],sum[3005];ll ans;
bool cmp(int a,int b){
	return a<b;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);
	if(n%2)printf("%d\n",(n/2+1)*(n/2));
	else printf("%d\n",n*n/4);
	return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    int x; cin >> x;

    int five = (x % 500) / 5 * 5;
    int sen = x / 500 * 1000;

    cout << five + sen << endl;
    return 0;
}

Measured memory_bytes: 3560
"use strict"

const input = require('fs').readFileSync('/dev/stdin','utf8');
var cards = input.trim().split('\n').slice(1);
var set = new Set();
for (var i in cards) {
	set.add(cards[i]);
}

['S', 'H', 'C', 'D'].forEach(
	function(suit) {
		for (var rank=1; rank<=13; rank++) {
			var card = suit + ' ' + rank;
			if (!set.has(card)) {
				console.log(card);
			}
		}
	}
);


Measured memory_bytes: 15392
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long

int main(){
  int a,b,c;
  cin >> a>> b>>c;
  cout <<  min(a+b,min(b+c,c+a)) <<endl;

  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        s: i64,
    }
    const W: i64 = 1_000_000_000;
    let x1 = W;
    let y1 = 1;
    let y2 = (s + W - 1) / W;
    let x2 = y2 * W - s;
    puts!("0 0 {} {} {} {}\n", x1, y1, x2, y2);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var A = input[0];
        var B = input[1];
        var K = input[2];

        var result = 0;
        var r = 0;
        for (var i = Math.Min(A, B); ; i--)
        {
            if (A % i == 0 && B % i == 0)
            {
                r++;
                if (K == r)
                {
                    result = i;
                    break;
                }
            }
        }
        Console.WriteLine(result);
    }
}


Measured memory_bytes: 28240
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    C = [II() for _ in range(n)]

    dp = [0] * (n + 1)
    dp[0] = 1
    color_index = defaultdict(int)
    for i, c in enumerate(C):
        if not color_index[c]:
            color_index[c] = i + 1
            dp[i + 1] = dp[i]
        else:
            if color_index[c] == i:
                dp[i + 1] = dp[i]
            else:
                dp[i + 1] = dp[i] + dp[color_index[c]]
                dp[i + 1] %= MOD
            color_index[c] = i + 1

    return dp[-1]


print(main())


Measured memory_bytes: 36880
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
const ll MAX=200000;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////


int main(){
    int n;
    int mx=0;
    cin>>n;
    vi a(n);
    
    rep(i,n){
        cin>>a[i];
        mx+=a[i]-1;

    }
    cout<<mx<<endl;
    return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

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



int main() {
    int n, m, Q;
    scanf("%d%d%d", &n, &m, &Q);
    int l, r;
    vector<vector<int>> ans(510, vector<int>(510));
    rp(i, 0, m) {
        scanf("%d%d", &l, &r);
        rp(j, r, n+1){
            ans.at(l).at(j)++;        
        }
    }
    int p, q;
    int res;
    rp(i, 0, Q){
        scanf("%d%d", &p, &q);
        res = 0;
        rp(j, p, q+1){
            res += ans.at(j).at(q);
        }
        printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long mpo(long long a, int n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n % 2) res = res * a % mod;
    a = a * a % mod;
    n /= 2;
  }
  return res;
}
int main () {
  const long long mod = 1e9 + 7;
  int N, K;
  cin >> N >> K;
  long long ans = (long long) K;
  long long dp[100010];
  dp[K] = 1;
  for (int i = K - 1; i >= 1; i --) {
    long long kj = (long long) K / i;
    long long al = mpo(kj, N, mod);
    //cout << al << endl;
    for (int j = 2; j <= kj; j ++) {
      al -= dp[i * j];
      if (al < 0) al += mod;
    }
    long long i_ = (long long) i;
    ans += al * i_;
    ans %= mod;
    dp[i] = al;
  }
  ans %= mod;
  cout << ans << endl;
}



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t n; cin>>n;
	vector<int64_t>a(5);
	for(auto&i:a)cin>>i;
	sort(a.begin(),a.end());
	int64_t ans=(n-1)/a.front()+5;
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n=input()
# lst=[int(n[i]) for i in range(len(n))]
# for i in range(len(n)):
#     lst.append(int(n[i]))
# n=int(n)

keta=len(n)
ans=0
# lst.reverse()

# dp=[[float('inf')]*2 for i in range(keta+1)]
dp=[[0,1]]
for i in range(keta):
    dp.append([float('inf')]*2)
# dp[0]=[0,1]
# print(dp)
for i in range(keta):
    s=int(n[-1-i])
    dp[i+1][0]=min(dp[i][0]+s,dp[i][1]+s+1)
    dp[i+1][1]=min(dp[i][0]+(10-s),dp[i][1]+(10-s-1))
# print(dp)
print(min(dp[-1][0],dp[-1][1]+1))

Measured memory_bytes: 187456
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (A, B, C) = Slice3<long>();
            WriteLine(Min(B / A, C));
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

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

typedef long long ll;

int main(){
	int m,k;
	scanf("%d%d",&m,&k);
	if(m == 0){
		if(k>0)puts("-1");
		else puts("0 0");
		return 0;
	}
	if(m == 1){
		if(k == 0)puts("0 0 1 1");
		else puts("-1");
		return 0;
	}
	m = 1<<m;
	if(k >= m){
		puts("-1");
		return 0;
	}
	vector<int> ret;
	for(int i = 0 ; i < m ; i ++){
		if(i != k)printf("%d ",i);
	}
	printf("%d ",k);
	for(int i = m-1 ; i >= 0 ; i --){
		if(i != k)printf("%d ",i);
	}
	printf("%d\n",k);
}

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

using namespace std;
typedef long long ll;

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

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

  ll ans = (1ll << 60);

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ll p = x[i] - x[j];
      ll q = y[i] - y[j];

      ll cnt = n;

      for (int k = 0; k < n; k++) {
        bool f = false;
        for (int l = 0; l < n; l++) {
          if (x[k] + p == x[l] && y[k] + q == y[l]) {
            f = true;
          }
        }
        if (f) {
          cnt -= 1;
        }
      }

      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
let () =
  let cross (x0,y0) (x1,y1) = x0*.y1-.x1*.y0 and
      inner (x0,y0) (x1,y1) = x0*.x1+.y0*.y1 and
      norm (x,y) = x*.x+.y*.y
  in
  let (px0,py0,px1,py1) = Scanf.scanf " %f %f %f %f\n" (fun w x y z -> (w,x,y,z)) and
      n = Scanf.scanf "%d\n" (fun x -> x) in
  let v0 = (px1-.px0, py1-.py0) in
  let rec read = function
      0 -> ()
    | i ->
       let (px2,py2) = Scanf.scanf " %f %f\n" (fun x y -> (x,y)) in
       let v1 = (px2-.px0, py2-.py0) in
       if cross v0 v1 > (1e-10) then print_endline "COUNTER_CLOCKWISE"
       else if cross v0 v1 < -.(1e-10) then print_endline "CLOCKWISE"
       else if inner v0 v1 < -.(1e-10) then print_endline "ONLINE_BACK"
       else if norm v0 < norm v1 then print_endline "ONLINE_FRONT"
       else print_endline "ON_SEGMENT";
       read (i-1)
  in read n
;;

Measured memory_bytes: 2764
// atcoder/abc165/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

const int N = 10;
lli x[N];
int n, m, q;
const int Q = 50;
int a[Q], b[Q], c[Q], d[Q];
lli rec(int nth, int prev = 1)
{
  if (nth == n) {
    lli sum = 0;
    for (int i = 0; i < q; ++i) {
      if (x[b[i]] - x[a[i]] == c[i]) sum += d[i];
    }
    return sum;
  }

  lli mx = -1;
  for (int i = prev; i <= m; ++i) {
    x[nth] = i;
    setmax(mx, rec(nth + 1, i));
  }
  return mx;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  while (cin >> n >> m >> q) {
    for (int i = 0; i < q; ++i) {
      cin >> a[i] >> b[i] >> c[i] >> d[i];
      --a[i];
      --b[i];
    }
    cout << rec(0) << endl;
  }

  return 0;
}


Measured memory_bytes: 3616
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll mod = 12345678910;
const int maxn = (int)1e5 + 5;
using namespace std;

int main()
{
	set<int> s;
	for(int i =1; i <= 3; i++){
		int x; cin >> x;
		s.insert(x);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    h,w,k=map(int,readline().split())
    grid=[readline().strip() for _ in range(h)]

    ans=float("inf")
    for i in range(1<<(h-1)):
        div=[(i>>j)&1 for j in range(h-1)]
        l=len([0 for i in range(h-1) if div[i]])+1
        cnt=[0]*l
        tmp=0
        for j in range(w):
            now=0
            flag=False
            for i_2 in range(h):
                if grid[i_2][j]=="1":
                    cnt[now]+=1
                    if cnt[now]>k:
                        flag=True
                        break
                if i_2<h-1 and div[i_2]==1: now+=1
            if flag:
                tmp+=1
                cnt=[0]*l
                now=0
                flag=False
                for i_2 in range(h):
                    if grid[i_2][j]=="1":
                        cnt[now]+=1
                        if cnt[now]>k:
                            flag=True
                            break
                    if i_2<h-1 and div[i_2]==1: now+=1
                if flag: break
        else:
            tmp+=l-1
            ans=min(ans,tmp)

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 45916
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin>>N;
    vector<int> a(4);
    int i=0;
    while(N>0){
        a[i]=N%10;
        i++;
        N=N/10;
    }
    if((a[0]==a[1]&&a[1]==a[2])||(a[1]==a[2]&&a[2]==a[3])){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int w,h;
pi ar[200005];
int main(){
  cin>>w>>h;
  REP(i,w){
    int a;
    scanf("%d",&a);
    ar[i]=mp(a,0);
  }
  REP(i,h){
    int a;
    scanf("%d",&a);
    ar[i+w]=mp(a,1);
  }
  sort(ar,ar+h+w);
  lint res=0;
  int cnt[2]={h+1,w+1};
  REP(i,h+w){
    res+=ar[i].fr*(lint)cnt[ar[i].sc];
    --cnt[ar[i].sc^1];
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 1792
/*
  Hey , lakshay 05
  while( ! ( succeed == try)); // Follow this
  Don't compare yourself with anyone in the world,if you do so it means you are insulting yourself -> Bill Gates
  
*/

#include <bits/stdc++.h>
#define ll long long
#define RUNFAST  ios_base::sync_with_stdio(false);    cin.tie(NULL);
#define vec  vector<ll>
#define pi vector<pair<ll,ll>>
#define fi first
#define se second
#define pb push_back
#define print1(a) cout<<a;
#define print2(a,b) cout<<a<<" "<<b;
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c;
#define sort(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define issorted(v) is_sorted(v.begin(),v.end()
#define eb emplace_back
#define mp make_pair
//#define MOD 1000000007 // 998244353
using namespace std;
 
ll visited[210000]={0}; 
vector<ll>vg[210000];

// Print vector

void printv(vector<ll> v)
{
   for(auto x:v)
   cout<<x<<" ";
}

// Important Functions 
ll n;
 vec v,v1;
// DFS
void dfs(ll current)
{
    ll i,y;
    if(visited[current])
    return;
    visited[current]=1;
    for(i=0;i<n;i++)
    {
        if(v[i]==v[current] or v1[i]==v1[current])
        {
            dfs(i);
        }
    }
}
 
// BFS

void bfs(ll current)
{
    ll x,y,i;
    queue<ll>q;
    q.push(current);
    visited[current]=1;
    while(!q.empty())
    {
        x=q.front();
   //     cout<<x<<" ";
        q.pop();
        visited[x]=1;
        for(i=0;i<vg[x].size();i++)
        {
            y=vg[x][i];
            if(visited[y]==0)
            {
                visited[y]=1;
                q.push(y);
            }
        }
    }
}


// Prime Numbers
void checkprime(ll N) {
        ll count = 0;
        for( ll i = 1;i * i <=N;++i ) {
             if( N % i == 0) {
                 if( i * i == N )
                         count++;
                 else       // i < sqrt(N) and (N / i) > sqrt(N)
                         count += 2;
              }
        }
        if(count == 2)
        {
           // prime number   
        }
}        

// IO File
void IO()
{
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
}

// Multiplicative Inverse

ll power(ll x, unsigned ll y, unsigned ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y / 2, m) % m; 
    p = (p * p) % m; 
  
    return (y % 2 == 0) ? p : (x * p) % m; 
} 

ll modInverse(ll a,ll m) 
{ 
     return power(a, m - 2, m); 
     
} 
  
// LCM

ll lcm(ll a,ll b)
{  return (a*b)/__gcd(a,b);  
}


/* ---------------------------------------------------------------------------------------------------------*/ 
 
 void lakshay()
 {
          ll i,z=0,maxi=0,c,d,y=0,x,l=0,A[1000],B[1000],a,b,s=0,j,m,p,q,k,r;
          bool ok=true;
          cin>>a>>b>>c>>d;
          
          while(b<=a)
          {
              b*=2;
              l++;
          }
          while(c<=b)
          {
              c*=2;
              l++;
          }
          if(l>d)
          cout<<"No";
          else
          cout<<"Yes";
         
    //print1(maxi);
 }
 
int main() 
{  RUNFAST
    ll num;
num=1;
//cin>>num;
while(num--)
{ 
lakshay();
cout<<"\n";
}
return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    vector<ll> X, so;
    cin >> N;
    X.resize(N);
    rep(i, N) cin >> X[i];
    so = vector<ll>(X.begin(), X.end());
    sort(so.begin(), so.end(), greater<>());
    rep(i, N) {
        if(X[i] >= so[(so.size() + 1) / 2 - 1]) cout << so[(so.size() + 1) / 2];
        else cout << so[(so.size() + 1) / 2 - 1];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,a[222222],ans=LLONG_MAX;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    a[i]+=a[i-1];
  }
  for(int i=1;i<n;i++) ans=min(ans,llabs(a[i]-(a[n]-a[i])));
  cout<<ans<<endl;
  return(0);
}


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

int main()
{
	int get ;
	while( cin >> get )
	{
		int sum = 1 ;
		for( int i = 1 ; i <= get ; i ++ )
		{
			sum += i ;
		}
		cout << (sum) << endl ;
	}
	return 0 ;
}

Measured memory_bytes: 1160
#include<stdio.h>

int search(int A[], int n, int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(){
  int i, n, A[10000 + 1], q, key, sum = 0;

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++) scanf("%d", &A[i]);

  scanf("%d", &q);
  for(i = 0 ; i < q ; i++){
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}


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

int main() {
	int score[4],a,b,total=0;
	
	for(int i=0;i<4;i++){
		cin>>score[i];
	}
	sort(score,score+4);
	
	for(int i=0;i<3;i++){
		total+=score[3-i];
	}
	cin>>a>>b;
	total+=max(a,b);
	cout<<total<<endl;
	
	return 0;
}

Measured memory_bytes: 3128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int A = sc.nextInt();
    		final int B = sc.nextInt();

    		System.out.println(Math.max(A - B*2, 0));

    	} finally {
    		sc.close();
    	}
    }
}



Measured memory_bytes: 24020
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

long long cnt;

void print(vector<int> &data){
	for (int i = 0; i < data.size(); ++i){
		cout << data[i];
		if (i == data.size() - 1) cout << endl;
		else cout << " ";
	}
}

vector<int> tmp;

void helper(vector<int> &data, int l, int m, int r){
	cnt += (r - l);

	for (int i = l; i < r; ++i) tmp[i] = data[i];

	int p1(l), p2(m);
	while (p1 < m && p2 < r) {
		if (tmp[p1] < tmp[p2]) data[l++] = tmp[p1++];
		else data[l++] = tmp[p2++];
	}

	while (p1 < m)	data[l++] = tmp[p1++];
	while (p2 < r)	data[l++] = tmp[p2++];
}

void mergeSort(vector<int> &data, int l, int r){
	if (l+1 < r){
		int m = l + (r - l) / 2;
		mergeSort(data, l, m);
		mergeSort(data, m, r);
		helper(data, l, m, r);
	}
}



int main(){
	int n; cin >> n;
	vector<int> data(n);
	for (int i = 0; i < n; ++i) cin >> data[i];

	tmp.resize(data.size());
	mergeSort(data, 0, data.size());
	print(data);
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 6708
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
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;}
int main(){
  double n,m,d;cin>>n>>m>>d ;
  double ans=0 ;
 if(d==0) ans=   double((m-1)/n) ; 
 else  ans= double(2*(n-d)*(m-1)/(n*n)) ;
   cout<<fixed<<setprecision(20) ;
   cout<<ans<<endl ;
   return 0;
  }

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 36

typedef struct{
    char c;
    int value;
}sort;


int main()
{
  int i,j,n,flag=0,minj;
  sort C1[N],C2[N],a;
  char emp;

  scanf("%d\n",&n);
  for(i=0;i<n;i++){
      scanf("%c%d%c",&C1[i].c, &C1[i].value,&emp);
      C2[i]=C1[i];
}


//bubble sort
    for(i=0;i<n;i++){
        for(j=n-1;j>i;j--){
             if(C1[j].value < C1[j-1].value){
               a=C1[j];
             C1[j] = C1[j-1];
            C1[j-1] =a;

            }
        }
    }
// bubble fin


//selection sort
    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++){
            if(C2[j].value <C2[minj].value ) minj=j;
        }
        if(minj != j){
                a=C2[i];
                C2[i]=C2[minj];
                C2[minj]=a;
        }
        }
  // selection fin


    for(j=0;j<n-1;j++){
        printf("%c%d ",C1[j].c,C1[j].value);
    }
    printf("%c%d\n",C1[n-1].c,C1[n-1].value);
    printf("Stable\n");

for(j=0;j<n-1;j++){
    printf("%c%d ",C2[j].c,C2[j].value );
    if(C1[j].c!=C2[j].c) flag=1;
}
printf("%c%d\n",C2[n-1].c,C2[n-1].value);
  if(C1[n-1].c!=C2[n-1].c) flag=1;

    if(flag==1) printf("Not stable\n");
    else printf("Stable\n");

    return 0;

}



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

const int M = 500, INF = 1e9;

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<vector<int>> dp(M, vector<int>(M, INF));
    dp[0][0] = 0;
    rep(_, N) {
        int a, b, c;
        cin >> a >> b >> c;
        for(int i = M - 1; i >= 0; --i) for(int j = M - 1; j >= 0; --j) {
            if(i + a >= M || j + b >= M) continue;
            chmin(dp[i + a][j + b], dp[i][j] + c);
        }
    }
    int ans = INF;
    rep(i, M) rep(j, M) {
        if(i && j && A * j == B * i) chmin(ans, dp[i][j]);
    }
    if(ans == INF) ans = -1;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4592
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

int pd(string s)
{
    int l=0,r=s.size()-1,f=0;
    for(;l<r;l++,r--)
        if(s[l]!=s[r]) {
            f=1;break;
        }
    if(f==0) return 1;
    return 0;
}
int main()
{
    string str;
    cin>>str;
    string a=str.substr(0,(str.size()-1)/2);
    string b=str.substr((str.size()+3)/2-1,str.size()-(str.size()+3)/2+1);
    if(pd(str)&&pd(a)&&pd(b)) printf("Yes");
    else printf("No");
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=998244353;

using mint = modint998244353;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

struct S{
	mint a,b,c;
	S(mint _a,mint _b,mint _c):a(_a),b(_b),c(_c){}
};

S op(S sa,S sb){
	return S(sa.a*sb.b+sb.a,sa.b*sb.b,sa.c*sb.b+sb.c);
}

S e(){
	return S(0,1,0);
}

S mapping(int a,S sa){
	if(a!=-1)sa.a=sa.c*a;
	return sa;
}

int comp(int a,int b){
	if(a==-1)return b;
	return a;
}

int id(){
	return -1;
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>m;
	vector<S> v1(n,S(1,10,1));
	lazy_segtree<S,op,e,int,mapping,comp,id> seg(v1);
	for(i=0;i<m;i++){
		cin>>a>>b>>c;
		a--;
		seg.apply(a,b,c);
		cout<<seg.all_prod().a.val()<<endl;
	}
}

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

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

using namespace std;

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

  string s="";
  while(n) {
    if(n%-2) {
      --n;
      s = "1"+s;
    } else {
      s = "0"+s;
    }
    n/=-2;
  }
  if(s == "")	s = "0";
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, a; char c; bool ok[4][13];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		cin >> c >> a;
		if(c == 'S') ok[0][a - 1] = true;
		if(c == 'H') ok[1][a - 1] = true;
		if(c == 'C') ok[2][a - 1] = true;
		if(c == 'D') ok[3][a - 1] = true;
	}
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 13; j++) {
			if(!ok[i][j]) {
				if(i == 0) printf("S %d\n", j + 1);
				if(i == 1) printf("H %d\n", j + 1);
				if(i == 2) printf("C %d\n", j + 1);
				if(i == 3) printf("D %d\n", j + 1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3172
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
    long answer = 0;
    long mod = 10;

    if(n % 2 == 0)//奇数なら0個
    {
      while(true)
      {
        answer += n/mod;

        if(mod*5 <= n) mod *= 5;
        else break;
      }
    }

		Console.WriteLine(answer);
	}
}

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a<=12) b/=2;
  if(a<=5) b=0;
  cout<<b<<endl;
}

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

int w, h, a[21][21];
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};

int INF = numeric_limits<int>::max();

int dfs(int y, int x, int cnt) {
    if(cnt == 10) return INF;
    int ret = INF;
    rep(i, 4) {
        int ny = y+dy[i];
        int nx = x+dx[i];
        if(ny<0 || ny>=h || nx<0 || nx>=w ||
           a[ny][nx] == 1) continue;
        while(ny>=0 && ny<h && nx>=0 && nx<w) {
            if(a[ny][nx] == 3) {
                ret = min(ret, cnt+1);
                break;
            }
            if(a[ny][nx] == 1) {
                a[ny][nx] = 0;
                ret = min(ret, dfs(ny-dy[i], nx-dx[i], cnt+1));
                a[ny][nx] = 1;
                break;
            }
            ny += dy[i];
            nx += dx[i];
        }
    }
    return ret;
}

int main(void){
    while(cin >> w >> h && w && h) {
        rep(i, h) rep(j, w) cin >> a[i][j];
        rep(i, h) rep(j, w) if(a[i][j]==2) {
            int ans = dfs(i, j, 0);
            if(ans==INF) cout << -1 << endl;
            else cout << ans << endl;
        }
    }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cout << fixed << setprecision(15);

  ll N;
  cin >> N;

  ll ans = 0;

  for (ll i = 3; i <= N; i += 2) {
    std::vector<pair<ll, ll>> primes;

    // 2 ~ √n の数で割ってみる
    ll n = i;
    for (ll j = 2; j * j <= i; j++) {
      if (n % j == 0) {
        // 割り切れるなら素因数
        ll count = 0;

        while (n % j == 0) {
          count++;
          // 割り切れなくなるまで割る
          n /= j;
        }
        primes.push_back(make_pair(j, count));
      }
    }

    // nがもともと素数だった場合、
    // または試し割りをした結果、素数だった場合
    if (n != 1) {
      primes.push_back(make_pair(n, 1));
    }

    ll result = 1;
    for (auto p : primes) {
      result *= p.second + 1;
    }

    if (result == 8) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
wa_check=[0 for _ in range(n+1)]
ac_check=[0 for _ in range(n+1)]
for i in range(m):
    p,s=input().split()
    p=int(p)
    if(ac_check[p]==0):
        if(s=='AC'):
            ac_check[p]=1
        else:
            wa_check[p]+=1
wa_ans=[wa_check[i] for i in range(n+1) if ac_check[i]!=0]
print(sum(ac_check),sum(wa_ans))


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

int main(){
    ll n,x,m;
    cin >> n >> x >> m;
    vector<bool> check(m+1,false);
    vector<ll> a;
    ll rs;
    check[x] = true;
    a.push_back(x);

    while(1){
        ll f = (x*x) %m;
        if(check[f] == true){
            rep(i,a.size()){
                if(a[i] == f)rs = i;
            } 
            break;
        }
        else{
            check[f] = true;
        }
        x = f;
        a.push_back(x);

    }
    ll roop = a.size() - rs;
    ll ans = 0;
    vector<ll>asum(a.size());

    rep(i,a.size()){
        if(i == 0)asum[i] = a[i];
        else asum[i] = asum[i-1]+a[i];
    }

    if(n < rs ){
        ans = asum[n];
    }
    else {
        ans = asum[rs] - a[rs];
        n = n-rs;
        ans += (n/roop)*(asum[asum.size()-1]-(asum[rs]-a[rs])) + ((asum[n%roop+rs]-a[n%roop+rs]) -(asum[rs]-a[rs]));
    }

    cout << ans << endl; 

    return 0;
}

Measured memory_bytes: 3980
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int a[maxn];
map<ll, ll> sum, cnt;

ll lowbit(ll x) {return x & (-x);}

void update(ll pos, ll val) {
    while (pos <= 1000000000LL) {
        sum[pos] += val;
        cnt[pos] += 1;
        pos += lowbit(pos);
    }
}

ll query_sum(ll pos) {
    ll res = 0;
    while (pos > 0) {
        res += sum[pos];
        pos -= lowbit(pos);
    }
    return res;
}

ll query_cnt(ll pos) {
    ll res = 0;
    while (pos > 0) {
        res += cnt[pos];
        pos -= lowbit(pos);
    }
    return res;
}

ll suffix[maxn];
ll suffix_cnt[maxn], suffix_sum[maxn];
int pre[maxn];

unordered_map<ll, int> pos;
ll ans[maxn];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = n; i >= 1; i--) {
        suffix[i] = suffix[i + 1] + a[i];
    }
    for (int i = n; i >= 1; i--) {
        suffix_cnt[i] = (n - i + 1) - query_cnt(a[i] - 1);
        suffix_sum[i] = suffix[i] - query_sum(a[i] - 1) - 1LL * a[i] * suffix_cnt[i];
        update(a[i], a[i]);
    }
    set<ll> se;
    set<ll>::iterator iter;
    for (int i = 1; i <= n; i++) {
        iter = se.upper_bound(-a[i]);
        if (iter != se.end()) pre[i] = pos[-(*iter)];
        if (!pos.count(a[i])) pos[a[i]] = i;
        se.insert(-a[i]);
    }
    ll maxvalue = 0, maxpos = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > maxvalue) {
            maxvalue = a[i];
            maxpos = i;
        }
    }
    suffix_sum[0] = suffix[1];
    while (maxpos) {
        int last = pre[maxpos];
        ans[maxpos] += suffix_sum[last] - suffix_sum[maxpos];
        maxpos = last;
    }
    for (int i = 1; i <= n; i++) {
        printf("%lld\n", ans[i]);
    }

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

//DONT WASTE YOUR TIME
//prove yourself
//remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it
const ll N= 1e6+55,mod = 1e9+7;
ll ans=-1,n;
ll gg[3][N];
void dfs(ll i, ll j,ll c){
	if(i>2 || i<1 || j>n || j<1)return;
	c+=gg[i][j];
	if(i==2 && j==n){
		ans=max(ans,c);
		return;
	}
	dfs(i+1,j,c);
	dfs(i,j+1,c);
}
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll i,j,k,a,b,c,d,x,y,z;
	sc(n);
	for(i=1;i<=2;i++)for(j=1;j<=n;j++)sc(gg[i][j]);
	dfs(1,1,0);
	pr(ans);
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
 
int main(){
    int  n,k;
    cin >> n >> k;
    int num = 1;
    for(int i=0;i<n;i++){
        if(num*2 < num+k){
            num = num*2;
        }
        else if(num*2 > num+k){
            num = num+k;
        }
        else num = num*2;
    }
    cout << num << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define pb push_back


///Input/Output macros!
#define gi(x) scanf("%d", &x)
#define gi2(x, y) scanf("%d%d", &x, &y)
#define gi3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define gill(x) scanf("%lld", &x)
#define gill2(x, y) scanf("%lld%lld", &x, &y)
#define gill3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define pi(x) printf("%d\n", x)
#define pill(x) printf("%lld\n", x)


///Basic Debugging macros!
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(ll __i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(ll __i__=0;__i__<r;__i__++){for(ll __j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}

using namespace std;

///Power of 2 till 2^31!
ll pow2[32] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648};

///Power function!
ll power(ll x,ll y)
{
        ll res = 1;
        while(y>0){
            if(y&1)
                res *= x;
            y>>=1;
            x*=x;
        }
        return res;
}

///Basic Sieve of Eratosthenes!
void Sieve(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool isPerfectSquare(ll x){ ll s = sqrt(x); return (s*s == x);}

bool isFibonacci(int n){return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4);}

bool isPrime(int n){if (n <= 1)return false;if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0)return false;
    return true;
}

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;


const int MOD = 1000000007;
const long double PI = 4*atan((long double)1);
const ll INF = 1e18;


bool vis[10000];

int main()
{
    int n;
    scanf("%d",&n);//cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++){
        int val;scanf("%d",&val);
        a.push_back(val);
    }
    sort(a.begin(),a.end());
    //for(auto it:a)cout<<it<<' ';
    //cout<<'\n';
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int val = -1;
            for(int k=n-1;k>j;k--){
                if(a[k]<(a[i]+a[j])){
                    val = k;
                    break;
                }
            }
            //cout<<n-val<<' ';
            if(val!=-1){
                ans+=(val-j);
            }
        }
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 256