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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

int fact[114514];

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

int extgcd(int a, int b, int &x, int &y)
{
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else { x = 1; y = 0; }
    return d;
}

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

int mod_inverse(int a, int m)
{
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}


int table(int n)
{
    int sum = 1;
    fact[0] = 1;
    Rep(i, n+1) {
        sum *= i;
        sum %= MOD;
        fact[i] = sum;
    }
}

int mod_fact(int n, int p, int &e)
{
    e = 0;
    if (n == 0) return 1;
    int res = mod_fact(n / p, p, e);
    e += n / p;

    if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
    return res * fact[n % p] % p;
}

int mod_comb(int n, int k, int p) {
    if (n < 0 || k < 0 || n < k) return 0;
    int e1, e2, e3;
    int a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n-k, p, e3);
    if (e1 > e2 + e3) return 0;
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

signed main()
{
    Int(n);
    table(n+10);
    vi data(n+1);
    rep(i, n+1) {
        cin >> data[i];
    }

    vb used(n+1, false);
    int targ;
    int tp1, tp2;
    rep(i, n+1) {
        if (used[data[i]]) {
            targ = data[i];
            tp2 = i;
            break;
        } else {
            used[data[i]] = true;
        }
    }
 //   cout << targ << endl;
    rep(i, n+1) {
        if (data[i] == targ) {
            tp1 = i;
            break;
        }
    }
   // cout << tp1 << " " << tp2 << endl;

    int dist = tp2 - tp1;
    int r = n - tp2, l = tp1;
    Rep(i, n+2) {
        if (l + r >= i-1) {
   /*         
            cout << mod_comb(n+1, i, MOD) << " " << 
                mod_comb(n-dist, i-1, MOD) << " ";
    */            
            cout << (mod_comb(n+1, i, MOD) - mod_comb(l+r, i-1, MOD) + MOD)
                % MOD
                << endl;
        } else {
            cout << mod_comb(n+1, i, MOD) << endl;
        }
    }


    return 0;
}



Measured memory_bytes: 2816
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 924844033;
 
////////////////////////////////////////////////////////////////////
 
const int N = 5e5 + 5;

int A[N];

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	string S; cin >> S;
	int n = sz(S);
	for (int i = 0; i < n; i++) if (S[i] == '<') A[i + 1] = max(A[i + 1], A[i] + 1);
	for (int i = n - 1; i >= 0; i--) if (S[i] == '>') A[i] = max(A[i], A[i + 1] + 1);
	ll sum = 0;
	for (int i = 0; i < n + 1; i++) sum += A[i];
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 5856
h, w = list(map(int, input().split()))
s = [input() for j in range(h)]
op = [(-1, 0), (0, -1), (0, 1), (1, 0)]
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      continue
    count = 0
    for k in range(4):
      x = i + op[k][0]
      y = j + op[k][1]
      if x < 0 or y < 0 or x >= h or y >= w:
        continue
      if s[x][y] == '.':
        count += 1
    if count == 4:
      print('No')
      exit()
      
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

inline int abs(int a, int b)
{
    return ((a - b) >= 0 ? (a - b):-1*(a - b));
}

const int Nmax = 1e5 + 1;
int a[Nmax];
int N,K,Dif_min;

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> N >> K;
    for(int i = 1; i <= N; ++i)
        cin >> a[i];
    sort(a + 1,a + N + 1);
    Dif_min = (1 << 30);
    for(int i = 1; i <= N - K + 1; ++i)
        Dif_min = min(Dif_min,abs(a[i] - a[i + K - 1]));
    cout << Dif_min;
    return 0;
}


Measured memory_bytes: 640
s = input().rstrip()

a, b = int(s[0:2]), int(s[2:4])

if 1 <= a <= 12 and 1 <= b <= 12:
    ans = 'AMBIGUOUS'
elif 1 <= a <= 12:
    ans = 'MMYY'
elif 1 <= b <= 12:
    ans = 'YYMM'
else:
    ans = 'NA'

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main(void){
	int n,m,c;
	cin >> n >> m >> c;
	vector<int> B_arr(m);
	for(int i=0; i<m; ++i){
		cin >> B_arr[i];
	}


	vector<vector<int>> A_arr(n);
	for(int i=0; i<n; ++i){
		A_arr[i] = vector<int>(m);
		for(int j=0; j<m; ++j){
			cin >> A_arr[i][j];
		}
	}

	int count = 0;
	for(int i=0; i<n; ++i){
		int score = 0;
		for(int j=0; j<m; ++j){
			score += A_arr[i][j] * B_arr[j];
		}
		score += c;
		if( score > 0 ) count++;
	}

	cout << count << endl;
	return 0;
}

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

using namespace std;

int main(){
	int n;
	string str;
	cin >> n;
	cin >> str;
	int ans = 0;

	for (int i = 0; i + 2 < n ; ++i)
	{
		if(str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C' ) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
List={}
x=0
for i in range(n):
    if not a[i] in List:
        List[a[i]] = 1
    else:
        List[a[i]]+=1
    
sigma=0

for key,item in List.items():
    sigma += item*(item-1)//2
for i in range(n):
    print(sigma-List[a[i]]+1)

Measured memory_bytes: 86476
import java.util.*;
 
public class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    long K = sc.nextLong();
    long[] A = new long [N];
    long[] B = new long [M];
    for (int i = 0; i < N; i++) {
      long a = sc.nextLong();
      A[i] = a;
    }
    for (int i = 0; i < M; i++) {
      long b = sc.nextLong();
      B[i] = b;
    }
    //累積和A
    for (int i = 1; i < N; i++) 
      A[i] = A[i-1]+A[i];
    //累積和B
    for (int i = 1; i < M; i++) 
      B[i] = B[i-1]+B[i];
    
    long ans = 0;

    if (A[N-1] <= K) 
      ans = N;
    if (B[M-1] <= K)
      ans = Math.max(ans,M);

    int j = M-1;

    for (int i = 0; i < N; i++) {
      long minuites = K - A[i];
      if (minuites < 0)
        break;
      if (j == -1)
        j = 0;
      while (B[j] > minuites) {
        j -= 1;
        if (j == -1) {
          break;
        }
      }
      ans = Math.max(ans,i+j+2);
    }

    int jj = N-1;

    for (int i = 0; i < M; i++) {
      long minuites = K - B[i];
      if (minuites < 0)
        break;
      if (jj ==-1)
        jj = 0;
      while (A[jj] > minuites) {
        jj -= 1;
        if (jj == -1) {
          break;
        }
      }
      ans = Math.max(ans,i+jj+2);
    }
    System.out.println(ans);
  }
}  

Measured memory_bytes: 63020
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 


int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans = 0;
  for(ll i=1;i<=n;i++){
    ll sum = 0;
    ll c = i;
    while(c>0){
    sum += c%10;
    c /=10;
  }
    if(sum >= a && sum <= b){
      ans += i;
    }
  }
  cout << ans;
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int>>
#define fin(ar,k,n) for(int i=k;i<n;i++) cin>>ar[i]
#define fout(ar,k,n) for(int i=k;i<n;i++) cout<<ar[i]<<' '
#define all(z) z.begin(),z.end()
#define mcc ((int)1e9+7)
#define mcf 998244353
#define mi map<int,int>
#define mem(a,n) memset(a,n,sizeof(a))
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> fst;

const int N=1e5+7;
ll dp[N],n,w;
ll maxl(ll a,ll b) {return (a>b)? a:b;}

void solve()
{
    cin>>n>>w;
	for (int i=1;i<=n;i++)
	{
		int u,v; cin>>u>>v;
		for(int j=N-u-1;j>=0;j--)
		{
			dp[j+u]=maxl(dp[j]+v,dp[j+u]);
		}
	}
	cout<<dp[w];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-3");


    int K; cin>>K;
    
    queue<int> que;
    FOR(i, 1, 10)
        que.push(i);

    vi lun;
    REP(i,K) {
        int x = que.front(); que.pop();
        lun.push_back(x);

        int d1 = x%10;
        if (d1 == 0) {
            for (int d = d1; d <=d1+1; d++) {
                que.push(x*10+d);
            }
        } else if (d1 == 9) {
            for (int d = d1-1; d <=d1; d++) {
                que.push(x*10+d);
            }
        } else {
            for (int d = d1-1; d <=d1+1; d++) {
                que.push(x*10+d);
            }
        }
    }

    int ans = lun[K-1];
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  string sa,sb,sc;
  cin >> sa >> sb >> sc;
  int u=0;
  char q='a';
  char w;
  size_t sizea = sa.size();
  size_t sizeb = sb.size();
  size_t sizec = sc.size();
  while(u==0){
    if(q=='a'){
      q = sa[0];
      
      
      if(sizea == 0){
        u=1;
        w='A';
      }
      else sa.erase(sa.begin());
      sizea--;
    }
    else if(q=='b'){
      q = sb[0];
      if(sizeb == 0){
        u=1;
        w='B';
      }
      else sb.erase(sb.begin());
      sizeb--;
    }
    else{
      q = sc[0];
      if(sizec == 0){
        u=1;
        w='C';
      }
      else sc.erase(sc.begin());
      sizec --;
    }
 //   cout << q << endl; 
  }
  cout << w << endl;
}

Measured memory_bytes: 256
<?php

function dfs($first, $last) {
    if (count($last) === 0) {
        return [$first];
    }

    $res = [];
    foreach ($last as $key => $val) {
        $next_f = $first;
        $next_l = $last;

        $next_f[] = $val;
        array_splice($next_l, $key, 1);
        $res = array_merge($res, dfs($next_f, $next_l));
    }

    return $res;
}

function next_permutation($start, $end) {
    return dfs([], range($start, $end));
}

fscanf(STDIN, "%d", $n);
$pers = next_permutation(1, $n);
$tmp = [];
foreach ($pers as $per) {
    $tmp[] = implode('', $per);
}
sort($tmp);

$p = implode('', explode(' ', trim(fgets(STDIN))));
$q = implode('', explode(' ', trim(fgets(STDIN))));

echo abs(array_search($p, $tmp) - array_search($q, $tmp));


Measured memory_bytes: 25464
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdint>
#include <limits>
using namespace std;



/**
* 10進数 v を base進数の文字列へ変換する。
* @param [in] v    10進数の整数
* @param [in] base 変換した 2~36 のN進数の値
* @return base進数へ変換した文字列
*/
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
	static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string ret;
	static numeric_limits<TypeInt> t;
	TypeInt n = v;
	if (t.is_signed) {
		if (v < 0) n *= -1;
	}

	while (n >= base) {
		ret += table[n%base];
		n /= base;
	}
	ret += table[n];
	if (t.is_signed) {
		if (v < 0 && base == 10) ret += '-';
	}
	// 文字列の順番を逆にする
	std::reverse(ret.begin(), ret.end());

	return ret;
}



int main(void)
{
    int n,k;
 	cin>>n>>k;
	cout <<  Itoa(n,k).size() << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    long C = scanner.nextLong();
    long[] x = new long[N];
    long[] v = new long[N];
    for (int i = 0; i < N; i++) {
      x[i] = scanner.nextLong();
      v[i] = scanner.nextLong();
    }

    long sum = 0;
    long[] lmax = new long[N + 1];
    long[] lsum = new long[N + 1];
    for (int i = 1; i <= N; i++) {
      sum += v[i - 1];
      lmax[i] = Math.max(lmax[i - 1], sum - x[i - 1]);
      lsum[i] = sum - x[i - 1] * 2;
    }

    sum = 0;
    long[] rmax = new long[N + 1];
    long[] rsum = new long[N + 1];
    for (int i = 1; i <= N; i++) {
      sum += v[N - i];
      rmax[i] = Math.max(rmax[i - 1], sum - (C - x[N - i]));
      rsum[i] = sum - (C - x[N - i]) * 2;
    }

    long max = lmax[N];
    max = Math.max(max, rmax[N]);

    for (int i = 1; i < N; i++) max = Math.max(max, rsum[i] + lmax[N - i]);
    for (int i = 1; i < N; i++) max = Math.max(max, lsum[i] + rmax[N - i]);

    System.out.println(max);
  }
}


Measured memory_bytes: 91560
Scanf.scanf "%d" (fun n ->
    let arr = Array.make n ' ' in
    let rec loop i c mx =
        if i = n then print_endline @@ String.init n (fun i -> arr.(i)) else
            if c <= mx then (
                arr.(i) <- char_of_int c;
                loop (i + 1) 97 (max mx (c + 1));
                loop i (c + 1) mx
            )
    in
    loop 0 97 97
)

Measured memory_bytes: 5732
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=2e5+5;
struct node
{
  int x;
  node()
  {
    x=0;
  }
}; 
node merge(node a,node b)
{
  node c;
  c.x=max(a.x,b.x);
  return c;
}
 
vector<node> bit(4*N);
void build(int id,int l,int r)
{
  if(l==r)
  {
      return;
  }
  int mid=(l+r)/2;
  build(2*id,l,mid);
  build(2*id+1,mid+1,r);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
}

 
node get(int id,int l,int r,int L,int R)
{
  if(R<l||r<L){
    node c;
    return c;
  }
  if(L<=l&&r<=R)
  {
    return bit[id];
  }
  int mid=(l+r)/2;
  return merge(get(2*id,l,mid,L,R),get(2*id+1,mid+1,r,L,R));
}
 
void upd(int id,int l,int r,int L,int R,int v)
{
  if(R<l||r<L)
    return;
  if(L<=l&&r<=R)
  {
    bit[id].x=v;
    return;
  }
  int mid=(l+r)/2;
  upd(2*id,l,mid,L,R,v);
  upd(2*id+1,mid+1,r,L,R,v);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
}
 
 
void solve()
{
 build(1,1,10);
 int n;
 cin>>n;
 int h[n+1],a[n+1];
 for(int i=1;i<=n;i++)
  cin>>h[i];
 for(int i=1;i<=n;i++)
  cin>>a[i];
 int ans=0;
 for(int i=1;i<=n;i++)
 {
  int x=a[i]+get(1,1,n,1,h[i]).x; 
  ans=max(ans,x);
  upd(1,1,n,h[i],h[i],x);
 }
 cout<<ans<<endl;


}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t;
 t=1;
 for(int i=1;i<=t;i++)
 {
   solve();
 }


} 

Measured memory_bytes: 12692
#include <stdio.h>
#define N 100

int main()
{

  int n,k=0,f;
  int A[N];
  int i,j;
  
  
  scanf("%d",&n);

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

Measured memory_bytes: 604
#include <array>
#include <iostream>

using namespace std;

array<int, 15> A;
array<array<int, 15>, 15> x, y;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;
  
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    for(int j = 0; j < A[i]; ++j) {
      cin >> x[i][j] >> y[i][j];
    }
  }
  
  int ans = 0;
  for(int bit = 1; bit < (1<<N); ++bit) {
    bool ok = true;
    for(int i = 0; i < N; ++i) {
      if(!(bit & (1 << i))) { continue; }
      for (int j = 0; j < A[i]; ++j) {
        auto flag = bit >> (x[i][j]-1);
        if ((flag & 1) ^ y[i][j]) {
          ok = false;
        }
      }
    }
    if(ok) {
      ans = max(ans, __builtin_popcount(bit));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define INF (1LL<<62)
#define MX 100005*3

LL a[MX];
LL ma[MX];
LL mi[MX];

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

    for (int i=1;i<=3*n;i++)
        scanf("%lld",&a[i]);
    priority_queue <LL> Q;
    LL sum = 0;
    for (int i=1;i<=2*n;i++)
    {
        Q.push(-a[i]);
        sum+=a[i];

        if (i>n) sum += Q.top(),Q.pop();
        ma[i]=sum;
    }

    while (!Q.empty()) Q.pop();
    sum=0;
    for (int i=3*n;i>=n+1;i--)
    {
        Q.push(a[i]);
        sum+=a[i];

        if (i<=2*n) sum -= Q.top(),Q.pop();
        mi[i]=sum;
    }

    LL ans = -INF;
    for (int i=n;i<=2*n;i++)
        ans = max (ans, ma[i]-mi[i+1]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7412
import sys
input = lambda: sys.stdin.readline().rstrip()
s=[i for i in input()]
x=0 ; st=[[],[]]
for _ in range(int(input())):
    inp=list(map(str,input().split()))
    if len(inp)==1: x^=1
    else: st[(int(inp[1])-1)^x].append(inp[2])
if x==0:
    st[0].reverse()
    ans=st[0]+s+st[1]
elif x==1:
    st[1].reverse()
    s.reverse()
    ans=st[1]+s+st[0]
print(''.join(ans))
    
    

Measured memory_bytes: 75184
#include<iostream>
using namespace std;
int main()
{
  int ans,cnt;
  string s,t;
  while(cin>>s>>t){
    ans=0;
    for(int k=0;k<2;k++){
      for(int i=0;i<s.size();i++){
	cnt=0;
	for(int j=0;j<s.size()-i;j++){
	  if(s[j+i]==t[j]){
	    cnt++;
	    ans=max(ans,cnt);
	  }else{
	    cnt=0;
	  }
	}
      }
      swap(s,t);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 940
#include <iostream>
#include <cstdio>

using namespace std;

struct Node {
    int key;
    Node *parent,*left,*right;
};

Node *root,*NIL;

void insert(int k) {
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=new Node;
    z->key=k;
    z->left=NIL;
    z->right=NIL;
    while(x!=NIL) {
        y=x;
        if(z->key < x->key) {
            x=x->left;
        }
        else {
            x=x->right;
        }
    }

    z->parent=y;
    if(y==NIL) {
        root=z;
    }
    else {
        if(z->key<y->key) y->left=z;
        else y->right=z;
    }
}

Node* find(Node *u,int k) {
    while(u!=NIL&&k!=u->key) {
        if(k<u->key) u=u->left;
        else u=u->right;
        
    }
    return u;
}

Node* treeMinimum(Node *x) {
    while(x->left!=NIL) x=x->left;
    return x;
}

Node* treeSuccessor(Node *x) {
    if(x->right!=NIL) return treeMinimum(x->right);
    Node *y=x->parent;
    while(y!=NIL && x==y->right) {
        x=y;
        y=y->parent;
    }
    return y;
}

void treeDelete(Node *z) {
    Node *y;
    Node *x;

    if(z->left==NIL||z->right==NIL) y=z;
    else y=treeSuccessor(z);

    if(y->left!=NIL) {
        x=y->left;
    }
    else {
        x=y->right;
    }
    if(x!=NIL) x->parent=y->parent;

    if(y->parent==NIL) {
        root=x;
    }
    else {
        if(y==y->parent->left) y->parent->left=x;
        else y->parent->right=x;
    }

    if(y!=z) z->key=y->key;

    delete y;
}

void inorder(Node *u) {
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n,x;
    string com;

    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>com;
        if(com=="insert") {
            cin>>x;
            insert(x);
        }
        else if(com=="print") {
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
        else if(com=="find") {
            cin>>x;
            if(find(root,x)!=NIL) cout<<"yes"<<endl;
            else cout<<"no"<<endl;

        }
        else if(com=="delete") {
            cin>>x;
            treeDelete(find(root,x));
        }
    }

    return 0;

}

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

int main() {
  int c[6];
  int p[6] = {1, 5, 10, 50, 100, 500};
  int sum = 0;
  int i;
  for (i = 0; i < 6; i++) {
    cin >> c[i];
    sum += c[i] * p[i];
  }
  cout << (sum >= 1000 ? 1 : 0) << endl;
  return 0;
}



Measured memory_bytes: 3084
function Main(input){
	input=input.split(/\s/);
	input.forEach(function(e,i,a){a[i]=Number(a[i]);});
	var a=input[3]-input[4];
	a=(a^(a>>31))-(a>>31);
	var b=input[3]<input[4]?0:1;//
	var c=(input[0]+input[1])*input[b+3];
	c=c<(input[2]*(input[b+3]<<1))?c:(input[2]*(input[b+3]<<1));
	b^=1;
	if(input[b]<(input[2]<<1)){c+=input[b]*a;}
	else{c+=(input[2]<<1)*a;}
	console.log(c);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<deque>
using namespace std;

int main(){
    int n,h[100000],cnt,ans=0;
    cnt=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    for(int i=0;i<n-1;i++){
        if(h[i]>=h[i+1]){
            cnt++;
        }
        else{
            cnt=0;
        }
        ans=max(ans,cnt);
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define M 10001
using namespace std;
long long n,k,t,u,v,l,d,c,x,a,s[M];

int main(){
  cin>>n>>k>>t>>u>>v>>l;
  for(int i=0;i<n;i++)cin>>d,s[d]=1;
  for(int i=0;i<l;i++){
    if(s[i])
      if(!x||k==c)x=v*t;
      else c++;
    else if(!x&&c)c--,x=v*t;
    if(x)a++,x--;
  }
  printf("%.8f\n",a*1.0/v+(l-a)*1.0/u);
  return 0;
}

Measured memory_bytes: 1268
#include <stdio.h>

void print(int A[],int n){
	int i;
	for(i=0;i<n;i++){
		printf("%d",A[i]);
		if(i<n-1)
		printf(" ");
	}
	printf("\n");
}

int main(void){
	int i,j,n,flag,A[100],temp,count=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	flag = 1;
	// print(A,n);
	while(flag){
		flag = 0;
		for (j=1;j<=n-1;j++){
			if(A[j] < A[j-1]){
				temp = A[j];
				A[j]= A[j-1];
				A[j-1]= temp;
				flag =1;
		count++;
			}
		}
		// print(A,n);
	}
	print(A,n);
	printf("%d\n",count);
	return 0;
}

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

namespace Atc_0028
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            str = Console.ReadLine();

            string S = str.Split(' ')[0];
            string T = str.Split(' ')[1];

            string result = "";

            for (int i = 0; i < S.Length; i++)
            {
                result += S.Substring(i, 1);
                result += T.Substring(i, 1);
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 25876
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,cnt=0;
    cin>>n;
    int h[n], max=0;
    for(int i=0; i<n; i++){
        cin>>h[i];
        if(h[i]>=max){
            cnt++;
            max=h[i];
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6//3 + 1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
x, y = map(int,input().split())

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
if (x + y)% 3 == 0:
    movtot = (x+y)//3
    movx = x - movtot

    ans = cmb(movtot,movx,mod)
    
print(ans)

Measured memory_bytes: 82516
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
int a[maxn], cnt[maxn];
int n;

ll my_pow(ll x, ll y) {
    ll ret = 1, t = x;
    while (y) {
        if (y & 1) { ret *= t; ret %= mod; }
        t *= t; t %= mod; y >>= 1;
    }
    return ret;
}

int main() {
#ifdef __AiR_H
    freopen("A.in", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]); ++cnt[a[i]];
    }
    bool flag = true;
    for (int i = n - 1; i >= 1; i -= 2) {
        if (cnt[i] != 2) { flag = false; break; }
    }
    if (n % 2 == 1 && cnt[0] != 1) { flag = false; }
    if (!flag) { printf("0\n"); return 0; }
    cout << my_pow(1ll * 2, 1ll * n / 2) << endl;
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%N;x=x*x%N;n>>=1;}return res;}
ll modinverse(ll a){return power(a,  998244353-2);}
void solve()
{
    string str="AWTR";
    vl vect(4);
    ll n;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        if(s[0]=='A')
        vect[0]++;
        if(s[0]=='W')
        vect[1]++;
        if(s[0]=='T')
        vect[2]++;
        if(s[0]=='R')
        vect[3]++;
    }
    cout<<"AC x "<<vect[0]<<endl;
    cout<<"WA x "<<vect[1]<<endl;
    cout<<"TLE x "<<vect[2]<<endl;
    cout<<"RE x "<<vect[3]<<endl;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)
 
int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
 
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
 
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
 
// --------------------------------------
ll a, b, c, d;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
 
ll lcm(ll a, ll b) {
  if(a < b) swap(a, b);
  return a * b / gcd(a, b);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin >> a >> b >> c >> d;
  ll cc = (b / c - (a - 1) / c);
  ll dc = (b / d - (a - 1) / d);
 
  ll lc = lcm(c, d);
  ll lcc = (b / lc - (a - 1) / lc);
 
  cout << (b - (a - 1)) - (cc + dc - lcc) << endl;
}

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

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
    int n;
    while (n = in()){
        int total = 0;
        priority_queue<pair<int, int> > Q;
        rep(i, n){
            int m, a, b;
            m = in();
            a = in();
            b = in();
            Q.push(make_pair(-a, m));
            Q.push(make_pair(-(b - 1), -m));
        }
        while (!Q.empty()){
            total += Q.top().second;
            Q.pop();
            if (total > 150){
                puts("NG");
                break;
            }
        }
        if (total <= 150){
            puts("OK");
        }
    }
    return (0);
}

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



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

    int n;
    cin>>n;
    ll a[n],b[n];
    ll ans=0;
    bool pos=false;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        if(a[i]!=b[i])pos=true;
        ans+=a[i];
    }
    
    if(!pos){
        cout<<0<<endl;
        return 0;
    }

    ll t=1e10,p=-1;
    for(int i=0;i<n;i++){
        if(a[i]>b[i] && t>b[i]){
            t=b[i];
            p=i;
        }
    }
    ans-=b[p];
    
    cout<<ans<<endl;




}


Measured memory_bytes: 640
// #define _GLIBCXX_DEBUG
#pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define reps(i, s, n) for (i64 i = s; i < (i64)(n); ++i)

void solve(vector<i64> P, i64 N, i64 M) {
    vector<i64> A;
    rep(i, N) rep(j, N) {
        if (M < P[i] + P[j]) {
            continue;
        }
        A.push_back(P[i] + P[j]);
    }
    sort(A.begin(), A.end());

    i64 ans = 0;
    // 矢が1本
    for (auto &&e : P) {
        if (e <= M) {
            ans = max(ans, e);
        }
    }
    // 矢が3本
    for (auto &&e : P) {
        if (M < e) continue;
        i64 add = M - e + 1;
        i64 idx = upper_bound(A.begin(), A.end(), add) - A.begin();
        if (idx != 0 and e + A[idx - 1] <= M) {
            ans = max(ans, e + A[idx - 1]);
        }
    }
    // 矢が2本
    for (auto &&e : A) {
        ans = max(e, ans);
    }
    // 矢が4本
    for (auto &&e : A) {
        i64 add = M - e + 1;
        i64 idx = upper_bound(A.begin(), A.end(), add) - A.begin();
        if (idx != 0 and e + A[idx - 1] <= M) {
            ans = max(ans, e + A[idx - 1]);
        }
    }
    cout << ans << "\n";
}
int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    i64 N, M;
    cin >> N >> M;
    while (N != 0 or M != 0) {
        vector<i64> P(N);
        for (auto &&i : P) {
            cin >> i;
        }

        solve(P, N, M);
        cin >> N >> M;
    }
}


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

int countdis(string s[],int n){
  sort(s,s+n);
  int res=0;
  for(int i=0;i<n;i++){
    while(i<n - 1 && s[i]==s[i+1])
      i++;

    res ++;
  }

  return res;
}

int main(){
  int n;
  cin>>n;
  string s[n];
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  cout<<countdis(s,n);
}


Measured memory_bytes: 9852
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int N,M;
ll X;
ll dp[214514][25];
int main(){
	cin>>N;
	vector<ll> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	for(int i=0;i<=20;i++){
		ll fi=N,sec=N;
		for(int j=N-1;j>=0;j--){
			if(A[j]%2==1){
				sec = fi;
				fi = j;
			}
			dp[j][i]=sec-j;
			A[j]=(A[j]>>1);
		}
	}
	/*rep(i,N)cout<<dp[i][0]<<" ";
	cout<<endl;*/
	ll ans = 0;
	for(int i=0;i<N;i++){
		ll mi = dp[i][0];
		for(int j=0;j<=20;j++){
			mi = min(mi,dp[i][j]);
		}
		ans += (ll)mi;
	}
	cout<<ans<<endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pi;

vector <int> g[maxn] ;
int a[maxn] ;
bool marked[maxn] ;
pi dp[maxn] ;

pi dfs(int u, int par)
{
    dp[u] = mp(-INF,INF) ;
    for(int i=0 ; i<g[u].size() ; i++)
    {
        int v = g[u][i] ;
        if( v==par ) continue ;
        pi p = dfs(v,u) ;
        if( p == mp(-INF,INF) ) continue ;
        p.xx-- ; p.yy++ ;
        if( dp[u]!= mp(-INF,INF) )
        {
            if( dp[u].xx%2 != p.xx%2 )
            {
                printf("No\n") ;
                exit(0) ;
            }
        }
        dp[u] = mp( max(p.xx,dp[u].xx) , min( p.yy,dp[u].yy ) ) ;
    }
    if( dp[u].xx > dp[u].yy || ( dp[u]!=mp(-INF,INF) && marked[u] && ( dp[u].xx > a[u] || dp[u].yy < a[u] || dp[u].xx%2 != a[u]%2 ) ) )
    {
        printf("No\n") ;
        exit(0) ;
    }
    if( marked[u] ) dp[u] = mp( a[u] , a[u] ) ;
    return dp[u] ;
}

void dfs1(int u, int par)
{
    if( !marked[u] )
    {
        if( par==0 )
        {
            a[u] = dp[u].xx ;
        }
        else{
            if( a[par]+1 <= dp[u].yy ) a[u] = a[par]+1 ;
            else if( a[par]-1 >= dp[u].xx ) a[u] = a[par]-1 ;
            else{
                printf("No\n") ;
                exit(0) ;
            }
        }
    }
    for(int i=0 ; i<g[u].size() ; i++)
    {
        int v = g[u][i] ;
        if( v!=par ) dfs1(v,u) ;
    }
    return ;
}

int main()
{
    int i , j , k , l , m , n ;

    scanf("%d",&n) ;

    for(i=1 ; i<n ; i++)
    {
        int u , v ;
        scanf("%d %d",&u,&v) ;
        g[u].pb(v) ; g[v].pb(u) ;
    }

    scanf("%d",&k) ;

    for(i=1 ; i<=k ; i++)
    {
        int idx , val ;
        scanf("%d %d",&idx,&val) ;
        a[idx] = val ;
        marked[idx] = 1 ;
    }

    dfs(1,0) ;
    dfs1(1,0) ;

    printf("Yes\n") ;
    for(i=1; i<=n ; i++) printf("%d\n",a[i]) ;

    return 0 ;
}
/*
6
1 2
1 3
2 6
3 4
3 5
3
3 9
1 8
6 7
*/


Measured memory_bytes: 13952
using System;
class ProgramD
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            string[] input_pqr = Console.ReadLine().Split(' ');
            int p = int.Parse(input_pqr[0]);
            int q = int.Parse(input_pqr[1]);
            int r = int.Parse(input_pqr[2]);
            string t = Console.ReadLine();
            
            //3桁があり得るかを見る準備
            long count = 0;
            long frag = 0;

            for(int j = 0; j < k ;j++)
                for(int i = 0; i < n;i = i + k)
                {
                    if(i + j >= n)
                      continue;
                   
                    if(i == 0)
                    {
                        frag = 0;
                        if(t[i + j] == 'r')
                            count += r;
                        else if(t[i + j] == 's')
                            count += p;
                        else
                            count += q;
                    }
                    else
                    {
                        if(t[i + j] == 'r')
                        {
                            if(t[i + j - k] == 'r' && frag == 0)
                                frag++;
                            else
                            {
                                count += r;
                                frag = 0;
                            }
                        }
                        else if(t[i + j] == 's')
                        {
                            if(t[i + j - k] == 's' && frag == 0)
                                frag++;
                            else
                            {
                                count += p;
                                frag = 0;
                            }
                        }
                        else
                        {
                            if(t[i + j - k] == 'p' && frag == 0)
                                frag++;
                            else
                            {
                                count += q;
                                frag = 0;
                            }
                            
                        }
                    }
                }

            //答え出力
            Console.WriteLine(count);
          
        }
    }

Measured memory_bytes: 13144
#include<bits/stdc++.h>
using namespace std;
long long a[200001],sum;
int main(){
	int n,times;
	cin>>n>>times;
 
	for(int i=0;i<n;i++)
	cin>>a[i];
	
	sort(a,a+n);
	for(int i=0;i<n-times;i++){
		sum+=a[i];
	}
	
	cout<<sum;
	return 0;
}

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

int main() {
  int table[10][10], temp2[10][10][10][10], count = 0, f;
  
  for (int i = 0; i < 10000; i++) temp2[i/1000][(i/100)%10][(i/10)%10][i%10]  = -1;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      cin >> table[i][j];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
	for (int l = 0; l < 10; l++) {
	  temp2[i][j][k][l] = table[table[table[table[0][i]][j]][k]][l];
	}
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
	for (int l = 0; l < 10; l++){
	  f = 0;
	  if(i != j && table[temp2[j][i][k][l]][temp2[i][j][k][l]] == 0){
	    count++;
	    continue;
	  } else if(j != k && table[temp2[i][k][j][l]][temp2[i][j][k][l]] == 0){
	    count++;
	    continue;
	  } else if(k != l && table[temp2[i][j][l][k]][temp2[i][j][k][l]] == 0){
	    count++;
	    continue;
	  }else if(l != temp2[i][j][k][l] && table[temp2[i][j][k][temp2[i][j][k][l]]][l] == 0){
	    count++;
	    continue;
	  }
	  for(int m = 0; m < 10; m++){
	    if(m != i){
	      if(table[temp2[m][j][k][l]][temp2[i][j][k][l]] == 0){
		f = 1;
		break;
	      }
	    }
	    if(m != j){
	      if(table[temp2[i][m][k][l]][temp2[i][j][k][l]] == 0){
		f = 1;
		break;
	      }
	    }
	    if(m != k){
	      if(table[temp2[i][j][m][l]][temp2[i][j][k][l]] == 0){
		f = 1;
		break;
	      }
	    }
	    if(m != l){
	      if(table[temp2[i][j][k][m]][temp2[i][j][k][l]] == 0){
		f = 1;
		break;
	      }
	    }
	    if(m != temp2[i][j][k][l]){
	      if(table[temp2[i][j][k][l]][m] == 0){
		f = 1;
		break;
	      }
	    }
	  }
	  if(f == 1) count++;
	}
      }
    }
  }

  cout<<count<<endl;
  
  
  return 0;
}



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

int N,M;
vector< vector<int> >R;
int res;

void make(vector<int> M){
	if(M.size()==0){
		for(int i=0;i<N;i++){
			vector<int> Next;
			Next.push_back(i);
			make(Next);
		}
		return;
	}

	for(int i=0;i<M[0];i++){
		bool f=true;
		vector<int> Next=M;
		Next.insert(Next.begin(),i);
		for(int j=0;j<M.size();j++){
			if(R[i][M[j]]==0){
				f=false;
				break;
			}
		}
		if(f) make(Next);
	}
	int point=0;
	if(M.size()>1){
		for(int i=0;i<M.size();i++){
			int temp=10000000;
			for(int j=0;j<M.size();j++){
				if(i==j) continue;
				temp=min(temp,R[M[i]][M[j]]);
			}
			point+=temp;
		}
	}
	res=max(point,res);
}
			

void solve()
{
	res=0;
	R.clear();
	R.resize(N,vector<int>(N,0));
	for(int i=0;i<M;i++){
		int x,y,r;
		cin>>x>>y>>r;
		x--;y--;
		R[x][y]=r;
		R[y][x]=r;
	}
	make(vector<int>(0));
	cout<<res<<endl;
}

int main()
{
	while(cin>>N>>M){
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())

cnt={'r':0,'s':0,'p':0}
for i in range(n):
  if i<=k-1:
    cnt[t[i]]+=1
  elif t[i]==t[i-k]:
    t[i]='o'
    continue
  else:
    cnt[t[i]]+=1
ans=p*cnt['r']+r*cnt['s']+s*cnt['p']
print(ans)

Measured memory_bytes: 4084
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = Input.Cin<int>();
        bool flag = false;
        for (int i = 0; i < N; i++) if (Input.Cin<int>() % 2 == 1) flag = true;
        Console.WriteLine(flag?"first":"second");
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    public static T Cin<T>()
    {
        if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        if (typeof(T) == typeof(int)) return (T)(object)int.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(long)) return (T)(object)long.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(string)) return (T)(object)(queue.Dequeue());
        else if (typeof(T) == typeof(double)) return (T)(object)double.Parse(queue.Dequeue());
        else return (T)(object)("");
    }
    public static T Line<T>()
    {
        foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        int c = queue.Count();
        if (typeof(T) == typeof(int[]))
        {
            int[] ret = new int[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<int>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(long[]))
        {
            long[] ret = new long[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<long>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(string[]))
        {
            string[] ret = new string[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<string>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(double[]))
        {
            double[] ret = new double[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<double>();
            return (T)(object)ret;
        }
        else return (T)(object)(0);
    }
}

Measured memory_bytes: 15296
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

vector<LL> fact;
vector<LL> inver(200001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 

int main(){
    LL N;cin >> N;
    vector<LL> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    set_combi();
    vector<LL> cum(N+1,0);
    for (int i = 0; i < N; i++) {
        cum[i+1] = (cum[i] + fact[N]*fpow(i+1,mod-2)%mod)%mod;
    }
    LL ans = 0;
    for (int i = 0; i < N; i++) {
        ans = (ans + (cum[N-i] + cum[i+1] - cum[1] )*a[i])%mod;

    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4976
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()
    a = li()

    s = sum(a)

    ans = 0

    for i in a:
        ans+=(s-i)*i
    
    print(ans//2)


main()


Measured memory_bytes: 22700