akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(vector<int>& A, vector<int>& B, int T) {
        int n = A.size();

        vector<pair<int,int>> D;
        for (int i = 0; i < n; ++i) {
            D.emplace_back(A[i], B[i]);
        }
        auto cmp = [&](const pair<int,int>& l, const pair<int,int>& r) {
            if (l.first == r.first) {
                return l.second > r.second;
            }
            return l.first < r.first;
        };
        sort(D.begin(), D.end(), cmp);

        const int INF = 1 << 28;
        vector<int> dp(T + 1, 0);
        dp[0] = 0;

        for (int i = 0; i < n; ++i) {
            for (int j = T - 1; j >= 0; --j) {
                int nj = j + D[i].first;
                nj = min(nj, T);
                dp[nj] = max(dp[nj], dp[j] + D[i].second);
            }
        }

        int res = *max_element(dp.begin(), dp.end());
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int t;
    cin >> t;
    vector<int> A(n);
    vector<int> B(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        cin >> B[i];
    }

    Solution sol;
    cout << sol.solve(A, B, t) << "\n";

    return 0;
}

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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

const int N = 1000006;

ll n, arr[N];
ll dp[N];

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n;
    for(int i = 0; i < n; i++) cin >> arr[i];
}

void process()
{
    dp[0] = 0, dp[1] = abs(arr[1]-arr[0]);
    for(int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i]-arr[i-2]));
    }
    cout << dp[n-1] << endl;
}



Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<int>a(N);
	rep(i, N)cin >> a[i];
	int i, j, b = 0, c = 0;
	sort(all(a), greater<int>());
	for (i = 0; i < N; i++) {
		b ^= a[i] & 1;
	}

	for (i = 0; (a[0] >> i) > 0; i++) {
		for (j = 0; j < N; j++) {
			c ^= (a[j] >> i) & 1;
		}
		if (b != c) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 640
n,m,c = gets.split(' ').map &:to_i
bs = gets.split(' ').map &:to_i
ans = 0
n.times{
  num = 0
  gets.chop.split(' ').each_with_index{ |a, k|
    num += a.to_i * bs[k]
  }
  ans += 1 if num + c > 0
}
p ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<long long, long long> pll;
#define has_bit(bit_mask, x) ((bit_mask) & (1ULL << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1ULL << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1ULL << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define decToBin(name, num) string name = bitset<8>(num).to_string();
#define binToDec(name, binary) unsigned long name = bitset<8>(binary).to_ulong();
#define radToDeg(name, radians) double name = radians * 180 / M_PI;
#define all(x) x.begin(), x.end()
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define printMat(mat) for (auto &x : mat) { for (auto &y : x) { if (y < INF) cout << setw(7) << y; else cout << setw(7) << "-"; } cout << '\n'; }
#define fillMat(mat, n, m, x) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) mat[i][j] = x;
#define printArr(arr) for (auto &x : arr) cout << x << " "; cout << '\n';
#define arrReplace(arr, from, to) for (auto &x : arr) if (x == from) x = to;
#define INF (1LL<<30)
#define INF32 (1LL<<62)
#define F first
#define S second
#define M_PI 3.14159265358979323846
inline int ceil(int a, int b) { return (a+b-1)/b; }
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
int str_replace(string& str, const string& from, const string& to, int limit = -1) { if(from.empty()) return 0; size_t start_pos = 0; int cnt = 0; while((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); cnt++; if (cnt == limit) break; } return cnt; }
#define MOD 1000000007
#define int ll

signed main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string str; cin >> str;
	if (str.size() >= 5 && str[2] == str[3] && str[4] == str[5]) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

using namespace std;

int main(void) {
	int num, i;
	double ans = 0.0;
	cin >> num;
	vector<double> d(num);
	for (i = 0; i < num; i++)
		cin >> d[i];
	sort(d.begin(), d.end());
	ans = d[0];
	for (i = 1; i < num; i++) {
		ans += d[i];
		ans /= 2.0;
	}
	printf("%.9lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    string S;
    cin >> S;
    int d = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'x') d++;
    }
    cout << (d <= 7 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

vector<int> z_algorithm(const string &s) {
    int n = s.size();
    vector<int> prefix(n);
    for(int i = 1, j = 0; i < n; i++) {
        if ((i + prefix[i - j]) < (j + prefix[j])) {
            prefix[i] = prefix[i - j];
        }
        else {
            int k = max(0, j + prefix[j] - i);
            while(((i + k) < n) && (s[k] == s[i + k])) k++;
            prefix[i] = k;
            j = i;
        }
    }
    prefix[0] = n;
    return prefix;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    rep(i, n) {
        string ss = s.substr(i);
        auto za = z_algorithm(ss);
        reps(j, 1, n - i) {
            ans = max(ans, min(j, (ll)za[j]));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
def main():
    infinity = 1e10

    n, k, height = getInputs()

    cost = [infinity] * n
    cost[0] = 0
    cost[1] = abs(height[0] - height[1])

    for i in range(2, n):
        for j in range(i - 1, i - k - 1, -1):
            if j >= 0:
                cost[i] = min(cost[i], cost[j] + abs(height[i] - height[j]))

    print(cost[-1])

def getInputs():
    n, k = map(lambda x: int(x), input().split())
    height = tuple(map(lambda x: int(x), input().split()))

    return n, k, height

main()


Measured memory_bytes: 87752
n=int(input())
l=list(map(int,input().split()))

rs=[0]*n
rs[0]=l[-1]
j=1
for i in range(n-2,-1,-1):
    rs[j]=rs[j-1]+l[i]
    j+=1
rs=rs[::-1]

ans=0
for i in range(n-1):
    ans+=(l[i]*rs[i+1])
print(ans%(10**9+7))


Measured memory_bytes: 31752
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;

  int l[Q];
  int r[Q];
  int save[S.size()];
  REP(i, 0, Q) {
    cin >> l[i];
    cin >> r[i];
  }

  REP(i, 0, S.size()){
    save[i] = 0; // initialize
  }

  ll temp = 0;
  REP(i, 0, S.size()-1){
    if ( (S.substr(i, 1) == "A") and (S.substr(i+1, 1) == "C") ){
      temp++;
    }
    save[i+1] = temp;
  }

  // REP(i, 0, S.size()){
  //   cout << save[i] << " ";
  // }
  // cout << endl;

  REP(i, 0, Q){
    ll left;
    ll right;
    if (l[i] == 1)
      left = 0;
    else
      left = save[l[i]-1];
    right = save[r[i]-1];

    cout << right - left << endl;
  }

  return 0;
}


Measured memory_bytes: 2176
# coding: utf-8


def main():
    A, B = map(int, input().split())
    ans = -1
    for i in range(10001):
        if i * 8 // 100 == A and i // 10 == B:
            ans = i
            break

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9108
#include <stdio.h>
int main(void)
{
    int x,d,r,i,a;
    scanf("%d", &r);
    scanf("%d", &d);
    scanf("%d", &x);
    for(i = 0;i < 10;i ++){
        a = r * x;
        x = a - d;
        printf("%d\n", x);
    }
    
    return 0;
}

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

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

	if (a < b){
		if (b < c){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else{
		cout << "No" << endl;
	}


	return 0;
}



Measured memory_bytes: 3064
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0

for i in range(len(A)-1):
    if A[i] >= B[i]:
        cnt += B[i]
    else:
        cnt += A[i]
        B[i] -= A[i] 
        if A[i+1] >= B[i]:
            cnt += B[i]
            A[i+1] -= B[i]
        else:
            cnt += A[i+1]
            A[i+1] = 0

print(cnt)

Measured memory_bytes: 18624
while True:
    if input() == '0':
        break
    actions = input().split()
    r, l = False, False
    floor = True
    n = 0
    for a in actions:
        if a[0] == 'r':
            r = not r
        elif a[0] == 'l':
            l = not l
        if r == l == floor:
            n += 1
            floor = not floor
    print(n)

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

void _main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x3 = x2 - (y2-y1);
  int y3 = y2 + (x2-x1);
  int x4 = x1 - (y2-y1);
  int y4 = y1 + (x2-x1);
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int n;
    scanf("%d",&n);
    
    int array[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&array[i]);
    }
    
    for(i=n-1;i>=0;i--){
        printf("%d",array[i]);
        if(i == 0){
            printf("\n");
        }
        else{
            printf(" ");
        }
    }
    
    return 0;
}

Measured memory_bytes: 600
import sys

N = int(input())
D1 = [0]*N
D2 = [0]*N
ans = 0
for i in range(N):
  D1,D2 = map(int,input().split())
  if D1 == D2:
    ans += 1
  else:
    ans = 0
  if ans == 3:
    print('Yes')
    sys.exit()
print('No')

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

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int s, w;

    cin >> s >> w;

    cout << (s <= w ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	vector<int> a, b;
	for(int i=0;i<n;i++){
		int x, y;
		cin>>x>>y;
		a.push_back(x);
		b.push_back(y);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	if(n%2==1){
		cout<<b[(n+1)/2-1]-a[(n+1)/2-1]+1;
	}
	else{
		cout<<b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1;
	}
}

Measured memory_bytes: 5084
#include <stdio.h>
#include <utility>
#include <array>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
typedef long long ll;
typedef pair<ll, ll> P;
P store[100001];

bool paircmp(const P& a, const P& b) {
    return a.first < b.first;
}

int main(int argc, char *argv[])
{
    scanf("%d %d", &n, &m);
    for (int i=0; i<n;i++) {
        ll a,b;
        scanf("%lld %lld", &a, &b);
        store[i] = P(a,b);
    }
    sort(store, store + n, paircmp);
    ll money=0,num=0;
    for (int i = 0; i < n; ++i) {
        ll a = store[i].first;
        ll b = store[i].second;
        if (num + b <= m) {
            num += b;
            money += a * b;
        } else {
            money += (m - num) * a;
            break;
        }
        // printf("%d %d\n", store[i].first, store[i].second);
    }
    printf("%lld", money);
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int n;
int cnt[112345];

int main() {
	cin >> n;
	
	int ans = 0;
	
	REP(i, n) {
		int a;
		scanf("%d", &a);
		if (a >= 112345) ans++;
		else cnt[a]++;
	}
	
	REP(i, 112345) {
		if (i < cnt[i]) ans += cnt[i] - i;
		if (i > cnt[i]) ans += cnt[i];
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define all(x) (x).begin(), (x).end()

int main(){
    int r; cin>>r;
    double op = (r*(acos(-1)))*2;
    cout<<op<<endl;
    return 0;
}



Measured memory_bytes: 3784
import copy

h, w, k = map(int, input().split())
clist0 = []
result = 0
for i0 in range(h):
    c = list(input())
    clist0.append(c)
for i in range(2**h):
    for j in range(2**w):
        clist = copy.deepcopy(clist0)
        for hi in range(h):
            #print(i, hi)
            if((i & 2**hi) == 2**hi):
                #print(i, hi)
                for j2 in range(w):
                    clist[hi][j2] = "1"
        for wi in range(w):
            if((j & 2**wi) == 2**wi):
                for i2 in range(h):
                    clist[i2][wi] = "1"
        temp = 0
        #print(clist)
        for ci in clist:
            temp += ci.count("#")
        if(temp == k):
            result +=1
print(result)

Measured memory_bytes: 77588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		a[0] = scanner.nextInt();
		int max = a[0], min = a[0];

		for (int i = 1; i < n; i++) {
			a[i] = scanner.nextInt();
			if(max < a[i]){
				max = a[i];
			}else if(min > a[i]){
				min = a[i];
			}
		}

		System.out.println(max-min);
	}
}

Measured memory_bytes: 21460
# B
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)] 
ct = 0
for i in range(N):
    if ((X[i][0] ** 2)+(X[i][1] ** 2)) ** 0.5 <= D:
        ct += 1
print(ct)


Measured memory_bytes: 45808
#include<iostream>

class judgeRecord
{
private:
	int midTermScore, endTermScore, reExamScore;
public:
	std::string Record();
	bool judgeInputEnd();
};

int main()
{
	judgeRecord jr;

	while (jr.judgeInputEnd() == true)
	{
		std::cout << jr.Record() << std::endl;
	}
}

bool judgeRecord::judgeInputEnd()
{
	std::cin >> midTermScore >> endTermScore >> reExamScore;

	if (midTermScore == -1 && endTermScore == -1 && reExamScore == -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

std::string judgeRecord::Record()
{

	int mid = midTermScore;
	int end = endTermScore;
	int re = reExamScore;
	int sum = mid + end;

	if (mid == -1 || end == -1 || sum < 30)
	{
		return "F";
	}
	else if (80 <= sum)
	{
		return "A";
	}
	else if (65 <= sum && sum < 80)
	{
		return "B";
	}
	else if ((50 <= sum && sum < 65) || ((30 <= sum && sum < 50) && 50 <= re))
	{
		return "C";
	}
	else if ((30 <= sum && sum < 50) && re < 50)
	{
		return "D";
	}
}


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

int main(){
	int n ; cin >> n ;
map<int,int> card;
for(int i = 0 ; i< n; i++) {
int num ; cin >> num ;
card[num]++;
}
int kind=0 , zero = 0;
for (auto x : card){
if(x.second % 2 == 0 ) zero ++;
kind ++;
}
if(zero%2==0)cout<<kind<<endl;
else cout <<kind-1<<endl;

} 


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	if(a.size()>b.size())  puts("GREATER");
	else if(a.size()<b.size())  puts("LESS");
	else if(a>b) puts("GREATER");
	else if(a<b)  puts("LESS");
	else  puts("EQUAL");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007
#define pi 3.14159265358979323846264338327950

void solve()
{
    int n, k;
    vector<int> all;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        all.push_back(t);
    }
    sort(all.begin(), all.end());
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans += all[i];
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3624
/*
 *    author:  gantheory
 *    created: 2018-07-19 23:18:57
 */
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

const int N = 6000 + 10;

template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

int n, m, cap;
string src, dest;
vector<pair<int, int>> adj[N], adj2[3001];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
  while (cin >> n >> m >> cap) {
    if (n + m + cap == 0) break;

    for (int i = 0; i < 2 * n + 2; ++i) adj[i].clear();
    for (int i = 0; i < n + 1; ++i) adj2[i].clear();

    cap *= 10;
    cin >> src >> dest;
    map<string, int> mp;
    mp[src] = 0, mp[dest] = 1;
    for (int i = 0; i < n; ++i) {
      string foo, bar;
      int c;
      cin >> foo >> bar >> c;
      int sz = mp.size();
      if (mp.count(foo) == 0) mp[foo] = sz;
      sz = mp.size();
      if (mp.count(bar) == 0) mp[bar] = sz;
      int u = mp[foo], v = mp[bar];
      adj[u].emplace_back(v, c), adj[v].emplace_back(u, c);
    }
    vector<string> cand = {src, dest};
    for (int i = 0; i < m; ++i) {
      string s;
      cin >> s;
      cand.push_back(s);
    }

    map<int, int> reach;
    queue<int> q;
    q.push(mp[src]);
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      if (reach.count(now)) continue;
      int sz = reach.size();
      reach[now] = sz;
      for (auto& p : adj[now]) q.push(p.first);
    }
    if (reach.count(mp[dest]) == 0) {
      cout << -1 << '\n';
      continue;
    }
    for (int i = 0; i < (int)mp.size(); ++i) {
      if (reach.count(i) == 0) continue;
      for (auto& p : adj[i])
        adj2[reach[i]].emplace_back(reach[p.first], p.second);
    }
    set<int> good;
    for (string& s : cand)
      if (mp.count(s) and reach.count(mp[s])) good.insert(reach[mp[s]]);

    int s = reach[mp[src]], t = reach[mp[dest]];
    vector<vector<int>> d(reach.size(), vector<int>(cap + 1, INT_MAX));
    vector<vector<bool>> visit(reach.size(), vector<bool>(cap + 1, false));
    d[s][cap] = 0;
    MinHeap<pair<pair<int, int>, int>> hp;
    hp.push({{0, cap}, s});
    while (1) {
      int now = -1, now_cap = -1;
      while (!hp.empty() and
             visit[now = hp.top().second][now_cap = hp.top().first.second])
        hp.pop();
      if (now == -1 or visit[now][now_cap]) break;
      visit[now][now_cap] = true;
      for (auto& p : adj2[now]) {
        int child = p.first, w = p.second;
        if (now_cap - w >= 0) {
          int nxt_cap = (good.count(child) ? cap : now_cap - w);
          if (d[now][now_cap] + w < d[child][nxt_cap]) {
            d[child][nxt_cap] = d[now][now_cap] + w;
            hp.push({{d[child][nxt_cap], nxt_cap}, child});
          }
        }
      }
    }

    cout << (d[t][cap] == INT_MAX ? -1 : d[t][cap]) << '\n';
  }
}



Measured memory_bytes: 53292
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

void tanzaku(string S){
  int N = S.size();
  FOR(i,0,(int)1<<8)cerr << "yay!";
  FOR(i,0,N+2){
    FOR(j,0,3){
      if(i == 0 && j == 0)cerr << "┏";
      else if(i == N+1 && j == 2)cerr << "┛";
      else if(i == 0 && j == 2)cerr << "┓";
      else if(i == N+1 && j == 0)cerr << "┗";
      else if(i == 0 || i == N+1)cerr << "━";
      else if(j == 0 || j == 2)cerr << "┃";
      else cout << S[i-1];
    }
    cerr << endl;
  }
  return;
}

int main(){
  int N,i;
  cin >> N >> i;
  tanzaku(to_string(N - i + 1));
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
typedef long long int lli;

int get_abs(int x);

int main(){
    int n;
    cin >> n;
    vector<int> w(n), sum(n);
    for(int i = 0; i < n; ++i){
        cin >> w[i];
        sum[i] = (i == 0)? w[i] : sum[i - 1] + w[i];
    }
    
    int ans = 300;
    for(int i = 0; i < n - 1; ++i){
        ans = min(ans, get_abs(sum[n - 1] - 2 * sum[i]));
    }
    cout << ans << endl;
    return 0;
}

int get_abs(int x){
    return (x > 0)? x : -x;
}

Measured memory_bytes: 256
let rec for_fold a b v f = if a >= b then v else for_fold (a+1) b (f a v) f
let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let x = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  for_fold 0 (n-k+1) 10101010101010 (fun i v ->
    let l, r = x.(i), x.(i+k-1) in
    if r <= 0 || l >= 0 then min v @@ max (abs l) (abs r)
    else min v @@ min (2 * r - l) (r - 2 * l))
  |> Printf.printf "%d\n"


Measured memory_bytes: 5248
while True:
    try:
        n = int(input())
        if n > 18:
            n = 36 - n

        ans = (n+1)*(n+2)*(n+3)/6
        if n >= 10:
            n = n - 10
            ans = ans - 2*(n+1)*(n+2)*(n+3)/3
        
        if n < 0:
            ans = 0

        print(int(ans))

    except EOFError:
        break


Measured memory_bytes: 5592
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int a;
    cin>>a;
    int b=a/500;
    int c=a%500;
    c/=5;
    cout<<b*1000+c*5<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int n;
int main(){
    cin>>n;
    for(int i=sqrt(n);i>=1;i--){
        if(n%i==0){
            int t=i,l=n/i;
            int s=1;
            while(l>=10){
                s++;
                l/=10;
            }
        cout<<s;
        return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define db long double
#define mp make_pair
#define X first
#define Y second
#define vi vector<int>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<(a).size();++i)
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
#define gc getchar
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
const int N=100010;
int n;ll sum;
struct st{int a,b;}p[N];
inline bool cmp(st x,st y){return x.a>y.a;}
int main()
{
	n=rd();
	rep(i,1,n)
	{
		p[i].a=rd();p[i].b=rd();sum+=p[i].a;
		p[i].a=max(p[i].a,p[i].b);
	}
	sort(p+1,p+n+1,cmp);
	int k=0;ll s=0,P=1,Q=1;
	rep(i,1,n)
	{
		s+=p[i].a;
		if(s>=sum){k=i;break;}
	}
	rep(i,1,n)
	{
		ll t=sum-(s-p[min(i,k)].a);
		if(t<=p[i].b&&t*Q<p[i].b*P)P=t,Q=p[i].b;
	}
	P=Q-P+(n-k)*Q;Q*=n;ll g=__gcd(P,Q);
	printf("%lld %lld\n",P/g,Q/g);return 0;
}


Measured memory_bytes: 4512
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<pair<long long int, long long int>> Students(N);
  vector<pair<long long int, long long int>> Points(M);
  
  for(int i = 0;i < N; i++){
    long long int a, b;
    cin >> a >> b;
    Students[i] = make_pair(a, b);
  }
  
  for(int i = 0;i < M; i++){
    long long int a, b;
    cin >> a >> b;
    Points[i] = make_pair(a, b);
  }
  
  vector<int> ans;
  
  for(int i = 0; i < N; i++){
    long long int tdist = 1000000000, tptnr = 100;
    for(int j = 0; j < M; j++){
      int td, tp;
      td = abs(Students[i].first - Points[j].first) + abs(Students[i].second - Points[j].second);
      tp = j+1;
      if(td < tdist) tdist = td, tptnr = tp;
      else if(td == tdist){
        if(tptnr > tp) tptnr = tp;
      }else{
        continue;
      }
    }
    ans.push_back(tptnr);
  }
  
  for(int i = 0; i < N; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL H,W,K,i,j,k,b,ans=INF,a,num[10],n[10],flag;
  char S[15][1005];
  scanf("%lld %lld %lld",&H,&W,&K);
  rep(i,H)scanf("%s",S[i]);
  rep(b,1<<(H-1)){
    a=0;
    rep(i,H)num[i]=0,n[i]=0;
    for(i=b;i>0;i/=2)a+=i%2;
    rep(i,W){
      k=0,flag=0;
      rep(j,H){
        n[j]=0;
        if(S[j][i]=='1')n[k]++;
        if(b&1<<j)k++;
      }
      //rep(j,H)printf("%lld ",n[j]);
      //printf(" ");
      rep(j,H){
        if(n[j]>K)goto END;
        num[j]+=n[j];
        if(num[j]>K)flag=1;
      }
      if(flag==1){
        a++;
        rep(j,H)num[j]=n[j];
      }
      //rep(j,H)printf("%lld ",num[j]);
      //printf(" %lld\n",a);
    }
    ans=MIN(ans,a);
  END:;
    //printf("\n");
  }

  printf("%lld\n",ans);
	return 0;
}


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

// 書きかけ。時間切れ。

void solve(string S){
    int n = S.size();
    int last[2019] = {0};
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int next[2019] = {0};
        for (int x = 0; x < 2019; x++) {
            int xx = (x * 10 + (S[i] - '0')) % 2019;
            next[xx] += last[x];
        }
        next[S[i] - '0'] += 1;
        ans += next[0];
        memcpy(last, next, 2019 * sizeof(int));
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define int long long int
#define ll long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bn begin()
#define en end()
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007
#define pi 3.141592653589
using namespace std;

int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie   
    int n ;
    cin >> n ;
    int a[n] ;
    rep(i, 0, n) cin >> a[i] ;
    sort(a, a+n, greater<int>()) ;
    int sum = a[0] ;
    n -= 2 ;
    int f = 0, i = 1 ;
    while(n--) {
        if(f == 2) {
            f = 1 ;
            i++ ;
            sum += a[i] ;
        }
        else {
            f++ ;
            sum += a[i] ;
        }
    }
    cout << sum << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

int gcd(int a,int 
b){
    if(a==0) return b;
    return gcd(b%a,a);
}


Measured memory_bytes: 5204
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}





int main(){
  int D,N;
  cin>>D>>N;
  if(D==0){
    if(N==100){
      cout<<101<<endl;
    }else{
      cout<<N<<endl;
    }
  }else if(D==1){
    if(N==100){
      cout<<10100<<endl;
    }else{
    

    cout<<100*N<<endl;}

  }else{
    if(N==100){
      cout<<1010000<<endl;
    }else{
    cout<<10000*N<<endl;}
  }




  





  



}


  
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;

template<typename T>
map<T,ll> factorize(T x){
	map<T,ll> res;
	for(ll i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
			res[i]++;
		}
	}
	if(x!=1) res[x]++;
	return res;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int p,q; cin >> p >> q;
	int g=__gcd(p,q);
	p/=g; q/=g;
	auto m=factorize(q);
	int res=1;
	for(auto p:m){
		res*=p.first;
	}
	cout << res << endl;
}


Measured memory_bytes: 3236
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;

int n, k, m;
long long s[MAXN];
long long L[MAXN], R[MAXN];

struct Node
{
	int l, r, v;
	Node *lc, *rc;
	Node(int _l, int _r) : l(_l), r(_r), v(0), lc(NULL), rc(NULL)
	{}
}
*root;

void change(Node *now, int v)
{
	now->v = v;
}

void down(Node *now)
{
	if(now->v)
	{
		change(now->lc, now->v);
		change(now->rc, now->v);
		now->v = 0;
	}
}

void modify(Node *now, int l, int r, int v)
{
	// cerr << l << ' ' << r << endl;
	if(now->r < l || r < now->l)
		return ;
	if(l <= now->l && now->r <= r)
		return change(now, v);
	int mid = (now->l + now->r) / 2;
	if(!now->lc || !now->rc)
		now->lc = new Node(now->l, mid), now->rc = new Node(mid + 1, now->r);
	down(now);
	modify(now->lc, l, r, v);
	modify(now->rc, l, r, v);
}

int query(Node *now, int x)
{
	if(x == now->l && now->r == x)
		return now->v;
	int mid = (now->l + now->r) / 2;
	if(!now->lc || !now->rc)
		now->lc = new Node(now->l, mid), now->rc = new Node(mid + 1, now->r);
	down(now);
	return x <= mid ? query(now->lc, x) : query(now->rc, x);
}

void no()
{
	cout << -1 << endl;
	exit(0);
}

long long f[MAXN];

long long calc(int cur)
{
	int nxt = query(root, cur);
	if(nxt == m + 1) return 0;
	return f[nxt] + (R[nxt] - cur + k) % k;
}

long long work()
{
	root = new Node(0, k - 1);
	modify(root, 0, k - 1, m + 1);
	f[m + 1] = 0;

	for(int i = m; i >= 1; i--)
	{
		// cerr << L[i] << ' ' << R[i] << endl;
		// f[i]
		int cur = R[i], nxt = query(root, cur);
		if(nxt == m + 1) f[i] = 0;
		else f[i] = f[nxt] + (R[nxt] - cur + k) % k;
		// add
		if(L[i] < R[i])
			modify(root, L[i] + 1, R[i] - 1, i);
		else
			modify(root, 0, R[i] - 1, i), modify(root, L[i] + 1, k - 1, i);
	}

	long long ret = calc(0);
	// cerr << ret << endl;
	for(int i = 1; i <= m; i++)
	{
		ret = min(ret, calc(L[i]));
		// cerr << ret << endl;
		ret = min(ret, calc(R[i]));
		// cerr << ret << endl;
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> k;
	s[0] = 0;

	for(int i = 1; i <= n; i++)
	{
		int a, b;
		cin >> a >> b;
		s[i] = s[i - 1] + a;
		if(b == 1)
		{
			if(2 * a > k) no();
			m++;
			L[m] = -2 * s[i], R[m] = -2 * s[i - 1];
			L[m] = (L[m] % k + k) % k;
			R[m] = (R[m] % k + k) % k;
		}
	}


	long long ans = work();
	// ans = 0;
	ans += 2 * s[n];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 129664
x1, y1, x2, y2 = map(int, input().split())
dx = x2 - x1
dy = y2 - y1
x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy
print(x3, y3, x4, y4)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define MP make_pair<ll>

#define INF (ll)(1e16)

#define N_MAX 1000010

ll n,q;
ll score[N_MAX],sorted[N_MAX];
multiset<ll> leaders;
multiset<ll>::iterator iter;

bool check(ll x,ll r){
  ll checked = 0, ans = 0;
  iter = leaders.begin();
  while(iter!=leaders.end()){
    ll lscore = *iter;
    ll pos = lower_bound(sorted,sorted+n,lscore-r)-sorted;
    ll cnt = pos -checked;
    if(cnt>0){
      ans += cnt;
      if(ans>x)return false;
    }
    checked = upper_bound(sorted,sorted+n,lscore)-sorted;
    ++iter;
  }
  return true;
}

int main(){
  cin >> n >> q;
  REP(i,n){
    ll s;
    cin >> s;
    score[i] = s;
    sorted[i] = s;
  }
  sort(sorted,sorted+n);
  leaders.insert(INF*10);

  REP(_,q){
    string cmd;
    ll a;
    cin >> cmd >> a;
    if(cmd=="ADD"){
      leaders.insert(score[a-1]);
    }else if(cmd=="REMOVE"){
      iter = leaders.find(score[a-1]);
      leaders.erase(iter);
    }else if(cmd=="CHECK"){
      ll left=0,right=INF;
      while(left+1<right){
        ll mid = (left+right)/2;
        bool ok = check(a,mid);
        if(ok)right = mid;
        else  left  = mid;
      }
      bool ok = check(a,left);
      if(ok)right = left;
      if(right==INF)cout << "NA" << endl;
      else          cout << right<< endl;
    }
  }
  return 0;
}

Measured memory_bytes: 16860
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout<<s,0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
	run();
	int k, n;
	cin >> k >> n;
	vector<int> v(n);
	for (auto &it : v)
		cin >> it;
	int ans = v.back() - v[0];
	for (int i = 0; i + 1 < n; i++)
		ans = min(ans, k - (v[i + 1] - v[i]));
	cout << ans << endl;
}


Measured memory_bytes: 1024
A, B, C = map(int, input().split())
ans = 0
if A == B == C:
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        print(ans)
        exit()
    print(-1)
    exit()
while True:
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        print(ans)
        exit()
    tmp = B // 2 + C // 2
    tmptmp = A // 2 + C // 2
    C = A // 2 + B // 2
    A = tmp
    B = tmptmp
    ans += 1


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

int main(){
    int n,q;
    cin >> n;
    int S[n];
    for(int i = 0; i < n; i++){
        cin >> S[i];
    }
    cin >> q;
    int T[q];
    for(int i = 0; i < q; i++){
        cin >> T[i];
    }
    int ans = 0;
    int j = 0;
    for(int i = 0; i < q; i++){
        for(int j = 0; j < n; j++){
            if(S[j] == T[i]){
                ans += 1;
                break;
            }
        }
    }

    cout << ans << endl;

}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;



int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<int> g(n);
  vector<int> a(m);
  vector<int> b(m);
  rep (i, n) {
    cin >> h.at(i);
    g.at(i) = h.at(i);
  }
  rep (j, m) {
    cin >> a.at(j) >> b.at(j);
    if (h.at(a.at(j) - 1) == h.at(b.at(j) - 1)) {
      g.at(a.at(j) - 1) = 0;
      g.at(b.at(j) - 1) = 0;
    }
    if (h.at(a.at(j) - 1) > h.at(b.at(j) - 1)) {
      g.at(b.at(j) - 1) = 0;
    }
    if (h.at(a.at(j) - 1) < h.at(b.at(j) - 1)) {
      g.at(a.at(j) - 1) = 0;
    }

  }
  int count = 0;
  rep (i, n) {
    // cout << g.at(i) << endl;
    if (g.at(i) == 0) {
      count++;
    } 
  }
  cout << n - count << endl;
}



Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        // cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

vector<bool> isprime;
void eratosthenes(int N) {
    isprime.resize(N + 1);
    fill(begin(isprime), end(isprime), true);
    isprime[0] = false;
    isprime[1] = false;
    for (int i = 2; i < sqrt(N) + 1; i++)
        if (isprime[i])
            for (int j = 2; i * j <= N; j++)
                isprime[i * j] = false;
}
signed main() {
    eratosthenes(55555);
    int n;
    cin >> n;
    vector<int> ans;
    REP(i, 55555) {
        if (isprime[i] && i % 5 == 1) {
            ans.push_back(i);
            n--;
            if (n == 0) break;
        }
    }
    cout << ans << 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 rep2(i,n) for(int i=1;i<(n);i++)
typedef long long ll;

int h,w;

string board[110];
bool goodx[110],goody[110];

int main() {
    cin >> h >> w;

    rep(i,h){
        cin >> board[i];
    }
    rep(i,h){
        rep(j,w){
            if(board[i][j]=='#'){
                goodx[i]=true;
                goody[j]=true;
            }
        }
    }
    rep(i,h){
        if(goodx[i]){
            rep(j,w){
                if(goody[j]) cout << board[i][j];
            }
        cout << endl;
        }
    }
}

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

using namespace std;


int main()
{
	int n,m; cin >> n >> m;
	int h[n];
	for(int i = 0; i < n; i++) cin >> h[i];
	vector<int> adj[n];
	for(int i = 0; i < m; i++){
		int x,y; cin >> x >> y;
		adj[--x].push_back(--y);
		adj[y].push_back(x);
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(adj[i].size() == 0){ ans++; continue;}
		bool good = true;
		for(int e : adj[i]){
			good &= h[i] > h[e];	
		}
		if(good) ans++;
	}
	cout << ans;
}


Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s="CODEFESTIVAL2016",s1;
	int ans=0;
	cin>>s1;
	for(int i=0;i<=15;i++)
	{
		if(s[i]!=s1[i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256