akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
using ll = long long;

struct process{
  string name;
  int time;
};

int main(){
  int n, q; cin >> n >> q;
  queue<process> p;
  REP(i,n){
    process buf;
    cin >> buf.name >> buf.time;
    p.push(buf);
  }
  int t = 0;
  while(p.size() > 0){
    process now = p.front();
    if(now.time > q){
      now.time -= q;
      t += q;
      p.push(now);
    }
    else{
      t += now.time;
      cout << now.name << " " << t << endl;
    }
    p.pop();
  }
  return 0;
}


Measured memory_bytes: 6324
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
int B[MAXN];
pii X[MAXN];
pii Y[MAXN];
bool visited[MAXN];

bool dfs(int a)
{
    visited[a] = true;

    for(int b:graph[a]){
        if(B[b]==-1||(!visited[B[b]]&&dfs(B[b]))){
            A[a] = b;
            B[b] = a;
            return true;
        }
    }

    return false;
}

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;

    graph = vector<vector<int> > (n+1);

    for(int i=0;i<n;i++)
        cin>>X[i].f>>X[i].s;

    for(int i=0;i<n;i++)
        cin>>Y[i].f>>Y[i].s;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            if(X[j].f<Y[i].f&&X[j].s<Y[i].s)graph[i].push_back(j);
    }

    fill(A,A+n,-1);
    fill(B,B+n,-1);

    for(int i=0;i<n;i++){
        if(A[i]==-1){
            fill(visited,visited+n,false);
            if(dfs(i))cnt++;
        }
    }
    cout<<cnt<<"\n";

    return 0;
}


Measured memory_bytes: 2304
n, a, b = [int(i) for i in input().split()]
citys = [int(i) for i in input().split()]

res = 0

for i in range(n-1):
    if (citys[i+1] - citys[i]) * a < b:
        res += (citys[i+1] - citys[i]) * a
    else:
        res += b

print(res)

Measured memory_bytes: 14252
n,m = map(int, input().split(" "))
ac = 0
wa = 0
en_li = [[] for i in range(n)]
print
for i in range(m):
    a, b = input().split(' ')
    en_li[int(a)-1].append(b)
ac = 0
wa = 0
for i in en_li:
    if 'AC' in i:
        wa += i.index('AC')
        ac += 1
print(ac, wa)


Measured memory_bytes: 20272
import java.util.*;

public class Main {
	int p, ace;
	char[] card;
	
	void add(char c){
		if(c=='A'){
			if(p+11<=21){
				ace++; 
				p+=11;
			}else{
				p++;
			}
		}else if(Character.isDigit(c)){
			p+=c-'0';
		}else{
			p+=10;
		}
		if(p>21 && ace>0){
			p-=10;
			ace--;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int t=0;t<n;t++){
			card = new char[10];
			for(int i=0;i<10;i++) card[i] = sc.next().charAt(0);
			p = 0;
			ace = 0;
			add(card[0]);
			add(card[1]);
			if(p==21){
				System.out.println("blackjack");
				continue;
			}
			
			boolean f = false;
			for(int i=2;i<10;i++){
				if(p<17 || p==17 && ace>0){
					add(card[i]);
				}else{
					if(p>21) System.out.println("bust");
					else System.out.println(p);
					f = true;
					break;
				}
			}
			if(f==false) System.out.println(p);
		}
	}
	
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, k;
  cin >> n >> k;
  if (k == 1)
    cout << 0 << endl;
  else
    cout << n - k << endl;
}


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

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i=0; i<N-1; i++) cin >> A[i];
    int ans[N]={0};
    for (int i=0; i<N-1; i++){
        ans[A[i]-1]++;
    }
    for (int x=0; x<N; x++){
        cout << ans[x] << endl;
    }
}

Measured memory_bytes: 5052
import java.util.*;

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

        int N = sc.nextInt();
        int X = sc.nextInt();
        int[] L = new int[N];
        int[] D = new int[N + 1];
        D[0] = 0;

        for(int i=0; i<N; i++){
            L[i] = sc.nextInt();
        }

        int ans = 1;
        for(int i=1; i<=N; i++){
            D[i] = D[i - 1] + L[i - 1];
            if(D[i]<=X){
                ans += 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n),b(n),c(m),d(m);
  rep(i,n){
    cin >> a.at(i) >> b.at(i);
  }
  rep(i,m){
    cin >> c.at(i) >> d.at(i);
  }
  rep(i,n){
    ll sum=1e9+7,ans;
    rep(j,m){
      ll p=abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
      if(sum>p){
        sum=p;
        ans=j+1;
      }
    }
    cout << ans << endl;
  }
}
      

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

const ll INF = 1LL << 60;

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

    int diff = b - a;
    ll total = 0;
    for (int x = 1; x <= diff; x++) {
        total += x;
    }
    cout << total - b << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        char[] tap = GetInputChar();

        string output = "Yes";

        for (int i = 0; i < tap.Length; i++)
        {
            if(i% 2 == 0)
            {
                //奇数
                if (tap[i] == 'R'  || tap[i] == 'U' || tap[i] == 'D')
                {
                }
                else
                {
                    output = "No";
                    break;
                }
            }
            else
            {
                //偶数
                if (tap[i] == 'L' || tap[i] == 'U' || tap[i] == 'D')
                {
                }
                else
                {
                    output = "No";
                    break;
                }
            }
        }

        Console.WriteLine(output);

        Console.ReadKey();


    }



    public static int GetInputInt()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] GetInputsInt()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static List<int> GetInputsIntList()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
    }
    public static List<float> GetInputsFloatList()
    {
        return Console.ReadLine().Split(' ').Select(float.Parse).ToList();
    }

    public static char[] GetInputChar()
    {
        return Console.ReadLine().ToCharArray();
    }

    public static long GetInputLong()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] GetInputsLong()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

char mapData[15][15];
int dp[15][15];
int h, w;
int dx[] = {-1, 0, 1};

main(){
  while(cin >> w >> h && (h || w)){ 
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> mapData[i][j];
      }
    }
    fill(dp[0], dp[15], 0);
    for(int i=0;i<w;i++){
      if(mapData[0][i] != '1')
	dp[0][i] = 1;
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(dp[i][j] == 0) continue;
	if(mapData[i][j] == '2'){
	  int ty = i + 2;
	  if(ty<0 || ty>=h) continue;
	  if(mapData[ty][j] == '1') continue;
	  dp[ty][j] += dp[i][j];
	}else{
	  for(int k=0;k<3;k++){
	    int ty = i + 1;
	    int tx = j + dx[k];
	    if(ty<0 || ty>=h) continue;
	    if(tx<0 || tx>=w) continue;
	    if(mapData[ty][tx] == '1') continue;
	    if(mapData[ty][tx] == '2' && k != 1) continue;
	    dp[ty][tx] += dp[i][j];
	  }
	}
      }
    }
    int ans = 0;
    for(int i=0;i<w;i++){
      if(mapData[h-2][i] == '2') ans += dp[h-2][i];
      if(mapData[h-1][i] != '1') ans += dp[h-1][i];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n, *a, *b;

	a = (int*)malloc(sizeof(int) * 200000);
	b = (int*)malloc(sizeof(int) * 200000);
	int i, flag = 1, head = 0;
	scanf("%d", &n);
	int end = n - 1;
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (i = n - 1; i >= 0; i--)
	{
		if (flag)
		{
			b[head++] = a[i];
			flag = 0;
		}
		else
		{
			b[end--] = a[i];
			flag = 1;
		}
	}
	for (i = 0; i < n - 1; i++)
		printf("%d ", b[i]);
	printf("%d\n", b[i]);

}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;

llong Merge(int* array, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int array_l[n1 + 1];
  int array_r[n2 + 1];
  for (int i = 0; i < n1; i++) {
    array_l[i] = array[left + i];
  }
  for (int i = 0; i < n2; i++) {
    array_r[i] = array[mid + i];
  }
  array_l[n1] = INT_MAX;
  array_r[n2] = INT_MAX;
  int i = 0;
  int j = 0;
  llong cnt = 0;
  for (int k = left; k < right; k++) {
    if (array_l[i] <= array_r[j]) {
      array[k] = array_l[i];
      i = i + 1;
    } else {
      array[k] = array_r[j];
      j = j + 1;
      cnt += n1 - i;
    }
  }
  return cnt;
}

llong MergeSort(int* array, int left, int right) {
  llong cnt = 0;
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    cnt += MergeSort(array, left, mid);
    cnt += MergeSort(array, mid, right);
    cnt += Merge(array, left, mid, right);
  }
  return cnt;
}

int main() {
  int n;
  cin >> n;
  int array[n];
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }
  llong cnt = MergeSort(array, 0, n);
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4660
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 11;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

char in[105];
int main() {
	scanf("%s", in);
	int L = strlen(in);
	printf("%c%d%c\n", in[0], L - 2, in[L - 1]);
	return 0;
}

Measured memory_bytes: 256
import itertools
import math

dishes = list(map(int, [input() for _ in range(5)]))
p_list = list(itertools.permutations(dishes))

min_total_time = 1000000000
for p in p_list:
    next_time = 0
    for idx, dish in enumerate(p):
        if idx <= 3:
            next_time = math.ceil((next_time + dish) / 10) * 10
        else:
            next_time += dish
    min_total_time = min(min_total_time, next_time)

print(min_total_time)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

int main() {
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];

    sort(all(a));
    sort(all(c));

    ll ans=0;
    rep(i,n){
        ll num1=lower_bound(all(a),b[i])-a.begin();
        ll num2=c.end()-upper_bound(all(c),b[i]);
        //cout<<num1<<" "<<num2<<endl;
        ans+=(num1*num2);
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <complex>
#include <cmath>
#include <algorithm>

using namespace std;

int n, m;
vector<int> r;
vector<int> got;

int main()
{
    cin >> n;
    m = n;
    n = (1 << n);
    r.resize(n + 1);
    got.resize(n + 1);
    for (int i = 0; i < n; i++)
        cin >> r[i];
    sort(r.begin(), r.end());
    reverse(r.begin(), r.end());
    got[0] = 1;
    for (int step = 1; step <= m; step++)
    {
        vector<int> have, create;
        for (int i = 0; i < n; i++)
        {
            if (got[i] == 1)
            {
                have.push_back(r[i]);
            }
            else
            {
                if (create.size() < have.size())
                {
                    if (r[i] < have[create.size()])
                    {
                        create.push_back(r[i]);
                        got[i] = 1;
                    }
                }
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (got[i] == 0)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 3632
class Knapsack
	def initialize(items, budget)
		@items = items.sort_by{|c, v| -v.to_f / c}
		@budget = budget

		@left_value = 0
		@left_cost = 0
		i = 0
		while i < @items.size
			c, v = @items[i]
			break if @left_cost + c > @budget
			@left_cost += c
			@left_value += v
			i += 1
		end

		@l = @r = i
		@states = []
		@lower_bound = @left_value
		@opt_cost = @left_cost 
	end

	def solve
		return @left_value if @left_cost == @budget || @l == @items.size

		@states << [@left_cost, @left_value]
		@states << [@left_cost + @items[@l][0], @left_value + @items[@l][1]]
	
		loop {
			if @r < @items.size - 1
				@r += 1
				@states += @states.map{|c, v|
					[c + @items[@r][0], v + @items[@r][1]]
				}
			end
	
			if @l > 0
				@l -= 1
				@left_cost -= @items[@l][0]
				@left_value -= @items[@l][1]
				@states += @states.map{|c, v|
					[c - @items[@l][0], v - @items[@l][1]]
				}
			end

			prun
			update_lower_bound
	
			break if @l == 0 && @r == @items.size-1
		}
	
		return [@opt_cost, @lower_bound]
	end

private
	def upper_bound(cost, value)
		if cost <= @budget
			if @r == @items.size-1
				value
			else
				value + (@budget - cost).to_f * @items[@r+1][1] / @items[@r+1][0]
			end
		else
			if @l == 0
				value
			else
				value + (@budget - cost).to_f * @items[@l-1][1] / @items[@l-1][0]
			end
		end
	end

	def prun
		@states.reject!{|c, v|
			next true if c - @left_cost > @budget
			next true if upper_bound(c, v) <= @lower_bound
			false
		}
		hash = Hash.new(0)
		@states.each{|c, v|
			hash[c] = v if v > hash[c]
		}
		@states = hash.to_a
	end

	def update_lower_bound
		@states.each{|c, v|	
			if c <= @budget && v > @lower_bound
				@lower_bound = v 
				@opt_cost = c
			end
		}
	end
end

def knapsack(items, budget, mode = :normal)
	cost_group = items.group_by(&:first)
	items = cost_group.map{|c, group|
		group.sort_by(&:last).last(budget / c)
	}.inject([], &:+)

	case mode
	when :normal
		return _knapsack_normal(items, budget) 
	when :core
		return _knapsack_core(items, budget)
	else
		raise "unknown mode"
	end
end

def _knapsack_normal(items, budget)
	table = (0..1).map{ Array.new(budget+1, 0) }
	for i in 0..items.size-1
		c, v = items[i]
		for j in 0..budget
			x = table[0][j]
			y = (j >= c ? table[0][j-c] + v : 0)
			table[1][j] = x > y ? x : y
		end
		table << table.shift
	end
	c = (1..budget).max_by{|i| table[0][i]}
	[c, table[0][c]]
end

def _knapsack_core(items, budget, mode = :normal)
	if mode == :drop_useless
		cost_group = items.group_by(&:first)
		items = cost_group.map{|c, group|
			group.sort_by(&:last).last(budget / c)
		}.inject([], &:+)
	end

	k = Knapsack.new(items, budget)
	k.solve
end

i = 1
loop {
	w = gets.to_i
	break if w == 0

	no_condition = 0
	n = gets.to_i
	items = []
	n.times { items << gets.split(/,/).reverse.map(&:to_i) }
	items.reject!{|c, v|
		if c == 0
			no_condition += v
			next true
		end
		false
	}
	
	c, v = knapsack(items, w, :normal)
	puts "Case #{i}:"
	puts v + no_condition
	puts c
	i += 1
}

Measured memory_bytes: 6920
# coding: utf-8
def search(l, k): # 二分探索を関数化
    # 現在の探索位置の左右端を管理
    left = 0
    right = len(l)
    while left + 1 < right:
        now = (left + right) // 2
        # 見つかった場合Trueを返す
        if l[now] == k:
            return(True)
        # 現在の探索位置が検索するものより大きい場合左側を探索
        elif k >= l[now]:
            left = now
        # 現在の探索位置が検索するものより小さい場合右側を探索
        else:
            right = now
    # 見つからない場合Falseを返す
    return(False)
# 各種入力
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
# 解答の初期化
ans = 0
for i in T:
    # 見つかった場合Trueが返ってくるのでansに1を足す
    if search(S, i) == True:
        ans += 1
# 解答の出力
print(ans)


Measured memory_bytes: 16712
// 5/6
// 個数制限なしナップサック問題

#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>;
using Graph = vector<vector<int>>;

ll dp[1010][10010];
// const int INF = 1000000000;

int main() {
    int H, N;
    cin >> H >> N;

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

    // dp初期化
    rep(i, H + 1) dp[0][i] = 10000000000;

    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j <= H; j++) {
            if (j <= A[i]) {
                dp[i + 1][j] = min(B[i], dp[i][j]);
            } else {
                dp[i + 1][j] = min(dp[i + 1][j - A[i]] + B[i], dp[i][j]);
            }
        }
    }

    cout << dp[N][H] << endl;
    return 0;
}

Measured memory_bytes: 78592
#include <stdio.h>
#include <stdlib.h>

typedef struct _node{
	struct _node *prev;
	struct _node *next;

	int val;

}Node;


void insert(Node **head, Node **tail,  int val ){

	Node *ptr;


	ptr = (Node*)malloc(sizeof(Node));
	ptr->val = val;

	ptr->prev = NULL;
	ptr->next = *head;

	if( *head != NULL ) {
		(*head)->prev = ptr;
		*head = ptr;
	}else{
		*head = ptr;
		*tail = ptr;
	}
	
}

void delete_first( Node **head, Node **tail ){
	
	Node *ptr = *head;

	if( ptr->next != NULL ){
		ptr->next->prev = NULL;
		*head = ptr->next;
	}else{
		*head = NULL;
		*tail = NULL;
	}

	free(ptr);
}


void delete_last( Node **head, Node **tail ){

	Node *ptr = *tail;

	if( ptr->prev != NULL ){
		ptr->prev->next = NULL;
		*tail = ptr->prev;
	}else{
		*head = NULL;	
		*tail = NULL;
	}
	free( ptr );
}

void delete(Node **head, Node **tail, int val ){

	Node *ptr = *head;
	if(*head == NULL) return;

	//Seek for matching node
	while( ptr->next!=NULL && ptr->val!=val  )
		ptr = ptr->next;

	// delete
	if( ptr->val == val ){

		if( ptr->next == NULL ){
			delete_last(head, tail);
		}else if( ptr->prev == NULL ){
			delete_first(head, tail);
		}else{
			ptr->prev->next = ptr->next;
			ptr->next->prev = ptr->prev;
			free(ptr);
		}
	}
}





void print( Node * node ){

		
	if(node==NULL) return;
	
	do{
		printf( "%d%c", node->val, (node->next!=NULL)?' ':'\n' );
		node  = node->next;
	}while( node != NULL  );
}

int main( ){

	int i, n, val;
	char cmd[33];
	Node *head=NULL, *tail=NULL;
	

	scanf( "%d\n", &n );
	
	for( i=0; i<n; i++ ){
		fgets( cmd, sizeof(cmd), stdin );

		if( cmd[0]=='d' && cmd[6]=='F' ){
			delete_first( &head, &tail );
		}
		else if( cmd[0]=='d' && cmd[6]=='L' ){
			delete_last( &head, &tail );
		}
		else if( cmd[0] == 'd' ){
			val = atoi( &cmd[7] );
			delete( &head, &tail, val );
		}
		if( cmd[0]=='i' ){
			val = atoi( &cmd[7] );
			insert( &head, &tail, val );
		}
	}

	print(head);
	
	return 0;
}


Measured memory_bytes: 32972
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int a1,a2,a3;
    cin>>a1>>a2>>a3;
    if(a1+a2+a3>=22){
        cout<<"bust"<<endl;
    }else{
        cout<<"win"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> x(m),y(m);
    rep(i,m){
        cin >> x[i] >> y[i];
        x[i]--;y[i]--;
    }
    int ans=0;
    vector<ll> num_ball(n,1);
    vector<bool> red_ball(n,false);
    red_ball[0]=true;
    rep(i,m){
        num_ball[x[i]]--;num_ball[y[i]]++;
        if(red_ball[x[i]]==true){
            red_ball[y[i]]=true;
            if(num_ball[x[i]]==0){
                red_ball[x[i]]=false;
            }
        }
    }
    rep(i,n){
        if(red_ball[i]==true){
            ans++;
        }
    }
    cout << ans << endl;

}

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i=0; i<N; i++){
        cin >> p.at(i);
    }
    sort(p.begin(),p.end());
    int total=0;
    for (int i=0;i<K;i++){
        total += p.at(i);
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
#include<math.h> 
int main()
{
	int i,j,t;
	int a[3]; 
	for(i=0;i<3;i++){
		scanf("%d",&a[i]); 
	} 
	for(i=1;i<3;i++){
		for(j=0;j<3-i;j++){
			if(a[j]>a[j+1]){
				t=a[j];a[j]=a[j+1];a[j+1]=t; 
			} 
		} 
	} 
	printf("%d",a[1]-a[0]+a[2]-a[1]); 
} 

Measured memory_bytes: 128
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int A = 2000000000;
        if (X <= Y) A = Math.abs(Y-X);
        int B = 2000000000;
        if (-X <= Y) B = Math.abs(Y+X)+1;
        int C = 2000000000;
        if (X <= -Y) C = Math.abs(-Y-X)+1;
        int D = 2000000000;
        if (-X <= -Y) D = Math.abs(-Y+X)+2;
        System.out.println(Math.min(Math.min(A, B), Math.min(C, D))); 
    }
    
}

Measured memory_bytes: 35760
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define repd(i,a,b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i, N) cin >> A.at(i);
	int l=0;
	
	rep(i, N)
	{
		if(A.at(i)%2==0)
		{
			if(A.at(i)%3!=0 && A.at(i)%5!=0)
			{
			    l=1;
			    break;
			}
		}
	}
	if(l==1) cout << "DENIED" << endl;
	else cout << "APPROVED" <<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemD solver = new ProblemD();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemD {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int height = in.nextInt();
			int width = in.nextInt();
			char[][] s = new char[height][];
			char[][] columns = new char[width][height];
			for (int r = 0; r < height; r++) {
				s[r] = in.next().toCharArray();
				for (int c = 0; c < width; c++) {
					columns[c][r] = s[r][c];
				}
			}
			int ans = 0;
			for (int i = 0; i + 1 < columns.length; i++) {
				ans += solve(columns[i], columns[i + 1]);
			}
			out.println(ans);
		}

		private int solve(char[] a, char[] b) {
			int n = a.length;
			int[][] cost = new int[n + 1][n + 1];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (a[i] == b[j]) {
						++cost[n - 1 - i][n - 1 - j];
					}
				}
			}
			for (int i = n - 1; i >= 0; i--) {
				for (int j = n - 1; j >= 0; j--) {
					cost[i][j] += cost[i + 1][j + 1];
				}
			}
			final int infinity = 1000000000;
			int[][] d = new int[n + 1][n + 1];
			for (int[] arr : d) {
				Arrays.fill(arr, infinity);
			}
			d[n][n] = 0;
			for (int s1 = n; s1 >= 0; s1--) {
				for (int s2 = n; s2 >= 0; s2--) {
					if (s1 < n) {
						d[s1][s2] = Math.min(d[s1][s2], d[s1 + 1][s2] + cost[s1][s2]);
					}
					if (s2 < n) {
						d[s1][s2] = Math.min(d[s1][s2], d[s1][s2 + 1] + cost[s1][s2]);
					}
				}
			}
			return d[0][0];
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



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

struct dice{
  int num[10];
};

dice hoge(dice d){
  int temp = d.num[6];
  d.num[6] = d.num[2];
  d.num[2] = d.num[1];
  d.num[1] = d.num[5];
  d.num[5] = temp;
  return d;
}

dice fuga(dice d){
  int temp = d.num[6];
  d.num[6] = d.num[3];
  d.num[3] = d.num[1];
  d.num[1] = d.num[4];
  d.num[4] = temp;
  return d;
}


int main(){
  int n;
  dice d;
  string s;

  for(int i = 1; i <= 6; i++){
    cin>>d.num[i];
  }

  cin>>s;

  for(int i = 0; i < s.size(); i++){//cout<<i<<endl;
    switch(s[i]){
    case 'S':
      d = hoge(d);
      break;
    case 'N':
      d = hoge(d);
      d = hoge(d);
      d = hoge(d);
      break;
    case 'E':
      d = fuga(d);
      break;
    case 'W':
      d = fuga(d);
      d = fuga(d);
      d = fuga(d);
      break;
    }
  }

  cout<<d.num[1]<<endl;

  return 0;
}



Measured memory_bytes: 3140
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a-b >= 0){
			System.out.println("delicious");
		}
		else{
			if(Math.abs(a-b)<=x){
				System.out.println("safe");
			}
			else{
				System.out.println("dangerous");
			}
		}
	}
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll l,r;
	cin>>l>>r;
	chmin(r,l+3000);
	ll ans=inf;
	FOR(i,l,r)FOR(j,i+1,r+1){
		chmin(ans,(i*j)%2019);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;

int n, a[maxn], pos[maxn];
int main() {
//	freopen("data.in","r",stdin);
	scanf("%d", &n);
	for(int i = 1;i <= n;i ++) scanf("%d", &a[i]), pos[a[i]] = i;
	int Mx = 0;
	pos[n + 1] = -1;
	for(int i = 1, j = 1;i <= n;i = j + 1) {
		j = i;
		while(pos[j + 1] >= pos[j])
			j ++;
		Mx = max(Mx,j - i + 1);
	}
	printf("%d\n", n - Mx);
	return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		if (ans * 2 < ans + k) {
			ans *= 2;
		} else {
			ans += k;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def prime?(n)
  limit = Math.sqrt(n)
  d = 2
  is = true
  while d <= limit
    if (n % d) == 0
      is = false
      break
    end
    d += 1
  end
  is
end


n = gets.strip.to_i
prime = 0
n.times do
  if prime?(gets.strip.to_i)
    prime += 1
  end
end

puts prime

Measured memory_bytes: 8788
# D - Megalomania
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

A.sort(key=lambda x: x[1])

tmp = 0
for i in range(N):
    tmp += A[i][0]
    if tmp <= A[i][1]:
        pass
    else:
        print('No')
        exit()

print('Yes')

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

using namespace std;

int main(){
    int n,m;
    int ans=0;
    cin>>n>>m;
    vector<vector<int>> d(m);
    for (int i = 0; i < m; ++i) {
        int k;
        cin>>k;
        for (int j = 0; j < k; ++j) {
            int l;
            cin>>l;
            --l;
            d[i].emplace_back(l);
        }
    }
    vector<int> p(m);
    for (int i = 0; i < m; ++i) {
        cin>>p[i];
    }
    for (int bit = 0; bit < 1<<n; ++bit) {
        bool ok=true;
        for (int i = 0; i < m; ++i) {
            int b=0;
            for(auto j:d[i]){
                if(bit&(1<<j))++b;
            }
            if(b%2!=p[i]){
                ok=false;break;
            }
        }
        if(ok)++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cstdlib>  // abs() for integer

using namespace std;

int main(){
    int N;
    vector<int> W;
    int w;
    cin >> N;
    for (int i = 0; i < N;i++){
        cin >> w;
        W.push_back(w);
    }

    int S1 = 0;
    int S2 = 0;
    for(int i = 0; i < N;i++)
        S2 += W[i];
    int min = S2;

    for(int i = 0; i < N;i++){
        S1 += W[i];
        S2 -= W[i];
        if(abs(S1 - S2) < min){
            min = abs(S1 - S2);
        }
    }
    cout << min;
}

Measured memory_bytes: 256
#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 a,b;cin >> a >> b;
    int A = 0;
    int B = 0;
    rep(i,b){
        A += a * pow(10,i);
    }
    rep(i,a)B += b * pow(10,i);
    if(a < b)cout << A << endl;
    else cout << B << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)

#define INF 0x3fffFFFF

signed main()
{
    int n,l; cin >> n >> l;
    int sum = 0; rep(i,n) sum += l+i;

    int eat = -1;
    int diffMin = INF;

    rep(i,n){
        int diff = abs(l+i);
        if (diffMin > diff){
            eat = i;
            diffMin = diff;
        }
    }

    cout << sum - (l+eat) << endl;

    return 0;
}


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

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d",x)
#define ps printf(" "); 
#define plint(x) printf("%lld",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define bg begin()
#define ed end()
#define Set(a, s) memset(a, s, sizeof (a))
#define mod 1000000007
#define tmod(k) if ((k) >= mod) k %= mod;
#define endl '\n'
#define nl printf("\n");
#define fors(i,n) for(int i=0; i<n; i++)
#define fore(i,n) for(int i=n-1; i>=0; i--)
#define forv(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef pair<int,int> pii;
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");forv(i,30,50){fors(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
const int INF = 0x3f3f3f3f;
float roundoff(float val, float p){ return floor(val*pow(10.0,p)+0.5)/pow(10.0,p);}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1};
class node{
public:
	int id;
	int prio;
	int prd;
};

class compare{
public:
	bool operator()(node &n1, node &n2){
		if(n1.prio>n2.prio)//ascending
			return true;
		else if(n1.prio==n2.prio){
			return n1.id>n2.id;
		}
		return false;
	}
};
//priority_queue<node, vector<node>, compare> pq;

int main(void) {
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission
    #endif*/
    int n;
    int1(n);
    map<int,int> mapp;
    int cnt=0;
    fors(i,n){
        int t;
        int1(t);
        if(mapp[t]==0){
            mapp[t]++;
            cnt++;
        }
        else{
            mapp[t]=0;
            cnt--;
        }
    }
    pint(cnt);
    
    return 0;
}



Measured memory_bytes: 4992
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n-=2;
    cout << n * 180 << endl;
}


Measured memory_bytes: 256
import sys


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    for i in sys.stdin.readlines():
        a, b = [int(x) for x in i.split()]
        print(gcd(a, b), lcm(a, b))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7636
S = input()
ans = []
for i in S:
    if(i in ['A','C','G','T']):
        ans.append(1)
    else:
        ans.append(0)
num = 0
max_num = 0
for i in ans:
    if(i==1):
        num += 1
        if(max_num < num):
            max_num = num
            
    else:
        num = 0
print(max_num)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    string S;
    ll K;
    cin >> S >> K;
    
    if(S.size() == 1){
        cout << K/2 << "\n";
        return 0;
    }
    
    ll sameFront = 1, sameBack = 1, count = 0;
    bool same = false;
    for(int i = 1; i < S.size(); i++){
        if(same){
            same = false;
        }else{
            if(S[i-1] == S[i]){
                count++;
                same = true;
            }
        }
    }
    
    for(int i = 1; i < S.size(); i++){
        if(S[i-1] == S[i]) sameFront++;
        else break;
    }
    for(int i = S.size() - 1; i > 0; i--){
        if(S[i-1] == S[i]) sameBack++;
        else break;
    }
    count *= K;
    
    bool allsame = true;
    for(int i = 1; i < S.size(); i++){
        if(S[i-1] != S[i]){
            allsame = false;
            break;
        }
    }
    if(allsame){
        count = S.size();
        count = (count * K) / 2;
        cout << count << "\n";
        return 0;
    }
    //cout << count << " " << sameFront << " " << sameBack << "\n";
    
    if(S[0] == S[S.size() - 1] && sameFront%2 == 1 && sameBack%2 == 1) count += K-1;
    
    cout << count << "\n";
    return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define j0 j5743892
#define j1 j542893
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> T gcd(T a, T b) { re a ? gcd (b % a, a) : b; }
template<class T> T sqr(T a) { re a * a; }
template<class T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }

#define filename ""

const string colors = "RYGB";
//const string colors = "0123";

int n;
int m;
int d;

int main () {
	cin >> n >> m >> d;
	if (d % 2 == 1) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++)
				printf ("%c", colors[(i + j) % 2]);
			printf ("\n");
		}
		re 0;
	} else {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int k = (j - i) / d;
				if ((j - i) % d != 0 && j < i) k--;
//				if ((i + j) % 2 == 1)
					printf ("%c", colors[(((i + j) / d * 2 + k) % 4 + 4) % 4]);
/*				else
					printf (".");	*/
			}
			printf ("\n");
		}
		re 0;
	}
	return 0;
}


Measured memory_bytes: 512
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

void pakuripair_sort(int N, int A[], int B[]) {
	const int b = 8;
	int tmp[100001], tmp2[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) {
			tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
			tmp2[kazu[A[i] >> k * b & ((1 << b) - 1)]] = B[i];
		}
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) {
			A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
			B[kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp2[i];
		}
	}
}

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


	int N = getint(), M = getint();

	int A[100000];
	rep(i, N) A[i] = getint();
	pakuri_sort(N, A);

	int B[100000],C[100000];
	rep(i, M) {
		B[i] = getint();
		C[i] = getint();
	}
	pakuripair_sort(M, C, B);

	ll kotae = 0;
	int kazu = 0;
	for (int i = M - 1; i >= 0; i--) {
		rep(j, B[i]) {
			if (kazu >= N) break;
			kotae += max(A[kazu], C[i]);
			kazu++;
		}
	}

	for (int i = kazu; i < N; i++) kotae += A[i];

	printf("%lld", kotae);

	Would you please return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll mod = 998244353;
#define EPS 1e-1
#define PI 3.14159265

#define iofile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

ll fastpow(ll base, ll pow)
{
    if (!base)
        return 0;
    if (!pow)
        return 1;
    if (pow == 1)
        return base;
    ll x = fastpow(base, pow / 2) % mod;
    x *= x;
    x %= mod;
    if (pow % 2)
        x *= base;
    return x % mod;
}

ll inverse(ll x)
{
    return fastpow(x, mod - 2) % mod;
}

ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}

void factorize(ll x, map<int, int> &ss)
{
    while (x % 2 == 0)
        ss[2]++, x /= 2;
    for (int i = 3; i <= sqrt(x); i += 2)
        while (x % i == 0)
            ss[i]++, x/= i;
    if (x > 2)
        ss[x]++;
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

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

int n, k;
ll arr[(int)1e5 + 5];
ll dp[(int)1e5 + 5];


int main()
{
    fastio
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    dp[0] = 0; // 0 1 2 3 4 5
    dp[1] = abs(arr[0] - arr[1]);
    for (int i = 2; i < n; i++)
    {
        ll c = 1e9;
        for (int j = max(0, i - k); j < i; j++)
            c = min(c, dp[j] + abs(arr[j] - arr[i]));
        dp[i] = c;
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  long long int a, b, n;
  scanf("%lld%lld%lld", &a, &b, &n);

  long long int ans;
  if(n < b){
    ans = n;
  }else{
    ans = b - 1;
  }

  ans = (long long int)(a * ans / b);
  
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1692
using System;
using System.Threading;

namespace ConsoleApp26
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力
            string line = Console.ReadLine();
            string[] array = line.Split(' ');

            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            int c = int.Parse(array[2]);
            int k = int.Parse(array[3]);

            if (a > k)
            {
                Console.WriteLine(k);
            }            
            else if (a + b >= k)
            {
                Console.WriteLine(a);
            }
            else {                
                Console.WriteLine(a- (k - (a + b)));
             }
        }
    }
}


Measured memory_bytes: 27492
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//入力
int n;
long long a[100010][3];

//DPテーブル
long long dp[100010][3];

int main() {
  cin >> n;
  for (int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if (j==k)continue;
        chmax(dp[i+1][j],dp[i][k]+a[i][j]);
      }
    }
  }

  long long res=0;
  for(int i=0;i<3;i++){
    chmax(res,dp[n][i]);
  }
  cout << res << endl;
}



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

using namespace std;

int main() {
int n; cin>>n;
vector<int> num(n);
vector<int> numO(n);
for(int i=0; i<n; i++){
cin >> num[i];
numO[i] = num[i];
}
sort(numO.begin(), numO.end());
int cont = 0;
for(int i=0; i<n; i++){
if(numO[i] - num[i] != 0) cont++;
}
if(cont > 2)
cout << "NO";
else
cout << "YES";

return 0;
}

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

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

  int rest = n % 10;
  if (rest == 2 || rest == 4 || rest == 5 || rest == 7 || rest == 9) {
    cout << "hon" << endl;
  }
  if (rest == 0 || rest == 1 || rest == 6 || rest == 8) {
    cout << "pon" << endl;
  }
  if (rest == 3) {
    cout << "bon" << endl;
  }
  return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n, n) {
    vector<int> imos(24 * 60 * 60 + 1);
    while (n--) {
      int h, m, s;
      char $;
      cin >> h >> $ >> m >> $ >> s;
      imos[h * 60 * 60 + m * 60 + s] += 1;
      cin >> h >> $ >> m >> $ >> s;
      imos[h * 60 * 60 + m * 60 + s] -= 1;
    }
    int res = 0;
    for (int t = 0; t < 24 * 60 * 60; ++t) {
      imos[t + 1] += imos[t];
      res = max(res, imos[t]);
    }
    cout << res << '\n';
  }
}



Measured memory_bytes: 3368