akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N;
long long a[100010][3];

long long dp[100010][3];

int main()
{
    cin >> N;
    rep(i,N){
        rep(j,3){
            cin >> a[i][j];
        }
    }

    rep(i,N){
        rep(j,3){
            rep(k,3){
                if(j == k) continue;
                chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }

    long long res = 0;
    rep(i,3) chmax(res,dp[N][i]);
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4992
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        long[] a = new long[10001];
        long counter = 0;

        for (int i = 1; i <= n; i++)
        {
            a[i] = int.Parse(input[i - 1]);
        }
        for (int i = 1; i <= n; i++)
        {
            while (a[i] % 2 == 0)
            {
                a[i] /= 2;
                counter++;
            }
        }
        Console.WriteLine(counter);
    }
}


Measured memory_bytes: 13920
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
int N;
int dp[200];
int NG[3];

int main(){
  string s;
  cin>>s;
  int k;
  cin>>k;
  ll cnt1=1,cnt2=1,cnt3 =1;
  bool test = true;
  ll sum = 0;
  ll perf = true;
  
  bool st = false;
  for(int i = 0; i < s.length();i++){
    if(s[i]==s[i+1]) {
      cnt1++;
    }
    else {
      sum+=cnt1/2;
      cnt1 = 1;
    }
  }
  
  for(int i = 0; i < s.length()-1;i++){
    if(s[i]==s[i+1]){
      cnt2++;
    }
    else{
      perf = false;
      break;
    }
  }
  for(int i = s.length()-1; i >= 0;i--){
    if(s[i]==s[i-1]){
      cnt3++;
    }
    else{
      break;
    }
  }
  
  
  if(perf){
    cout<<(s.length()*k)/2<<endl;
    return 0;
  }
  if(s[0]==s[s.length()-1]) cout<<sum*k-(cnt2/2+cnt3/2-(cnt2+cnt3)/2)*(k-1)<<endl;
  else cout<<sum*k<<endl;
  return 0;
}


Measured memory_bytes: 256
import bisect
X,Y,A,B,C=map(int,input().split())

AList=list(map(int,input().split()))
BList=list(map(int,input().split()))
CList=list(map(int,input().split()))

AList.sort(reverse=True)
BList.sort(reverse=True)
CList.sort(reverse=True)

alist = AList[0:X] + BList[0:Y]
clist = CList
alist.sort()
ans = sum(alist)
cnt = 0

for i in range(C):
  a = clist[i]
  b = bisect.bisect_left(alist,a)
  if i < b:
    ans += a
    cnt += 1



aa = sum(alist[:cnt])

print(int(ans -aa))

Measured memory_bytes: 22720
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int A = int.Parse(Console.ReadLine());
        int B = int.Parse(Console.ReadLine());
        int C = int.Parse(Console.ReadLine());
        int D = int.Parse(Console.ReadLine());

        Console.WriteLine(Math.Min(A, B) + Math.Min(C,D));
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <iostream>
#include <set>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

typedef unsigned long long ull;

ull const B = 9973ULL;
ull const Binv = 9063375710536127837ULL;

int main(){
    int n,m;
    while(scanf("%d %d", &n,&m)!=EOF){
        ull Bmax = 1;
        int L=0,R=0;
        static char s[300020];
        scanf("%s",s);
        ull H = s[0];
        set<ull> hs;
        while(m--){
            char q[4];
            scanf("%s",q);
            if(q[0]=='R'){
                if(q[1]=='+'){
                    R++;
                    Bmax *= B;
                    H = H+s[R]*Bmax;
                }

                else {
                    H = H-s[R]*Bmax;
                    Bmax = Bmax*Binv;
                    R--;
                }

            } else {
                if(q[1]=='+'){
                    H = (H-s[L])*Binv;
                    Bmax *= Binv;
                    L++;
                }

                else {
                    L--;
                    H = H * B + s[L];
                    Bmax *= B;
                }

            }

            hs.insert(H);
        }

        cout << hs.size() << endl;
    }
}

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

#define int long long
#define rep(i, n) for (int i = 0; (int) (i) < n; i++)
#define reps(i, n) for (int i = 1; (int) (i) <= n; i++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << x << endl
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) { return b < a && (a = b, true); }
struct SetUp { SetUp() { cout << fixed << setprecision(20); }; } setUp;

int A, B;
signed main() {
    cin >> A >> B;
    int K = gcd(A, B);
    int ans = 0;
    int rt = round(sqrt(K));
    reps(i, rt) {
        if (K % i == 0) { ans++; }
        if (i == 1) { continue; }
        while (K % i == 0) { K /= i; }
    }
    if (K != 1) { ans++; }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;

struct edge {
  int to;
  int weight;
};

const int N = 1e5 + 10;
int n;
vector<edge> g[N];
ll dist[N];
bool color[N];

void dfs(int x, int p) {
  // dist[x] already calculated
  color[x] = dist[x] & 1;
  for (edge &e : g[x]) {
    if (e.to == p) continue;
    dist[e.to] = dist[x] + e.weight;
    dfs(e.to, x);
  }
}

int main() {
  
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    g[u].pb({v, w});
    g[v].pb({u, w});
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    printf("%d\n", int(color[i]));
  }

  return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int ara[n+5];
  for(int i=1;i<=n;i++)cin>>ara[i];
  if(n%2==0)
  {
    for(int i=n;i>=2;i-=2)cout<<ara[i]<<" ";
    for(int i=1;i<=n-1;i+=2)cout<<ara[i]<<" ";
    cout<<endl;
  }
  else
  {
    for(int i=n;i>=1;i-=2)cout<<ara[i]<<" ";
    for(int i=2;i<=n-1;i+=2)cout<<ara[i]<<" ";
    cout<<endl;
  }
}

Measured memory_bytes: 2944
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll gcd(ll a, ll b){//計算量はO(log(max(a,b))
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll kai(ll x){
  if(x == 1) return 1;
  return x * kai(x-1) % MOD;
}



int main(){
  int N; cin >> N;
  string S; cin >> S;
  int now = 0;
  ll m = 0;
  rep(i, N){
    if(S[i] == 'I'){
      now++;
    }else{
      now--;
    }
    m = max(m, now);
  }
  cout << m << endl;
}


Measured memory_bytes: 256
sortsecond = lambda val:val[1]
n = int(input())
l = []
t=0
for _ in range(n):
    a,b = map(int,input().split())
    l.append((a,b))
l.sort(key=sortsecond)
i=0
while(i<n):
    t+=l[i][0]
    if t>l[i][1]:
        print("No")
        break
    if i==n-1:
        print("Yes")
    i+=1

Measured memory_bytes: 31860
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    const int N = 1e5;
    vector <int> ans(N, 0);
    for (int x = 1; x <= 100; x++) {
        for (int y = 1; y <= 100; y++) {
            for (int z = 1; z <= 100; z++) {
                int num = x*x + y*y + z*z + x*y + y*z + z*x;
                ans[num]++;
            }
        }
    }
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}




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

namespace ABC127_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = NM[0];
            var M = NM[1];
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();

            var d = new Dictionary<long, long>();
            for (int i = 0; i < A.Length; i++)
            {
                if (d.ContainsKey(A[i]))
                {
                    d[A[i]]++;
                }
                else
                {
                    d.Add(A[i], 1);
                }
            }

            for (int i = 0; i < M; i++)
            {
                var BC = Console.ReadLine().Split().Select(long.Parse).ToArray();
                var B = BC[0];
                var C = BC[1];
                if (d.ContainsKey(C))
                {
                    d[C]+=B;
                }
                else
                {
                    d.Add(C, B);
                }
            }

            var newd = d.OrderByDescending(x => x.Key);

            long c = 0;
            long ans = 0;
            foreach (var item in newd)
            {
                if (N >= c+item.Value)
                {
                    ans += item.Key * item.Value;
                    c += item.Value;
                }
                else
                {
                    ans += item.Key * (N - c);
                    break;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 35644
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    cout<<accumulate(v.begin(),v.begin()+k,0)<<endl;
}

Measured memory_bytes: 3620
N = int(input())
A_list = list(map(int, input().split(' ')))

sum_a_list = sum(A_list)
middle_num = sum_a_list/2

temp_sum = 0

middle_block = -1

for j in range(len(A_list)):
    temp_sum += A_list[j]
    if temp_sum == middle_num:
        print(0)
        exit(0)
    if temp_sum > middle_num:
        middle_block = j
        break


diff_go_right = abs(sum(A_list[:middle_block]) - sum(A_list[middle_block:]))
diff_go_left = abs(sum(A_list[:middle_block+1]) - sum(A_list[middle_block+1:]))

print(min(diff_go_right, diff_go_left))

Measured memory_bytes: 26220
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main() //input->compute->output
{
        int N, M;
        cin >> N >> M;
        vector<string> A(N), B(M);
        rep(i, N)
        {
                cin >> A[i];
        }

        rep(i, M)
        {
                cin >> B[i];
        }

        int c, r;
        bool flag = false;

        rep(h, N - M + 1)
        {
                rep(i, N - M + 1)
                {
                        if (A[h].substr(i, M) == B[0])
                        {
                                r = h;
                                c = i;
                                int m = 0;
                                for (int k = r; k < r + M; k++)
                                {
                                        if (A[k].substr(c, M) == B[m])
                                        {
                                                m++;
                                        }
                                }
                                if (m == M)
                                {
                                        cout << "Yes" << endl;
                                        return 0;
                                }
                        }
                }
        }

        cout << "No" << endl;
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    int n_a, n_b;
    string s_a, s_b;

    for(int i=0; i<b;i++){
        s_a+=to_string(a);
    }
    for(int i=0; i<a;i++){
        s_b+=to_string(b);
    }

    n_a = stoi(s_a);
    n_b = stoi(s_b);

    if(a<b){
        cout << n_a << endl;
    }
    else{
        cout << n_b << endl;
    }

    return 0;
}


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

int main(int argc, char const* argv[])
{
    ll x;
    cin >> x;

    ll ans = 0;
    ans += x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <numeric>

int main() {
	usize n;
	::std::cin >> n;
	::std::vector<i64> a(n), b(n);
	for (const auto i : rep<>(0, n)) {
		::std::cin >> a[i] >> b[i];
	}
	i64 ans = 0;
	::std::vector<usize> idx(n);
	::std::iota(idx.begin(), idx.end(), 0);
	::std::sort(idx.begin(), idx.end(), [&](usize l, usize r) {
		return a[l] + b[l] > a[r] + b[r];
	});
	for (const auto i : rep<>(0,n)) {
		if (i % 2 == 0) {
			ans += a[idx[i]];
		}
		else {
			ans -= b[idx[i]];
		}
	}
	::std::cout << ans << ::std::endl;
	return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7


int main(){
  string s,t;
  cin>>s;cin>>t;
  VE sv,tv;
  REP(i,s.size()){
    sv.push_back(s[i]-'a');
  }
  REP(i,t.size()){
    tv.push_back(t[i]-'a');
  }
  sort(sv.begin(),sv.end());
  sort(tv.begin(),tv.end(),greater<int>());
  //REP(i,sv.size())print(sv[i]);///
  //REP(i,tv.size())print(tv[i]);///
  REP(i,sv.size()){
    if(sv[i]<tv[i]){
      print("Yes");return 0;
    }else if(sv[i]>tv[i]){
      print("No");return 0;
    }
  }
  if(sv.size()==tv.size()){print("No");}
  else {print("Yes");}
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, m = MI()
    a = LI()

    a.sort()

    counter = cl.Counter({})

    for i in range(m):
        b, c = MI()
        counter.update({c: b})
    items = counter.items()
    items = sorted(items, key=lambda x: x[0], reverse=True)
    values, counts = map(list, zip(*items))

    lergest = 0
    finish = False
    for i in range(n):

        while not finish and a[i] > values[lergest]:
            lergest += 1
            if lergest == len(values):
                finish = True
                break
        if finish:
            break
        a[i] = values[lergest]
        counts[lergest] -= 1
        if counts[lergest] == 0:
            lergest += 1
            if lergest == len(values):
                break
    print(sum(a))


main()


Measured memory_bytes: 112844
#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]

use std::{cmp, fmt};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};

fn main() {
    let (n, xs) = {
        let mut sc = InputScanOnce::new(io::stdin(), 1024);
        let n = sc.next();
        (n, sc.vec::<u64>(n))
    };
    let mut vs = xs.iter().cloned().collect::<Vec<_>>();
    vs.sort();
    let stdout = io::stdout();
    let mut stdout = BufWriter::new(stdout.lock());
    let x1 = vs[n / 2 - 1];
    let x2 = vs[n / 2];
    for j in 0..n {
        if x1 < xs[j] {
            writeln!(stdout, "{}", x1).unwrap();
        } else {
            writeln!(stdout, "{}", x2).unwrap();
        }
    }
    stdout.flush().unwrap();
}

struct InputScanOnce {
    buf: Vec<u8>,
    pos: usize,
}

#[allow(dead_code)]
impl InputScanOnce {
    fn new<R: Read>(mut reader: R, estimated: usize) -> Self {
        let mut buf = Vec::with_capacity(estimated);
        let _ = io::copy(&mut reader, &mut buf).unwrap();
        InputScanOnce { buf: buf, pos: 0 }
    }

    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        T::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
        T3::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        T::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                let l = self.next::<String>();
                l.as_bytes().iter().cloned().map(&mut f).collect()
            })
            .collect()
    }
}


Measured memory_bytes: 10232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define pii pair<int , int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll)INF;
const int MAX = 2005;
const int LOG = 20;
int f(int a)
{
	int ans = 0;
	while(a)
	{
		a >>= 1;
		ans += a;
	}
	return ans;
}
int c(int n , int k)
{
	return f(n) == f(k) + f(n - k);
}
int main()
{
	int n;
	scanf("%d" , &n);
	vector<int> a(n);
	for(auto &x : a)
		scanf("%1d" , &x);
	vector<int> b(n - 1);
	bool was1 = false;
	n--;
	for(int i = 0; i < n; i++)
	{
		b[i] = abs(a[i] - a[i + 1]);
		was1 |= b[i] == 1;
	}
	if(was1)
	{
		for(int i = 0; i < n; i++)
			if(b[i] == 2)
				b[i] = 0;
	}
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		ans ^= b[i] * c(n - 1, i);
	}
	cout << ans;
}


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

int a[12] = {111, 222, 333, 444, 555, 666, 777, 888, 999};

int main(int argc, char *argv[]) {  
	int n;
	std::cin >> n;
	std::cout << a[std::lower_bound(a, a+9, n)-a];
}

Measured memory_bytes: 256
### constant

N = 3
NN = N * N

DIRS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### main

ch2xy = {}
for y in (0...N)
  for x in (0...N)
    id = y * N + x
    ch2xy[('A'.ord + id).chr] = [x, y]
  end
end
#p ch2xy

zmtx = NN.times.map{0.0}

loop do
  n = gets.to_i
  break if n == 0

  s, t, b = gets.split

  sx, sy = ch2xy[s]
  tx, ty = ch2xy[t]
  bx, by = ch2xy[b]
  #p [sx, sy, tx, ty, bx, by]

  pmtx = zmtx.clone
  pmtx[sy * N + sx] = 1.0

  n.times do
    pmtx0 = pmtx
    pmtx = zmtx.clone

    for y in (0...N)
      for x in (0...N)
        for dir in DIRS
          x0 = x + dir[0]
          y0 = y + dir[1]
          if x0 >= 0 && x0 < N && y0 >= 0 && y0 < N && (x0 != bx || y0 != by)
            pmtx[y0 * N + x0] += pmtx0[y * N + x] * 0.25
          else
            pmtx[y * N + x] += pmtx0[y * N + x] * 0.25
          end
        end
      end
    end
  end

  printf("%.8f\n", pmtx[ty * N + tx])
end

Measured memory_bytes: 6180
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>
#include <iomanip>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;


int main(){
    string s,t;
    cin >> s >> t;
    cout << t+s << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
 
using namespace std;
typedef long long ll;
 
int main(){
string n;
  cin>>n;
  ll count=0;
  ll count1=0;
  for(ll i=0;i<n.size();i++){
  if(n[i]=='0')
    count++;
    else
      count1++;
  }
  if(count1<count)
    cout<<count1*2;
    else
      cout<<count*2;

  return 0;
 
}
 

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 998244353
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 100010
ll fac[N],inv[N],ivf[N];
ll C(ll n,ll k){
    if(n<k)return 0;
    return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mod;
	x=x*x%mod;
    }
    return res;
}
ll n,x[210],y[210];
int main(){
    fac[0]=ivf[0]=inv[1]=1;
    for(int i=1;i<N;i++){
	if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
	fac[i]=fac[i-1]*i%mod;
	ivf[i]=ivf[i-1]*inv[i]%mod;
    }
  cin>>n;
  for(int i=0;i<n;i++){
      cin>>x[i]>>y[i];
  }
  ll ans=po(2,n)-C(n,0)-C(n,1)-C(n,2);
  for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
      bool th=0;
      for(int k=0;k<j;k++){
	  if(k!=i&&(y[k]-y[i])*(x[j]-x[i])==(x[k]-x[i])*(y[j]-y[i]))th=1;
      }
      if(th)continue;
      ll cnt=2;
      for(int k=j+1;k<n;k++){
	  if((y[k]-y[i])*(x[j]-x[i])==(x[k]-x[i])*(y[j]-y[i]))cnt++;
      }
      ll res=po(2,cnt)-C(cnt,0)-C(cnt,1)-C(cnt,2);
      mad(ans,-res);
  }
  ans%=mod;
  if(ans<0)ans+=mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		int r=0;
		for(int l=getInt();l>0;--l) {
			r+=1-getInt()+getInt();
		}
		System.out.println((r));
	}
}

Measured memory_bytes: 24404
from math import gcd

K = int(input())

def gcd_calc(x:int, y:int):
  while(y != 0):
    z = x % y;
    x = y;
    y = z;
  return x

output = 0

for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      output += gcd_calc(a, gcd_calc(b,c))

print(output)

Measured memory_bytes: 73940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f[520][100005],ans[100005];
int n,q,v[300005],w[300005];
typedef pair<int,int> pr;
vector<pr> qr[300005];
ll Query(int x,int va){
	if(x<512)return f[x][va];
	ll ret=Query(x/2,va);
	if(va>=v[x])ret=max(ret,Query(x/2,va-v[x])+w[x]);
	return ret;
}
void dp(int x){
	if(x>n)return ;
	if(x<512){
		for(int i=100000;i>=v[x];i--)f[x][i]=max(f[x/2][i],f[x/2][i-v[x]]+w[x]);
		for(int i=v[x]-1;i>=0;i--)f[x][i]=f[x/2][i];
		for(pr a:qr[x])ans[a.second]=f[x][a.first];
	}
	else {
		for(pr a:qr[x])ans[a.second]=Query(x,a.first);
	}
	dp(x*2),dp(x*2+1);
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d%d",&w[i],&v[i]);
	cin>>q;
	for(int i=1,x,y;i<=q;i++)scanf("%d%d",&x,&y),qr[x].push_back(make_pair(y,i));
	dp(1);
	for(int i=1;i<=q;i++)cout<<ans[i]<<'\n';
}


Measured memory_bytes: 415900
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 3005;

int main(){
    int n, m;
    cin >> n >> m;
    PQ(P) q;
    rep(i, n){
        int a,b;
        cin >> a >> b;
        q.push(P(a,b));
    }

    ll ans = 0;

    rep(i, m){
        auto p = q.top();
        q.pop();
        ans += p.first;
        if(p.second>1){
            p.second--;
            q.push(p);
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;
int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int sub(int a, int b){
	if(a  >= b )return a -  b;
	return a  - b + mod;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int const N  = 1e5 + 10;


/********************i**********************************/
void show(vector<int> a){
	for(auto b : a)cout << b << " " ;
	cout << endl;
}
void solve(){
	int n, k;
	cin >> n >> k;
	vector<int> dp(k +  5, 0);
	dp[0] = 1;
	for(int x =0; x<n; x++){
		vector<int> sum(k+5, 0);
		sum[0] = dp[0];
		for(int y = 1; y<= k+2; y++)
			sum[y] = add(sum[y-1], dp[y]);
		// show(sum);
		int a1;cin >> a1;
		for(int y = 1; y<= k; y++){
			int a = 0;
			if(y > a1)a = sub(sum[y] , sum[y-a1-1]);
			else a = sum[y];
			dp[y] =  a;
		}
		// show(dp);
	}
	if(k == 0){
		cout << 1 << "\n";
		return ;
	}
	cout << dp[k];
}


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

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i=0; i < s.size();i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3896
S = input()
for i in range(len(S)):
    if i%2 == 0:
        if S[i] != "R" and S[i] != "U" and S[i] != "D":
            print("No")
            exit()
    else:
        if S[i] != "L" and S[i] != "U" and S[i] != "D":
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

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

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<llong> a(n,0);
    vector<llong> b(n,0);
    vector<llong> c(n,0);
    REP(i,n)
    {
        cin>>a[i];
    }
    REP(i,n)
    {
        cin>>b[i];
    }
    REP(i,n)
    {
        cin>>c[i];
    }
    llong ans=0;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    for(int i=0; i<n; i++)
    {
        auto cit=upper_bound(c.begin(),c.end(),b[i]);
        llong cindex=cit-c.begin();
        llong ansc=c.size()-cindex;

        auto ait=lower_bound(a.begin(),a.end(),b[i]);
        llong aindex=ait-a.begin();
        ans+=aindex*ansc;
    }
    cout<<ans<<endl;
    return  0;
}

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

int main(void){
    int n;
    cin >> n;
    map<int, int> cnt;
    rep(i,n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    vector<int> key, value;
    for (auto itr : cnt) {
        key.push_back(itr.first);
        value.push_back(itr.second);
    }
    if (key.size() == 1) {
        cout << ((key[0] == 0) ? "Yes" : "No") << endl;
    } else if (key.size() > 3 || n % 3 != 0) {
        cout << "No" << endl;
    } else if (key.size() == 2) {
        cout << ((key[0] == 0 && value[0] == n/3) ? "Yes" : "No") << endl;
    } else {
        assert(key.size() == 3);
        cout << (((key[0] ^ key[1] ^ key[2]) == 0 && value[0] == n/3 && value[1] == n/3 && value[2] == n/3) ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 4860
from collections import deque

n, m = map(int, input().split())
ways = [tuple(map(int, input().split())) for _ in range(m)]
ans = [None] * (n+1)

hush = {}
hush[1] = True
for i in range(2, n+1):
    hush[i] = False
table = [list() for _ in range(n+1)]
for a, b in ways:
    table[a].append(b)
    table[b].append(a)

que = deque([1])
while len(que) > 0:
    room = que.popleft()
    for next in table[room]:
        if hush[next] == False:
            ans[next] = room
            que.append(next)
            hush[next] = True

print('Yes')
for i in range(2, n+1):
    print(ans[i])

Measured memory_bytes: 56592
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAX_V = 6010, MAX_CAP = 2010;

int dist[MAX_V][MAX_CAP]; // ?????? ??????????????????
using tup = tuple<int, int, int>;

int dijkstra(int start, int goal, int cap, const vector<vector<pair<int, int>>>& G, const set<int>& LPG) {

    for (int i = 0; i < MAX_V; ++i) for (int j = 0; j < MAX_CAP; ++j) dist[i][j] = INF;
	cap *= 10;

	dist[start][cap] = 0;
	priority_queue<tup, vector<tup>, greater<tup>> que; // ?????¢ ?????? ?????????LPG
	que.push(make_tuple(0, start, cap));

	while(!que.empty()){

		int cost, u, lpg; // ?????¢ ?????? ?????????LPG
		tie(cost, u, lpg) = que.top(); que.pop();

		if(dist[u][lpg] < cost) continue; // ?????????????????????????¶????

		for (const auto& tmp : G[u]){
			int v = tmp.first, e = tmp.second;
			int nlpg = lpg - e; // ??????v?????§?????£??????????????????LPG
			int ncost = cost + e; // ??????v?????§?????£??????????????????????????¢
			if(nlpg < 0) continue; // LPG????¶??????????

			if(LPG.count(v)) { // ??????v???LPG??????????????§???
				if(dist[v][cap] > ncost) {
					dist[v][cap] = ncost;
					que.push(make_tuple(ncost, v, cap));
				}
			}else{
				if(dist[v][nlpg] > ncost) {
					dist[v][nlpg] = ncost;
					que.push(make_tuple(ncost, v, nlpg));
				}
			}
		}
	}

	int ans = INF;
	for(int j = 0; j <= cap; j++) ans = min(ans, dist[goal][j]);
	return (ans != INF) ? ans : -1;

}

int main(void) {

	while(1) {
		int N, M, cap; cin >> N >> M >> cap;
		if(N == 0 && M == 0 && cap == 0) break;
		
		string src, dest;
		cin >> src >> dest;

		vector<string> c1(N), c2(N);
		vector<int> d(N);
		for (int i = 0; i < N; ++i) cin >> c1[i] >> c2[i] >> d[i];

		vector<string> s(M);
		for (int i = 0; i < M; ++i) cin >> s[i];
		
		set<string> city;
		city.insert(src), city.insert(dest);
		for (int i = 0; i < N; ++i) city.insert(c1[i]), city.insert(c2[i]);

		int cnt = 0;
		map<string, int> city2num;
		for(const auto& t : city) city2num[t] = cnt++;

		set<int> lpg;
		for (int i = 0; i < M; ++i) lpg.insert(city2num[s[i]]);
		vector<vector<pair<int, int>> >  G(6010);
		for (int i = 0; i < N; ++i) {
			G[city2num[c1[i]]].push_back(make_pair(city2num[c2[i]], d[i]));
			G[city2num[c2[i]]].push_back(make_pair(city2num[c1[i]], d[i]));
		}

		cout << dijkstra(city2num[src], city2num[dest], cap, G, lpg) << endl;
	}

	return 0;
}

Measured memory_bytes: 75608
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int a,b,c; cin >> a >> b >> c;
    if(a+b==c || a+c==b || b+c==a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

long long recurse(int n, int w, vector<int> &weights , vector<long long> &values, vector<vector<long long>> &dp)
{
    if(w <= 0 || n <=0) return 0;
    else
    {
        if(dp[w][n] != -1) return dp[w][n];
        else
        {
            if(w -weights[n-1] >= 0) dp[w][n] = max(recurse(n-1,w - weights[n-1],weights,values,dp) + values[n-1],recurse(n-1,w,weights,values,dp));
            else dp[w][n] = recurse(n-1,w,weights,values,dp);
            return dp[w][n];
        }
        
    }
    

}

int main(int argc, char const *argv[])
{
    int n, w;
    long long temp;
    cin >> n >> w;
    vector <int> weights(n,0);
    vector <long long> values(n,0);
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        weights[i] = temp;
        cin >> temp;
        values[i] = temp;
    }

    vector<vector<long long>> dp(w+1,vector<long long>(n+1,-1));

    cout << recurse(n,w,weights,values,dp);
                             
    return 0;
}


Measured memory_bytes: 83840
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    int O = 0;
    rep(i, 0, N)
    {
        int A;
        cin >> A;
        if (A % 2 == 1) ++O;
    }
    cout << (O % 2 == 0 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
ans=0
while not all(i==0 for i in h):
  for j in range(N):
    if h[j]>0:
      break
  for i in range(j,N):
    if h[i]==0:
      break
    h[i]-=1
  ans+=1
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}




ll N, A, B;

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

  if (N == 1) {
    if (A == B) {
      cout << "1\n";
    } else {
      cout << "0\n";
    }
  } else {
    if (A > B) {
      cout << "0\n";
    } else {
      ll ans = (N - 2) * (B - A) + 1;
      cout << ans << "\n";
    }
  } 

}

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

int main(){
  
  char a,b; cin >> a >> b;
  
  if(b == 'H'){
    if(a == 'H'){
      cout << 'H' << endl;
    }
    else if(a == 'D'){
      cout << 'D' << endl;
    }
  }
  
  else if(b == 'D'){
    if(a == 'H'){
      cout << 'D' << endl;
    }
    else if(a == 'D'){
      cout << 'H' << endl;
    }
  }
  
  return 0;
}
  
  


Measured memory_bytes: 256