akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int h, w; cin >> h >> w;
  vector<string> a(h); REP(i, h) cin >> a[i];
  int s = 1, t = h - 2;
  for (;; ++s) {
    bool exist = false;
    REP(j, w) exist |= a[s][j] == '#';
    if (exist) break;
  }
  for (;; --t) {
    bool exist = false;
    REP(j, w) exist |= a[t][j] == '#';
    if (exist) break;
  }
  vector<vector<char> > red(h, vector<char>(w, '.')), blue(h, vector<char>(w, '.'));
  REP(y, h) red[y][0] = red[y][w - 1] = '#';
  REP(x, w) red[s][x] = '#';
  for (int y = s + 2; y <= t;) {
    bool exist = false;
    REP(x, w) exist |= a[y][x] == '#';
    if (exist) {
      REP(x, w) red[y][x] = '#';
      y += 2;
    } else {
      ++y;
    }
  }
  REP(y, h) {
    if (red[y][1] == '.') {
      FOR(x, 1, w - 1) blue[y][x] = '#';
    }
  }
  REP(y, h) REP(x, w) {
    if (a[y][x] == '#') red[y][x] = blue[y][x] = '#';
  }
  REP(y, h) {
    REP(x, w) cout << red[y][x];
    cout << '\n';
  }
  cout << '\n';
  REP(y, h) {
    REP(x, w) cout << blue[y][x];
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 1536
/* This Template is property of Pranav Khiste aka desmond_kaneki*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define vll vector<ll>
#define pb push_back
#define qll queue<ll>
#define mp make_pair
#define fst first
#define snd second
#define pll pair<ll,ll>
#define vpll vector<pll>
#define debug(x) cout<<#x<<' '<<x<<endl;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'
#define mod 1000000007
#define SUP LLONG_MAX
#define INF LLONG_MIN
#define test() ll var;  cin>>var; while(var--)
#define fileio freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);  // use cin cout only!!
main()
{
    fastio;
  	ll n;
  cin>>n;
  ll ar[n];
  fi(0,n)
    	cin>>ar[i];
  ll out=0;
  fi(0,n)
  {
    if(i%2==0&&ar[i]%2==1)
      out++;
  }
  cout<<out<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <numeric>
#include <limits>

const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;

int main() {
	long long int n, x, a[100000], ans = 0;
	std::cin >> n >> x;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	for (int i = 0;i < n - 1;i++) {
		if (a[i] + a[i + 1] > x) {
			if (a[i] + a[i + 1] - x > a[i + 1]) {
				ans += a[i] - x;
				ans += a[i + 1];
				a[i + 1] = 0;
			}
			else {
				ans += (a[i] + a[i + 1]) - x;
				a[i + 1] -= (a[i] + a[i + 1]) - x;
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	checkErr(err)

	scanner.Scan()
	arr := make([]int, n)
	for i, s := range strings.Split(scanner.Text(), " ") {
		arr[i], err = strconv.Atoi(s)
		checkErr(err)
	}

	for i := 1; i < n; i++ {
		printArr(arr)
		v := arr[i]
		j := i - 1
		for j >= 0 && arr[j] > v {
			arr[j+1] = arr[j]
			j--
		}
		arr[j+1] = v
	}
	printArr(arr)
}

func printArr(arr []int) {
	s := strings.Trim(fmt.Sprint(arr), "[]")
	fmt.Println(s)
}

func checkErr(e error) {
	if e != nil {
		log.Fatalln(e)
	}
}



Measured memory_bytes: 1260
#include <iostream>

using namespace std;

int prime_checker(long x){
    int flag = 0;
    for(int i = 2; i <= x/2; i++){
        if(x % i == 0){
            flag = 1;
            break;
        }
    }
    if(flag == 0){
        return 1;
    }
    else 
        return 0;
}

int main ()
{
  long x;
  int flag = 0;
  cin >> x;
  while (1){
      if(prime_checker(x) == 1){
        break;
      }
      else 
        x++;
  }
    
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
@n, @k, @c = gets.chomp.split(" ").map(&:to_i)
@s = gets.chomp

def getPositions()
  res = []
  i = 0
  while i < @n do
    break if res.count >= @k
    if @s[i] == 'o'
      res.push(i)
      i += @c + 1
    else
      i += 1
    end
  end
  return res 
end

l = getPositions()
@s = @s.reverse
r = getPositions()
@k.times do |i|
  r[i] = @n - 1 - r[i]
end
@s = @s.reverse

lastL = Array.new(@n+1, -1)
@k.times {|i| lastL[l[i]+1] = i}
@n.times do |i|
  lastL[i+1] = lastL[i] if lastL[i+1] == -1
end

lastR = Array.new(@n+1, -1)
@k.times {|i| lastR[r[i]] = i}
(@n-1).downto(0) do |i|
  lastR[i] = lastR[i+1] if lastR[i] == -1
end

@n.times do |i|
  next if @s[i] == 'x'
  li = lastL[i]
  ri = lastR[i+1]
  cnt = 0
  cnt += li + 1 if li != -1
  cnt += ri + 1 if ri != -1
  cnt-=1 if li != -1 && ri != -1 && r[ri]-l[li] <= @c
  next if cnt >= @k
  puts i+1
end

Measured memory_bytes: 10232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();

		int A = 0;
		int B = 0;

		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == '0' ^ i % 2 == 0) {
				A++;
			} else {
				B++;
			}
		}
		System.out.println(Math.min(A, B));

	}
}

Measured memory_bytes: 27476
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R; cin >> R;
    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
first_word = input()
word_list = [first_word]
last_char = first_word[-1:]
flag = 0
for i in range(n-1):
    word = input()
    word_list.append(word)
    first_char = word[0]
    if first_char == last_char:
        last_char = word[-1:]
    else:
        flag = 1
        break;
if(flag):
    print("No")
else:
    if(n == len(list(set(word_list)))):
        print("Yes")
    else:
        print("No")

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

using namespace std;

int main() {
	int n;
	long sum = 0;
	cin >> n;
	vector<int> time(n+1);
	for (int i = 1; i<=n; i++) {
		cin >> time[i];
		sum += time[i];
	}
	int m;
	cin >> m;
	for (int k = 0; k<m; k++) {
		int x, y;
		cin >> x >> y;
		cout << sum - time[x] + y << endl;	
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T[2],A[2],B[2];
	cin >> T[0] >> T[1];
	cin >> A[0] >> A[1];
	cin >> B[0] >> B[1];
	if((T[0]*A[0] + T[1] * A[1]) == (T[0]*B[0]+T[1]*B[1])){
		cout << "infinity" << endl;
		return 0;
	}
	ll k1 = T[0]*(A[0]-B[0]);
	ll k2 = T[1]*(A[1]-B[1]);
	if( (k1>0 && k2>0) || (k1<0&&k2<0) ){
		cout << "0" << endl;
		return 0;
	}
	if( abs(k1) > abs(k2)){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	if(k1>0){
		k1 *= -1;
		k2 *= -1;
	}
	if((-k1)%(k1+k2)){
		ans =(-k1)/(k1+k2) * 2LL + 1;
	}else ans = (-k1)/(k1+k2) * 2LL;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int main() {
	string s;
	cin >> s;
	map<char, int> count; 
	for(int i=0; i<s.size(); i++) {
		count[s[i]]++;
	}
	bool ok = true;
	if(count['N'] * count['S'] == 0 && (count['N'] > 0 || count['S'] > 0) )
		ok = false;
	if(count['W'] * count['E'] == 0 && (count['W'] > 0 || count['E'] > 0) )
		ok = false;
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cstring>
#include <bits/stdc++.h>
#include <search.h>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include<stack>
#include <utility>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    cout<<(n*(n-1))/2;
return 0;
}


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

#define int long long

using namespace std;

const int N = 3001;
const int inf = INT_MAX;

int h, w, k, mat[N][N], pr[N][N], ans = inf;
string s[N];

signed main() {
    scanf("%d %d %d", &h, &w, &k);
    for (int i = 1; i <= h; ++i)
        cin >> s[i];
    for (int i = 1; i <= h; ++i)
        for (int j = 0; j < w; ++j)
            mat[i][j + 1] = (s[i][j] - '0');
    for (int i = 1; i <= h + 1; ++i)
        for (int j = 1; j <= w; ++j)
            pr[i][j] = pr[i][j - 1] + mat[i][j];
    for (int mask = 0; mask < (1 << (h - 1)); ++mask) {
        int cnt = __builtin_popcount(mask);
        int last = 0;
        for (int i = 1; i <= w ; ++i) {
            int col = 0;
            int mx = 0;
            for (int j = 1; j <= h; ++j) {
                col += pr[j][i] - pr[j][last];
                if (mask & (1<<(j - 1))) {
                    mx = max(mx , col);
                    col = 0;
                }
            }
            mx = max(mx , col);
            if(i - last == 1 && mx > k){
				cnt += 10000;
				break; 
			}
            if (mx > k) {
			    last = i - 1;
                cnt++;
            }
            col = 0;
        }
        ans = min(ans, cnt);
    }
    printf("%d", ans);
}
/*
3 3 1
111
111
111
*/


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

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

    vector<int> x(n);
    rep(i,n) cin >> x[i];

    int sum = 0;
    int min = 0;
    rep(i,n) {
        sum += pow(x[i], 2);
    }
    min = sum;
    sum = 0;
  

    for (int i = 1; i < 100; ++i) {
        for (int j = 0; j < n; ++j) {
            sum += pow(x[j] - i, 2.0);
        }
        if(sum < min){
            min = sum;
        }
        sum = 0;
    }
    print(min);
}

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

int main() {
	int n,x;
  	cin>>n>>x;
  	
  	int l[n+1];
  rep(i,n+1)cin>>l[i];
  int hazumu=1;
  int sum=0;
  for(int i=0;i<n;i++){
  	sum+=l[i];
    if(sum<=x){
    	hazumu++;
    }
  }
	  
  cout<<hazumu<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long int N,A[200200],B[200200];
  	cin>>N;
  	for(long long int i=0;i<N;i++){
     	cin>>A[i]>>B[i]; 
    }
  	sort(A,A+N);
    sort(B,B+N);
    if(N%2==1){
    	cout<<B[N/2]-A[N/2]+1<<endl; 
    }else{
        cout<<(B[N/2]+B[N/2-1])- (A[N/2]+A[N/2-1])+1<<endl;
    }
}


Measured memory_bytes: 6768
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


// 68 11 55 - rank 3
// 69 12 19 - rank 3
// 70 12 34 - rank 100
// 71 12 58 -

ull gcd(ull a, ull b) {
    while (b != 0) {
        auto na = a % b;
        a = b;
        b = na;
    }
    return a;
}


void oneCase() {
    int n;
    cin >> n;
    map<ll, int> s;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        ++s[-a];
    }
    ll last = 0;
    for (auto p : s) {
        if (p.second == 1) {
            continue;
        }
        if (last == 0) {
            last = p.first;
            if (p.second >= 4) {
                cout << last * last << "\n";
                return;
            }
        } else {
            cout << last * p.first << "\n";
            return;
        }
    }
    cout << 0 << "\n";


}


int main() {
    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


Measured memory_bytes: 6528
#include <stdio.h>
long long n, i, j, ans;
int main(){
	scanf("%lld", &n);
	for(i=2; i*i<=n; i++){
		if(n%i) continue;
		for(j=i; j<=n; j*=i){
			if(n%j == 0){
				n /= j;
				ans++;
			}
		}
		while(n%i == 0) n /= i;
	}
	if(n > 1) ans++;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1724
import itertools
def LI(): return list(map(int,input().split()))
while 1:
    n,x = LI()
    if n==x==0:
        break
    ans = 0
    for i,j,k in itertools.combinations(range(1,n+1),3):
        if i+j+k==x:
            ans += 1
    print(ans)


Measured memory_bytes: 5636
#include <iostream>
#include <stdio.h>

#define MAX 100
#define NIL -1

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

int n;
Node T[MAX];

void preorder(int id) {
    if (id == NIL) return;
    
    printf(" %d", id);
    preorder(T[id].left);
    preorder(T[id].right);
}

void inorder(int id) {
    if (id == NIL) return;
    
    inorder(T[id].left);
    printf(" %d", id);
    inorder(T[id].right);
}

void postorder(int id) {
    if (id == NIL) return;
    
    postorder(T[id].left);
    postorder(T[id].right);
    printf(" %d", id);
}

int main() {
    int id, left, right;
    int root = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        T[i].parent = T[i].left = T[i].right = NIL;
    }
    
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &id, &left, &right);
        T[id].left = left;
        T[id].right = right;
        if (left != NIL) T[left].parent = id;
        if (right != NIL) T[right].parent = id;
    }
    
    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) root = i;
    }
    
    printf("Preorder\n");
    preorder(root);
    printf("\nInorder\n");
    inorder(root);
    printf("\nPostorder\n");
    postorder(root);
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 3180
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
constexpr int INF = std::numeric_limits<int>::max() / 2;  // 1.073741823e9
constexpr int64 INF64 = std::numeric_limits<int64>::max() / 2;  // 4.611686018427387903e18
constexpr int64 MOD = 1000000007;

std::vector<std::pair<int64, int64>> prime_fact(int64 n){
  std::vector<std::pair<int64, int64>> result;
  for (int64 i = 2; i * i <= n; ++i){
    if (n % i != 0) continue;
    int cnt = 0;
    while (n % i == 0){
      n /= i; ++cnt;
    }
    result.emplace_back(i, cnt);
  }
  if (n != 1) result.emplace_back(n, 1);
  return result;
}

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  //std::ifstream in("input.txt");
  //std::cin.rdbuf(in.rdbuf());

  int n; cin >> n;
  map<int64, int64> mp;
  int64 ans = 1;
  for (int64 i = 2; i <= n; ++i) {
    vector<pair<int64, int64>> v = prime_fact(i);
    for (size_t j = 0; j < v.size(); ++j) {
      mp[v[j].first] += v[j].second;
    }
  }

  for (auto x : mp) {
    //cerr << x.first << " " << x.second << endl;
    ans *= x.second + 1;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H*W - (h*W + H*w - h*w) << '\n';
}

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

using namespace std;

int main() {
    int N, K, minnk;
    cin >> N >> K;
    minnk=N;
    
    long double ans=0;
    if(K<=N) ans=(long double)(N-K+1)/N, minnk=K-1;
    if(ans==1) {
        cout << ans << endl;
        return 0;
    }

    long long int k=K;
    long long int pow=1;
    while(k>pow) {
        pow *= 2;
    }

    // cout << pow << endl;
    
    long long int pow2=1;
    for(int i=1; i<minnk+1; i++) {
        if(pow2==i) {
            if(i!=1) pow /= 2;
            long long int pp = N*pow;
            // if(pp<10000000000) ans += (long double) 1/(N*pow);
            ans += (long double) 1/pp;
            // cout << i << " " << pow << " " << ans << endl;
            pow2 *= 2;
        } else {
            if((pow/2)*(long long int)i>=k) {
                long long int pp = N*pow/2;
                // if(pp<10000000000) ans += (long double) 1/(N*(pow/2));
                ans += (long double) 1/pp;
                // cout << i << " " << pow/2 << " " << ans << endl;
            } else {
                long long int pp = N*pow;
                // if(pp<10000000000) ans += (long double) 1/(N*pow);
                ans += (long double) 1/pp;
                // cout << i << " " << pow << " " << ans << endl;
            }
        }
    }
    
    cout << setprecision(15) << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int Divisor(int n) {
	int res = 0;
	for(int i = 1; i * i <= n; ++i) {
		if( n % i == 0 ) { 
			res++;
			
			if( i < n / i ) res++;
		}
	}
	
	return res;
}

int main(void) {
	int n;
	cin >> n;
	
	int ans = 0;
	for(int i = 1; i <= n; i += 2) {
		if( Divisor(i) == 8 ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long i = 0; i < n; i++)
using ll = long long;
using ld = long double;
using namespace std;
int main() {
  ll N, T, X;
  cin >> N >> T;
  X = T;
  vector<int>t(N), u(N - 1);
  rep(i, N) {cin >> t.at(i);}
  rep(i, N - 1) {u.at(i) = t.at(i + 1) - t.at(i);}
  rep(i, N - 1) {
    if (u.at(i) < T) {X += u.at(i);}
    else {X += T;}
  }
  cout << X << endl;
}

Measured memory_bytes: 4824
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
using namespace std;
int A;
int B;

int main(void)
{
	int Sum = 0;

	cin >> A >> B;

	if (A>1)
	{
		Sum += (A*(A - 1)) / 2;
	}

	if (B>1)
	{
		Sum += (B*(B - 1)) / 2;
	}

	cout << Sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#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 PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	string s;

	cin >> s;

	int a=0;

	for (int i = 0; i < 3; i++)
	{
		if (s[i] == 'o')a++;
	}

	cout << 700+100*a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs, x) vector<vector<T>> xs(n, vector<T>(m, x))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs, 0); For(i, n) For(j, m) cin >> xs[i][j]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"

using namespace std;
using ll = long long;

int main(void){
    Cin(string, a);
    Cin(string, b);
    int n = atoi((a + b).c_str());
    
    For(i, 400) if(i*i == n){ Cout("Yes"); return 0; }
    Cout("No");
}


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

using ll=long long;
bool all_same(vector<int>& vec){
    return vec[0]==vec[1] && vec[1]==vec[2] && vec[2]==vec[3];
}
bool rot_same(vector<int> &vec){
    return vec[0]==vec[2] && vec[1]==vec[3];
}
enum{ALL,ROT,REG};
struct reg_pat{
    int type;
    ll all_c;
    ll rot_c;
    ll x;
};
const ll NUM=1000;
ll rot(vector<int> &vec){
    ll c1=min(vec[0],vec[1]);
    ll c2=max(vec[0],vec[1]);
    return c1*NUM+c2;
}
ll regular(vector<int> &vec){
    ll res=1e17;
    for(int i=0;i<4;i++){
        ll num=0;
        for(int j=0;j<4;j++){
            num*=NUM;
            num+=vec[(i+j)%4];
        }
        res=min(num,res);
    }
    return res;
}
ll regul(vector<int> &c){
    if(all_same(c)){
        return c[0];
    }
    else if(rot_same(c)){
        return rot(c);
    }
    else{
        return regular(c);
    }
}

int main(){
    int n;
    cin>>n;
    vector<vector<int>> c(n,vector<int>(4));
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            cin>>c[i][j];
            c[i][j]++;
        }
    }
    map<ll,ll> pat_cnt;
    for(int i=0;i<n;i++){
        pat_cnt[regul(c[i])]++;
    }
    ll res=0;
    auto par=[](ll x,ll y){
        ll res=1;
        for(int i=0;i<y;i++){
            res*=(x-i);
        }
        return res;
    };
    for(int i=0;i<n;i++){
        pat_cnt[regul(c[i])]--;
        for(int j=i+1;j<n;j++){
            pat_cnt[regul(c[j])]--;
            vector<int> top=c[i];
            vector<int> bot(4);
            for(int r=0;r<4;r++){
                for(int k=0;k<4;k++){
                    bot[k]=c[j][(k+r)%4];
                }
                map<ll,int> cnt;
                vector<int> fr={top[3],top[2],bot[3],bot[2]};
                vector<int> ri={top[2],top[1],bot[0],bot[3]};
                vector<int> ba={top[1],top[0],bot[1],bot[0]};
                vector<int> le={top[0],top[3],bot[2],bot[1]};
                cnt[regul(fr)]++;
                cnt[regul(ri)]++;
                cnt[regul(ba)]++;
                cnt[regul(le)]++;
                ll pat=1;
                for(auto &e:cnt){
                    if(e.first<NUM){
                        pat*=par(pat_cnt[e.first],e.second);
                        for(int z=0;z<e.second;z++) pat*=4;
                    }else if(e.first<NUM*NUM){
                        
                        pat*=par(pat_cnt[e.first],e.second);
                        for(int z=0;z<e.second;z++) pat*=2;
                    }
                    else{
                        pat*=par(pat_cnt[e.first],e.second);
                    }
                }
                
                res+=pat;
            }
            pat_cnt[regul(c[j])]++;
        }

        
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 80128
n, k = map(int, input().split())
A = list(map(int, input().split()))

l = 1
r = 10**9+1

while l < r:
    mid = (l+r)//2
    count = 0
    for i in range(n):
        if A[i] > mid:
            count += A[i]//mid

    if count <= k:
        r = mid
    else:
        l = mid+1


print(l)

Measured memory_bytes: 31048
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
		if((1<=i && i<=9) || (100<=i & i<=999) || (10000<=i & i<=99999)) ans++;
	cout<<ans<<'\n';
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <deque>

template <class T>
using greater_queue=std::priority_queue<T, std::deque<T>, std::greater<T>>;

template <class T>
constexpr T inf=(T(1)<<(8*sizeof(T)-3));

template <class Weight>
struct Edge {
  size_t src, dst;
  Weight cost;
  Edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}
};

template <class Weight>
using Graph=std::vector<std::vector<Edge<Weight>>>;

template <class Weight>
std::vector<Weight> dijkstra(const Graph<Weight> &g, size_t s) {
  std::vector<Weight> dist(g.size(), inf<Weight>);
  greater_queue<std::pair<Weight, size_t>> q;
  dist[s] = 0;
  q.emplace(0, s);
  while (!q.empty()) {
    auto p=q.top();
    q.pop();
    Weight w=p.first;
    size_t v=p.second;
    if (w > dist[v])
      continue;

    for (const Edge<Weight> &e: g[v]) {
      if (dist[e.dst] > w + e.cost) {
        dist[e.dst] = w + e.cost;
        q.emplace(dist[e.dst], e.dst);
      }
    }
  }
  return dist;
}

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  Graph<int> g(N);
  for (size_t i=0; i<M; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a;
    --b;

    g[a].emplace_back(a, b);
    g[b].emplace_back(b, a);
  }

  printf("%sPOSSIBLE\n", dijkstra(g, 0)[N-1]>2? "IM":"");
}


Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,M;cin >> N >> M;
    vector<int> L(M);
    vector<int> R(M);
    rep(i,M)cin >> L[i] >> R[i];

    int l = 0;
    int r = N+1;
    rep(i,M){
        chmax(l,L[i]);
        chmin(r,R[i]);
    }
    int ans = r - l + 1;

    if(ans < 0)ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int n  = sc.nextInt();
		
		double r = 2. * Math.PI * (double)n ;
		System.out.println(r);
	}
	
	
}

Measured memory_bytes: 27100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
using namespace std;
const long INF = 1000000009;

long m, n;

int main(){
	cin >> n >> m;
	long ans = 1;
	for(int i = 0; i < m; i++){
		ans *= 2;
	}
	ans *= 100*(n-m) + 1900*m;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;



//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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



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

	int ans;

	if(n*a>=b){
		ans=b;
	}
	else{
		ans=n*a;
	}
	cout<<ans<<endl;
	

	
return 0;
}



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

using namespace std;

int selectionSort (int A[], int n) {
    
    int cnt = 0;

    for (int i = 0; i < n - 1; i++) {
        int minj = i;

        for (int j = i; j < n; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }

        if (i != minj) {
            swap(A[i], A[minj]);
            cnt++;
        }
    } 

    return cnt;

}

void disp (int A[], int n) {

    for (int i = 0; i < n; i++) {
    
        if (i > 0) {
            cout << " ";
        }
        cout << A[i];
    
    }

    cout << endl;

}

int main (void) {

    int N;
    cin >> N;

    int A[100];

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int cnt = selectionSort (A, N);

    disp (A, N);

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3080
import java.io.InputStream;
import java.io.IOException;
import java.lang.NumberFormatException;
import java.util.BitSet;
import java.util.NoSuchElementException;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    FastScanner fs = new FastScanner();
    int N = fs.nextInt();
    BitSet[] A = new BitSet[N];
    BitSet[] dpl = new BitSet[N];
    BitSet[] dpr = new BitSet[N];
    for (int i=0;i<N;i++) {
      A[i] = new BitSet();
      dpl[i] = new BitSet();
      dpr[i] = new BitSet();
      dpl[i].set(i);
      dpr[i].set(i);
    }
    for (int i=1;i<N;i++) {
      char[] s = fs.nextString().toCharArray();
      for (int j=0;j<i;j++) {
        A[i].set(j,s[j] == '1');
        A[j].set(i,s[j] == '0');
      }
    }
    for (int i=1;i<N;i++) {
      for (int l=0;l<N-i;l++) {
        int r = l+i;
        BitSet tmp = A[r].get(0,N);
        tmp.and(dpl[l]);
        tmp.and(dpr[r-1]);
        dpl[l].set(r,!tmp.get(l,r).isEmpty());
        tmp = A[l].get(0,N);
        tmp.and(dpl[l+1]);
        tmp.and(dpr[r]);
        dpr[r].set(l,!tmp.get(l+1,r+1).isEmpty());
      }
    }
    int ans = 0;
    for (int i=0;i<N;i++) {
      if (dpl[0].get(i) && dpr[N-1].get(i)) ans++;
    }
    System.out.println(ans);
  }
}
class FastScanner {
  private final InputStream ins = System.in;
  private final byte[] buf = new byte[1024];
  private int ptr = 0;
  private int len = 0;
  private boolean hasNextByte() {
    if (ptr < len) return true;
    ptr = 0;
    try {
      len = ins.read(buf);
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (len < 1) return false;
    return true;
  }
  private int read() {
    if (hasNextByte()) return buf[ptr++];
    return -1;
  }
  private static boolean isPrintable(int c) {
    return 32 < c && c < 127;
  }
  private void skipUnprintable() {
    while (hasNextByte() && !isPrintable(buf[ptr])) ptr++;
  }
  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }
  public String nextString() {
    if (!hasNext()) throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    for (int b = read();isPrintable(b);b = read()) sb.appendCodePoint(b);
    return sb.toString();
  }
  public int nextInt() {
    if (!hasNext()) throw new NoSuchElementException();
    int n = 0;
    boolean negative = false;
    int b = read();
    if (b == '-') {
      negative = true;
      b = read();
    }
    if (b < '0' || '9' < b) throw new NumberFormatException();
    while (true) {
      if (b == -1 || !isPrintable(b)) return negative ? -n : n;
      if (b < '0' || '9' < b) throw new NumberFormatException();
      n = 10*n+(b-'0');
      b = read();
    }
  }
}

Measured memory_bytes: 355080
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int64_t INF = 1LL << 60;


int main() {
  string s;
  cin>>s;
  string t,h="";
  int ans=0;
  for(int i=0;i<s.size();i++){
   t+=s[i];
   if(t==h){continue;}
   h=t;
   t="";
   ans++;
  }
  cout<<ans<<endl;
   return 0;
  }

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

int main()
{
	long long n; cin >> n;
	long long a[] = { 1, 4, 16, 61, 230, 865, 3247, 12185, 45719, 171531, 643550, 2414454, 9058467, 33985227, 127504505, 478366600, 794717734, 733354121, 261943303, 776803305, 580025381, 51688048, 44657419, 737209731, 604119499, 159693437, 858533109, 639056669, 549054109, 996291083, 531294469, 23314687, 783022045, 855462856, 649970414, 68697295, 409213624, 604356692, 88638656, 978442997, 534833116, 763737161, 785892908, 123883652, 639213333, 181836645, 998121103, 124885216, 501575626, 39816123, 113468411, 799008836, 775465589, 256852905, 664630886, 971550783, 751629411, 51018086, 702530485, 725438992, 696683714, 792638194, 221791721, 149602322, 414054379, 986519078, 981760191, 305799096, 515140586, 406959393, 975058685, 245601370, 324759692, 673385295, 191483611, 570246669, 427196161, 781042769, 569725155, 842176273, 25328739, 847501730, 206282374, 353770801, 323137024, 371653459, 940737264, 123820509, 915711339, 847205021, 252858375, 718889563, 866398347, 738390145, 133009077, 333099663, 170591295, 329869205, 616680192, 597534442, 388130742 };

	cout << a[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n;
    scanf("%d", &n);
    int ans[n+1];
    memset(ans, 0, sizeof(ans));
    For(x, 1, 150)For(y, 1, 150)For(z, 1, 150){
        int tmp = (x+y)*(x+y) + (y+z)*(y+z) + (z+x)*(z+x);
        if(tmp/2 <= n) ++ans[tmp/2];
    }
    For(i, 1, n+1) printf("%d\n", ans[i]);
}

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

#define INF INT_MAX

using namespace std;

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

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

    int X,A;
    cin >> X >> A;
    
    int ans = 0;

    ans = X < A? 0:10;
 
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 15000
char c[205][205];
int col[205];
int n;
bool dfs(int x,int color){
    col[x]=color;
    for(int i = 1;i<=n;i++){
        if(c[x][i]=='1'){
            if(col[i]==-1)
                if(!dfs(i,color^1))
                    return false;
            if((color^1)!=col[i])return false;
        }
    }
    return true;
}
int dis[205][205];
int main(){
    MEMS(col);
    //int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++){
        for(int j =1;j<=n;j++)
            dis[i][j]=1e9;
        dis[i][i]=0;
    }
    for(int i = 1;i<=n;i++){
        scanf("%s",c[i]+1);
        for(int j =1;j<=n;j++){
            if(c[i][j]=='1')dis[i][j]=1;
        }
    }
    if(!dfs(1,0)){
        printf("-1\n");
        return 0;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
            }
        }
    int Max=0;
    for(int i = 1;i<=n;i++)
        for(int j=1;j<=n;j++){
            Max=max(Max,dis[i][j]);
        }
    printf("%d\n",Max+1);
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#define int long long

using namespace std;

signed main()
{

    int k;
    cin >> k;
    queue<int> q;
    for (int i = 1; i <= 9; i++)
        q.push(i);
    while (!q.empty())
    {
        int x = q.front();
        q.pop();
        k--;
        if (k == 0)
        {
            cout << x << '\n';
            break;
        }
        int t = x % 10;
        for (int y = t - 1; y <= t + 1; y++)
        {
            if (y < 0)
                continue;
            if (y > 9)
                break;
            q.push(x * 10 + y);
        }
    }

    return 0;
}

Measured memory_bytes: 5168
loop_cnt = 10 ** 5 + 1

N = map(int, input().split())
A = [0] * (loop_cnt + 1)

A_lis = list(map(int, input().split()))
for a in A_lis:
    A[a] += 1

Q = int(input())

ans = 0

for i in range(loop_cnt):
    ans += i * A[i]

for _ in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * A[B]
    A[C] += A[B]
    A[B] = 0
    print(ans)


Measured memory_bytes: 21968
n = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(n):
  e = str(input())
  if e  == "AC":
    AC += 1
  elif e  == "WA":
    WA += 1
  elif e  == "TLE":
    TLE += 1
  else:
    RE += 1
print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

    ll N, M;
    ll a;
    cin >> N >> M;
    map<ll, ll> num;
    REP(i, N){
        cin >> a;
        num[a]++;
    }

    int b, c;
    REP(i, M){
        cin >> b >> c;
        num[c] += b;
    }

    map<ll,ll>::reverse_iterator i = num.rbegin();
    ll count = 0;
    ll ans = 0;
    for( ; i != num.rend() ; ++i ){
        // cout << count+i->second << endl;
        if(count+i->second > N){
            ans += (N-count) * i->first;
            break;
        }else{
            ans += i->second * i->first;
            count += i->second;
            // cout << ans << " " << count << endl;
        }
    }
    cout << ans << endl;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

 
signed main(void) {
    string S;
    cin >> S;

    int ans = 0;

    rep(i, S.size()) {
        if (S[i] == '+') ans++;
        else ans--;
    } 

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



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

vector<pair<int,int> >vec;

int main(){
    double x[4],y[4];
    while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=EOF){
        double a[4],b[4];
        for(int i=0;i<4;i++){
            a[i]=x[(i+1)%4]-x[i];
            b[i]=y[(i+1)%4]-y[i];
        }
        int suc=1;
        for(int i=0;i<4;i++){
            if((a[i]*b[(i+1)%4]-b[i]*a[(i+1)%4])*(a[(i+1)%4]*b[(i+2)%4]-b[(i+1)%4]*a[(i+2)%4])<0){
           //     cout<<(x[i]*y[(i+1)%4]-y[i]*x[(i+1)%4])<<"     "<<(x[(i+1)%4]*y[(i+2)%4]-y[(i+1)%4]*x[(i+2)%4])<<endl;
                suc=0;
                break;
            }
          //  cout<<(x[i]*y[(i+1)%4])<<"    "<<(y[i]*x[(i+1)%4])<<"     "<<(x[(i+1)%4]*y[(i+2)%4])<<"    "<<(y[(i+1)%4]*x[(i+2)%4])<<endl;
        }
        if(suc)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr ll INF = 1e18 + 10;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

vector<pair<ll, ll>> primeFactorize(ll N)
{
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        ll ex = 0;

        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }

    if (N != 1)
        res.push_back({N, 1});
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s;
    cin >> s;
    int min = 1000;
    for (int i = 0; i < s.size() - 2; i++)
    {
        int num = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
        int diff = abs(num - 753);
        if (min > diff)
        {
            min = diff;
        }
    }
    cout << min << "\n";

    return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <string>
#include <algorithm>
//typedef long long LL;
using namespace std;

int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int a[100000];

int compare(const void *a, const void *b) {
	return *(const int *)a - *(const int *)b;
}

int main(void) {
	int n;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);

	qsort(a, n, sizeof(int), &compare);

	double min_diff = 1e9;
	int min_num = -1;
	for (int i = 0; i < n; i++) {
		const double diff = fabs(a[n - 1] / 2. - a[i]);
		if (diff < min_diff) {
			min_diff = diff;
			min_num = a[i];
		}
	}

	printf("%d %d\n", a[n - 1], min_num);

	return 0;
}


Measured memory_bytes: 892
s = input()

mae = int(s[0] + s[1])
ushiro = int(s[2] + s[3])

if (1 <= mae and mae <= 12 and 1 <= ushiro and ushiro <= 12):
    print("AMBIGUOUS")
elif(1 <= mae and mae <= 12):
    print("MMYY")
elif(1 <= ushiro and ushiro <= 12):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int o,s[25],i,n;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&s[i]);
    }
    o=31;
    i=0;
    while(o!=1){
      printf("%d\n%d\n",o,o-s[i]);
      o-=5;
      i++;
      if(i==n)i=0;
    }
    printf("1\n0\n");
  }
  return 0;
}

Measured memory_bytes: 612
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

void solve() {
    int n, q;
    cin >> n >> q;

    atcoder::fenwick_tree<ll> fw(n);
    rep(i, n) {
        ll a;
        cin >> a;
        fw.add(i, a);
    }

    while (q--) {
        int cmd, a, b;
        cin >> cmd >> a >> b;
        if (cmd == 0)
            fw.add(a, b);
        else
            cout << fw.sum(a, b) << "\n";
    }
}
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 8248