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

int H,W;
int C[10][10];
int A[210][210];
const int Inf = 10000*100000+100;

int main(){
	while(cin >> H >> W  && H > 0){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				cin >> C[i][j];
			}
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cin >> A[i][j];
			}
		}
		int ct[10];
		for(int i=0;i<10;i++){
			ct[i] = Inf;
		}
		ct[1] = 0;
		for(int i=0;i<10;i++){
			int cost[10];
			for(int j=0;j<10;j++){
				cost[j] = Inf;
			}
			cost[i] = 0;
			priority_queue<pair <int,int> > P;
			P.push(make_pair(0,i));
			while(!P.empty()){
				pair<int,int> t = P.top();
				int s = t.second;//スタート
				P.pop();
				if(cost[s] < t.first) continue;
				for(int j=0;j<10;j++){
					pair<int,int> e = make_pair(C[s][j],j);
					if(cost[e.second] > cost[s] + e.first){
						cost[e.second] = cost[s] + e.first;
						P.push(make_pair(-cost[e.second],e.second));
					}
				}
			}
			ct[i] = cost[1];
		}
		int ans = 0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(A[i][j]!=-1)
					ans += ct[A[i][j]];
			}
		}
		cout << ans << endl;
	}
}

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

int main( void )
{
    long long N, K;
    cin >> N >> K;

    string S;
    cin >> S;

    vector<long long> seq;
    vector<long long> seqsum;
    long long sumtmp = 0;
    char nows = '1';
    long long tmp = 0;

    for(int i=0;i<N-1;i++){
        if(nows == S[i]){
            tmp++;
        }else{
            seq.push_back(tmp);
            sumtmp += tmp;
            seqsum.push_back(sumtmp);
            tmp = 1;
            nows = S[i];
        }
    }
    if(nows == S[N-1]){
        tmp++;
    }else{
        seq.push_back(tmp);
        sumtmp += tmp;
        seqsum.push_back(sumtmp);
        tmp = 1;
        nows = S[N-1];
    }
    seq.push_back(tmp);
    sumtmp += tmp;
    seqsum.push_back(sumtmp);
    if(nows == '0'){
        seq.push_back(0);
        seqsum.push_back(sumtmp);
    }

    long long result;

    long long seqsize = seq.size();
    if(seqsize <= 2*K+1){
        result = seqsum[seqsize-1];
    }else{
        result = seqsum[2*K];
        long long kukan = 2*K+2;
        while(kukan < seqsize){
            long long tmpres = seqsum[kukan] - seqsum[kukan - 2*K - 1];
            if(tmpres > result){
                result = tmpres;
            }
            //cout << result << "\n";
            kukan += 2;
        }

    }

    cout << result << "\n";

    
    /*
    for(int i=0;i<seqsize;i++){
        cout << seqsum[i] << "\n";
        //cout << S[i] << "\n";
    }
    */

	return 0;
}

Measured memory_bytes: 2164
histo = ["" for i in range(6)]
n = int(raw_input())
for i in range(n):
    h = float(raw_input())
    if   h < 165.0: histo[0] += "*"
    elif h < 170.0: histo[1] += "*"
    elif h < 175.0: histo[2] += "*"
    elif h < 180.0: histo[3] += "*"
    elif h < 185.0: histo[4] += "*"
    else          : histo[5] += "*"

for i in range(6):
    print "%d:%-s"%(i+1,histo[i])

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

int main() {
    bool first = true;
    int n;
    int p[4] = {10, 50, 100, 500};
    int c[4], d[4];
    int a[4];

    while(true) {
        cin >> n;
        if(n == 0) break;
        if(!first) {
            cout << endl;
        }
        first = false;
        int mdec = 80;
        cin >> c[0] >> c[1] >> c[2] >> c[3];
        for(d[0] = 0; d[0] <= c[0]; ++d[0]) {
            for(d[1] = 0; d[1] <= c[1]; ++d[1]) {
                for(d[2] = 0; d[2] <= c[2]; ++d[2]) {
                    for(d[3] = 0; d[3] <= c[3]; ++d[3]) {
                        int dec = -d[0] -d[1] -d[2] -d[3];
                        int change = p[0]*d[0] + p[1]*d[1] + p[2]*d[2] + p[3]*d[3] - n;
                        if(change < 0) {
                            continue;
                        }
                        int m;
                        for(m = 3; m >= 0; --m) {
                            if(d[m] > 0 && change / p[m] > 0) break;
                            dec += change / p[m];
                            change %= p[m];
                        }
                        if(m < 0 && dec < mdec) {
                            mdec = dec;
                            for(int m = 0; m < 4; ++m) {
                                a[m] = d[m];
                            }
                        }
                    }
                }
            }
        }

        for(int i = 0; i < 4; ++i) {
            if(a[i] > 0) {
                cout << p[i] << " " << a[i] << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main()
{
	int n;
	scanf("%d", &n);
	vector<ll> p;
	p.push_back(2);
	for(ll i=3; i<100000; i+=2){
		bool e=0;
		for(ll j=3; j*j<=i; j+=2){
			if(i%j==0){
				e=1;
				break;
			}
		}
		if(e==0){
			p.push_back(i);
		}
	}
	ll s[100000], s1[100000], t[100000];
	for(int i=0; i<n; i++){
		scanf("%lld", &s[i]);
	}
	vector<ll> ss;
	ll s0;
	int i0=0;
	int count[100000]={};
	for(int i=0; i<n; i++){
		for(int j=0; j<430; j++){
			if(s[i]%p[j]!=0) continue;
			while(s[i]%(p[j]*p[j]*p[j])==0){
				s[i]/=(p[j]*p[j]*p[j]);
			}
		}
	}
	sort(s, s+n);
	for(int i=0; i<n; i++){
		if(i==0){
			s0=s[0];
			ss.push_back(s0);
			count[i0]++;
		}else if(s0==s[i]){
			count[i0]++;
		}else{
			s0=s[i];
			ss.push_back(s0);
			i0++;
			count[i0]++;
		}
	}
	int m=i0+1;
	int ans=n;
	if(ss[0]==1) ans-=(count[0]-1);
	for(int i=0; i<m; i++){
		if(ss[i]==1) continue;
		s1[i]=1, t[i]=1;
		for(int j=0; j<430; j++){
          if(ss[i]%p[j]!=0) continue;
			if(ss[i]%(p[j]*p[j])==0){
				s1[i]*=(p[j]*p[j]);
				t[i]*=p[j];
			}else if(ss[i]%p[j]==0){
				s1[i]*=p[j];
				t[i]*=(p[j]*p[j]);
			}
		}
		if(ss[i]==s1[i]){
			if(s1[i]<t[i]) continue;
			auto itr=lower_bound(ss.begin(), ss.end(), t[i]);
			if(*itr==t[i]){
				ans-=min(count[i], count[itr-ss.begin()]);
			}
		}else{
			if(*lower_bound(p.begin(), p.end(), ss[i]/s1[i])==ss[i]/s1[i]){
				t[i]*=((ss[i]/s1[i])*ss[i]/s1[i]);
				auto itr=lower_bound(ss.begin(), ss.end(), t[i]);
				if(*itr==t[i]){
					ans-=min(count[i], count[itr-ss.begin()]);
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define N 200005
#define mod 1000000007
#define pp pair<ll,ll>
typedef long long int ll;
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++)    
void fastIO(void);
 
void decimal(int);
ll modmulti(ll, ll, ll);
ll modadd(ll, ll, ll);
ll modpower(ll, ll, ll);
ll gcd(ll, ll );
ll modinv(ll, ll);
 

int main()
{
  // decimal(1);
   fastIO();
   ll n,k;
   cin>>n>>k;
   string s;
   cin>>s;
   ll ans = 0;
   rep1(i,n) if(s[i]==s[i-1]) ans++;
   ll d = ans+2*k;
   cout<<min(n-1,d)<<endl;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b, ll m){
   return ((a%m)*(b%m))%m;
}
ll modadd(ll a, ll b, ll m){
   return ((a%m)+(b%m)+m)%m;
}
ll modpower(ll a, ll n, ll m){
   if(n==0)
      return 1;
   ll result = 1;
   while(n>0){
      if(n%2==1)
         result = modmulti(result,a,m);
      a = modmulti(a,a,m);
      n = n/2;
   }
   return result;
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a, ll m){
   return modpower(a,m-2,m);
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){

    int N , D ;
    scanf("%d%d",&N,&D);
    int i = D+1 ; int count = 0 , k = 2;

    if(N<=D){
        printf("%d",1);
    }else{

        while(i <= N){
            count++;
            if(N > (i+(2*(D+1)))){
                i += (2*(D+1)) -1 ;
            }
            else{
                if((i+D) >= N){
                    break ;
                }else{
                    count++;
                    break ;
                }
            }

        }
        printf("%d",count) ;
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N;
    vector<LL> A(N);

    LL original = 0;
    REP(i,N)
    {
        cin >> A[i];
        if(i == 0)
        {
            original += abs(A[i]);
        }
        else
        {
            original += abs(A[i] - A[i-1]);
        }
    }
    original += abs(A[N-1]);
    vector<LL> dif(N);
    REP(i,N)
    {
        if(i == 0)
        {
            LL bef = abs(A[i] - 0) + abs(A[i+1] - A[i]);
            LL aft = abs(A[i+1] - 0);
            dif[i] = aft - bef;
        }
        else if(i == N-1)
        {
            LL bef = abs(A[i] - A[i-1]) + abs(A[i] - 0);
            LL aft = abs(A[i-1] - 0);
            dif[i] = aft - bef;
        }
        else
        {
            LL bef = abs(A[i] - A[i-1]) + abs(A[i+1] - A[i]);
            LL aft = abs(A[i+1] - A[i-1]);
            dif[i] = aft - bef;
        }
    }
    REP(i,N)
    {
        cout << original + dif[i] << endl;
    }



}


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

namespace program
{
    class Program
    {
        static void Main()
        {
          char[] s = Input.ScanStr().ToCharArray();
          
          if(s.Length==1){ Console.WriteLine("No"); return; }
          
          Array.Sort(s);
          int c=1;
          for(int i=0;i<s.Length-1;i++){
            if(s[i]==s[i+1]) c++;
            else if(c%2==1){ Console.WriteLine("No"); return; }
            else c=1;
          }
          Console.WriteLine("Yes");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11348
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<ll, int> mp;
	rep(i,n){
		ll a;
		cin >> a;
		++mp[a];
	}
	if(mp[0] == n){
		cout << "Yes" << endl;
	}
	else if(mp[0] == n/3 && mp.size() == 2){
		cout << "Yes" << endl;
	}
	else if(mp.size() == 4){
		bool ok = true;
		vector<ll> v(3);
		int idx = 0;
		for(auto p : mp){
			if(p.first == 0) continue;
			if(p.second != n/3) ok = false;
			v[idx++] = p.first;
		}
		if((v[0] ^ v[1] ^ v[2]) != 0) ok = false;
		if(ok) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 8472
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string a,b,c;
  cin >> a >> b >> c;
  cout << 'A' << b[0] << "C" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#define pi 3.141592653589793238

using namespace std;


int main() {

	char op;
	int ans[10000] = { 0 };

	for (int i = 0; i > -1; i++) {

		int a = 0;
		int b = 0;

		cin >> a >> op >> b;

		switch (op) {

		case '+':
			ans[i] = a + b;
			break;

		case '-':
			ans[i] = a - b;
			break;

		case '*':
			ans[i] = a * b;
			break;

		case '/':
			ans[i] = a / b;
			break;

		case '?':
			for (int u = 0; u < i; u++) {

				cout << ans[u] << endl;

			}
			return 0;

		}


	}

	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	string s,t;
	int a,b;
	cin >> s >> t;
	cin >> a >> b;
	string u;
	cin >> u;
	if (s == u){
		a--;
	}else{
		b--;
	}
			cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define up(i,a,b) for(int i=a;i<=b;i++)
#define down(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a-1;i>=b;i--)
#define CL(x) (x<<1)
#define CR(x) (x<<1)+1
#define pb push_back
#define bit1(x) __builtin_popcount(x)

using namespace std;

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

template<typename T> inline void _read(T &x){
    char ch; x=0; bool neg=false;
    for(ch=getchar();ch<'0'||ch>'9';ch=getchar())
        if(ch=='-') neg=true;
    for(;ch>='0'&&ch<='9';ch=getchar()) x=10*x+ch-'0';
    if(neg) x=-x;
}
#define read(a) _read(a)
#define Read(a,b) _read(a),_read(b)

const int maxn=1e5+7;
const int maxS=(1<<6);
const ll mod=1e9;
const int inf=1e9+7;
const ll linf=1e16+9;

int n,t[maxn],kq;
struct Neko{
    int x,y;
}a[maxn];

inline void Enter(){
    cin>>n;
    up(i,1,n) cin>>t[i]>>a[i].x>>a[i].y;
}

inline int dis(Neko x,Neko y){
    return abs(x.x-y.x)+abs(x.y-y.y);
}

inline void Solve(){
    up(i,1,n){
        int Time=t[i]-t[i-1];
        if(dis(a[i],a[i-1])%2 == Time%2 && dis(a[i],a[i-1])<=Time) kq++;
    }
    if(kq!=n) cout<<"No";
    else cout<<"Yes";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    //freopen("TEST.INP","r",stdin);
    //freopen("TEST.OUT","w",stdout);

    Enter();
    Solve();

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define For(i, l, r) for (int i = l; i <= r; ++ i)
using namespace std;

inline int read() {
	int x = 0, p = 1; char c;
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("c.in", "r", stdin);
	freopen("c.out", "w", stdout);
}

const int N = 2e5 + 10;
int n, a[N];


int main() {

	n = read();
	For(i, 1, n) a[i] = read() - i;

	sort(a + 1, a + 1 + n);
	int t = a[n + 1 >> 1];

	long long ans = 0;
	For(i, 1, n) ans += abs(a[i] - t);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,flag=0;
    cin>>n;
    for(int i=1;i<=9;++i){
        for(int j=1;j<=9;++j){
            if(i*j==n){
                flag=1; break;
            }
        }
    }
    if(flag==1)
    	cout<<"Yes\n";
    else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
//Ford-Fulkerson O(FE)
#include<algorithm>
#include<utility>
#include<vector>
#include<limits>
template<typename T>
struct MF{
	vector<vector<pair<pair<int,int>,T> > >G;
	vector<int>used;
	MF(int n_=0):G(n_),used(n_,0){}
	void add_edge(int from,int to,T cap)
	{
		G[from].push_back(make_pair(
			make_pair(to,G[to].size()),cap
		));
		G[to].push_back(make_pair(
			make_pair(from,G[from].size()-1),0
		));
	}
	T dfs(int u,int t,T f,int dfstime)
	{
		if(u==t)return f;
		used[u]=dfstime;
		for(pair<pair<int,int>,T>&e:G[u])
		{
			if(used[e.first.first]<dfstime&&e.second>0)
			{
				T d=dfs(e.first.first,t,min(f,e.second),dfstime);
				if(d>0)
				{
					e.second-=d;
					G[e.first.first][e.first.second].second+=d;
					return d;
				}
			}
		}
		return 0;
	}
	T max_flow(int s,int t)
	{
		T ret=0;
		for(int dfstime=1;;dfstime++)
		{
			T f=dfs(s,t,numeric_limits<T>::max(),dfstime);
			if(f>0)ret+=f;
			else break;
		}
		return ret;
	}
};
int N,M,S,T;
int GID[1000];
int B[1000];
main()
{
	cin>>N>>M;
	MF<int>mf(N);
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		mf.add_edge(a,b,1);
		mf.add_edge(b,a,1);
		GID[i]=mf.G[b].size()-1;
		B[i]=b;
	}
	cin>>S>>T;
	cout<<mf.max_flow(S-1,T-1)<<endl;
	vector<int>ret;
	for(int i=0;i<M;i++)if(mf.G[B[i]][GID[i]].second==0)ret.push_back(i+1);
	cout<<ret.size()<<endl;
	for(int u:ret)cout<<u<<endl;
}



Measured memory_bytes: 3276
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
using namespace std;
typedef long long ll;
const int maxn = 100005;

ll f[41][2];
int c[41];

void pd(ll&ret, ll val){
  if(ret<val)ret=val;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
  int n;
  ll K;
  cin>>n>>K;
  for(int i=0;i<n;i++) {
    ll x;
    cin >> x;
    for (int j = 0; j < 40; j++)if (x & (1LL << j))c[j]++;
  }
  memset(f, -1,sizeof(f));
  f[40][1] = 0;
  for(int i=39;i>=0;i--){
    if(f[i+1][1]!=-1){
      int lim = ((K&(1LL<<i)) > 0LL ? 1:0);
      if(lim==0){
        pd(f[i][1],f[i+1][1] + (1LL<<i)*c[i]);
      } else {
        pd(f[i][1], f[i+1][1] + (1LL<<i)*(n-c[i]));
        pd(f[i][0], f[i+1][1] + (1LL<<i)*c[i]);
      }
    }
    if(f[i+1][0]!=-1){
      pd(f[i][0],f[i+1][0]+(1LL<<i)*c[i]);
      pd(f[i][0],f[i+1][0]+(1LL<<i)*(n-c[i]));
    }
  }
  cout<<max(f[0][1], f[0][0])<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1ll << 59;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

/*<ここから>***********************************************************/


int main()
{
	int N;
	cin >> N;
	vc S(N);
	rep(i, N) cin >> S[i];

	bool ans = false;
	rep(i, N) if (S[i] == 'Y') { ans = true; }

	if (ans) cout << "Four" << endl;
	else cout << "Three" << endl;

		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>     
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

 
using namespace std;
 
const int maxn = (int)155;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int n, x, d;
int get(int x){
	return x * (x + 1) / 2;
}
map<int, vpii> g;
main () {
	cin >> n >> x >> d;
	if(!d){
		if(!x){
			cout << 1;
			return 0;
		}
		cout << n + 1;
		return 0;
	}
	if(d < 0){
		x = -x, d = -d;
	}
	forn(k, 0, n){
		int rem = (k * x) % d, l = k * x / d + get(k - 1), r = k * x / d + get(n - 1) - get(n - k - 1);
		g[rem].pb(mp(l, r));	
	}
	int ans = 0;
	for(auto x : g){
		vpii cur = x.s;
		sort(all(cur));
		int l = cur[0].f, r = cur[0].s;
		for(auto x : cur){
			if(max(l, x.f) <= min(r, x.s)){
				r = max(r, x.s);
			}else{
				ans += r - l + 1;
				l = x.f, r = x.s;
			}
		}
		ans += r - l + 1;
	}
	cout << ans;
}

Measured memory_bytes: 22144
#include <iostream>
using namespace std;
typedef long long ll;
ll n,s[200000],t[200000],u[200000],ans=1e18;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    t[0]=s[0];
    for(int i=1;i<n-1;i++){
        t[i]=s[i]+t[i-1];
    }
    u[n-2]=s[n-1];
    for(int i=n-2;i>0;i--){
        u[i-1]=s[i]+u[i];
    }
    for(int i=0;i<n-1;i++){
        //cout<<t[i]<<" "<<u[i]<<endl;
        ans=min(ans,abs(t[i]-u[i]));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
const int INF = 1e9;
struct SegmentTree {
private:
    int n;
    vector<int> node;
 
public:
    SegmentTree() {
        int sz = 200010;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, -INF);
        for(int i=0; i<sz; i++) node[i+n-1] = -INF;
        for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1], node[2*i+2]);
    }
 
    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }
    // hannkaikukann 
    int getmax(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return -INF;
        if(a <= l && r <= b) return node[k];
 
        int vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
};

//const ll mod = 1000000007;
int N;
SegmentTree seg;
vector<ll> paths[201000];
ll ans[201000];
vector<int> a;
void dfs(int now, int p) {
    ll tmp = seg.getmax(0, a[now]);
    tmp++;
    ll before = seg.getmax(a[now], a[now]+1);
    chmax(tmp, before);
    seg.update(a[now], tmp);
    ans[now] = seg.getmax(0, N + 1);
    for(auto to : paths[now]) {
        if(to == p) continue;
        dfs(to, now);
    }
    seg.update(a[now], before);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    vector<int> cmp;
    a.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        cmp.push_back(a[i]);
    }
    cmp.push_back(-1);
    sort(cmp.begin(), cmp.end());
    cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
    for(int i = 0; i < N; i++) {
        auto itr = lower_bound(cmp.begin(), cmp.end(), a[i]);
        a[i] = itr - cmp.begin();
    }
    for(int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        paths[a].push_back(b);
        paths[b].push_back(a);
    }
    seg.update(0, 0);
    dfs(0, -1);
    for(int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 45244
readlines.map(&:to_i).each do |n|
  break if n.zero?

  result = Array.new(n) { Array.new(n) }
  inserted_index = { x: n / 2, y:  n / 2 + 1 }
  result[inserted_index[:y]][inserted_index[:x]] = 1

  2.upto(n * n) do |i|
    next_index = { x: inserted_index[:x] + 1, y: inserted_index[:y] + 1 }

    # ???????????????????????´???
    if next_index[:x] >= n
      next_index[:x] = 0
    end

    # ???????????????????????´???
    if next_index[:y] >= n
      next_index[:y] = 0
    end

    if result[next_index[:y]][next_index[:x]].nil?
      result[next_index[:y]][next_index[:x]] = i
      inserted_index = next_index

      next
    end

    next_index = { x: next_index[:x] - 1, y: next_index[:y] + 1 }

    # ???????????????????????´???
    if next_index[:x] < 0
      next_index[:x] = n - 1
    end

    # ???????????????????????´???
    if next_index[:y] >= n
      next_index[:y] = 0
    end

    result[next_index[:y]][next_index[:x]] = i
    inserted_index = next_index
  end

  result.each do |row|
    printf "%4d" * n + "\n",  *row
  end
end

Measured memory_bytes: 8856
#include <bits/stdc++.h>
#define inchar			getchar
#define outchar(x)		putchar(x)
#define ll long long int
#define all(v) v.begin(), v.end()
#define SP outchar(' ')
#define LN outchar('\n')
using namespace std;

template<typename T> void inpos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=0; if(c=='-')neg=1;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
template<typename T> void outpos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do{snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);}
inline void instr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while(c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}

ll dp[105][int(1e5) + 5];

ll Calc(ll * Weight, ll * value, ll n, ll Wt) {
	if (n <0 || Wt == 0 ) { // n< 0 ka soch
		return 0;
	}
	if (dp[n][Wt] != 0) {
		return dp[n][Wt];
	}
	ll answer;
	if(Wt>= Weight[n]) {
		answer = max(Calc(Weight, value, n-1 , Wt - Weight[n] )+value[n] , Calc(Weight, value , n-1,Wt) );
	} else {
		answer= Calc(Weight, value , n-1,Wt);
	}
	dp[n][Wt] = answer;
	return answer;
}



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

	ll n;
	ll Wt;
	inpos(n); inpos(Wt);
	ll value[n]; ll Weight[n];
	for (int i =0 ; i<n;i++) {
		inpos(Weight[i]); inpos(value[i]);
	}
	outpos(Calc(Weight, value, n-1, Wt ));
	
}

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

#define inf 1e9+1
#define ll long long

struct item{
    ll wt,val;
};

ll knapsack(ll n, ll W, vector<item> &a){

    ll maxValue = n*1000;
    ll dp[n+1][maxValue+1];

    for(ll val=0;val<=maxValue;val++)
        dp[1][val] = inf;
    dp[1][0] = 0;
    dp[1][a[1].val] = a[1].wt;

    for(ll i=2;i<=n;i++){
        for(ll v=0;v<=maxValue;v++){
            dp[i][v] = dp[i-1][v];
            if(a[i].val>v) continue;
            dp[i][v] = min(dp[i][v],a[i].wt + dp[i-1][v-a[i].val]);
        }
    }

    ll ans = 0;
    for(ll x=0;x<=maxValue;x++){
        if(dp[n][x]<=W)
            ans = x;
    }

    return ans;

}

int main() {
    
    ll n,W;
    cin>>n>>W;

    vector<item> a(n+1);

    for(ll i=1;i<=n;i++){
        cin>>a[i].wt>>a[i].val;
    }

    cout<<knapsack(n,W,a);

    return 0;
}


Measured memory_bytes: 81760
S = input()
N = len(S)
mod = 2019
d = [0] * mod
d[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    #print(i, rem)
    rem %= mod
    #print("\t", rem)
    t *= 10
    t %= mod
    d[rem] += 1

print(int(sum([i * (i-1) / 2 for i in d])))

Measured memory_bytes: 9324
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


int main() {
    int x,a;
    cin>>x>>a;
    if(x<a)cout<<0<<endl;
    else cout<<10<<endl;
    return 0;
}


Measured memory_bytes: 256
def build_maxv(x, v, maxv):
    mv = 0
    sv = 0
    for i in range(len(x)):
        sv += v[i]
        mv = max(mv, sv - x[i])
        maxv.append(mv)


def build_retmaxv(x, v, retmaxv):
    mv = 0
    sv = 0
    for i in range(len(x)):
        sv += v[i]
        mv = max(mv, sv - x[i]*2)
        retmaxv.append(mv)


N, C = map(int, input().split())
ans = 0
x = []
v = []
for i in range(N):
    tx, tv = map(int, input().split())
    x.append(tx)
    v.append(tv)
x_rev = [C-i for i in x[::-1]]
v_rev = v[::-1]
maxv = []
build_maxv(x, v, maxv)
maxv_rev = []
build_maxv(x_rev, v_rev, maxv_rev)
retmaxv = []
build_retmaxv(x, v, retmaxv)
retmaxv_rev = []
build_retmaxv(x_rev, v_rev, retmaxv_rev)
ans = max(maxv[N-1], maxv_rev[N-1])
if N != 1:
    for i in range(N-1):
        t1 = maxv[i] + retmaxv_rev[N-i-2]
        t2 = maxv_rev[i] + retmaxv[N-i-2]
        ans = max(ans, t1, t2)
print(ans)


Measured memory_bytes: 28976
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;vector<ll>arr;
vl gr[100005];
bool visited[100005];
ll ans[100004];
void dfs(ll i){
    visited[i]=1;
    ans[i]=0;
    for(auto j : gr[i]){
        if(!visited[j])
            dfs(j);
        ans[i]=max(ans[i],ans[j]+1);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    in(n);in(m);
    for(int i=0;i<m;i++){
        in(u);in(v);
        gr[u].push_back(v);
    }
    memset(ans,0,sizeof(ans));
    memset(visited,0,sizeof(visited));
    for(int i=1;i<=n;i++){
        if(!visited[i])
            dfs(i);
    }
    ll out=0;
    for(int i=1;i<=n;i++){
        out=max(out,ans[i]);
    }
    cout<<out<<endl;
    return 0;
}

Measured memory_bytes: 12684
n, k = map(int, input().split())

ans = 0

for b in range(k+1,n+1):
  s = n // b
  a = n % b
  ans += s * (b - k)
  ans += max(a - k + 1, 0)
  if k == 0:
    ans -= 1

print(ans)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    int N; cin >> N;
    vector< pair<int,int> > P;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        P.push_back(make_pair(a,i+1));
    }
    sort(P.begin(),P.end());
    for (int i = 0; i < N-1; i++)
    {
        cout << P[i].second << " ";
    }
    cout << P[N-1].second << endl;
}

Measured memory_bytes: 1780
#include <iostream>
#include <vector>
#include <cstdio>
#include <utility>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef pair<int, int> pii;

const char *p;

int solve() {
  int ret = 0;
  ++p;
  if(*p=='['){
    vector<int> v;
    while(*p == '['){
      v.push_back(solve());
    }
    sort(v.begin(), v.end());
    ret = 0;
    for(int i=v.size()/2; i>=0; i--) {
      ret += v[i];
    }
  }
  else {
    char *e;
    ret = strtol(p, &e, 10)/2 + 1;
    p = e;
  }
  ++p;
  return ret;
}

int main() {
  int n;
  string s;
  cin>>n;
  for(int i=0; i<n; i++) {
    cin>>s;
    p = s.c_str();
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1284
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){

			final String inputLine = br.readLine();
			final String[] inputNumbers = inputLine.split(" ");

			final Integer W = Integer.valueOf(inputNumbers[0]);
			final Integer H = Integer.valueOf(inputNumbers[1]);
			final Integer x = Integer.valueOf(inputNumbers[2]);
			final Integer y = Integer.valueOf(inputNumbers[3]);
			final Integer r = Integer.valueOf(inputNumbers[4]);

			if(x - r >= 0 && x + r <= W
					&& y - r >= 0 && y + r <= H) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		}

	}

}


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

using namespace std;

typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int,int,int> iii;

#define pb push_back
#define ctz __builtin_ctz
#define csb __builtin_popcount
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl

vector<iii> v,w;
const ll inf=1LL<<60;

int n;
int cmp(iii a,iii b) {
	if(get<1>(a)!=get<1>(b)) return get<1>(a)<get<1>(b);
	if(get<0>(a)!=get<0>(b)) return get<0>(a)<get<0>(b);
	return get<2>(a)>get<2>(b);
}

ll f(int flag) {
	int lidx=0,ridx=0,l=n,cur=0;
	//for(iii &p:v) printf("%d %d %d\n",get<0>(p),get<1>(p),get<2>(p));
	//	printf("\n");
	//for(iii &p:w) printf("%d %d %d\n",get<0>(p),get<1>(p),get<2>(p));
	ll ans=0;
	vi vis(n,0);
	while(l) {
		l--;
		if(flag) {
			while(vis[get<2>(v[lidx])]) ++lidx;
			vis[get<2>(v[lidx])]=1;
			int l=get<0>(v[lidx]),r=get<1>(v[lidx]);
			if(cur<l) {
				ans+=l-cur;
				cur=l;
			} else if(cur>r) {
				ans+=cur-r;
				cur=r;
			}
			//db3(l,r,cur);
			++lidx;
		} else {
			while(vis[get<2>(w[ridx])]) ++ridx;
			vis[get<2>(w[ridx])]=1;
			int l=get<0>(w[ridx]),r=get<1>(w[ridx]);
			if(cur<l) {
				ans+=l-cur;
				cur=l;
			} else if(cur>r) {
				ans+=cur-r;
				cur=r;
			}
			//db3(l,r,cur);
			++ridx;
		}
		flag^=1;
	}
	//db(ans);
	ans+=abs(cur);
	return ans;
}

int main() {
	int l,r;
	ll ans=inf;
	scanf("%d",&n);
	for(int i=0;i<n;++i) {
		scanf("%d%d",&l,&r);
		iii t(l,r,i);
		v.pb(t);
		w.pb(t);
	}
	sort(v.begin(),v.end(),greater<iii>()); // right hand side
	sort(w.begin(),w.end(),cmp);
	ans=f(0);
	ans=max(ans,f(1));
	cout<<ans<<endl;


}


Measured memory_bytes: 2988
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] A = Console.ReadLine().Split();
            string[] B = Console.ReadLine().Split();
            int a;
            a = (int.Parse(A[0]) - int.Parse(B[0])) * (int.Parse(A[1]) - int.Parse(B[1]));
            Console.Write(a);
        }
    }
}

Measured memory_bytes: 11092
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll n,m;
    cin>>n>>m;
    priority_queue<pll> Q;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        Q.push({a,1});
    }
    for(int i=0;i<m;i++){
        ll l,r;
        cin>>l>>r;
        Q.push({r,l});
    }
    ll ans=0;
    for(ll i=0;i<n;){
        pll w=Q.top(); Q.pop();
        //cout<<w.F<<" "<<w.S<<endl;
        ans+=w.F*min(n-i,w.S);
        i+=min(n-i,w.S);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 6256
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int p, l ,r; };
struct Node T[MAX];
int n;

/* 先行順巡回*/
void preParse(int u) {
    if ( u == NIL ) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

/* 中間順巡回*/
void inParse(int u) {
    if ( u == NIL ) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

/* 後行順巡回*/
void postParse(int u) {
    if ( u == NIL ) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main(){
    int i, v, l, r, root;
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
        T[i].p = NIL;
    }
    for ( i = 0; i < n; i++ ) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if ( l != NIL ) T[l].p = v;
        if ( r != NIL ) T[r].p = v;
}

for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;
    
printf("Preorder\n");
preParse(root);
printf("\n");
printf("Inorder\n");
inParse(root);
printf("\n");
printf("Postorder\n");
postParse(root);
printf("\n");
return 0;

}


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	int N,Q; cin >> N >> Q;
	vector<VI> ab(N);
	vector<int> cost(N);
	REP(i,N-1){
	    int a,b; cin >> a >> b;
	    a--; b--;
	    ab[a].PB(b);
	    ab[b].PB(a);
	}

	REP(i,Q){
		int p,x; cin >> p >> x;
		p--;
		cost[p] += x;
	}

	queue<int> que;
	que.push(0);
	vector<bool> visited(N);
	visited[0] = true;

	while(!que.empty()){
		int now = que.front(); que.pop();
		REP(i,ab[now].size()){
		    int next = ab[now][i];
		    if (visited[next] == true) continue;
		    cost[next] += cost[now];
		    visited[next] = true;
		    que.push(next);
		}
	}

	REP(i,N){
	    cout << cost[i] << " ";
	}
	cout << endl;



}


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

int main() {
  int a, b, t;
  cin >> a >> b >> t;
  int ans = (t / a) * b;
  cout << ans << endl;
}


Measured memory_bytes: 3580
#include <stdio.h>

void bubbleSort(int[],int);

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

void bubbleSort(int A[],int N){
  int i,count=0,flag=1,kari;

   while(flag){
    flag = 0;
    for(i=N-1;i>0;i--){
      if(A[i] < A[i-1]){
	kari = A[i];
	A[i] = A[i-1];
      A[i-1] = kari;
      count++;
      flag = 1;
      }
    }
  }
   for(i=0;i<N;i++){
     printf("%d",A[i]);
     if(i != N-1)printf(" ");
   }
  printf("\n%d\n",count);
}



Measured memory_bytes: 2048
import math
a,b,c=map(int, input().split())

S=((1/2)*a*b*math.sin(math.radians(c)))
L=a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(c)))
h=b*math.sin(math.radians(c))

print(S)
print(L)
print(h)


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

using namespace std;

int main() {

	int k, x;
	cin >> k >> x;
	for (int i=x-k+1; i <=x+ k-1; i++) {
		if (i >= -1000000 && i<=1000000) {
			cout << i << " ";
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) lower_bound(all(v),k)-v.begin()
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=100100100100;
const int mod=1000000007;
int main(){
   int n,w;cin>>n>>w;
   vvi dp(n,vi(w+1));
   vi omosa(n),kachi(n);
   rep(i,n)cin>>omosa[i]>>kachi[i];
   rep(i,n){
      rep(j,w+1){
         if(j>=omosa[i]){
            dp[i][j]=kachi[i];
            if(i>0){
               chmax(dp[i][j],dp[i-1][j-omosa[i]]+kachi[i]);
               chmax(dp[i][j],dp[i-1][j]);
            }
         }
         else{
            if(i>0)dp[i][j]=dp[i-1][j];
         }
      }
   }
   cout<<dp[n-1][w]<<endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int mins = min(min(a, b), min(min(a, b), c));
  int second_min = max(min(a, b), min(max(a, b), c));
  cout << mins + second_min;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int X, A, B;
	char buf[128];
	
	fgets(buf,128,stdin);
	sscanf(buf,"%d %d %d",&X,&A,&B);
	
	if(X < B - A) {
		printf("dangerous");
	} else {
		if(A < B) {
			printf("safe");
		} else {
			printf("delicious");
		}
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],dis[1000000],vis[1000000];
vector <long long> v[1000000];
queue <long long > q;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
	long long n,m,a,b,i,j,k,x,y,z;
	cin>>n>>m;
	for (i=0;i<m;i++)
	{
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dis[1]=0;
	for (i=2;i<=m;i++)
	{
		dis[i]=1e17;
	}
	q.push(1);
	vis[1]=1;
	while (!(q.empty()))
	{
		x=q.front();
		for (i=0;i<v[x].size();i++)
		{
			if (vis[v[x][i]]!=1)
			{
				vis[v[x][i]]=1;
				dis[v[x][i]]=x;
				q.push(v[x][i]);
			}
		}
		q.pop();
	}
	for (i=1;i<=n;i++)
	{
		if (vis[i]==0)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	for (i=2;i<=n;i++)
	{
		cout<<dis[i]<<endl;
	}
}

Measured memory_bytes: 35616
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define endl "\n"
#define maX 1000005
int main(){
	ll n,k,total=0;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
		for(int i=0;i<k;i++){
		total+=a[i];
	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vc=vector<char>;

const double pi = acos(-1);

int io(int x){
  int a=1;
  for(int i=0;i<x;i++){
    a*=10;
  }
  return a;
}

int main(){
  int i,N;
  cin>>N;
  vector<string> C(N);
  int c1=0,c2=0,c3=0,c4=0;
  for(i=0;i<N;i++){
    cin>>C[i];
    if(C[i]=="AC")c1++;
    else if(C[i]=="WA")c2++;
    else if(C[i]=="TLE")c3++;
    else c4++;
  }
  cout<<"AC x "<<c1<<endl;
  cout<<"WA x "<<c2<<endl;
  cout<<"TLE x "<<c3<<endl;
  cout<<"RE x "<<c4<<endl;
}
  


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

int main(){
    string S, T; cin>>S>>T;
    bool ans = false;
    int n = S.size();
    for(int i=0; i<n; ++i){
      if (S==T){
        ans = true;
        break;
      }
    S = S.back()+S.substr(0, n-1);
    }
    if(ans){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256