akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> H(N);
    for(ll i = 0; i < N; i++){
        cin >> H[i];
    }
    sort(H.begin(),H.end());
    ll count = 0;
    for(int i = 0; i < N - K; i++){
        count += H[i];
    }
    cout << count << endl;

}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>

using namespace std;

const int mod = 1'000'000'007;

int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

const int N = 2'009;

int c[N][N];

int calc(int n, int m) {
  return c[n + m - 1][n];
}

int main() {
  memset(c, 0, sizeof c);
  for (int i = 0; i < N; ++i) {
    c[i][0] = 1;
    c[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  }
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    if (i - 1 > n - m) {
      puts("0");
      continue;
    }
    printf("%d\n", mul(calc(m - i, i), calc(n - m - (i - 1), (i - 1) + 2)));
  }
}


Measured memory_bytes: 15872
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

vector<pair<int,int> > lst[15];
vector<pair<pair<int,int>, pair<int,int> > > tq;
int n, m, q;
int val[15];
int ubah[15];
int ans = 0;

void solve(int idx, int mn) {
	if(idx == n) {
		int res = 0;
		for(int i = 0;i < q;i++) {
			int a = tq[i].F.F;
			int b = tq[i].F.S;
			int c = tq[i].S.F;
			int d = tq[i].S.S;
			if(val[b] - val[a] == c) res += d;
		}
//		for(int i = 0;i < n;i++) cout<<val[i]<<" ";
//		cout<<res<<endl;
		ans = max(ans, res);
		return ;
	}
	for(int i = mn;i <= m;i++) {
		val[idx] = i;
		solve(idx + 1, i);
	}
}

void hora(int tc) {
	cin>>n>>m>>q;
	for(int i = 0;i < q;i++) {
		int a, b, c, d;
		cin>>a>>b>>c>>d;
		a--, b--;
		lst[a].pb({b, c});
		tq.pb({{a, b}, {c, d}});
	}
	val[0] = 1;
	solve(1, 1);
	cout<<ans<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}

Measured memory_bytes: 3660
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

//Union-Find木
struct UnionFind{
  //メンバ変数 
  vector<long long>par; //par[i]:=頂点iの親
  vector<long long>s; //s[i]:=頂点iが属する集合の個数(iが根のとき)
  
  //コンストラクタ
  UnionFind(long long N):par(N),s(N){
    for(long long i=0;i<N;i++){
      par[i]=i; //最初はすべてが根として初期化
      s[i]=1;
    }
  }
  //メンバ関数
  //root(i):=頂点iの根
  long long root(long long i){
    if(par[i]==i) return i;
    par[i]=root(par[i]); //経路圧縮
    return root(par[i]); //再帰
  }
  //size[i]:=iが属する集合の個数
  long long size(long long i){
    return s[root(i)];
  }
  //same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか)
  bool same(long long x, long long y){
    return root(x)==root(y);
  }
  //unite(x,y) xの根をyの根に繋げる(集合を合併)
  void unite(long long x, long long y){
    if(!same(x,y)){
      long long rx=root(x);
      long long ry=root(y);
      par[rx]=par[ry];
      s[ry]=s[rx]+s[ry];
    }
  }
};

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////


//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  

  lin(N); lin(D);
  ll res = 0;
  rep(i, N){
    lin(x);lin(y);
    if(x*x + y*y <= D*D) res++;
  }

  cout << res << endl;
}

Measured memory_bytes: 3628
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n;
	cin >> n;
	cout << n / 3 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << 0; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

int ask(int val, vector <int> & a) {
    int ans = 0;
    loop(i, a.size()) {
        int l = -1, r = a.size();
        while (r - l > 1) {
            int m = l + r >> 1;
            if (a[i] + a[m] >= val)
                l = m;
            else
                r = m;
        }
        ans += l + 1;
    }
    return ans;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector <int> a(n), p(n + 1);
    loop(i, n)
        cin >> a[i];
    sort(all(a), greater<int>());
    loop1(i, n)
        p[i] = p[i - 1] + a[i - 1];
    int l = 0, r = 200007;
    while (r - l > 1) {
        int m = l + r >> 1;
        if (ask(m, a) >= q)
            l = m;
        else
            r = m;
    }
    int ans = 0, calc = 0;
    loop(i, a.size()) {
        int lef = -1, rig = a.size();
        while (rig - lef > 1) {
            int m = lef + rig >> 1;
            if (a[i] + a[m] >= r)
                lef = m;
            else
                rig = m;
        }
        calc += lef + 1;
        ans += p[lef + 1] + (lef + 1) * a[i];
    }
    ans += (q - calc) * l;
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


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

int main()
{
    int n, l, s = 0, m = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> l;
        m = max(m, l);
        s += l;
    }
    cout << ((m*2 < s) ? "Yes" : "No");
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

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



Measured memory_bytes: 1024
package main
 
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main(){
    
    N := nextInt()
    K := nextInt()
    ans := K
    for i := 1; i < N; i++ {
        ans *= K-1
    }
    fmt.Println(ans)
}

/* templates */


func Max(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r < a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Min(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r > a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Sum(a []int) (r int) {
    for i := range a {
        r += a[i]
    }
    return r
}
 
func Abs(a float64) float64 {
    if a < 0 {
        return -a
    }
    return a
}
 
type Pair struct {
    first, second int
}
 
type Pairs []Pair
  
func (p Pairs) Swap(i, j int) {
    p[i], p[j] = p[j], p[i]
}
 
var nextReader func() string
 
func init() {
    nextReader = NewScanner()
}
 
func NewScanner() func() string {
    r := bufio.NewScanner(os.Stdin)
    r.Buffer(make([]byte, 1024), int(1e+11))
    r.Split(bufio.ScanWords)
    return func() string {
        r.Scan()
        return r.Text()
    }
}

func nextString() string {
    return nextReader()
}
 
func nextInt64() int64 {
    v, _ := strconv.ParseInt(nextReader(), 10, 64)
    return v
}
 
func nextInt() int {
    v, _ := strconv.Atoi(nextReader())
    return v
}
 
func nextInts(n int) []int {
    r := make([]int, n)
    for i := 0; i < n; i++ {
        r[i] = nextInt()
    }
    return r
}

func nextStrings(n int) []string {
    r := make([]string, n)
    for i := 0; i < n; i++ {
        r[i] = nextString()
    }
    return r
}

func nextFloat64() float64 {
    f, _ := strconv.ParseFloat(nextReader(), 64)
    return f
}


Measured memory_bytes: 640
I = input().split()
K = int(I[0])
N = int(I[1])

I = input().split()

A = [ int(I[0]) ]
L = [ A[0] ]
for i in range(1,N):
  A.append( int(I[i]) )
  L.append( A[i] - A[i-1] )

L[0] = A[0]+(K-A[N-1])

L.sort()
print(K - L[N-1])
  


Measured memory_bytes: 29584
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int N,M,Q;
    cin >> N >> M >> Q;
    vector<int> l(M);
    vector<int> r(M);
    vector<int> p(Q);
    vector<int> q(Q);
    rep(i,M) cin >> l[i] >> r[i];
    rep(i,Q) cin >> p[i] >> q[i];

    vector<vector<int>> a(N,vector<int>(N));
    rep(i,N) rep(j,N) a[i][j] = 0;

    rep(i,M)
    {
        int li = l[i];
        int ri = r[i];
        rep2(j,ri-1,N)
            a[li-1][j]++;
    }

    rep(i,Q)
    {
        int cnt = 0;
        int pi = p[i];
        int qi = q[i];
        rep2(j,pi-1,qi)
            cnt += a[j][qi-1];
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 4224
import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N, M, Q = LI()
numlist = [LI() for _ in range(Q)]
part = 0
sum = 0
maxAs = 0
hist = []
stack = collections.deque()
stack.append([1,-1])	#sumleft, histpos
while True:
	now = stack.pop()
	sumleft = now[0]
	histpos = now[1]
	hist.append(sumleft)
	histpos+=1
	if histpos == N:
		# 計算してもとに戻る
		val = 0
		for l in numlist:
			if hist[l[1]-1]-hist[l[0]-1] == l[2]:
				val+=l[3]
		if val > maxAs:
			maxAs = val
		if not stack:
			break
		next = stack[len(stack)-1]
		hist = hist[0:next[1]+1]
		continue
	for i in range(0,M+1-sumleft):
		stack.append([sumleft+i, histpos])
print(maxAs)


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

int main()
{
    int N, M, C;
    cin >> N >> M >> C;
    int B[21];
    for (int i = 0; i < M; i++) cin >> B[i];
    int A[21][21];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    int cnt = 0;

    for (int i = 0; i < N; i++) {
        int sum = 0;
        for (int j = 0; j < M; j++) {
            sum += A[i][j] * B[j];
        }
        sum += C;
        if (sum > 0) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
s = map(ord, raw_input())
k = int(raw_input())

for i in xrange(len(s)):
    if s[i] == 97:
        continue
    n = 123 - s[i]
    if n <= k:
        s[i] = 97
        k -= n

k %= 26
s[-1] += k

print ''.join(map(chr, s))

Measured memory_bytes: 4228
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
const int mod = 1e9+7;
const int maxn = 1e2+5;
const double EPS = 1e-6;
using namespace std;
int a[maxn];
int n;
ll ans;
map<ll,int> mp;
void dfs(ll pre,ll sum,int d){
	if(d==n){
		//de(sum);
		if(!mp[sum]&&pre%2==0){
			mp[sum]=1;
			ans++;
		}
		return;
	}
	dfs(pre*a[d],sum*10+a[d],d+1);
	dfs(pre*(a[d]-1),sum*10+a[d]+1,d+1);
	dfs(pre*(a[d]+1),sum*10+a[d]-1,d+1);
}
int main()
{
	cin>>n;
	rep(i,0,n) scanf("%d",&a[i]);
	ans=0;
	dfs(1,0,0);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3968
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
koma_pos = [0]

distance = [0] * (m - 1) 
for i in range(m - 1):
    tmp = x[i + 1] - x[i]
    distance[i] = [tmp, i + 1]

distance.sort(reverse=True)

res = 0
for i in range(min(n - 1, len(distance))):
    tmp, index = distance[i]
    koma_pos.append(index)

koma_pos.sort()
koma_pos.append(m)
for i in range(min(n, len(koma_pos) - 1)):
    l = koma_pos[i]
    r = koma_pos[i + 1]
    res += x[r - 1] - x[l]

print(res)
# print(koma_pos)
# print(distance)
# print(x)

Measured memory_bytes: 25788
Ball = {'A': 1, 'B': 0, 'C': 0}
while 1:
    try:
        a, b = raw_input().split(',')
    except EOFError:
        break
    Ball[a], Ball[b] = Ball[b], Ball[a]
for b in Ball:
    if Ball[b] == 1:
        print b

Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

template <ll Mod>
struct modint {
  ll n;

  modint(const ll x = 0) : n(x % Mod) {}
  modint operator+(const modint r) const { return modint(*this) += r; }
  modint operator-(const modint r) const { return modint(*this) -= r; }
  modint operator*(const modint r) const { return modint(*this) *= r; }
  modint operator/(const modint r) const { return modint(*this) /= r; }
  modint &operator+=(const modint r) {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  modint &operator-=(const modint r) {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  modint &operator*=(const modint r) {
    n = n * r.n % Mod;
    return *this;
  }
  modint &operator/=(const modint r) { return *this *= r.inv(); }
  modint pow(ll x) const {
    modint<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  modint inv() const { return pow(Mod-2); }
  friend ostream& operator<<(ostream& os, const modint& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, modint& obj) { return is >> obj.n; }
};
constexpr ll mod = 1000000007;
using mint = modint<mod>;

// T modint
template<class T>
struct Combination {
  vector<T> fact, inv_fact;
  Combination(ll n) : fact(n+1), inv_fact(n+1) {
    fact[0] = T(1);
    for (ll i = 1; i <= n; i++) fact[i] = fact[i-1] * static_cast<T>(i);
    inv_fact[n] = fact[n].inv();
    for (ll i = n; i > 0; i--) inv_fact[i-1] = inv_fact[i] * static_cast<T>(i);
  }

  T P(ll n, ll k) const {
    return fact[n] * inv_fact[n-k];
  }

  T C(ll n, ll k) const {
    if(n<k||k<0) return T(0);
    return fact[n] * inv_fact[n-k] * inv_fact[k];
  }

  T H(ll n, ll k) const {
    return C(n+k-1, n-1);
  }
};

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

  ll n, k;
  cin >> n >> k;
  vector<ll> b(n);
  rep(i, n) {
    cin >> b[i];
  }
  sort(all(b));
  vector<mint> a(n);
  rep(i, n) {
    if (b[i] < 0) {
      b[i] += mod;
    }
    a[i] = mint(b[i]);
  }

  mint ans = 0;
  mint ma = 0;
  mint mi = 0;
  Combination<mint> comb(2*n);
  rep(i, n) {
    ll l = i;
    ma += a[i] * comb.C(l, k-1);
  }
  rep(i, n) {
    ll r = n-1-i;
    mi += a[i] * comb.C(r, k-1);
  }
  cerr << ma << " " << mi << endl;
  ans = ma-mi;
  cout << ans << endl;
}


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

ll c[51][51]={{0,0}};
void make_conb(){
    for (int i=0; i<51; i++){
        for (int j=0; j<i+1; j++){
            if (j==0||j==i){
                c[i][j]=1;
            }else {
                c[i][j]=c[i-1][j-1]+c[i-1][j];
            }
        }
    }
}

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    ll v[n];
    for (int i=0; i<n; i++){
        cin >> v[i];
    }
    sort(v,v+n);
    reverse(v,v+n);
    make_conb();
    double sum=0;
    for (int i=0; i<a; i++){
        sum+=v[i];
    }
    cout.precision(8);
    cout << sum/a << endl;
    if (v[a-1]==v[0]){
        int k=0;
        for (int i=0; i<n; i++){
            if (v[i]==v[0]){
                k++;
            }
        }
        ll count=0;
        for (int i=a; i<=b; i++){
            count+=c[k][i];
        }
        cout << count << endl;
    }else {
        int k=0;
        int l=0;
        for (int i=0; i<n; i++){
            if (v[i]==v[a-1]){
                k++;
            }
            if (v[i]>v[a-1]){
                l++;
            }
        }
        cout << c[k][a-l] << endl;
    }
}       


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  string str;
  cin >> str;
  for(int i=0;i<str.length();i++){
    for(int j=i+1;j<str.length();j++){
      if(str[i]==str[j]){
        cout << "no" <<endl;
        return 0;
      }
    }
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int cnt[3];
vector <int> vec[SIZE];
bool use[SIZE][2];

void solve(int v)
{
	queue <P> que;
	que.push(P(v,0));
	use[v][0]=true;
	int nm=0;
	while(!que.empty())
	{
		P p=que.front();que.pop();
		nm++;
		int s=p.first,t=p.second;
		for(int i=0;i<vec[s].size();i++)
		{
			int to=vec[s][i];
			if(!use[to][1-t])
			{
				use[to][1-t]=true;
				que.push(P(to,1-t));
			}
		}
	}
	if(nm==1) cnt[0]++;
	else if(use[v][1]) cnt[1]++;
	else cnt[2]++;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		a--,b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	for(int i=0;i<n;i++)
	{
		if(!use[i][0]&&!use[i][1])
		{
			solve(i);
		}
	}
	int zan=n;
	ll ret=0;
	while(cnt[0]>0)
	{
		ret+=2*zan-1;
		cnt[0]--;
		zan--;
	}
	ret+=(ll) cnt[1]*(ll) cnt[1];
	ret+=(ll) cnt[1]*(ll) cnt[2]*2LL;
	ret+=(ll) cnt[2]*(ll) cnt[2]*2LL;
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 7680
import java.util.*;

public class Main{
    public static void main(String args[]){
      
      
      Scanner scn = new Scanner(System.in);
      int s = scn.nextInt();
      int w = scn.nextInt();
      
      if(s<=w){System.out.print("unsafe");
              }else{
      System.out.print("safe");}

    }
}

Measured memory_bytes: 35756
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int n;
  cin>>n;
  bool exists=false;
  vector<int>dice1(n),dice2(n);
  for(int i=0;i<n;i++){
    cin>>dice1[i]>>dice2[i];
    if(i>1){
      if((dice1[i]==dice2[i]&&dice1[i-1]==dice2[i-1]&&dice1[i-2]==dice2[i-2])){
        exists=true;
      }
    }
  }
  if(exists){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int X, A, B;
  cin >> X >> A >> B;

  if(B-A > X){
    cout << "dangerous" << endl;
  }else if(B-A > 0){
    cout << "safe" << endl;
  }else{
    cout << "delicious" << endl;
  }

  return 0;
}


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

int main(){
    long long N;
    cin >> N;
    cout << N*(N-1)/2;
}


Measured memory_bytes: 256
#include <cstdio>
#define MAXN 15
#define MAXT 100

const int inf=0x3f3f3f3f;

int n,m,d[MAXN][MAXN],f[MAXT+5][MAXT+5];

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d", &d[i][j]);
        }
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            int mx=0;
            for(int ii=1;ii<=n;ii++){
                for(int jj=1;jj<=m;jj++){
                    if(mx<d[ii][jj]-ii*i-jj*j)
                        mx=d[ii][jj]-ii*i-jj*j;
                }
            }
            f[i][j]=mx;
        }
    }
    int psb=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int mn=inf;
            for(int ii=0;ii<=100;ii++){
                for(int jj=0;jj<=100;jj++){
                    if(mn>f[ii][jj]+ii*i+jj*j)
                        mn=f[ii][jj]+ii*i+jj*j;
                }
            }
            if(d[i][j]!=mn){
                psb=0;
                break;
            }
        }
        if(!psb){
            break;
        }
    }
    if(!psb){
        printf("Impossible\n");
    }
    else{
        printf("Possible\n");
        printf("202 10401\n");
        for(int i=1;i<=100;i++){
            printf("%d %d X\n",i,i+1);
        }
        for(int j=1;j<=100;j++){
            printf("%d %d Y\n",j+101,j+102);
        }
        for(int i=0;i<=100;i++){
            for(int j=0;j<=100;j++){
                printf("%d %d %d\n",i+1,202-j,f[i][j]);
            }
        }
        printf("1 202\n");
    }
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int

using namespace std;

inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int main(){

	vector<int> a(3);
	for (int i = 0; i < 3; i++)
		a[i] = nxt();
	sort(all(a));
	if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0){
		puts("0");
	} else {
		cout << 1ll * a[0] * a[1] << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int n, k, ans = 1;
	cin >> n >> k;
	lp(n)ans = min(ans * 2, ans + k);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    vector<int> v(3);
    for(int i = 0 ; i < 3; i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    cout << v[0] + v[1];
    
    cout << endl;
}


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

#define mp make_pair
#define pb push_back

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
 
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
 
const int MOD = 1000000007;
double PI = 4*atan(1);

ll dp[5001][5001];


ll po(ll a, ll po) {
	ll p = a, ans = 1;
	while (po) {
		if (po & 1) ans = ans*p % MOD;
		p = p*p % MOD;
		po >>= 1;
	}
	return ans;
}

ll inv(ll a) {
	return po(a,MOD-2);
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N; string s; cin >> N >> s;
	dp[0][0] = 1;
	F0R(i,5000) F0R(j,i+1) {
		dp[i+1][j+1] += 2*dp[i][j];
		dp[i+1][j+1] %= MOD;
		dp[i+1][max(j-1,0)] += dp[i][j];
		dp[i+1][max(j-1,0)] %= MOD;
	}
	cout << (dp[N][s.length()]*inv(po(2,s.length())) % MOD);
}

Measured memory_bytes: 116992
/*
    NO 
        TIME 
            TO 
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define OS //single input use oeis
lli INF=1e17;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,z,k,x,m;
const double pi=3.14159265358979323846;
lli add(lli a, lli b) {
 	lli res = a + b;
 
 	while (res >= mod) res -= mod;
 
 	while (res < 0) res += mod;
 
 	return res;
}
 lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
// Thi
//matrix exponentiation is associative and distributive
// lli dp[2][2000005][2];
int lis(vector<lli> a)
{
    set < int > s;
set < int > :: iterator it;

n=a.size();

for(int i=0;i<n;i++)
{
    s.insert(a[i]);
    
    it = s.upper_bound(a[i]);

    if(it != s.end())
        s.erase(it);
}

return s.size();
}
int main()
{
 IO;
 OS;
 lli a,b,c;
 lli flag=0;
 cin>>a>>b>>c;
 if(a==b)
 {
     if(b!=c)
     flag=1;
 }
 else if(a==c)
 {
     if(c!=b)
     flag=1;
 }
 else if(b==c)
 {
     if(a!=b)
     flag=1;
 }
 if(flag)
 cout<<"Yes";
 else
 cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll k, x;
    cin >>k >>x;
    
    for(int i = x -(k-1); i <= x +(k-1); i++) {
        cout <<i << endl;
    }
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,y;
    cin>>n>>y;
    y/=1000;
    int a=-1,b=-1,c=-1;    //a 1000 b 5000 c 10000
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            if(i+5*j+(n-i-j)*10==y){
                a=i;
                b=j;
                c=n-i-j;
            }
        }
    }
    cout<<c<<' '<<b<<' '<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
    int ans = 1, H, W;
    char[][] maze;
    int[] dr = new int[]{1,0,-1,0}, dc = new int[]{0,1,0,-1};
    static public void main(String[] args) throws Exception{
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ")
        Main main = new Main();
        int res = main.solve();
        System.out.println(res);
    }
    int solve(){
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt(); W = sc.nextInt();
        maze = new char[H][W];
        for(int i=0;i<H;i++){
            String s = sc.next();
            for(int j=0;j<W;j++) maze[i][j] = s.charAt(j);
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(maze[i][j]=='#') continue;
                ans = Math.max(ans,startFrom(i,j));
            }
        }
        return ans;
    }
    int startFrom(int sR, int sC){
        int step = 0;
        Queue<int[]> current = new LinkedList<>(), next = new LinkedList<>();
        current.add(new int[]{sR,sC});
        boolean[][] visited = new boolean[H][W];
        visited[sR][sC] = true;
        while(current.size()>0){
            for(int[] now:current) {
                int curR = now[0], curC = now[1];
                for (int j = 0; j < 4; j++) {
                    int r = curR + dr[j], c = curC + dc[j];
                    if (r >= 0 && r < H && c >= 0 && c < W && (!visited[r][c]) && maze[r][c]=='.') {
                        visited[r][c] = true;
                        next.add(new int[]{r, c});
                    }
                }
            }
            if(next.size()>0){
                step += 1;
            }
            current = next;
            next = new LinkedList<>();
        }
        return step;
    }
}



Measured memory_bytes: 29356
#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 SQ(x)           ((x)*(x))
#define LCM(x,y)        (((x)/gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             printf("Ripon\n")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int kx[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
int ky[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<'\n';}
//------------useless stuff--------------//
#define TC 0
#define mod 10000007
#define N 1000000
int n,m;
string str;
vector<int> v;


void solve(int T) {
    int n,x,k,y;
    ll sum = 0;
    cin>>n>>k>>x>>y;
    rep(i,1,n){
        sum+= (i<=k)?x:y;
    }
    cout<<sum<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}



Measured memory_bytes: 256
#include <iostream> 
#include <sstream> // istringstream
#include <string> // 文字列
#include <algorithm> // アルゴリズム
#include <cmath> // 
#include <vector> // vector
#include <set> // set
#include <map> // map

using namespace std;

int main()
{   
    // input sample
    int N, X, T;
    cin >> N >> X >> T;
    // int A[N];
    // for (int i = 0; i < N; ++i) cin >> A[i]; 
    // string s = "";

    // output sample
    if (N % X == 0) {
        cout << (N/X) * T << endl;
    } else {
        cout << (N/X + 1) * T << endl;
    }

    return 0;
}

Measured memory_bytes: 3664
package main

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

func main() {
	n := getInt()
	ss := getIntSlice(n)

	sumAll := sum(ss...)

	notDivisible10 := make([]int, 0, 100)
	for _, s := range ss {
		if s%10 != 0 {
			notDivisible10 = append(notDivisible10, s)
		}
	}
	sort.Ints(notDivisible10)

	if sumAll%10 != 0 {
		fmt.Println(sumAll)
	} else {
		if len(notDivisible10) == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(sumAll - notDivisible10[0])
		}
	}
}

func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1000000007;
ll mod(ll x){
        return ((x%M + M)%M);
    }
ll add(ll a, ll b){
        return mod(mod(a)+mod(b));
    }
ll mul(ll a, ll b){
        return mod(mod(a)*mod(b));
    }
ll minu(ll a, ll b){
        return mod(mod(a)-mod(b));
    }
ll power(ll a, ll b){
    ll res=1;
    while(b>0){
        if(b&1) res=mul(res,a);
        b = b>>1;
        a=mul(a,a);
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    ll a[n];
    ll s=0;
    for(ll i=0;i<n;++i){
        cin>>a[i];
        s=add(s,a[i]);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        s=minu(s,a[i]);
        ll val=mul(a[i],s);
        ans=add(ans,val);
    }
    cout<<ans;
    return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		for(int i=0;i<=N;i++){
			for(int j=0;j<=M;j++){
				int c = i * M + j * N - i * j * 2;
				if(c == K){
					Console.WriteLine("Yes");
					return;
				}
			}
		}
		Console.WriteLine("No");
		
		
		
	}
	int N,M,K;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1]; K = d[2];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.append(0)

ans=0
j=N+1
for i in A:
    ans+=B[i-1]
    if j+1==i:
        ans+=C[j-1]
    j=i
print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k;std::cin>>n>>k;
    std::vector<lint>pos,neg;
    for(lint i=0;i<n;i++){
        lint x;std::cin>>x;
        if(0<=x)pos.push_back(x);
        else neg.push_back(-x);
    }
    std::reverse(neg.begin(),neg.end());
    pos.insert(pos.begin(),0);
    neg.insert(neg.begin(),0);
    lint inf=std::numeric_limits<lint>::max()/3;
    while((lint)pos.size()<=k)pos.push_back(inf);
    while((lint)neg.size()<=k)neg.push_back(inf);
    lint ans=inf;
    for(lint i=0;i<=k;i++){
        lint x=pos.at(i),y=neg.at(k-i);
        lint now=x+y+std::min(x,y);
        if(now<ans)ans=now;
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 2548
n,a = map(int, input().split())
X = list(map(int, input().split()))
x = [i-a for i in X]
dp = [[0]*5201 for i in range(n+1)]
dp[0][2600] = 1 
for i,xi in enumerate(x):
  for k in range(99,5101):
    dp[i+1][k+xi] += dp[i][k] 
    dp[i+1][k] += dp[i][k]
ans = dp[n][2600] - 1
print(ans)

Measured memory_bytes: 7156
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

struct Edge{
    // 始点, 終点, 重み, 最大量
    long long src, dst, weight, capacity;
    Edge(): src(0), dst(0), weight(0), capacity(0) {}
    Edge(long long s, long long d, long long w): src(s), dst(d), weight(w) {}
    Edge(long long s, long long d, long long w, long long c): src(s), dst(d), weight(w), capacity(c) {}
};

class Graph{
public:
    long long size;
    vector<vector<Edge>> node;
    Graph(long long n): size(n), node(n) {}
    // 無向辺の追加
    void addEdge(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
        node[d].emplace_back(d, s, w);
    }
    // 有向辺の追加
    void addArc(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
    }
    // ノードの追加
    void addNode(){
        size++;
        node.emplace_back();
    }
};

// TopologicalSort; トポロジカルソート
// ：有向非巡回グラフ（DAG）の全ての辺が右向きになるように整列する。[O(E+V)]
vector<long long> TopologicalSort(const Graph &g){
    vector<long long> indegree(g.size), sorted;
    for(long long v=0; v<g.size; v++) for(auto &edge: g.node[v]) indegree[edge.dst]++;
    queue<long long> que;
    for(long long i=0; i<g.size; i++) if(indegree[i] == 0) que.push(i);
    while(!que.empty()){
        long long v = que.front();
        que.pop();
        sorted.emplace_back(v);
        for(auto &edge: g.node[v]) if (--indegree[edge.dst] == 0) que.push(edge.dst);
    }
    return *max_element(indegree.begin(), indegree.end()) == 0LL ? sorted : vector<long long>();
}

long long encode(long long i, long long j){
    if(i<j) swap(i, j);
    return i*(i-1)/2+j+1;
}

vi d(1000*999/2+1, 0);
vi seen(1000*999/2+1, 0);
long long dfs(Graph &g, ll now){
    if(seen[now] == 1) return d[now];
    for(auto &edge: g.node[now]) chmax(d[now], dfs(g, edge.dst)+1);
    seen[now] = 1;
    return d[now];
}

int main(){
    Init();
    ll n; cin >> n;
    Graph g(n*(n-1)/2+1);
    vi d(n*(n-1)/2+1, 0);
    rep(i, n){
        ll now = 0;
        rep(j, n-1){
            ll num;
            cin >> num;
            num--;
            ll next = encode(i, num);
            g.addArc(now, next);
            now = next;
        }
    }

    // 閉路判定
    auto p = TopologicalSort(g);
    ll cnt = 0;
    if(!p.size()) cnt = -1;
    // 閉路が無いなら最長距離を求める
    else cnt = dfs(g, 0);
    cout << cnt << endl;
}

Measured memory_bytes: 80424
s = input()[::-1]
templates = [s[::-1] for s in ["dream", "dreamer", "erase", "eraser"]]
while s:
    for template in templates:
        if s.startswith(template):
            s = s.replace(template, "", 1)
            break
    else:
        break
print("YES" if not s else "NO")

Measured memory_bytes: 9116
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int qtime; cin >> qtime;
    ll x=0,c = 0,ls=0,rs=0;
    priority_queue<ll> q;
    priority_queue<long long int, vector<long long int>, greater<long long int>> qq;
    rep(dfas,qtime){
       // printf("x,ls,rs : %lld, %lld, %lld \n", *itr, ls, rs);
        ll com,a,b; cin >> com;
        if(com==1){
            cin >> a >> b;
            c += b;
            q.push(a);
            qq.push(a);
            if(q.top() > qq.top()){ 
                c += abs(q.top()-qq.top()); 
                ll tq=q.top(),tqq = qq.top();
                q.pop(); qq.pop();
                q.push(tqq); qq.push(tq);
            }
        }else{
            cout << q.top() << " " << c << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4588
#include<stdio.h>

int main(void)
{
	int i,j,k,v,N;
	int A[1000];

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

	for(i = 1;i <= N - 1;i++){
		for(k = 0;k < N;k++){
			if(k > 0)printf(" ");
			printf("%d",A[k]);
		}
		printf("\n");
		v = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > v){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
	}
	for(i = 0;i < N;i++){
		if(i > 0)printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 604