akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<pii,int> ppiii ;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
int n,m;
int main(){
	int x;
	cin>>n>>m;
	vi b,c;
	int cnt=0;
	for(int i=0;i<m;i++){
		cin>>x;
		if(x%2==1)b.pb(x);
		else c.pb(x);
	}
	if(b.size()>=3){
		cout<<"Impossible"<<endl;
	}else{
		vi ans,check;
		if(b.size()>0)check.pb(b[0]);
		for(int i=0;i<c.size();i++)check.pb(c[i]);
		for(int i=1;i<b.size();i++)check.pb(b[i]);
		for(int i=0;i<check.size();i++){
			int hoge=check[i];
			if(i==0){
				hoge--;
			}
			if(i==check.size()-1){
				hoge++;
			}
			if(hoge!=0)ans.pb(hoge);
		}
		if(check.size()==1){
			ans.clear();
			ans.pb(1);
			if(check[0]!=1)ans.pb(check[0]-1);
		}
		for(int i=0;i<check.size();i++){
			cout<<check[i];
			if(i!=check.size()-1)cout<<" ";
			else cout<<endl;
		}
		cout<<ans.size()<<endl;
		for(int i=0;i<ans.size();i++){
			cout<<ans[i];
			if(i!=ans.size()-1)cout<<" ";
			else cout<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
struct position{
    int y, x;
};
 
int main(){
    int H, W, D;
    cin >> H >> W >> D;
    position number_position[H * W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int num;
            scanf("%d", &num);
            number_position[num - 1] = {i, j};
        }
    }
    int need_magic_cost[H * W];
    for(int i = H * W - D; i < H * W; i++){
        need_magic_cost[i] = 0;
    }
    for(int i = H * W - D - 1; i >= 0; i--){
        need_magic_cost[i] = need_magic_cost[i + D] + abs(number_position[i].y - number_position[i + D].y) + abs(number_position[i].x - number_position[i + D].x);
    }
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int left, right;
        scanf("%d%d", &left, &right);
        printf("%d\n", need_magic_cost[left - 1] - need_magic_cost[right - 1]);
    }
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>
#include <stdlib.h>
# include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    if((n == 7)||(n == 5)||(n == 3)){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import sys

def parent(i):
    return (i + 1) / 2 - 1

def insert(S, k):
    S.append(k)
    idx = len(S) - 1
    while True:
        p = parent(idx)
        if p < 0 or S[idx] <= S[p]:
            break
        else:
            S[idx], S[p] = S[p], S[idx]
            idx = p

def maxHeapify(A, i, size):
    l = 2 * i + 1
    r = 2 * i + 2

    if l < size and A[l] > A[i]:
        largest = l
    else:
        largest = i

    if r < size and A[r] > A[largest]:
        largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(A, largest, size)

def extract(S):
    print S[0]
    S[0] = S[-1]
    S.pop()
    maxHeapify(S, 0, len(S))

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    lines.pop()

    S = []
    for line in lines:
        if line[0] == "i":
            insert(S, int(line[7:]))
        else:
            extract(S)

Measured memory_bytes: 159016
#include <bits/stdc++.h>
#define P pair<int, int>

using namespace std;
const int INF=1e5;

int main(){
  long long n, a[3*100009];
  cin >> n;
  for(int i=0;i<3*n;i++)cin >> a[i];
  sort(a, a+3*n);
  long long sm=0;
  for(int i=n;i<3*n;i+=2)sm+=a[i];
  cout << sm << endl;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    if (i)
    {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main()
{
  int n;
  cin >> n;
  vector<vector<vector<int>>> vec(4, vector<vector<int>>(3, vector<int>(10)));

  rep(i, n)
  {
    int b, f, r, v;
    cin >> b >> f >> r >> v;

    vec.at(b - 1).at(f - 1).at(r - 1) += v;
  }

  rep(i, 4)
  {
    if (i)
    {
      printf("####################\n");
    }
    for (auto &&j : vec.at(i))
    {
      rep(k, 10)
      {
        printf(" %d", j.at(k));
      }
      printf("\n");
    }
  }
}



Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, k, s; cin >> n >> k >> s;
    VL ans;
    if (s == INF) {
        FOR(i, 0, k)ans.push_back(s);
        FOR(i, 0, n - k)ans.push_back(INF - 1);
    }
    else {
        FOR(i, 0, k)ans.push_back(s);
        FOR(i, 0, n - k)ans.push_back(INF);
    }
    FOR(i, 0, n)cout << ans[i] << ENDL(i, n);
}


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

using namespace std;

using ll = long long;

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

    int n, m, x, y;

    cin >> n >> m >> x >> y;
    int max_x = -200, min_y = 200;
    for (int i = 0, tx; i < n; ++i) {
        cin >> tx;
        max_x = max(tx, max_x);
    }
    for (int i = 0, ty; i < m; ++i) {
        cin >> ty;
        min_y = min(ty, min_y);
    }
    int z = min_y;

    if (max_x < z && x < z && z <= y) cout << "No War\n";
    else cout << "War\n";

    return 0;
}


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

using namespace std;
#define scd(a) scanf("%d", &a)
#define scdd(a,b) scanf("%d%d", &a, &b)
#define scddd(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define X first
#define Y second
#define lowbit(x) ((x) & (-x))
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e7 + 10, INF = 0x3f3f3f3f;
const ll mod =  1e9 + 7;
const double eps = 1e-10, Pi = 2*acos(0);
ll LINF = 1LL<<62;
ll n, m;
void solve(){
    scanf("%lld%lld",&n, &m);
    int cnt = 0;
    while(n <= m){
        cnt++;
        n = n*2;
    }

    printf("%d\n", cnt);
}
int main()
{
    #ifdef local
        freopen("in.txt", "r", stdin);
        //freopen("in.txt", "w", stdout);
    #endif
    int ce, c = 0;
        solve();
    return 0;
}


Measured memory_bytes: 256
A, B, K = map(int,input().split())

# 愚直に for で回すとTLEになりそう
# for _ in range(K):
#    if A >= 1:
#        A = A - 1
#    elif B >= 1:
#        B = B - 1

if A >= K:
    A -= K
else:
    K -= A
    A = 0
    if B >= K:
        B -= K
    else:
        B = 0

print(str(A), end = " ")
print(str(B))


Measured memory_bytes: 2940
s = int(input())
l = input().split()

if "0" in l:
    print(0)
else:
    p = int(l[0])
    flag = True
    for el in l[1:]:
        p *= int(el)
        if p > 10**18:
            print(-1)
            flag = False
            break
    if flag:
        print(p)

Measured memory_bytes: 19496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll a;
    long double b;
    cin >> a >> b;
    long double c = a*b;
    ll ans = floor(c);
    cout << ans << endl;
}

Measured memory_bytes: 3732
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Map;
import java.util.Collections;
import java.util.LinkedHashMap;

public class Main {
    public static Scanner sc;
    public static LinkedHashMap<Integer, Integer> map;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if (n == 0 && m == 0) break;
            
            int[] ary = new int[m];
            
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (sc.nextInt() == 1) {
                        ary[j]++;
                    }
                }
            }
            
            map = new LinkedHashMap<>();
            
            for (int i = 0; i < m; i++) {
                map.put(i+1, ary[i]);
            }
            
            List<Map.Entry<Integer, Integer>> entry = new ArrayList<Map.Entry<Integer, Integer>>(map.entrySet());
            
            Collections.sort(entry, new Comparator<Map.Entry<Integer, Integer>>() {
                @Override
                public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                    return o2.getValue().compareTo(o1.getValue());
                }
            });
            
            StringBuilder sb = new StringBuilder();
            for (Map.Entry e: entry) {
                sb.append(e.getKey()).append(" ");
            }
            sb.delete(sb.length()-1, sb.length());
            System.out.println(sb.toString());
        }
    }
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

struct Mystruct
{
    long long atack;
    long long mp;
    double cost;

    Mystruct(long long input_a, long long input_b)
    {
        atack = input_a;
        mp = input_b;
        cost = input_a * 1.0 / input_b;
    }
    bool operator<(const Mystruct &another) const
    {
        if (cost == another.cost)
        {
            return mp < another.mp;
        }
        return cost < another.cost; //年齢を比較
    };
};

int main()
{
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;

    if (u == s)
    {
        a--;
    }
    else
    {
        b--;
    }

    cout << a << " " << b << endl;
    return 0;
}


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

int main(){
  int n;
  cin>> n;
  vector<vector<int>> v(n,vector<int>(2));
  for (int i=0; i<n; i++) cin>> v[i][0] >> v[i][1];
  
  double ans=0;
  for (int i=0; i<n; i++){
    for (int j=0; j<n; j++){
      ans+=sqrt((v[i][0]-v[j][0])*(v[i][0]-v[j][0])+(v[i][1]-v[j][1])*(v[i][1]-v[j][1]));
    }
  }
  
  printf("%.6f",ans/n);
}

Measured memory_bytes: 256
def s_gen():
    for x in S: 
        yield x
def t_gen():
    for x in T:
        yield x
        

N=int(input())
S,T=input().split()
S,T=S[:N],T[:N]

it=s_gen()
it2=t_gen()

print("".join([next(it)+next(it2) for _ in range(N)]))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>

#define div 1000000000+7

typedef long long ll;

using namespace std;

void solve(){
    int n, m, a, b;
    int result[50];

    cin >> n >> m;
    for(int i = 0; i < n; i++){
        result[i] = 0;
    }
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        result[a-1]++;
        result[b-1]++;
    }
    for(int i = 0; i < n; i++){
        cout << result[i] << endl;
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::*;
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        n: usize, m: usize
    }
    let mut g = vec![vec![]; n];
    for i in 0..n {
        g[i] = Vec::new();
    }
    for _ in 0..m {
        input! {
            mut a: usize, mut b: usize
        }
        g[a-1].push(b-1);
        g[b-1].push(a-1);
    }
    let mut q = VecDeque::new();
    let mut checked = vec![false; n];
    let mut ans = vec![0; n];
    q.push_front(0);
    checked[0] = true;
    while q.len() > 0 {
        let b = q.pop_back().unwrap();
        for i in &g[b] {
            if !checked[*i] {
                ans[*i] = b;
                q.push_front(*i);
                checked[*i] = true;
            }
        }
    }
    println!("Yes");
    for i in 1..n {
        println!("{}", ans[i]+1);
    }
}


Measured memory_bytes: 14304
#include<iostream>
#include<cstdio>
using namespace std;
long long n,a,b;
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	if((n>1 && b>=a) || (n==1 && a==b))
	{
		printf("%lld\n",(n-2)*(b-a)+1);
	}
	else
	{
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
typedef long long ll;

const int m = 2019;

int main(){
    string s;
    cin >> s;
    // string searchStr = "";
    // ll ssize = s.size();
    // ll ans = 0;
    // for(int i = 1; i <= 10000; i++) {　
    //     searchStr = to_string(i * 2019);
    //     if(searchStr.size() > ssize) break;
    //     if(searchStr.find("0") != string::npos) continue;

    //     int pos = 0;
    //     while (pos != string::npos) {
            
    //         pos = s.find(searchStr, pos );
    //         if(pos != string::npos)pos++;
    //         ans++;
    //     }
    //     ans--;
    // }
    // cout << ans << endl;

    int n = s.size();
    reverse(s.begin(), s.end());
    int x = 1, tot = 0;
    vector<int> cnt(m);
    ll ans = 0;
    FOR(i, 0, n) {
        cnt[tot]++;
        tot += (s[i] - '0') * x;
        tot %= m;
        ans += cnt[tot];
        x = x * 10 % m;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n, s = 0; cin >> n;
  vector<int> v(n), c(n);
  rep(i, n) cin >> v[i];
  rep(i, n) cin >> c[i];
  rep(i, n) s += max(0, v[i] - c[i]);
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
const int mod=1e9+7;
const int inf=1e9+7;

const int maxn=2e3+10;

int num[maxn];

int a,b,c;

inline bool check(int now)
{
	if(a+b>num[now]&&(b-a)<num[now])
		return true;
	return false;
}
 
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    int n;
    cin>>n;
    
    for(int i=0;i<n;i++)
    	cin>>num[i];
    
    sort(num,num+n);
    
    ll int cnt=0;
    
    for(int i=0;i<n;i++)
    {
    	for(int j=i+1;j<n;j++)
    	{
    		a=num[i];
    		b=num[j];
    		
    	//	dd;
    	//	cout<<i<<" "<<j<<endl;
    	//	dd;
    		
    		int left=j,right=n;
    		
    		int mid;
    		
    		while(left<right)
    		{
    			mid=(left+right+1)/2;
    			if(check(mid))
    			{
    				left=mid;
				}
				else
				{
					right=mid-1;
				}
			}
			
		//	cout<<left<<" "<<mid<<" "<<right<<endl;
		//	dd;
			
			cnt+=(left-j);
    		
		}
	}
    
    cout<<cnt<<endl;
    
    return 0;
}

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

const int nIMPOS = -1;
struct StDist
{
  int m_nDist;
  int m_nFromMeTo;

  StDist(int nDist) : m_nDist(nDist), m_nFromMeTo(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StDist>& rvoDist)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StDist oDist(nIMPOS);
  rvoDist.resize(nxSiz + 1, oDist);
}

void fnBreadthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, 
                          queue<int>& rqnBFSrch, vector<StDist>& rvoDist)
{
  while (rqnBFSrch.size())
  {
    int nx = rqnBFSrch.front(); rqnBFSrch.pop();
    if (rvoDist[nx].m_nDist == nIMPOS)  continue;

    for (int ny = 1; ny < cnrvvnAdjcy[nx].size(); ++ny)
    {
      if (cnrvvnAdjcy[nx][ny] == 1  &&
          rvoDist[nx].m_nFromMeTo == 0)
      {
        int nDist = rvoDist[nx].m_nDist + 1;
        if (rvoDist[ny].m_nDist == nIMPOS)
          rvoDist[ny].m_nDist = nDist;
        else
          rvoDist[ny].m_nDist = min(rvoDist[ny].m_nDist, nDist);

        rqnBFSrch.push(ny);
      }
    }
    rvoDist[nx].m_nFromMeTo = 1;
  }
}

void fnResult(const vector<StDist>& cnrvoDist)
{
  for (int i = 1; i < cnrvoDist.size(); ++i)
    cout << i <<  " " << cnrvoDist[i].m_nDist << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  queue<int>  qnBFSrch;
  vector<StDist> voDist;

  fnInput(vvnAdjcy, voDist);

  voDist[1].m_nDist = 0;
  qnBFSrch.push(1);
  fnBreadthFirstSearch(vvnAdjcy, qnBFSrch, voDist);
  fnResult(voDist);

  return 0;
}

Measured memory_bytes: 3164
N, A, B = map(int, input().split())
ans = 0
for n in range(1, N+1):
    n_str = str(n)
    n_lst = list(n_str)
    n_lst = list(map(int, n_lst))
    sum_ = sum(n_lst)
    if A <= sum_ and sum_ <= B:
        ans += n
print(ans)

Measured memory_bytes: 9160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 *
 * @author dyominov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoodDistance solver = new BGoodDistance();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoodDistance {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int[][] a = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    a[i][j] = in.nextInt();
                }
            }
            int count = 0;
            for (int i = 0; i < n - 1; i++) {
                for (int j = i + 1; j < n; j++) {
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        int tmp = a[i][k] - a[j][k];
                        sum += tmp * tmp;
                    }
                    if (Math.sqrt(sum) == (int) Math.sqrt(sum)) {
                        count++;
                    }
                }

            }
            out.println(count);
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

        public void close() {
        }

    }
}



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

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

const int INF = 1e+9 * 2;
int n, x, d[16], c[16], ofs = 100010;
int dir[200100];

void dijkstra(int s){
	for(int i = 0; i < 200100; ++i)
		dir[i] = INF;
	dir[s] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(dir[v] < p.first)
			continue;
		for(int i = 0; i < n; ++i){
			int next1 = v + d[i], next2 = v - d[i];
			if(next1 < 200100 && dir[next1] > p.first + c[i]){
				dir[next1] = p.first + c[i];
				que.push(P(p.first + c[i], next1));
			}
			if(next2 >= 0 && dir[next2] > p.first + c[i]){
				dir[next2] = p.first + c[i];
				que.push(P(p.first + c[i], next2));
			}
		}
	}
	return;
}

int main() {
		
	cin >> n >> x;
	for(int i = 0; i < n; ++i){
		cin >> d[i] >> c[i];
	}
	dijkstra(ofs);
	if(dir[ofs + x] == INF)
		cout << "-1" << endl;
	else
		cout << dir[ofs + x] << endl;
	return 0;
}


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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define ll long long
#define pii pair<ll, int>
#define is insert
#define er erase

using namespace std;

const int MAX_N = 1e5;

int solve();

#define TASK ""

int main()
{
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        //freopen(TASK".in", "r", stdin);
        //freopen(TASK".out", "w", stdout);
    #endif // DEBUG
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

int n;

ll a[MAX_N];
ll b[MAX_N];

vector<pii> vec;

bool check(int x)
{
    ll sum = 0;
    for (int i = 0; i < x; ++i)
    {
        sum += vec[i].X;
    }
    for (int i = 0; i < n; ++i)
    {
        if (vec[i].X < 0)
        {
            sum += vec[i].X;
        }
    }
    return sum >= 0;
}

int solve()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> b[i];
    }
    int k = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] < b[i])
        {
            k++;
        }
        vec.pb(mp(a[i] - b[i], i));
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    int ind = -1;
    for (int i = 0; i < n; ++i)
    {
        if (vec[i].X >= 0)
        {
            ind = i;
        }
    }
    if (!check(ind + 1))
    {
        cout << -1 << '\n';
        return 0;
    }
    int l = -1;
    int r = ind + 1;
    while (r - l > 1)
    {
        int m = (l + r) / 2;
        if (check(m))
        {
            r = m;
        }
        else
        {
            l = m;
        }
    }
    cout << r + k << '\n';
    return 0;
}




Measured memory_bytes: 3956
#include<bits/stdc++.h>
#include <cstdio>   
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
#define EPS         1e-9
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;

 
int main(){
    ofstream out("output.txt");


    int n,x;

    cin>>n>>x;

    int cont = 1,acum = 0;
    int dist;
    int a[1000];
    for(int i= 0; i<n; i++){
        cin>>a[i];
    }

    for(int i = 0; i<n; i++){
        acum += a[i];
        if(acum > x){
            break;
        }
        cont++;
        
    }
    cout<<cont;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N,K;
  	cin >>N>>K;
    int ans=0;
    REP(i,N){
        int a;
        cin >>a;
        if(a>=K){
            ans++;
        }
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,K,A;
int main(){
	scanf("%d",&A);
	n=1;
	while((1+n)*n/2<A)n++;
	K=1;
	while((1+K)*K/2<=A)K++;
	K--;int S=(K+1)*K/2;
	for(int i=1;i<=n-K-1;i++)printf("(");
	for(int i=1;i<=n;i++){
		printf(")");
		if (i==A-S) printf("(");
	}
	for (int i=1;i<=K;i++) printf("(");
	printf("\n");
	return 0;
}

Measured memory_bytes: 2680
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi t(n),a(n);
    rep(i,0,n)cin>>t[i]>>a[i];
    ll ans=2;
    ll A=1,T=1;
    rep(i,0,n){
        ll ti=(T+(t[i]-1))/t[i];
        ll ai=(A+(a[i]-1))/a[i];
        ll c=max(ti,ai);
        T=c*t[i],A=c*a[i];
    }
    cout<<T+A<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include <set>
#include<map>
#include <unordered_map>
#include <vector>

using namespace std;
const int N = 1e5+10;
typedef long long ll;
typedef  pair<ll,ll>PII;


int n;
string s1,s2,ans;

ll a,b;

ll f(ll a,ll b){
   return b==0? a:f(b,a%b);
}

int main(){

       cin>>a>>b;
       cout<<a*b/f(a,b);

}

Measured memory_bytes: 256
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n, c = ns()
    l = 10 ** 5
    table = [[0 for _ in range(l + 1)] for __ in range(c)]

    for _ in range(n):
        s, t, ci = ns()
        ci -= 1
        table[ci][s] += 1
        table[ci][t] -= 1

    ans = 0
    tmp = 0
    for i in range(l + 1):
        fin = 0
        for j in range(c):
            if table[j][i] > 0:
                tmp += table[j][i]
            else:
                fin += table[j][i]
        ans = max(ans, tmp)
        tmp += fin
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32992
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

using ipair = pair<ll,ll>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

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

int main(){

  int N;
  cin >> N;

  vector<ll> A(N+1);
  rep(i, N){
    cin >> A[i+1];
  }

  vector<ll> f(N+1);
  vector<ll> b(N+1);

  f[0] = A[1];
  b[N] = A[N];

  rep(i, N){
    f[i+1] = gcd(f[i], A[i+1]);
    b[N-1-i] = gcd(b[N-i], A[N-i]);
  }

  // cout << "f:" << endl;
  // rep(i, N+1) cout << f[i] << " ";
  // cout << endl;

  // cout << "b:" << endl;
  // rep(i, N+1) cout << b[i] << " ";
  // cout << endl;

  ll ans = -1;
  for(int i=0; i<N; i++){
    ll tmp_ans = -1;
    if(i==0){
      tmp_ans = b[1];
    }else if(i==N-1){
      tmp_ans = f[i];
    }else{
      tmp_ans = gcd(f[i], b[i+1]);
    }

    ans = max(ans, tmp_ans);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
from collections import Counter

# forを逆から回して下から素直にmodを取るとTLEだった
# 累積和的な計算で高速化、やりやすくするためにreverse
S = input()[::-1]
# ex. 1817181712114 → 4112171817181
# print(S)

# 0桁目までのMODを0とすることで、
# 1桁目を含む数が2019の倍数の時に都合が良くなる
X = [0]

# 4,14,114,2114,12114,...のmod2019を計算

# pow(a,b,c)は普通にMODするより速い
# 普通にやったらTLEだった
for i, s in enumerate(S):
    X.append((X[-1] + int(s) * pow(10, i, 2019)) % 2019)
# print(X)


C = Counter(X)
# print(C)

ans = 0
# Xが同じになったところを2つ選べば題意を満たす
# v_C_2の計算
for v in C.values():
    ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 82140
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

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

    int n, d, a;
    cin >> n >> d >> a;
    pii xh[n];
    for (int i = 0; i < n; i++) {
        cin >> xh[i].first >> xh[i].second;
        xh[i].second = (xh[i].second - 1) / a + 1;
    }
    sort(xh, xh+n);

    int cur = 0;
    long long ans = 0;
    int cov[n];
    int j1 = 0;
    for (int i = 0; i < n; i++) {
        while (xh[j1].first < xh[i].first - 2 * d) {
            cur -= cov[j1++];
        }

        cov[i] = max(0, xh[i].second - cur);
        cur += cov[i];
        ans += cov[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
package main

import (
	"fmt"
)

func main() {
	var x, y int32
	fmt.Scan(&x)
	fmt.Scan(&y)

	if x < y {
		fmt.Println(gcd(y, x))
	} else {
		fmt.Println(gcd(x, y))
	}
	
}

func gcd(b, s int32) int32 {
	if b % s == 0 {
		return s
	}
	return gcd(s, b - s * (b / s))
}



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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    string s;
    cin >> s;
    if(s=="#") return 0;
    set<pair<string,int>> se;
    se.insert({s,0});
    string u;
    bool okflag,henflag;
    int pos;
    for(char i='a';i<='z';i++){
      // cout << i << endl;
      list<pair<string,int>> add;
      for(auto t:se){
        // cout << t.first << endl;
        pos=-1;
        okflag=false,henflag=false;
        if(i=='a') okflag=true;
        for(int j=0;j<s.length();j++){
          if(t.first[j]==i){
            if(t.second&(1<<j)){
              if(pos==-1) okflag=true,pos=j;
            }else{
              if(!okflag){
                if(!henflag){
                  if(i=='z') goto next;
                  t.first[j]=i+1;
                  t.second|=(1<<j);
                  henflag=true;
                }else{
                  goto next;
                }
              }
            }
          }
        }
        // cout << t.first << endl;
        add.push_back(t);
        if((!henflag)&&okflag&&(i!='z')){
          for(int j=pos+1;j<s.length();j++){
            if(t.first[j]==i){
              u=t.first;
              u[j]=i+1;
              add.push_back({u,t.second|(1<<j)});
            }
          }
        }
        next:
        continue;
      }
      se.clear();
      for(auto t:add){
        se.insert(t);
      }
    }
    cout << se.size() << endl;
    if(se.size()<=10){
      for(auto t:se){
        cout << t.first << endl;
      }
    }else{
      int c=0;
      for(auto t=se.begin();t!=se.end();t++,c++){
        cout << t->first << endl;
        if(c>=4) break;
      }
      for(auto t=next(se.end(),-5);t!=se.end();t++){
        cout << t->first << endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 7560
/**
 *    author:  tourist
 *    created: 14.07.2019 15:48:21       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  if (m % 2 == 1) {
    cout << -1 << '\n';
    return 0;
  }
  vector<pair<int, int>> res;
  vector<int> deg(n, 0);
  vector<int> depth(n, -1);
  function<void(int, int)> Dfs = [&](int v, int pr) {
    for (int u : g[v]) {
      if (depth[u] == -1) {
        depth[u] = depth[v] + 1;
        Dfs(u, v);
      } else {
        if (depth[u] > depth[v]) {
          res.emplace_back(v, u);
          ++deg[v];
        }
      }
    }
    if (deg[v] % 2 == 1) {
      assert(pr != -1);
      res.emplace_back(v, pr);
      ++deg[v];
    } else {
      if (pr != -1) {
        res.emplace_back(pr, v);
        ++deg[pr];
      }
    }
  };
  depth[0] = 0;
  Dfs(0, -1);
  for (auto& p : res) {
    cout << p.first + 1 << " " << p.second + 1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 14836
# -*- coding: utf-8 -*-

H,W,K=map(int, input().split())
val=[input() for i in range(H)]


temp=[[0]*W for i in range(H)]
counter=1
for j in range(W):
    lbound=0
    for i in range(H):
        if val[i][j]=="#":
            for k in range(H-lbound):
                temp[k+lbound][j]=counter
            counter=counter+1
            lbound=i+1
            
for jtemp in range(W-1):
    j=jtemp+1
    for i in range(H):
            if temp[i][j]==0:
                temp[i][j]=temp[i][j-1]
                
for jtemp in range(W-1):
    j=W-2-jtemp
    for i in range(H):
            if temp[i][j]==0:
                temp[i][j]=temp[i][j+1]  
for i in range(H):
    for j in range(W):
        if j==W-1:
            print(temp[i][j])
        else:
            print(temp[i][j],end=' ')

Measured memory_bytes: 7500
#include<iostream>

using namespace std;

class dice
{
public:
  int d[6];
  int t;
  int n;
  int e;
  int s;
  int w;
  int b;
  
  dice();
  int init();
  int move(char c);
  int runCmd(string cmd);
  int toTop(int x);
  int toFront(int x);
  int top();
  int right();
};

dice::dice()
{
  t = 0;
  n = 4;
  e = 2;
  s = 1;
  w = 3;
  b = 5;
}

int dice::init()
{
  for(int i = 0; i < 6; i++ )
    {
      cin >> d[i];
    }
  return 0;
}

int dice::move(char c)
{
  int tmp;
  
  if ( c == 'E' )
    {
      tmp = t;
      t = w;
      w = b;
      b = e;
      e = tmp;
    }
  else if ( c == 'N' )
    {
      tmp = t;
      t = s;
      s = b;
      b = n;
      n = tmp;
    }
  else if ( c == 'S' )
    {
      tmp = t;
      t = n;
      n = b;
      b = s;
      s = tmp;
    }
  else if ( c == 'W' )
    {
      tmp = t;
      t = e;
      e = b;
      b = w;
      w = tmp;
    }

  return 0;
}

int dice::runCmd(string cmd)
{
  for ( int i = 0; i < (int)cmd.size(); i++ )
    move( cmd[i] );

  return 0;
}

int dice::toTop(int x)
{
  int pt;
  
  for ( int i = 0; i < 6; i++ )
    {
      if ( d[i] == x )
        {
          pt = i;
          break;
        }
    }
  
  if ( n == pt )
    {
      runCmd( "S" );
    }
  else if ( e == pt )
    {
      runCmd( "W" );
    }
  else if ( s == pt )
    {
      runCmd( "N" );
    }
  else if ( w == pt )
    {
      runCmd( "E" );
    }
  else if ( b == pt )
    {
      runCmd("NN");
    }

  return 0;
}

int dice::toFront(int x)
{
  int pt;
  
  for ( int i = 0; i < 6; i++ )
    {
      if ( d[i] == x )
        {
          pt = i;
          break;
        }
    }
  
  if ( n == pt )
    {
      runCmd( "ESWESW" );
    }
  else if ( e == pt )
    {
      runCmd( "NWS" );
    }
  else if ( w == pt )
    {
      runCmd( "ESW" );
    }
}

int dice::top()
{
  cout << d[t] << endl;
  return 0;
}

int dice::right()
{
  cout << d[e] << endl;
  return 0;
}

int main()
{
  int n, t, f;
  dice d;
  
  d.init();

  cin >> n;

  for ( int i = 0; i < n; i++ )
    {
      cin >> t >> f;
  
      d.toTop(t);
      d.toFront(f);
      d.right();
    }

  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;

const int MAXN = 1000*1000 + 7;
const int SS = 1<<20;
const int INF = 1000*1000*1000 + 7;

int t[MAXN];
int n, m, q;

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

	int T;
	//cin >> T;
	T = 1;
	while(T--)
	{
		long long x, d, k;
		cin >> x >> k >> d;
		long long ile = abs(x)/d;
		if(ile >= k)
		{
			cout << abs(x) - k*d << '\n';
			continue;
		}
		long long pom = k - ile;
		if(pom%2 == 0)
		{
			cout << abs(x) - ile*d << '\n';
			continue;
		} 
		cout << d - (abs(x) - ile*d) << '\n';
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define F first
#define S second
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define EPS 1e-7
#define iof freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
long long mod = 1e9;
const int N = 1e9;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1);
typedef complex <ll> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
ll n, m, x, ans;
priority_queue<ll> q;
int main()
{
    em3
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
        cin >> x, q.push(x);
    while(m--)
    {
        ll temp = q.top();
        q.pop();
        q.push(temp / 2);
    }
    while(!q.empty())
    {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
typedef long long ll;
const int maxn = 2000 + 5;
using namespace std;
int n;
ll z, w, a[maxn];
int main()
{
    cin >> n >> z >> w;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    if(n == 1)
        cout << abs(a[1]-w) << endl;
    else
        cout << max(abs(a[n]-w),abs(a[n]-a[n-1])) << endl;
    return 0;
}


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

int main(){
    int n; cin>>n;
    vector<int> a(n);
    ll S = 0,hS = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        S += a[i];
        if(i&1)hS += a[i];
    }
    vector<ll> x(n);
    x[0] = S-2*hS;

    for(int i = 0; i < n-1; i++){
        x[i+1] = 2*a[i]-x[i];
    }
    for(auto e:x){
        cout << e << " ";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 2432
N = int(input())
mod = 10**9 + 7

pf = {}
for i in range(2, N+1):
    for j in range(2, int(i**0.5)+1):
        while i % j == 0:
            pf[j] = pf.get(j, 0) + 1
            i //= j
    if i > 1:
        pf[i] = pf.get(i, 0) + 1

ans = 1
for p in pf.values():
    ans = ans * (p+1) % mod

print(ans)

Measured memory_bytes: 3064
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

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

lli n; 
string s;

void solve(){
    cin >> n >> s;
    vpi pref(n), suff(n);
    pref[0] = (s[0]=='R') ? make_pair(1,0) : make_pair(0,1);
    NA(i,1,n) pref[i].fi = pref[i-1].fi + (s[i]=='R'), pref[i].se = pref[i-1].se + (s[i]=='W');
    suff[n-1] = (s[n-1]=='R') ? make_pair(1,0) : make_pair(0,1);
    for(lli i=n-2; i>-1; --i) suff[i].fi = suff[i+1].fi + (s[i]=='R'), suff[i].se = suff[i+1].se + (s[i]=='W');
    lli ans = 2e5+1;
    NA(i,0,n) {
        if(!i) {
            ans = min(ans, suff[i+1].fi);
        } else if(i==n-1) {
            ans = min(ans, pref[i].se);
        } else {
            ans = min(ans, max(pref[i].se, suff[i+1].fi));
        }
    }
    cout << ans << '\n';
    return;
}

int main(){
    fastIO;
    lli t = 1;
    // cin >> t;
    NA(i,0,t){ 
		// cout << "Case #" << i+1 << ": \n";
		solve();
	}
	return 0;
}


Measured memory_bytes: 9624
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n,t;
	cin >> n >> t;
	int a;
	cin >> a;
	int b;
	int ans = t;
	rep(i,n-1){
		cin >> b;
		int sub = b - a;
		if (sub < t){
			ans += sub;
		}
		else {
			ans += t;
		}
		a = b;
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<endl;}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
}

int main(){
  int x,y;cin>>x>>y;
  cout<<x+(y/2)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[110],n,res,ans=~0ull>>1;
int main()
 {
 	scanf("%lld",&n);
 	for(ll i=1;i<=n;i++)
 		scanf("%lld",&a[i]);
 	for(ll i=-100;i<101;i++)
 	{
		res=0;
		for(ll j=1;j<=n;j++)
			res=res+(i-a[j])*(i-a[j]);
		ans=min(ans,res); 
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<queue>
#include<cctype>
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>
const int N=2007;
using pi=std::pair<int,int>;
int n,a[N],vis[N],deg[N];std::vector<int>e[N];std::priority_queue<pi>q;
int read(){int x=0,c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
void dfs(int u)
{
    for(int v=vis[u]=1;v<=n;++v) if(!vis[v]&&std::__gcd(a[u],a[v])>1) e[u].push_back(v),++deg[v],dfs(v);
}
int main()
{
    n=read();
    for(int i=1;i<=n;++i) a[i]=read();
    std::sort(a+1,a+n+1);
    for(int i=1;i<=n;++i) if(!vis[i]) dfs(i);
    for(int i=1;i<=n;++i) if(!deg[i]) q.emplace(a[i],i);
    for(int u;!q.empty();)
    {
	printf("%d ",q.top().first),u=q.top().second,q.pop();
	for(int v:e[u]) if(!--deg[v]) q.emplace(a[v],v);
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll A, B, C;
	cin >> A >> B >> C;
	cout << min(B/A, C) << endl;
    return 0;
}

Measured memory_bytes: 256