akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;



int main() {
	string s;
	cin >> s;
	long long a[500010];
	long long n = s.size()+1;

	a[0] = 0;
	if (s[0] == '<') {
		long long k = 0;
		while (s[k] == '<') {
			a[k + 1] = a[k] + 1;
			k++;
		}
	}

	for (long long i = 0; i < n-2; i++) {
		if (s[i] == '>' && s[i + 1] == '<') {
			a[i + 1] = 0;
			long long j = i + 1;
			while (s[j] == '<') {
				a[j + 1] = a[j] + 1;
				j++;
				if (j > n - 2)break;
			}
			j = i + 1;
			while (s[j - 1] == '>') {
				if (j == 1)a[j - 1] = a[j] + 1;
				else if (s[j - 2] == '>')a[j - 1] = a[j] + 1;
				else a[j - 1] = max(a[j - 1], a[j] + 1);
				j--;
				if (j < 1)break;
			}
		}
	}


	if (s[n - 2] == '>') {
		a[n - 1] = 0;
		long long k = n - 1;
		while (s[k - 1] == '>') {
			if(k==1)a[k - 1] = a[k] + 1;
			else if (s[k - 2] == '>')a[k - 1] = a[k] + 1;
			else a[k - 1] = max(a[k - 1], a[k] + 1);
			k--;
			if (k < 1)break;
		}
	}

	long long ans = 0;
	for (long long i = 0; i < n; i++)ans += a[i];
	cout << ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll sum = 0;
    REP(i, N) sum += A[i];

    REP(i, N/2){
    	sum -= 2*A[2*i+1];
    }

    vector<ll> B(N);
    B[0] = sum;
    REP(i, N-1){
    	B[i+1] = 2*A[i] - B[i];
    }
    REP(i, N) cout << B[i] << " ";
    cout << endl; 
    return 0;
}

Measured memory_bytes: 2944
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
from bisect import bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()
L = [LIST() for i in range(M)]
dic = defaultdict(int)

# for a, b in L:
    # dic[A[a]] = b
A.sort()
L = sorted(L, key=lambda x : x[1], reverse=True)
# print(L)
i = 0
# for i, a in enumerate(A):
for f, t in L:
    while f > 0 and i < N:
        if t > A[i]:
            A[i] = t
            f -= 1
            i += 1
        else:
            print(sum(A))
            exit()
print(sum(A))
    
    

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int k;

bool visited[MAX_N];
ll dist[MAX_N];

ll ans;

ll solve() {
  fill_n(visited, k + 1, false);
  fill_n(dist, k + 1, INF);

  deque<pair<int, ll>> deq;

  deq.push_front(make_pair(1, 0LL));

  ll ret = 0;

  while (!deq.empty()) {
    auto cur = deq.front();
    deq.pop_front();

    int node = cur.first;
    ll cost = cur.second;

    visited[node] = true;
    dist[node] = cost;

    if (node == 0) {
      ret = cost;
      break;
    }

    int next_p1 = (node + 1) % k;
    if (!visited[next_p1]) {
      if (dist[next_p1] > cost + 1LL) {
        deq.push_back(make_pair(next_p1, cost + 1LL));
      }
    }

    int next_t10 = (node * 10) % k;
    if (!visited[next_t10]) {
      if (dist[next_t10] > cost) {
        deq.push_front(make_pair(next_t10, cost));
      }
    }
  }

  return ret + 1LL;
}

int main(void) {
  // Here your code !
  scanf("%d", &k);

  ans = solve();

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

  return 0;
}


Measured memory_bytes: 2176
l,r=list(map(int, input().split()))
minmod=2018
if r-l>=2018:
	print(0)
else:
	for i in range(l,r+1):
		for j in range(i+1,r+1):
			minmod=min(minmod,(i*j)%2019)
	print(minmod)

Measured memory_bytes: 3188
#include <cstdio>

const int maxn = 510;

int n, m, a, b, x, y;

int main() {
	scanf("%d%d%d%d", &n, &m, &a, &b);
	if(n % a == 0 && m % b == 0) {
		puts("No");
		return 0;
	}
	x = 4000;
	y = x * (a * b - 1) + 1;
	y = -y;
	puts("Yes");
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			printf("%d%c", (i % a == 0 && j % b == 0) ? y : x, " \n"[j == m]);
		}
	}
	return 0;
}

Measured memory_bytes: 1536
import numpy as np
N = int(input())
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = np.zeros(N+1)
count = 0
for i in range(N):
  a = A[i] - B[i] -C[i]
  if a >= 0:
    count += B[i] + C[i]
  else:
    count += A[i]
    if A[i] - C[i] < 0:
      C[i+1] = B[i]
    else:
      C[i+1] = -a
if C[N] > 0:
  if A[N] < C[N]:
    count += A[N]
  else:
    count += C[N]
print(int(count))

Measured memory_bytes: 27352
// Math = ♥️

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
// #define ordered_set                            \
//     tree<ll, null_type, less<ll>, rb_tree_tag, \
//          tree_order_statistics_node_update>

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s, t;
    cin >> s >> t;

    ll ans = 0;
    for (int i = 0; i < sz(s); i++) {
        if (s[i] != t[i]) {
            ans++;
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 3820
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 1; i--) {
    if (a[i - 1] > a[i]) {
      a[i - 1]--;
    }
  }
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}


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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;

const int M = 2000002;

/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    VI a(n);
    FOR(i,0,n-1) cin >> a[i];
    
    int s = 0;
    for (int x : a) s += x;
    
    int atMost = s / 2;
    
    bitset <M> b;
    b[0] = 1;
    
    for (int x : a) {
        b |= b << x;
    }
    
    FORD(x,atMost,0) if (b[x]) {
        cout << s - x;
        return 0;
    }

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 1024
s=int(input())
l=[s]
if s!=1 and s!=2:
        for i in range(10**6):
                if l[i]%2==0:
                        l.append(int(l[i]/2))
                else:
                        l.append(int(3*l[i]+1))
                if l[i+1]==1:
                        break
        print(i+3)
else:
        print(4)


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

int func(string s,string t){
    int ans = 0;
    for(char c= 'a';c<='z';c++){
        bool founds=false, foundt = false;
        for(int i = 0;i<s.length();i++){
            if(s[i]==c){
                founds = true;
            }
        }
        for(int i = 0;i<t.length();i++){
            if(t[i]==c){
                foundt = true;
            }
        }
        if(founds && foundt) ans++;
    }
    return ans;
}

int main(){
    int N;
    string s;
    cin >> N >> s;
    int ans = 0;

    rep(i,N){
        int tmp = func(s.substr(0,i),s.substr(i));
        ans = max(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define rep(i,s,n) for(ll (i)=(s);(i)<(n);(i)++)
#define repd(i,n,s) for(ll (i)=(n-1);(i)>=(s);(i)--)
#define all(x) x.begin(),x.end()
#define size(x) ((ll)(x).size()
#define PB push_back

int main(){
  int a[3][3];
  bool b[3][3];
  rep(i,0,3){
      rep(j,0,3){
          cin >> a[i][j];
          b[i][j] = false;
      }
  }
  int n;
  cin >> n;
  vector<int> c(n);

  rep(i,0,n) cin >> c[i];

  rep(i,0,3){
      rep(j,0,3){
          rep(k,0,n){
              if(a[i][j]==c[k])
              b[i][j]=true;
          }
      }
  }
  rep(i,0,3){
        if(b[i][0] && b[i][1] && b[i][2]){ 
            cout << "Yes" << endl;
            return 0;
        }
        if(b[0][i] && b[1][i] && b[2][i]){ 
            cout << "Yes" << endl;
            return 0;
        }
    }

    if(b[0][0] && b[1][1] && b[2][2]){ 
        cout << "Yes" << endl;
        return 0;
    }
    if(b[0][2] && b[1][1] && b[2][0]){ 
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
   
 return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Scan()
	s := stdin.Text()
	var out int
	for _, i := range s {
		if i == '1' {
			out++
		}
	}
	fmt.Println(out)
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    for (int i = k; i < n; ++i) {
        if (a[i - k] < a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4032
dance = input()

for i in range(len(dance)):
    if i%2==0:
        if dance[i] != 'R' and dance[i] != 'D' and dance[i] != 'U':
            print("No")
            exit()
    else:
        if dance[i] != 'L' and dance[i] != 'D' and dance[i] != 'U':
            print("No")
            exit()

print("Yes")


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int a,b,m,n;
    int gcd(int a,int b);
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        if(a>b)
        {
            m=gcd(a,b);
            n=gcd(b,a%b);
            if(m==n)
            {
                printf("%d\n",m);
            }
        }
        else
        {
            int t;
            t=a;a=b;b=t;
            m=gcd(a,b);
            n=gcd(b,a%b);
            if(m==n)
            {
                printf("%d\n",m);
            }
        }
    }
    return 0;
}
int gcd(int a,int b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pll = pair < ll, ll >;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
 
int main(){
	ll a, b, c, d; cin >> a >> b >> c >> d;
	int a1 = ceil((c * 1.0)/ (b * 1.0));
	int a2 = ceil((a * 1.0) / (d * 1.0));
	if(a1 <= a2) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	// int flag = 0;
	// while(a > 0 && c > 0) {
	// 	if(!flag) {
	// 		c -= b;
	// 		flag = 1;
	// 	} else {
	// 		a -= d;
	// 		flag = 0;
	// 	}
	// 	cout << a  << " " << b << " " << c << " " << d << endl;
	// 	if(c <= 0) break; 
	// 	if(a <= 0) break;
	// }
	// if(a <= 0) {
	// 	cout << "No\n";
	// } else {
	// 	cout << "Yes\n";
	// }
}

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

namespace ABC96
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var a = int.Parse(s[0]);
            var b = int.Parse(s[1]);
            if (a > b)
            { 
                Console.WriteLine(a-1);
            }else
            Console.WriteLine(a);
        }
    }
}


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

using i64 = int64_t;

constexpr int INF = 1 << 30;

int dp[10004];

int main(){
    int d, l;
    cin >> d >> l;
    dp[0] = 0;
    for(int i=1;i<=d;++i)dp[i] = INF;
    for(int i=0;i<d;++i){
        dp[i+1] = min(dp[i+1], dp[i]+1);
        if(i+l <= d)dp[i+l] = min(dp[i+l], dp[i]+1);
    }

    cout << dp[d] << endl;

    return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <cstring>
using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
	int m,f,r;
 	cin >> m >> f >> r;
 	while(m!=-1||f!=-1||r!=-1){
	 	if(m==-1||f==-1) cout << "F" << endl;
	 	else if(m+f>=80) cout << "A" << endl;
	 	else if(m+f>=65) cout << "B" << endl;
	 	else if(m+f>=50) cout << "C" << endl;
	 	else if(m+f>=30)
		 	if(r>=50) cout << "C" << endl;
		 	else cout << "D" << endl;
	 	else cout << "F" << endl;

	 	cin >> m >> f >> r;
	}
}

int main() {
  solve();
  return 0;
}



Measured memory_bytes: 3096
n = int(input())
s = str(input())
ans = -1
for i in range(1, n):
    x = s[0:i]
    y = s[i:]
    temp = 0
    for j in range(26):
        c = chr(ord('a')+j)
        if c in x and c in y:
            temp += 1
    ans = max(ans, temp)
print(ans)


Measured memory_bytes: 39280
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  cout << (1000-n%1000)%1000 << endl;
  return 0;
}

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

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

	if (A % 2 != B % 2) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << (A + B) / 2 << endl;
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  
  long long sum = 0;
  
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  
  for(int i = 0; i < n; i++){
    cin >> b.at(i);
    sum += b.at(i);
  }
  
  for(int i = 0; i < n; i++){
    cin >> c.at(i);
  }
  
  for(int i = 0; i < n-1; i++){
    if(a.at(i+1)==a.at(i)+1){
      sum += c.at(a.at(i)-1);
    }
  }
  
  cout << sum << endl;
}

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

using namespace std;

typedef long long ll;
const int MAXN = 16;

int n, a[MAXN][MAXN], b[MAXN+1];
ll f[1<<MAXN], g[1<<MAXN];

inline int count(int x)
{
	int res = 0;
	for(int i=0;i<n;++i)
		if(x&(1<<i)) ++res;
	return res;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	const int MAXS = 1<<n;
	for(int s=1;s<MAXS;s++)
	{
		int num = 0; g[s] = 0;
		for(int i=0;i<n;i++)
			if(s & (1<<i)) b[++num] = i;
		for(int i=1;i<num;i++)
			for(int j=i+1;j<=num;j++)
				g[s] += a[b[i]][b[j]];
	}
	for(int s=1;s<MAXS;s++){
		for(int t=s;t;t=(t-1)&s){
			f[s] = max(f[s], f[s^t] + g[t]);
		}
	}
	printf("%lld\n",f[MAXS-1]);
	return 0; 
}

Measured memory_bytes: 1280
import sys
N = int(input())
W = [input() for _ in range(N)]

if len(set(W)) != len(W):
    print('No')
    sys.exit()

for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
// #include <numeric>
using namespace std;

#define ll long long

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

// template<class T>
// T gcd(T a, T b) {
// 	if (a == 0) return b;
// 	return gcd(b % a, a);
// }

int main()
{
    ll a, b, n;
    cin >> a >> b;
    n = gcd(a, b);

    ll ans = 1;
    for (ll i = 2; i * i < n; i++)
    {
        if (!(n % i))
        {
            ans++;
            while (!(n % i)) n /= i;
        }
    }

    if (n != 1) ans++;
    cout << ans << "\n";
}

Measured memory_bytes: 3604
@T=map {scalar reverse $_} ("dream","dreamer","erase","eraser");
$s=<>;
chomp($s);
$s=reverse($s);
$l=length($s);
for($c=0;$c<$l;){
	$k=-1;
	for($i=0;$i<4;$i++){
		if(substr($s,$c,length($T[$i])) eq $T[$i]){
			$k=length($T[$i]);
			last;
		}
	}
	if($k<0){
		print'NO';
		exit
	}
	$c+=$k;
}
print'YES'

Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

string S;
LL c[26] = {};

int main(){
	cin >> S;
	for(int i=0; i<S.size(); i++) c[S[i]-'a']++;
	LL ans = (LL)S.size() * (LL)(S.size()-1) / 2LL;
	for(int i=0; i<26; i++) ans -= c[i] * (c[i]-1) / 2LL;
	cout << ans+1LL << endl;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,k=MI()
ls=sorted(LI(),reverse=True)
ans=0
for i in range(k):
    ans+=ls[i]
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;

const ll inf = 5e15;
ll N;

ll min_time(const VV<ll> &times, ll PS, ll stage) {
    ll ret = times[stage][0];
    for(ll i = 0; i < N; i++) {
        if(!((PS >> i) & 1)) continue;
        ret = min(ret, times[stage][i + 1]);
    }
    return ret;
}

bool solve() {
    cin >> N;
    if(!N) return false;

    VV<ll> times(N, V<ll>(N + 1));
    for(auto &v : times) for(ll &e : v) cin >> e;

    V<ll> dp(1ll << N, inf);
    dp[0] = 0;

    for(ll S = 0; S < dp.size(); S++) {
        for(ll i = 0; i < N; i++) {
            if(!((S >> i) & 1)) continue;
            ll PS = S ^ (1ll << i);
            dp[S] = min(dp[S], dp[PS] + min_time(times, PS, i));
        }
    }

    cout << dp.back() << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



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

int main(){
  int s;
  cin >> s;
  int a = s % 100;
  int b = (s-a) / 100;
  if(1<=a&&a<=12){
    if(1<=b&&b<=12){
      cout << "AMBIGUOUS" << endl;
    }
    else
      cout << "YYMM" << endl;
  }
  else{
    if(1<=b&&b<=12)
      cout << "MMYY" << endl;
    else 
      cout << "NA" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
struct unionfind{
  private:
  int par[1401],treesize[1401];
  public:
  unionfind(int N){
    for(int i=0;i<N;++i){
      par[i]=i;
      treesize[i]=1;
    }
  }
  int root(int x){
    while(par[x]!=x){
      x=par[x]=par[par[x]];
    }
    return x;
  }
  bool unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return false;
    if(treesize[x]>treesize[y])swap(x,y);
    par[x]=y;
    treesize[y]+=treesize[x];
    return true;
  }
  bool parcheck(int x,int y){
    return root(x)==root(y);
  }
};
bool used[701],g[701][701];
bitset<800> bs(1);
int main(){
  // startupcpp();
  int i,j,N,M;
  scanf("%d %d",&N,&M);
  unionfind utree(N*2);
  while(M--){
    scanf("%d %d",&i,&j);
    --i;--j;
    if(i>j)swap(i,j);
    g[i][j]=true;
  }
  rep(i,N)For(j,i+1,N)if(!g[i][j]){
    utree.unite(i,j+N);
    utree.unite(j,i+N);
  }
  rep(i,N)if(utree.parcheck(i,i+N))break;
  if(i!=N){
    puts("-1");
    return 0;
  }
  rep(i,N){
    if(used[i])continue;
    int cnta=0,cntb=0;
    For(j,i,N)if(utree.parcheck(i,j)){
      ++cnta;
      used[j]=true;
    }
    For(j,N,N<<1)if(utree.parcheck(i,j)){
      ++cntb;
      used[j-N]=true;
    }
    bs=(bs<<cnta)|(bs<<cntb);
  }
  i=(N+1)>>1;
  while(!bs[i])--i;
  printf("%d",(i*(i-1)+(N-i)*(N-i-1))>>1);
}

Measured memory_bytes: 768
#include <iostream>

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

    int l, i = 0, a[n];
    int sum = 0;
    while (std::cin >> l) {
        a[i] = l;
        sum += a[i];
        i++;
        if (i >= n) {
            break;
        }
    }

    int max = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] >= max) {
            max = a[i];
        }
    }
    if (max < sum-max) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
N=int(input())
numbers=[]
for a in range(2):
    A=input().split()
    AS=[int(a) for a in A]
    numbers.append(AS)
answers=[]
for a in range(N):
    answer=0
    answer+=sum(numbers[0][:a+1])
    answer+=sum(numbers[1][a:])
    answers.append(answer)
print(max(answers))


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int oct[12000]={};
    int dec[12000]={};

    rep(i,12000){
        oct[i] = 0.08*i;
        dec[i] = 0.10*i;

        //db3(i,oct[i],dec[i]);ln;
    }


    int a,b;
    cin>>a>>b;

    rep(i,12000){
        if(oct[i]==a && dec[i]==b){
            cout<<i<<endl;
            return 0;
        }
    }
    //cout <<fixed<<setprecision(16)<< << endl;
    
    cout<<-1<<endl;
    
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N;
vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

  string s;
  cin >> s;
  string ans = "";
  rep(i, s.length()) {
   ans += "x";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

N, u, v = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for a, b in X:
    graph[a].append(b)
    graph[b].append(a)


def bfs(s):
    INF = 10 ** 9 + 7
    d = [INF] * (N + 1)
    d[s] = 0
    q = deque([s])
    while q:
        u = q.popleft()
        for v in graph[u]:
            if d[v] > d[u] + 1:
                d[v] = d[u] + 1
                q.append(v)

    return d


to = bfs(u)
ot = bfs(v)

ans = 0
for i, (a, b) in enumerate(zip(to, ot)):
    if a < b:
        ans = max(ans, b)
print(ans - 1)


Measured memory_bytes: 103964
// https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}


const MOD: usize = 1e6 as usize + 3;

fn powmod(a: usize, p: usize, m: usize) -> usize {
    let mut ret = 1usize;
    let mut aa = a;
    let mut pp = p;
    while pp >= 1 {
        if pp & 1 == 1 {
            ret *= aa;
            ret %= m;
        }
        aa = aa * aa % m;
        pp >>= 1;
    }
    ret
}

fn inv(a: usize, m: usize) -> usize {
    powmod(a, m-2, m)
}

fn go(from: usize, n: usize, tbl: &Vec<usize>) -> usize {
    assert!(from >= 1);
    if from + n - 1 >= MOD {
        return 0;
    }
    tbl[from+n-1] * inv(tbl[from-1], MOD) % MOD
}

fn main() {
    input! {
        q: usize,
        queries: [(usize, usize, usize); q]
    };

    let mut tbl = vec![0; MOD];
    tbl[0] = 0;
    tbl[1] = 1;
    for i in 2..MOD {
        tbl[i] = tbl[i-1] * i % MOD;
    }

    for &(x, d, n) in &queries {
        if x == 0 {
            println!("{}", 0);
        } else if d == 0 {
            println!("{}", powmod(x, n, MOD) % MOD);
        } else {
            let from = x * inv(d, MOD) % MOD;
            let pw = powmod(d, n, MOD);
            println!("{}", go(from, n, &tbl) * pw % MOD);
        }
    }
}


Measured memory_bytes: 22008
import java.util.*;
import java.util.Map.*;

class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] $){
		int n=s.nextInt();
		TreeMap<Integer,Integer> m=new TreeMap<>();
		for(int i=0;i<n;++i)
			m.merge(Integer.parseInt(s.next()),1,Integer::sum);

		int r=0;
		while(!m.isEmpty()){
			Entry<Integer,Integer> e=m.pollLastEntry();
			
			if(Integer.bitCount(e.getKey())==1) {
				r+=e.getValue()/2;
				continue;
			}
			
			int q=(int)((Long.highestOneBit(e.getKey())<<1)-e.getKey());
			Integer f=m.get(q);
			if(f!=null){
				int v=Math.min(f,e.getValue());
				r+=v;
				if(f>v)
					m.merge(q,-v,Integer::sum);
				else
					m.remove(q);
			}
			
			//System.err.println(q);
			//System.err.println(m);
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 71396
#include <iostream>
using namespace std;
const long long INF = 1LL<<60;

int main() {
    int H, N; cin >> H >> N;
  	long long  A[1010], B[1010];
    long long dp[10010];
    for (int i = 0; i < N; ++i) cin >> A[i] >> B [i];
    for (int i = 0; i < 10010; ++i) dp[i] = INF;
    dp[0] = 0;
    for (int i = 1; i < H+1; ++i) {
      for(int j = 0;j<N; ++j){
        if(i>=A[j]){
          dp[i] = min(dp[i], dp[i-A[j]]+B[j]); 
        }
        else{
          dp[i] = min(dp[i], B[j]);
        }
      }
    }
    cout << dp[H] << endl;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(1000000)
n=input()
def f(x):
    if len(x)>1:
        
        a=0
        for i in range(len(x)):
            a+=int(x[i])
    
        f(str(a))
    else:
    
        if x=="9" or x=="0":
            print("Yes")
            return
        else:
            print("No")
            return
f(n)

Measured memory_bytes: 9340
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;
const ll MOD = 1000000007;

vector<int> G[200010];
int ABC[200010][2];
bool er[200010];

int main() {
	for (int i = 0;i < 200010;i++)ABC[i][0] = ABC[i][1] = er[i] = 0;
	int N, M, a, b;
	cin >> N >> M;
	string S;
	cin >> S;
	for (int i = 0;i < M;i++) {
		cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	queue<int> Q;
	for (int i = 0;i < N;i++) {
		for (int x : G[i]) {
			if (S[x] == 'A') {
				ABC[i][0]++;
			}
			if (S[x] == 'B') {
				ABC[i][1]++;
			}
		}
		if (ABC[i][0] == 0 || ABC[i][1] == 0) {
			Q.push(i);
			er[i] = 1;
		}
	}
	bool ab = 0;
	while (!Q.empty()) {
		a = Q.front();
		Q.pop();
		if (S[a] == 'A')ab = 0;
		else ab = 1;
		for (int x : G[a]) {
			ABC[x][ab]--;
			if (ABC[x][ab] == 0 && !er[x]) {
				Q.push(x);
				er[x] = 1;
			}
		}
	}
	for (int i = 0;i < N;i++) {
		if (!er[i]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 12676
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
ll qpow(ll x, ll k) {
    ll r = 1;
    while(k) {
        if(k & 1) r = r * x % MOD;
        k >>= 1;
        x = x * x % MOD;
    }
    return r;
}
ll x[N], y[N], n, m;
void up(ll& a, ll b) {
    a += b;
    a %= MOD;
}
int main() {
    cin >> n >> m;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for(int i = 0; i < m; i++) {
        cin >> y[i];
    }
    for(int i = 1; i < m; i++) {
        ans += 1LL * i * (m-i) % MOD * (n-1) % MOD * (y[i] - y[i-1]) % MOD * (x[1] - x[0]) % MOD;
    }
    ll res = ans;
    for(int i = 2; i < n; i++) {
        res = res * qpow(i-1, MOD - 2) % MOD * qpow(n-i+1, MOD-2) % MOD;
        res = res * i * (n-i) % MOD;
        res = res * qpow(x[i-1] - x[i-2], MOD-2) % MOD * (x[i] - x[i-1]) % MOD;
        up(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import Foundation

private func readInt() -> [Int]{
    return readLine()!.split(separator: " ").map{Int($0)!}
}

func mainB() {
    let line = readInt()
    var A = line[0]
    let B = line[1]
    var C = line[2]
    let D = line[3]
    
    while true {
        C -= B
        if C <= 0 {
            print("Yes")
            return
        }
        A -= D
        if A <= 0 {
            print("No")
            return
        }
    }
}

mainB()


Measured memory_bytes: 13632
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  string s;
  cin >> s;
  int n=s.size();
  int ans=100;
  char a[26];
  for(int i=0;i<26;i++) a[i]='a'+i;
  for(int i=0;i<26;i++){
    int x[n];
    for(int j=0;j<n;j++){
      if(s[j]==a[i]){
        x[j]=1;
      }
      else{
        x[j]=0;
      }
    }
   int p=0;
   int count=0;
    for(int j=0;j<n;j++){
      if(x[j]==0){
        count++;
      }
      else{
        p=max(p,count);
        count=0;
      }
    }
    p=max(p,count);
    ans=min(ans,p);
  }
  cout << ans << endl;
}

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

const int INF = 1e+9+7;
const int MAX = 1e+5;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
    int Q;
    cin >> Q;
    vector<int> S(MAX+1,0);
    vector<bool> sosu(MAX+1);
    rep(i,MAX+1){
        sosu[i]=IsPrime(i);
    }

    rep2(i,2,MAX){
        if(i%2==0) S[i+1]=S[i];
        else if(sosu[i]==true&&sosu[(i+1)/2]==true) S[i+1]=S[i]+1;
        else S[i+1]=S[i];
    }

    vector<int> l(Q),r(Q);
    rep(i,Q) cin >> l[i] >> r[i];
    rep(i,Q){
        cout << S[r[i]+1] - S[l[i]] << endl;
    }

}

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

int main() {
  int A;
  int B;
  int C;
  cin >> A >> B >> C;
  int t = A;
  A = B;
  B = t;
  t = A;
  A = C;
  C = t;
  cout << A << " " << B << " " << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin,(x).end()

int main(){
  vector<int> a(3);
  rep(i,3){cin >> a[i];}
  sort(a.begin(),a.end());
  
  int kind = 1;
  for(int i = 1; i < 3; i++){
    if(a[i] != a[i-1]) kind++;
  }
  
  cout << kind << endl;
}

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

class UnionFind {
public:
vector<int> Parent;

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

int root(int A) {
  if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
}

int size(int A) {
  return -Parent[root(A)];
}

bool connect(int A, int B) {
  A = root(A);
  B = root(B);
  if (A == B) {
    return false;
  }
  if (size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};

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

  vector<pair<int,int>> vec;
  for (int i = 0; i < m; i++)
  {
    int a,b;
    cin >> a >> b;
    vec.emplace_back(a-1,b-1);
  }

  int ans = 0;
  for (int i = 0; i < m; i++)
  {
    UnionFind uni(n);
    for (int j = 0; j < m; j++) if(i!=j) uni.connect(vec[j].first,vec[j].second);
    
    set<int> roots;
    for (int k = 0; k < n; k++) roots.insert(uni.root(k));
    if(roots.size()>1) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
  int N, P[100];
  while (scanf("%d", &N) == 1) {
    for (int i = 0; i < N; i++)
      scanf("%d", P+i);
    sort(P, P+N);
    int s = 0;
    for (int i = 0; i < N; i++)
      s += P[i] * (N-i);
    printf("%d\n", s);
  }
  return 0;
}

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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define vec vector
#define countSetBits(x) __builtin_popcountll(x)
#define trailingz(x) __builtinctzll(x)
#define leadingz(x) __builtinclzll(x)
#define maxbit(x) __lg(x)
#define minbit(x) __builtin_ffs(x) //lsb index+1
#define debug(args...) cerr << "["#args"] = ["; dbg,args; cerr << "]" << endl;
struct debugger {
    template<typename T> debugger& operator , (const T& v) {    
        cerr<<v<<" ";    
        return *this;
    }
} dbg;
//debug(n, x, s, c);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,n,m,mx,mn,flag,sum=0;
    cin>>n>>k;
    ll a[n],h[n];
    for(i=0;i<n;i++)
        cin>>h[i];
    a[0]=0;
    for(i=1;i<n;i++)
    {
        mx=1000000000;
        for(j=max(i-k,(ll)0);j<i;j++)
        {
            mx=min(mx,abs(h[i]-h[j])+a[j]);
            
        }
        a[i]=mx;
    }
    cout<<a[n-1];
    return 0;
       
}

Measured memory_bytes: 5116
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a, sum = 0;
	cin >> a;
	if(a>=1000 && a<10000)a=999;
	if (a == 100000) {
		a = 99999;
	}
	if (a >= 10000 && a < 100000) {
		sum += a + 1 - 10000;
		a = 999;
	}
	if (a >= 100 && a < 1000) {
		sum += a + 1 - 100;
		a = 9;
	}
	if (a >= 10) {
		sum += 9;
	} else {
		sum += a;
	}
	cout << sum << endl;

	return 0;
}



Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, L;
ll d[333][333], g[333][333];
queue <int> q;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   scanf ("%d%d%d", &n, &m, &L);
   for (int i = 1; i <= n; i ++) {
      for (int j = 1; j <= n; j ++)
         d[i][j] = g[i][j] = inf;
      d[i][i] = g[i][i] = 0;
   }
   for (int i = 1; i <= m; i ++) {
      int x, y, cost;
      scanf ("%d%d%d", &x, &y, &cost);
      if (cost > L) continue;
      d[x][y] = min (d[x][y], (ll)cost);
      d[y][x] = min (d[y][x], (ll)cost);
   }
   for (int k = 1; k <= n; k ++)
      for (int i = 1; i <= n; i ++)
         for (int j = 1; j <= n; j ++)
            d[i][j] = min (d[i][j], d[i][k] + d[k][j]);
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= n; j ++)
         if (d[i][j] <= L)
            g[i][j] = 1;
         else 
            g[i][j] = inf;
   for (int k = 1; k <= n; k ++)
      for (int i = 1; i <= n; i ++)
         for (int j = 1; j <= n; j ++)
            g[i][j] = min (g[i][j], g[i][k] + g[k][j]);
   int query;
   scanf ("%d", &query);
   while (query --) {
      int a, b;
      scanf ("%d%d", &a, &b);
      ll ans = g[a][b];
      if (ans == inf) ans = 0;
      printf ("%lld\n", -- ans);
   }
}

int main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   //boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}

Measured memory_bytes: 2048
max_n=10**6
mod=10**9+7

frac=[1]
for i in range(1,max_n+1):
  frac.append((frac[-1]*i)%mod)

inv=[1,1]
inv_frac=[1,1]
for i in range(2,max_n):
  inv.append((mod-inv[mod%i]*(mod//i))%mod)
  inv_frac.append((inv_frac[-1]*inv[-1])%mod)
  
def perm(m,n):
  if m<n:
    return 0
  if m==1:
    return 1
  return (frac[m]*inv_frac[m-n])%mod

def comb(m,n):
  if m<n:
    return 0
  if m==1:
    return 1
  return (frac[m]*inv_frac[n]*inv_frac[m-n])%mod




n,m=map(int,input().split())
l=[]
for i in range(2,int(m**0.5)+1):
  if m%i==0:
    c=0
    while m%i==0:
      m//=i
      c+=1
    l.append(c)
if m!=1:
  l.append(1)

r=1
for i in l:
  r=(r*comb(n+i-1,i))%mod
print(r)

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6");
            WillReturn.Add("1 2 3 4 5 6");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2");
            WillReturn.Add("10 -10");
            //20
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
        int UB = AArr.GetUpperBound(0);

        long TotalSum = 0;
        Array.ForEach(AArr, X => TotalSum += X);

        long Answer = long.MaxValue;

        long RunSum = 0;
        for (int I = 0; I <= UB - 1; I++) {
            RunSum += AArr[I];

            long OtherSum=TotalSum-RunSum;

            long AnswerKouho = Math.Abs(RunSum - OtherSum);
            if (Answer > AnswerKouho)
                Answer = AnswerKouho;
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 35676
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  if X[i][2] > 0:
    x, y, h = X[i][0], X[i][1], X[i][2]
    break
for i in range(0, 101):
  for j in range(0, 101):
    H = h + abs(x-i) + abs(y-j)
    a = 0
    for k in range(N):
      if X[k][2] == max(H - abs(X[k][0]-i) - abs(X[k][1]-j), 0):
        continue
      else:
        a = 1
        break
    if a == 0:
      print(i, j, H, sep=' ')
      break
  else:
    continue
  break
    
      

Measured memory_bytes: 9132
#include <stdio.h>
void s(int *a,int *b){int i=*a;*a=*b;*b=i;}
void c(char *a,char *b){char i=*a;*a=*b;*b=i;}
void sB(int *A,char *C,int a){
  int i,j;
  for(i=0;i<a-1;i++)
    for(j=a-1;j>i;j--)
      if(A[j]<A[j-1]){
	s(&A[j],&A[j-1]);
	c(&C[j],&C[j-1]);
      }
}  
void sS(int *A,char *C,int a){
  int i,j;
  for(i=0;i<a;i++){
    int m=i;
    for(j=i;j<a;j++)
      if(A[j]<A[m])
	m=j;
    if(A[i]!=A[m]){
      s(&A[i],&A[m]);
      c(&C[i],&C[m]);
    }
  }
}

int cS(int *Ac,char *Cc,int *A,char *C,int N){
  int n=0;
  for(n=0;n<N-2;n++){
    if(Ac[n]==Ac[n+1]){
      int m=0;
      while((Ac[n]==Ac[n+1])&&(n<N-2)){
	while(Ac[n]!=A[m])
	  m++;
	if(Cc[n]!=C[m])
	  return 1;
	n++; m++;
      }
    }
  }
  return 0;
}

int main(void){
  int n,N,No[36],Nb[36],Ns[36];char C[36],Cb[36],Cs[36];
  scanf("%d\n",&N);
  for(n=0;n<N;n++){
    scanf("%c%d ",&C[n],&No[n]);
    Cb[n]=C[n];Cs[n]=C[n];Nb[n]=No[n];Ns[n]=No[n];
  }
  sB(Nb,Cb,N);
  for(n=0;n<N-1;n++)
    printf("%c%d ",Cb[n],Nb[n]);
  printf("%c%d\n",Cb[N-1],Nb[N-1]);
  if(cS(Nb,Cb,No,C,N))
    printf("Not Stable\n");
  else
    printf("Stable\n");
  sS(Ns,Cs,N);
  for(n=0;n<N-1;n++)
    printf("%c%d ",Cs[n],Ns[n]);
  printf("%c%d\n",Cs[N-1],Ns[N-1]);
  if(cS(Ns,Cs,No,C,N))
    printf("Not stable\n");
  else
    printf("Stable\n");
  return 0;
}

Measured memory_bytes: 612