akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <map>
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i = 0; i < n ; i++)
#define rep_(i , n ) for ( int i = 1; i <= n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/
vector<int> prime_no;
vector<int> prime_no_backup;
map<int, ll> part;

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

	int N;
	
	cin >> N;

	rep_(i, N)
	{	
		if (i > 1)
		{
			prime_no.pb(i);
		}
	}

	int j = 0;

	while(j < prime_no.size())
	{
		for(int i = prime_no_backup.size() - 1; i >= j; i--)
		{
			prime_no_backup.erase(prime_no_backup.begin() + i);
		}

		int tmp = prime_no[j];
		prime_no_backup.pb(tmp);

		std::vector<int> idx;
		for (int i = j+1; i < prime_no.size(); i++)
		{
			//cout << "prime_no=" << prime_no[i] << endl;
			if (prime_no[i] % tmp == 0)
			{
				continue;
			}

			prime_no_backup.pb(prime_no[i]);
		}

		prime_no = prime_no_backup;
		j++;
		//cout << j << ";" << prime_no.size() << endl;
	}

	/*
	for (int i = 0; i < prime_no.size(); i++)
	{
		cout << "i=" << i << "; n=" << prime_no[i] << endl;
	}
	*/

	//cout << "sdta" << endl;

	rep_(i, N)
	{
		int tmp = i;

		for (int j = 0; j < prime_no.size(); j++)
		{
			if (tmp < prime_no[j])
			{
				break;
			}

			while(tmp && (tmp % prime_no[j] == 0))
			{
				if (part.find(prime_no[j]) == part.end())
				{
					part[prime_no[j]] = 1;
				}
				else
				{
					part[prime_no[j]]++;
				}
				tmp /= prime_no[j];
			}

		}
	}

	ll ret = 1;
	map<int, ll>::iterator it;
	//cout << "part size = " << part.size() << endl;
	for ( it = part.begin(); it != part.end(); it++ )
	{
		//cout << it->first << "--" << it->second << endl;
		ret = (ret * (it->second + 1)) % MOD;
	}

	cout << ret << endl;
	return 0;
}


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

static const int kiMaxSize = 2000000;
static const int kiMaxValue = 10000;

//?¬¬????????°????????????????????????????¬¬????????°?????\????????¢??°
void CountingSort(const int aiArray[], int aiSortedArray[], const int iNumA) {
	int aiValCouArray[kiMaxValue] = { 0 };

	//aiValCouArray???aiArray???????´????????????°??????????????????????¨??????????
	for (int i = 0; i < iNumA; i++) 
		aiValCouArray[aiArray[i]]++;

	//aiValCouArray???aiArray???????´???\??????????????°??????????????????????¨??????????
	for (int i = 1; i < kiMaxValue; i++)
		aiValCouArray[i] += aiValCouArray[i - 1];

	for (int i = iNumA-1; i >= 0; i--) {
		int iValue_count = aiValCouArray[aiArray[i]];
		//????????°???(?????????????????????,????????????????????????)???aiSortedArray[1]?????\??£??????????????????
		aiSortedArray[iValue_count-1] = aiArray[i];
		aiValCouArray[aiArray[i]]--;
	}
}

//??\??????????????°??????O(n+k(??°???????????§????´?))??§?????????????????????????????¢??°
int main() {
	int aiArray[kiMaxSize];
	int iNumA;
	
	//??\???
	cin >> iNumA;
	for (int i = 0; i < iNumA; i++) cin >> aiArray[i];


	int aiSortedArray[kiMaxSize];
	CountingSort(aiArray, aiSortedArray, iNumA);


	//??????
	for (int i = 0; i < iNumA; i++) {
		if (i) cout << " ";
		cout << aiSortedArray[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 18700
import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._

  solve
  @tailrec
  def solve: Unit = {
    val record = readLine.trim
    if (record == "0") return
    val (a, b) = calScore(record.tail.toList)
    println(s"$a $b")
    solve
  }
  @tailrec
  def calScore(serves: List[Char], pointA: Int = 0, pointB: Int = 0): (Int, Int) = {
    serves match {
      case Nil if pointA > pointB ⇒ (pointA + 1, pointB)
      case Nil ⇒ (pointA, pointB + 1)
      case 'A'::t ⇒ calScore(t, pointA + 1, pointB)
      case 'B'::t ⇒ calScore(t, pointA, pointB + 1)
    }
  }
  implicit class Extension[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}


Measured memory_bytes: 43880
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    LL N, A, B;
    cin >> N >> A >> B;
    if(A <= B && (N >= 2 || A == B)) {
        LL S = A + B + max(0LL, A * (N-2));
        LL T = A + B + max(0LL, B * (N-2));
        cout << T - S + 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var ans int

func main() {
	var max_g int

	c := make([][]int, 3)
	for i := 0; i < 3; i++ {
		c[i] = make([]int, 3)

		for j := 0; j < 3; j++ {
			fmt.Scan(&c[i][j])
			max_g = max(max_g, c[i][j])
		}
	}

	for a1 := 0; a1 <= max_g; a1++ {
		b1 := c[0][0] - a1
		b2 := c[0][1] - a1
		b3 := c[0][2] - a1

		for a2 := 0; a2 <= max_g; a2++ {
			if (a2 + b1) != c[1][0] {
				continue
			}
			if (a2 + b2) != c[1][1] {
				continue
			}
			if (a2 + b3) != c[1][2] {
				continue
			}
			for a3 := 0; a3 <= max_g; a3++ {
				if (a3 + b1) != c[2][0] {
					continue
				}
				if (a3 + b2) != c[2][1] {
					continue
				}
				if (a3 + b3) != c[2][2] {
					continue
				}
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}

/*  ----------------------------------------  */
func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] > a[j] }


Measured memory_bytes: 512
N,X=map(int,input().split())
S=[]
eat=1000000
eatpos=0
for i in range(N):
    S.append(X+i)
    if abs(S[i])<eat:
        eat=abs(S[i])
        eatpos=i

goukei=0
for i in range(N):
    if i!=eatpos:
        goukei+=S[i]
print(goukei)

Measured memory_bytes: 3064
from fractions import gcd
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

ctr = Counter(A)
solos = []
for k,v in ctr.items():
    if v > 1: continue
    solos.append(k)
solos.sort()

if len(solos) == 0:
    g = A[0]
    for a in A:
        g = gcd(g,a)
    print(g)
    exit()

g1 = g2 = None
for k in ctr.keys():
    if k != solos[0]:
        if g1 is None:
            g1 = k
        else:
            g1 = gcd(g1,k)
    if len(solos) > 1 and k != solos[1]:
        if g2 is None:
            g2 = k
        else:
            g2 = gcd(g2,k)

if g2 is None: g2 = 0
print(max(g1,g2))

Measured memory_bytes: 16608
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

vector<int> a(10);
int N;
vector<vector<ll>> F;
vector<vector<ll>> P;
ll ans = -INF64;

auto cal = []() {
    REP(i, a.size()) {
        if (a[i] != 0)
            break;
        if (i == a.size() - 1)
            return;
    }

    ll score = 0;
    REP(i, N) {
        int cnt = 0;
        REP(j, 10) if (a[j] == 1 && F[i][j] == 1) { cnt++; }
        score += (ll)P[i][cnt];
    }

    chmax(ans, score);
};

auto dfs = [](auto pos) {
    if (pos == 10) {
        cal();
        return;
    }
    a[pos] = 0;
    dfs(pos + 1);
    a[pos] = 1;
    dfs(pos + 1);
};

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

    cin >> N;
    F.resize(N, vector<ll>(10));
    P.resize(N, vector<ll>(11));
    REP(i, N) REP(j, 10) cin >> F[i][j];
    REP(i, N) REP(j, 11) cin >> P[i][j];

    dfs(0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
MOD = 998244353
def inv_mod(a,p=MOD):
    def inv_mod_sub(a,p):
        if a == 1:
            return 1,0
        else:
            d,r = p//a,p%a
            x,y = inv_mod_sub(r,a)
            return y-d*x,x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n,k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD

f_mod=[1]*(10**6)
f_mod_inverse=[1]*(10**6)
for i in range(1,10**6):
  f_mod[i]=f_mod[i-1]*i%MOD
  f_mod_inverse[i]=f_mod_inverse[i-1]*inv_mod(i)%MOD
n,m,k = map(int,input().split())
c = 0
for i in range(k+1):
    c += comb_mod(n-1, i)*m*pow(m-1,n-i-1,MOD)
    c %= MOD
print(c)

Measured memory_bytes: 89252
from collections import*
(h,w),(s,t),(f,g)=eval('map(int,input().split()),'*3)
d=eval('[-1]*w,input(),'*h)
q=deque([(s-1,t-1,0)])
while q:
 y,x,c=q.pop()
 if d[y+y][x]<0:
  for a in range(25):a,b=a//5-2,a%5-2;i=a+y;j=b+x;d[y+y][x]=c;h>i>-1<j<w!=d[i-~i][j]>'#'!=(abs(a)+abs(b)<2!=q.append((i,j,c)),q.appendleft((i,j,c+1)))
print(d[f+f-2][g-1])

Measured memory_bytes: 256172
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='+') ans++;
        else ans--;
    }
    printf("%d\n",ans);
    return 0;
}

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

 int main() {
  int a, b;
  cin >> a >> b;
  int res = -1;
  int s,t;
  for (size_t i = 0; i < 100000; i++) {
    s = i* 0.08;
    t = i* 0.1;
    //cout << s << t << '\n';
     if (a == s && b == t) {
       res = i;
       break;
     }
  }

  cout << res << '\n';
 }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	char map[110][110];
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++)cin >> map[i][j];
	}
	for (int i = 1; i <= h; i++) {
		bool f = true;
	HERE:
		for (int j = 1; j <= w; j++) {
			cout << map[i][j];
		}
		cout << endl;
		if (f) {
			f = false;
			goto HERE;
		}
	}
	return 0;
}

Measured memory_bytes: 256
r = 0
c = 0


def input_size():
    global r, c
    r, c = map(int, input().split(' '))


def input_table(table):
    for i in range(0, r):
        vs = list(map(int, input().split(' ')))
        row = []
        for v in vs:
            row.append(v)
        table.append(row)


def calc_total(table):
    total = []
    for i in range(0, c + 1):
        total.append(0)

    for i in range(0, r + 1):
        if i < r:
            t = 0
            for j in range(0, c):
                t += table[i][j]
                total[j] += table[i][j]
            table[i].append(t)
            total[c] += t

        if i == r - 1:
            table.append(total)


def output(vs):
    for row in vs:
        first = True
        for v in row:
            if not first:
                print(end=' ')
            print(v, end='')
            first = False
        print()


input_size()
vs = []
input_table(vs)
calc_total(vs)
output(vs)



Measured memory_bytes: 6472
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt(), a = in.nextInt(), b = in.nextInt();
        if (Math.abs(a - x) < Math.abs(b - x)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

void Print  (const int a, const int b, const string& dummy, string& str);
void Reverse(const int a, const int b, const string& dummy, string& str);
void Replace(const int a, const int b, const string& p,     string& str);

struct operateTable {
	string str;
	void (*func)(const int, const int, const string&, string&);
};

operateTable tbl[] =
    {
        { "print",		Print },
        { "reverse",	Reverse },
        { "replace",	Replace }
	};

int main() {
	string str, opeStr, op3;
	const string emptyStr = "";
	int q, op1, op2;

	cin >> str;
	cin >> q;
	for(int i = 0; i < q; ++i){
		cin >> opeStr;
		cin >> op1;
		cin >> op2;
		for(const auto& e : tbl){
			if(e.str == opeStr){
				if(e.str == "replace"){
					cin >> op3;
					e.func(op1, op2, op3, str);
				}else{
					e.func(op1, op2, emptyStr, str);
				}
				break;
			}
		}
	}

	return 0;
}

void Print(const int a, const int b, const string& dummy, string& str) {
	cout << str.substr(a, b - a + 1) << endl;
}

void Reverse(const int a, const int b, const string& dummy, string& str) {
	reverse(str.begin() + a, str.begin() + b + 1);
}

void Replace(const int a, const int b, const string& p, string& str) {
	str.replace(a, b - a + 1, p);
}



Measured memory_bytes: 3180
#include<bits/stdc++.h>
#define int long long
using namespace std;

vector<int> operator+(vector<int> v, int a) {
	v.push_back(a);
	return v;
}

vector<int> operator+(vector<int> v, vector<int> w) {
	for (auto x : w)v.push_back(x);
	return v;
}

signed main() {
	int ans = 0;
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)cin >> v[i];
	int minus = 0;
	for (int x : v)if (x < 0)++minus;
	vector<int> lsum(n), rsum(n);
	vector<vector<int>> lminus(n), rminus(n);
	lsum[0] = v[0];
	rsum[0] = v[n - 1];
	if (v[0] < 0)lminus[0] = { v[0] };
	else lminus[0] = {};
	if (v[n - 1] < 0)rminus[0] = { v[n - 1] };
	else rminus[0] = {};
	for (int i = 1; i < n; ++i) {
		lsum[i] = lsum[i - 1] + v[i];
		rsum[i] = rsum[i - 1] + v[n - i - 1];
		lminus[i] = v[i] < 0 ? lminus[i - 1] + v[i] : lminus[i - 1];
		rminus[i] = v[n - i - 1] < 0 ? rminus[i - 1] + v[n - i - 1] : rminus[i - 1];
	}
	vector<int> ev;
	ev.clear();
	lsum.insert(lsum.begin(), 0);
	rsum.insert(rsum.begin(), 0);
	lminus.insert(lminus.begin(), ev);
	rminus.insert(rminus.begin(), ev);
	for (int i = 0; i <= k; ++i) {
		for (int j = 0; i + j <= k && i + j <= n; ++j) {
			int res = k - i - j;
			int preans = lsum[i] + rsum[j];
			vector<int> mm = lminus[i] + rminus[j];
			sort(mm.begin(), mm.end());
			for (int x = 0; x < res && x < mm.size(); ++x)preans -= mm[x];
			ans = max(ans, preans);
		}
	}
	cout << ans << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> ac(N), wa(N);
    rep(i, M) {
        int p;
        string S;
        cin >> p >> S;
        --p;
        if (ac[p]) continue;
        if (S == "AC") ac[p] = 1;
        else ++wa[p];
    }
    int AC = 0, WA = 0;
    rep(i, N) {
        AC += ac[i];
        if (ac[i]) WA += wa[i];
    }
    printf("%d %d\n", AC, WA);
    return 0;
}


Measured memory_bytes: 1024
H, W = map(int, input().split())
S = []
for h in range(H):
  S.append(list(input()))


for h in range(H):
    for w in range(W):
        cnt = 0
        if S[h][w]==".":
            if w > 0:
                cnt += int(S[h][w-1] == "#")
            if w < W-1:
                cnt += int(S[h][w+1] == "#")
                
            if h > 0:
                cnt += int(S[h-1][w] == "#")
                if w > 0:
                    cnt += int(S[h-1][w-1] == "#")
                if w < W-1:
                    cnt += int(S[h-1][w+1] == "#")
                    
            if h < H-1:
                cnt += int(S[h+1][w] == "#")
                if w > 0:
                    cnt += int(S[h+1][w-1] == "#")
                if w < W-1:
                    cnt += int(S[h+1][w+1] == "#")
            
            S[h][w] = str(cnt)

for s in S:
    print("".join(s))
            
               

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

using namespace std;

int main() {
  int a,b,n;
  int ans=0;
  cin >> n >> a >>b;
  
  for(int j=1; j<=n;j++){
    int sum=0;
    string s =to_string(j);
 
  for(int i=0; i<s.size(); i++){
    sum +=s.at(i)-'0';
  }
  if(a<=sum && sum<=b)
    ans +=j;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf=100000000;
int n,m;
int a[1100],b[1100],c[1100],dist[110][110];
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;
        b[i]--;
    }
    for(int i=0;i<n;i++)
    {
        for (int j=0;j<n ;j++ )
        {
            if(i==j)
            {
                dist[i][j]=0;
            }
            else
            {
                dist[i][j]=inf;
            }
        }
    }

    for(int i=0;i<m;i++)
    {
//        dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
//        dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
        dist[a[i]][b[i]]=c[i];
        dist[b[i]][a[i]]=c[i];
    }

    for (int k=0;k<n ;k++ )
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }

    }
    int ans=m;
    for(int i=0;i<m;i++)
    {
        bool shortest=false;
        for(int j=0;j<n;j++)
        {
            if(dist[j][a[i]]+c[i]==dist[j][b[i]])
            {
                shortest =true;
            }
        }
        if(shortest==true)
        {
            ans--;
        }
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n, i, j, x, y;
	vector<int>a;
	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> j;
		a.push_back(j);
	}

	sort(a.begin(), a.end());

	x = 0;
	y = 0;
	j = a[n - 1];
	for (i = n - 2; i >= 0; i--) {
		if (j == a[i]) {
			if (x == 0) {
				x = j;
				j = a[--i];
			}
			else {
				y = j;
				break;
			}
		}
		else {
			j = a[i];
		}
	}
	cout << (long long int)x * y;

	return 0;
}

Measured memory_bytes: 892
N, M = map(int, input().split())
imgA = [input() for i in range(N)]
imgB = [input() for i in range(M)]
flag = -1
flags = []

for i in range(N - M + 1):
    while True:
        flag = imgA[i].find(imgB[0], flag+1)
        if flag >= 0:
            for j in range(1, M):
                if imgA[i+j].find(imgB[j], flag) == flag:
                    continue
                else:
                    break
            else:
                print('Yes')
                exit()
        else:
            break
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#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 ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int k, x;
    cin >> k >> x;
    FOR(i, x - k + 1, x + k){
        cout << i;
        if(i != x + k - 1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int findSumOfDigits(int n) {
  int sum=0;
  while(n>0) {
    sum+=n%10;
    n/=10;
  }
  return sum;
}
int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int ans=0;
  for(int i=1;i<=n;++i) {
    if(findSumOfDigits(i)>=a && findSumOfDigits(i)<=b) {
      ans+=i;}
  }
  cout << ans << endl;
  return 0;
}
  


Measured memory_bytes: 256
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<int>A(n);
  rep(i,n){
    cin>>A[i];
  }
  rep(i,n){
    int x;
    cin>>x;
    A[i]-=x;
    A[i]=A[i]*(-1);
 //   cout<<A[i]<<endl;
  }
  sort(A.begin(),A.end());
  int sum=0;
  rep(i,n){
    A[i]=A[i]*(-1);
    if(A[i]<=0)break;
    sum+=A[i];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	string s;
	cin >> s;

	string ans = "Good";
	rep(i, 0, 3) {
		if (s[i] == s[i + 1]) ans = "Bad";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
    string S;
    ll n = 0;
    cin >> S;
    n = S.size();
    for(ll i = 0;i < n;i++){
        cout << "x";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

// 二つの値の最大値を求める関数
Int Max(const Int a, const Int b) {
    if (a >= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    Int n;
    cin >> n;
    vector<Int> a1(n);
    vector<Int> a2(n);
    vector<Int> a1Sum(n);
    vector<Int> a2Sum(n);
    for (Int i = 0; i < n; ++i) {
        cin >> a1[i];
    }
    for (Int i = 0; i < n; ++i) {
        cin >> a2[i];
    }
    a1Sum[0] = a1[0];
    a2Sum[0] = a2[n - 1];
    for (Int i = 1; i < n; ++i) {
        a1Sum[i] = a1Sum[i - 1] + a1[i];
        a2Sum[i] = a2Sum[i - 1] + a2[n - 1 - i];
    }
    Int result = 0;
    for (Int i = 0; i < n; ++i) {
        result = Max(result, a1Sum[i] + a2Sum[n - 1 - i]);
    }
    cout << result << endl;
    return 0;
}



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

using namespace std;

int main(){
    int n;
    cin >> n;
    std::multiset<int> st;
    int cnt = -1;
    ll h = 0;
    ll ph = 0;
    rep(i, n) {
        cin >> h;
        if(cnt == -1) {
            cnt++;
            ph = h;
        } else {
            if(ph >= h) {
                cnt++;
                ph = h;
            } else {
                st.insert(cnt);
                cnt = 0;
                ph = h;
            }
        }
        
    }
    st.insert(cnt);
    
    cout << *(st.rbegin()) << endl;
    
}


Measured memory_bytes: 4992
#include<algorithm>
#include<cstdio>
#define N 101
#define p 1000000007
#define ll long long
using namespace std;
inline int mod(int x){return x<p?x:x-p;}
inline int calc(int x,int y)
{
    int z=1;
    for(;y;x=(ll)x*x%p,y>>=1)if(y&1)z=(ll)x*z%p;
    return z;
}
int a[N],b[N],d[N],e[N],f[2][N],g[N],h,i,j,n;
inline bool cmp(int u,int v){return a[u]<a[v];}
inline int mul(int u,int v){return(ll)d[v]*e[u]%p;}
int main()
{
    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%d",a+i),b[i]=i;
    sort(b+1,b+n+1,cmp);
    for(i=1;i<=n;a[b[i++]]=h)if(a[b[i]]!=g[h])g[++h]=a[b[i]];
    for(i=0;i<=n;i++)e[i]=calc(d[i]=calc(2,g[i]),p-2);
    for(i=1,*f[0]=mod(p+d[a[1]]-mod(mul(1,a[1])<<1)),f[0][a[1]]=2;i<a[1];i++)f[0][i]=mod(mod(p+mul(i,a[1])-mul(i+1,a[1]))<<1);
    for(i=2;i<=n;i++)
    if(a[i-1]<a[i])
    {
        for(j=0;j<a[i-1];f[i&1][j++]=0)f[i&1^1][j]=(ll)f[i&1][j]*mul(a[i-1],a[i])%p;
        for(f[i&1^1][a[i]]=h=mod(f[i&1][j=a[i-1]]<<1),f[i&1][j]=0;j<a[i];j++)f[i&1^1][j]=(ll)h*(p+mul(j,a[i])-mul(j+1,a[i]))%p;
    }
    else
    {
        for(j=0;j<a[i];f[i&1][j++]=0)f[i&1^1][j]=f[i&1][j];
        for(j=a[i];j<=a[i-1];f[i&1][j++]=0)f[i&1^1][a[i]]=mod(f[i&1^1][a[i]]+mod(f[i&1][j]<<1));
    }
    for(i=j=0;i<=a[n];i++)j=mod(j+f[n&1^1][i]);
    return 0&printf("%d\n",j);
}

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

typedef long long ll;
typedef vector<int> vi;

const int M = 1000000007, BIG = 0x3f3f3f3f;

ll x, k, d;

ll Process() {
  x = abs(x);
  ll q = x / d;
  ll moves = min(k, q);
  k -= moves;
  x = x - moves * d;
  return (k & 1) ? abs(x - d) : x;
}

void Output() { cout << Process() << "\n"; }

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

  while (cin >> x) {
    cin >> k >> d;

    Output();
  }

  return 0;
}

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

#define INF (int)(1e9)
#define N_MAX (40)
#define AB_MAX (400)

using namespace std;

typedef long long int Int;


Int a[N_MAX],b[N_MAX],c[N_MAX];
Int dp[N_MAX+1][AB_MAX+1][AB_MAX+1];

int main(void)
{
    Int N,Ma,Mb;
    cin>>N>>Ma>>Mb;

    for(int i = 0;i <= N_MAX;i++) {
	for(int j = 0;j <= AB_MAX;j++) {
	    for(int k = 0;k <= AB_MAX;k++) {
		dp[i][j][k] = INF;
	    }
	}
    }

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

    dp[0][0][0] = 0;
    for(int i = 0;i < N_MAX;i++) {
	for(int j = 0;j <= AB_MAX;j++) {
	    for(int k = 0;k <= AB_MAX;k++) {
		if(dp[i][j][k] == INF)
		    continue;
		dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
		dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
	    }
	}
    }

    Int ans = INF;
    for(int j = 1;j <= AB_MAX;j++) {
	for(int k = 1;k <= AB_MAX;k++) {
	    if(j*Mb==k*Ma)
		ans = min(ans,dp[N][j][k]);
	}
    }

    if(ans == INF)
	ans = -1;
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 51712
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;
constexpr int64_t kMod1 = 1000000007LL;
constexpr int64_t kMod2 = 998244353LL;
constexpr int64_t kMod3 = 3571L;

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

  constexpr int64_t kN = 26;
  int64_t D;
  cin >> D;
  vector<int64_t> C(kN + 1, 0);
  for (int64_t c = 1; c <= kN; ++c) {
    cin >> C[c];
  }
  vector<vector<int64_t>> S(D + 1, vector<int64_t>(kN + 1));
  for (int64_t d = 1; d <= D; ++d) {
    for (int64_t c = 1; c <= kN; ++c) {
      cin >> S[d][c];
    }
  }
  vector<vector<int64_t>> last(D + 1, vector<int64_t>(kN + 1, 0));
  vector<int64_t> contests(D + 1);
  for (int64_t d = 1; d <= D; ++d) {
    cin >> contests[d];
  }

  auto Score = [&](const int64_t day) -> int64_t {
    int64_t score = 0;
    for (int64_t d = 1; d <= day; ++d) {
      last[d] = last[d - 1];
      last[d][contests[d]] = d;
      score += S[d][contests[d]];
      for (int64_t c = 1; c <= kN; ++c) {
        score -= C[c] * (d - last[d][c]);
      }
    }
    return score;
  };

  auto OutputResults = [&]() {
    for (int64_t d = 1; d <= D; ++d) {
      cout << contests[d] << endl;
    }
  };

  for (int64_t d = 1; d <= D; ++d) {
    int64_t best_score = INT64_MIN;
    int64_t best_conte = -1;
    for (int64_t c = 1; c <= kN; ++c) {
      contests[d] = c;
      int64_t temp_score = Score(d);
      if (temp_score > best_score) {
        best_score = temp_score;
        best_conte = c;
      }
    }
    contests[d] = best_conte;
  }

  int64_t prev_score = Score(D);
  constexpr int64_t kIgnoreBunbo = 5;
  constexpr int64_t kIgnoreBunshi = 0;
  constexpr int64_t kMaxConsecutiveWorse = 3;

  vector<int64_t> best_contests;
  int64_t best_score = INT64_MIN;
  int64_t consecutive_worse = 0;
  vector<int64_t> better_contests;
  for (int64_t i = 0; i < 50000; ++i) {
    const int64_t day_candidate_1 = (rand() % D) + 1;
    const int64_t day_candidate_2 = (rand() % D) + 1;
    swap(contests[day_candidate_1], contests[day_candidate_2]);
    const int64_t temp_score = Score(D);
    if (temp_score > prev_score) {
      // KEEP
      consecutive_worse = 0;
      better_contests = contests;
      if (temp_score > best_score) {
        best_score = temp_score;
        best_contests = contests;
      }
    } else if ((rand() % kIgnoreBunbo) <= kIgnoreBunshi && temp_score > prev_score * 0.97 &&
               consecutive_worse <= kMaxConsecutiveWorse) {
      // KEEP
      ++consecutive_worse;
    } else {
      swap(contests[day_candidate_1], contests[day_candidate_2]);
    }
    if (temp_score < best_score * 0.9) {
      contests = better_contests;
    }
    if (temp_score < best_score * 0.5) {
      contests = best_contests;
    }
  }

  contests = best_contests;
  OutputResults();
  return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
	bool is_visited;
} edge;
void recursive_comb( int*indexes, int s, int rest, std::function <void( int* )> f ) {
	if (rest == 0){
		f( indexes );
	}
	else {
		if (s < 0) return;
		recursive_comb( indexes, s - 1, rest, f );
		indexes[ rest - 1 ] = s;
		recursive_comb( indexes, s - 1, rest - 1, f );
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb( int n, int k, std::function <void( int* )> f ) {
	int indexes[ k ];
	recursive_comb( indexes, n - 1, k, f );
}

int main( void ){
	int N, C; cin >> N >> C;
	vector <vector <int> > color( N, vector <int>( N )), cost( C, vector <int>( C ));
	rep( i, 0, C ) rep( j, 0, C ) cin >> cost[ i ][ j ];
	rep( i, 0, N ) rep( j, 0, N ) cin >> color[ i ][ j ];

	vector <vector <int> > cost_of_colors( 3, vector <int>( C, 0 ));
	rep( i, 0, N ){
		rep( j, 0, N ){
			int index = ( i + j ) % 3;
			rep( c, 0, C )
				cost_of_colors[ index ][ c ] += cost[ color[ i ][ j ] - 1 ][ c ];
		}
	}
	int min_cost = k_mod;
	foreach_comb( C, 3, [ cost_of_colors, &min_cost ]( int*indexes ) {
		vector<int> v{indexes[0],indexes[1],indexes[2]};
		do {
			int sum = 0;
			rep( i, 0, 3 )
				sum += cost_of_colors[ i ][ v[ i ] ];
			min_cost = min( min_cost, sum );
		} while (std::next_permutation( v.begin(), v.end()));
	} );
	cout << min_cost << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

using namespace std;

int main()
{
    deque<int> q;
    int n;
    bool re = false;
    cin >> n;
    int t;
    while (n--)
    {
        cin >> t;
        if (re)
            q.emplace_back(t);
        else
            q.emplace_front(t);
        re = !re;
    }
    if (re)
        for (auto i : q)
            cout << i << " ";
    else
        for (auto it = q.rbegin(); it != q.rend(); it++)
            cout << *it << " ";
    cout << endl;
    return 0;
}

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

int main(){
  int N;
  int K;
  int Q;
  int P[N];
  int seikai;
  cin >> N;
  cin >> K;
  cin >> Q;
  for(int i = 0; i < N; i++)
  {
    P[i] = K - Q;
  }
  for(int i = 0; i < Q; i++){
    cin >> seikai;
    P[seikai - 1] += 1;
  }
  for(int i = 0; i < N; i++) {
    if(P[i] > 0) {cout << "Yes" << endl;}
    else {cout << "No" << endl;}
  }
  return 0;
}

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

public class Main {
    // 最小非負剰余
    static void divmod (int[] vi, int a, int b) {
        int q;
        int r;
        if (b < 0) {
            b = -b;
            a = -a;
        }
        q = 0;
        r = a;
        if (r > 0) {
            while (r - b >= 0) {
                q += 1;
                r -= b;
            }
        } else if (r < 0) {
            do {
                q -= 1;
                r += b;
            } while (r < 0);
        }
        vi[0] = q;
        vi[1] = r;
    }
    public static void main (String[] args) throws IOException {
        final String s;
        try (BufferedReader reader =
                 new BufferedReader (new InputStreamReader (System.in))) {
            s = reader.readLine();
        }
        int[] vi           = new int[2];
        int           N    = Integer.parseInt (s);
        StringBuilder sb   = new StringBuilder();
        int           base = 2;
        while (0 != N) {
            // base = 3 でうまくいかない
            // 例えば 7
            // base = 2 は OK
            // sb.insert (0, String.valueOf (Math.abs (N % base)));
            // N -= Math.abs (N % base);
            // N /= -base;

            // base = 3 でもうまくいく
            divmod (vi, N, base);
            sb.insert (0, String.valueOf (vi[1]));
            N -= vi[1];
            divmod (vi, N, -base);
            N = vi[0];
            System.gc();
        }
        if (sb.length() == 0) sb.append ("0");
        System.out.println (sb);
    }
}


Measured memory_bytes: 35028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll N, K;
  cin >> N >> K;

  ll ans = 0;
  for (ll i = 0; i < N; i++)
  {
    ll h;
    cin >> h;
    if (h >= K)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final Queue<Dish> eatQueue = new PriorityQueue<>(Comparator.<Dish>comparingInt(dish -> dish.getA() + dish.getB()).reversed());
        for (int i = 0; i < n; i++) {
            final Dish dish = new Dish(scanner.nextInt(), scanner.nextInt());
            eatQueue.add(dish);
        }

        boolean isTurnOnTakahashi = true;
        long takahashi = 0;
        long aoki = 0;
        while (!eatQueue.isEmpty()) {
            final Dish d = eatQueue.remove();
            if (isTurnOnTakahashi) {
                takahashi += d.getA();
            } else {
                aoki += d.getB();
            }
            isTurnOnTakahashi = ! isTurnOnTakahashi;
        }

        System.out.print(takahashi - aoki);

    }

    static class Dish {
        private final int a;
        private final int b;
        public Dish(final int a, final int b) {
            this.a = a;
            this.b = b;
        }

        public int getA() {
            return a;
        }

        public int getB() {
            return b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Dish dish = (Dish) o;
            return a == dish.a &&
                    b == dish.b;
        }

        @Override
        public int hashCode() {
            return Objects.hash(a, b);
        }

        @Override
        public String toString() {
            return "Dish{" +
                    "a=" + a +
                    ", b=" + b +
                    '}';
        }
    }

}


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

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

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

  int total = 0;
  rep(i, 3) {
    total = 0;
    rep (j, 3) {
      total += c[i][j];
    }
    if (total == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  rep(i, 3) {
    total = 0;
    rep (j, 3) {
      total += c[j][i];
    }
    if (total == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (c[0][0] + c[1][1] + c[2][2] == 3) {
    cout << "Yes" << endl;
    return 0;
  }
  if (c[0][2] + c[1][1] + c[2][0] == 3) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int ac=0,wa=0,tle=0,re=0;
	while(n--)
	{
		string s;
		cin>>s;
		if(s=="AC")
		{
			ac++;
		}
		else if(s=="WA")
		{
			wa++;
		}
		else if(s=="TLE")
		{
			tle++;
		}
		else if(s=="RE")
		{
			re++;
		}
	}
	cout<<"AC x "<<ac<<"\n";
	cout<<"WA x "<<wa<<"\n";
	cout<<"TLE x "<<tle<<"\n";
	cout<<"RE x "<<re;
}

Measured memory_bytes: 3592
#include <stdio.h>
 
int main(void) {
    int a[4][3][10]={0};
    int n, b, f, r, v;
    int i, j, k;
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        a[b-1][f-1][r-1]+=v;
    }
    for(i=0; i<4; i++) {
        for(j=0; j<3; j++) {
            for(k=0; k<10; k++) {
                printf("%2d", a[i][j][k]);
            }
            putchar('\n');
            if(i<3 && j==2) printf("####################\n");
        }
    }
     
    return 0;
}


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

int main(){
    long n,m,k=0;
    cin>>n>>m;
    vector<long> A(n);
    vector<pair<long,long>> BC(m);
    vector<long> change;
    For(i,n){
        cin>>A.at(i);
    }
    For(i,m){
        long b,c;
        cin>>b>>c;
        BC[i] = make_pair(c, b);
        k+=b;
    }
    sort(A.begin(),A.end());
    sort(BC.begin(),BC.end());//firstが数字 secondが個数
    
    long t=0;
    long num=m-1;
    long kosuu=0;
    while(A.at(t)<BC[num].first){
        A.at(t)=BC[num].first;
        t++;
        kosuu++;
        if(kosuu>=BC[num].second){
            num--;
            kosuu=0;
        }
        if(t>=k||t>=n){
            break;
        }
    }
    long ans=0;
    For(i,n){
        //cout<<A.at(i)<<endl;
        ans+=A.at(i);
    }
    cout<<ans<<endl;
    //For(i,m){
        //cout<<BC[i].first<<BC[i].second<<endl;
    //}    
}



Measured memory_bytes: 2560
from collections import defaultdict
N = int(input())
C = [int(input()) for _ in range(N)]
dic = defaultdict(list)
for i in range(N):
    dic[C[i]].append(i)
es = [[] for _ in range(N)]
for i in range(N - 1):
    es[i].append(i + 1)
for key in dic:
    if len(dic[key]) == 1:
        continue
    i, L, v1, v2 = 1, len(dic[key]) - 1, dic[key][0], dic[key][1]
    while True:
        if v1 + 1 != v2:
            es[v1].append(v2)
        v1 = v2
        if i < L:
            i += 1
            v2 = dic[key][i]
        else:
            break
dp = [0 for _ in range(N)]
dp[0], MOD = 1, 10**9 + 7
for i in range(N - 1):
    for j in es[i]:
        dp[j] = (dp[j] + dp[i]) % MOD
print(dp[N - 1])

Measured memory_bytes: 121080
#include <iostream>
#include <queue>
#include <vector>
#include <utility>

int main(void){
  int n, q;
  std::pair<int, int> max;
  std::priority_queue<std::pair<int, int> > v;
  std::vector<int> a(1000000, 0);
  std::cin >> n >> q;
  for(int i=0; i < q; i++){
    int man, fish_number; std::cin >> man >> fish_number;
    a[man] += fish_number;
    v.push(std::pair<int, int>(a[man], -man));
    
    while(1){
      max = v.top();
      if(max.first == a[-max.second]){
	std::cout << -max.second << " " << max.first << std::endl;
	break;
      }
      v.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 6012
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int a, b, n;
	while (cin >> a >> b >> n) {
		int ans(0);
		int r = a%b;
		rep(i, 0, n) {
			r *= 10;
			ans += r / b;
			r %= b;
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

void F(int x,map<int,int>&mp){
  if(x <= 1)return;
  if(x == 2){
    mp[x]++;
    return;
  }
  if((x&1)==0){
    F(2,mp);F(x>>1,mp);
    return;
  }
  for(int i = 3; i*i <= x; i+=2){
    if(x % i == 0){
      F(i,mp);F(x/i,mp);
      return;
    }
  }
  mp[x]++;
}

int Cnt(int x){
  int cnt = 0;
  while(x%2 == 0){
    x /= 2;
    cnt++;
  }
  return cnt;
}

void M(map<int,int>&a,map<int,int>&b){
  for(auto&e:b){
    ChangeMax(a[e.first],e.second);
  }
}

int Pow(int a,int b){
  if(b == 0) return 1;
  if(b == 1) return a;
  if((b&1) == 1) return Pow(Pow(a,b>>1),2)*a;
  if(b == 2) return a*a;
  return Pow(Pow(a,b>>1),2);
}

int main(){
  int n,m; cin >> n >> m;
  vector<int> v(n); cin >> v;
  {
    int pre = 0;
    for(int i = 0; i < n; ++i){
      if(i == 0)pre = Cnt(v[i]);
      else if(pre != Cnt(v[i])){
	cout << 0 << endl;
	return 0;
      }
    }
  }  
  map<int,int> mp;
  for(auto e:v){
    map<int,int> nw;
    F(e,nw);
    M(mp,nw);
  }
  ll base = 1;
  for(auto e:mp){
    base *= pow(e.first,e.second);
  }
  int ans = 2*m/base;
  ans = (ans+1)/2;
  cout << ans << endl;
}


Measured memory_bytes: 4060
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int r,c;
    cin >> r>>c;

    int x[105][105];

    for (int i = 0; i < r;i++){
        for (int j = 0; j < c;j++){
            cin >> x[i][j];
        }
    }
    for (int i = 0; i < r;i++){
        x[i][c] = 0;
        for (int j = 0; j < c;j++){
            x[i][c] += x[i][j];
        }
    }
    for (int j = 0; j <= c; j++)
    {
        x[r][j] = 0;
        for (int i = 0; i < r; i++)
        {
            x[r][j] += x[i][j];
        }
    }
    for (int i = 0; i <= r;i++){
        for (int j = 0; j <= c;j++){
            cout << x[i][j];
            if(j<c)
                cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int ans=0;
  REP(i,0,A){
    REP(j,0,B){
      REP(k,0,C){
        if(i*500+j*100+k*50==X)
          ans++;
      }
    }
  }
  cout<<ans;
  }


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

void mul(const int A[4],const int B[4],int C[4]){
	C[0] = A[0]*B[0] - A[1]*B[1] - A[2]*B[2] - A[3]*B[3];
	C[1] = A[1]*B[0] + A[0]*B[1] - A[3]*B[2] + A[2]*B[3];
	C[2] = A[2]*B[0] + A[3]*B[1] + A[0]*B[2] - A[1]*B[3];
	C[3] = A[3]*B[0] - A[2]*B[1] + A[1]*B[2] + A[0]*B[3];
}

int main(){
	int n,A[4],B[4];
	while(cin >> n, n != 0){
		for(int t=0;t < n;t++){
			cin >> A[0] >> A[1] >> A[2] >> A[3] >> B[0] >> B[1] >> B[2] >> B[3];
			int C[4];
			mul(A,B,C);
			cout << C[0] << " " << C[1] << " " << C[2] << " " << C[3] << endl;
		}
	}
	return 0;
}



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

int main (void){
  char a[10];

  cin >> a;

  if(a[0] == '7' || a[1] == '7' || a[2] == '7'){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 3632