akhauriyash/Code-Regression huggingface dataset:
#include<string>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<ios>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<type_traits>
#include<random>
#include<vector>
#include<map>

using namespace std;


int main()
{
	int N;
	int K;
	cin >> N >> K ;
	int t;
	int d;
	map<int,vector<int>> M;
	for(int in=0;in<N;in++)
	{
		cin >> t >> d;
		M[t].push_back(d);
	}
	
	vector<int> maxes;
	vector<int> others;
	for(auto& e : M)
	{
		auto vec = e.second;
		sort(vec.rbegin(),vec.rend());
		maxes.push_back(vec[0]);
		for(int i=1;i<vec.size();i++)
		{
			others.push_back(vec[i]);
		}
	}
	
	sort(maxes.rbegin(),maxes.rend());
	sort(others.rbegin(),others.rend());
	int kmax = min(K , (int) M.size());
	vector<int64_t> maxsum(M.size()+1,0);
	vector<int64_t> othersum(N+1,0);
	
	for(int i=0;i<M.size();i++)
	{
		maxsum[i+1] = maxsum[i] + maxes[i];
	}
	for(int i=0;i<others.size();i++)
	{
		othersum[i+1] = othersum[i] + others[i];
	}

	int64_t ans = 0;

	for(int64_t k=1;k<=kmax;k++)
	{
		int64_t result = maxsum[k] + othersum[K-k] + k*k;
		ans = max(result,ans);
	}
	cout << ans << endl ;
}

	

Measured memory_bytes: 13304
#!/usr/bin/env python
# coding: utf-8

# In[15]:


from collections import deque


# In[38]:


N,M = map(int, input().split())
alist = [False]*N
for _ in range(M):
    alist[int(input())-1] = True


# In[41]:


dp = deque([0]*2)
dp[0] = 1
ans = 0
mod = 10**9+7
if N == 1:
    ans = 1
else:
    if alist[0]:
        dp[1] = 0
    else:
        dp[1] = 1
    for i in range(2,N+1):
        if alist[i-1]:
            dp.append(0)
        else:
            dp.append((dp[0]+dp[1])%mod)
        dp.popleft()
    ans = dp[-1]
print(ans)


# In[ ]:






Measured memory_bytes: 9988
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5 +10;

int N;
long long K, pre = 0;
pair<int, int> P[maxn];

int main(){
    cin>>N>>K;
    for(int i = 0, a, b; i < N; i ++){
        cin>>a>>b;
        P[i].first = a;
        P[i].second = b;
    }
    sort(P, P + N);
    int ans;
    for(int i = 0; i < N; i ++){
        if(pre < K && K <= P[i].second + pre){
            ans = P[i].first;
            break;
        }
        pre += P[i].second;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
import java.io.*;

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String s = br.readLine();

    br.close();

    int ans = 0;
    for(int i = 0; i < s.length(); i++){
      if(s.charAt(i) == '2') ans++;
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N;
    int a[20],b[20];
    vector<pair<int,int>> AB;
    cin >> N;
    REP(i,N){
        cin >> a[i];
    }
    REP(i,N){
        cin >> b[i];
    }
    REP(i,N){
        AB.push_back({a[i],b[i]});
    }
    int Ans=INF;
    for(int l=0;l<(1<<N);l++){
        vector<pair<int,int>> S;
        int num=0;
        REP(i,N){
            if((l>>i)%2==1){
                S.push_back({AB[i].first,0});
            }else{
                S.push_back({AB[i].second,1});
            }
        }
        bool forbid = false;
        
        //REP(i,N){cout << S[i].first << " ";}cout << endl;
        //REP(i,N){cout << S[i].second << " ";}cout << endl;
        bool carry = false;
        
        REP(i,N){
            int mn = N-1;
            for(int j=N-1;j>=i;j--){
                if(S[mn].first>=S[j].first && (i+j+S[j].second)%2==0){
                    mn=j;
                    carry=true;
                }
            }
            //cout << mn << endl;
            //mnをiに移行
            if(!carry)continue;
            for(int j = mn;j>=i+1;j--){
                swap(S[j],S[j-1]);
                S[j].second ^=1;
                S[j-1].second ^=1;
                num++;
            }
            /*
            if(l==4){
                REP(k,N){
                    cout << S[k].first << " ";
                }cout << endl;
                REP(k,N){
                    cout << S[k].second << " ";
                }cout << endl;
            }*/
        }
        
        REP(i,N){
            if(S[i].second==1){
                forbid=true;
            }
            if(i!=0 && S[i].first<S[i-1].first){
                forbid=true;
            }
        }
        
        if(forbid==false){
            Ans=min(Ans,num);
        }
        
        //cout << num << "  " <<(forbid?"true":"false") << endl;
        
    }
    
    if(Ans==INF){
        cout << -1 << endl;
    }else{
        cout << Ans << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int n,ans[4],final_ans[12],tmp,length,S;

	for(int i = 0; i < 12; i++)final_ans[i] = 100000001;
	for(int i = 0; i < 4; i++)ans[i] = 100000001;

	scanf("%d",&n);

	//???????°???????4????????????????????????????????????????????£?????????
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);

		if(tmp < ans[0]){
			ans[3] = ans[2];
			ans[2] = ans[1];
			ans[1] = ans[0];
			ans[0] = tmp;
		}else if(tmp < ans[1]){
			ans[3] = ans[2];
			ans[2] = ans[1];
			ans[1] = tmp;
		}else if(tmp < ans[2]){
			ans[3] = ans[2];
			ans[2] = tmp;
		}else if(tmp < ans[3]){
			ans[3] = tmp;
		}

	}

	int index = 0;
	for(int i = 0; i < 4; i++){
		for(int k = 0; k < 4; k++){
			if(i != k){
				S = 1;
				for(length = 0; ;length++){
					if(ans[k]/S == 0){
						break;
					}else{
						S *= 10;
					}
				}
				final_ans[index++] = ans[i]*pow(10,length)+ans[k];
			}
		}
	}

	for(int i = 1; i <= 11; i++){
		for(int k = 11; k >= i; k--){
			if(final_ans[k] < final_ans[k-1])swap(final_ans[k],final_ans[k-1]);
		}
	}

	printf("%d\n",final_ans[2]);

	return 0;
}

Measured memory_bytes: 2868
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q,a,b,c,d;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>a>>b>>c>>d;
      cout<<max(a*c,max(a*d,max(b*c,b*d)));
}

Measured memory_bytes: 3636
from collections import defaultdict

n = int(input())
G = defaultdict(list)
rec = []
for i in range(n):
    a, b = map(int, input().split())
    rec.append((i, a, b))

for i in range(n):
    c, d = map(int, input().split())
    for index, p, q in rec:
        if p < c and q < d:
            G[index].append(i + n)
            G[i + n].append(index)

used = [False] * 2 * n
match = [-1] * 2 * n

def dfs(v):
    used[v] = True
    for u in G[v]:
        w = match[u]
        if w < 0 or not used[w] and dfs(w):
            match[v] = u
            match[u] = v
            return True
# dfs(0)
# print(match)
# print((used))
ma = 0
for i in range(n):
    if match[i] < 0:
        used = [False] * 2 * n
        if dfs(i):
            ma += 1

print(ma)

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

int n, x, tab[100003], temp;

int main() {
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> tab[i];
    }
    if (n == 1) {
        cout << abs(tab[0] - x);
        return 0;
    }
    tab[n] = x;
    sort(tab, tab + n + 1);
    temp = tab[n - 1];
    for (int i = 1; i <= n; i++) {
        tab[i - 1] = tab[i] - tab[i - 1];
    }
    tab[n] -= temp;
    int res = tab[0];
    for (int i = 1; i <= n; i++) {
        res = __gcd(res, tab[i]);
    }
    cout << res;
}

Measured memory_bytes: 640
/*
 *
 * Author: r3gz3n
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <utility>
#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 <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define ll long long


#define rep(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)


const int MAX = 1e3 + 5;
const int MOD = 1e9 + 7;

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		ll a[MAX] = {0};
		int n, x;
		in >> n;
		rep(i, 2, n+1, 1) {
			x = i;
			rep(j, 2, n+1, 1) {
				while (x % j == 0) x /= j, a[j]++;
			}
		}
		ll ans = 1;
		rep(i, 1, n+1, 1) ans = (ans * (a[i]+1)) % MOD;
		out << ans << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    Solution solution;
    solution.solve(in, out);
}


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>

int main()
{
    int n, k;
    std::cin >> n >> k;

    if(n % 2 == 0){
        if(n / 2 >= k){
            std::cout << "YES\n" ;
        }
        else{
            std::cout << "NO\n" ;
        }
    }
    else{
        if((n + 1) / 2 >= k){
            std::cout << "YES\n" ;
        }
        else{
            std::cout << "NO\n" ;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,w;
vector<ll> we;
vector<ll> val;
ll max(ll a,ll b)
{
    return a>b?a:b;
}

int main()
{
    cin>>n>>w;
    we.resize(n);
    val.resize(n);
    for(int i=0;i<n;i++)
    {
        cin>>we[i];
        cin>>val[i];
    }
    vector<vector<ll> > ans(n+1,vector<ll> (w+1,0));

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(j-we[i-1]>=0)
            ans[i][j]=(ll)max(ans[i-1][j],ans[i-1][j-we[i-1]]+val[i-1]);
            else
            ans[i][j]=ans[i-1][j];
        }
    }
    cout<<ans[n][w];
    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const ll mod=1e9+7;
ll suffixSum[200005];
ll a[200005];
int main(void)
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i) cin>>a[i];
    suffixSum[n]=0;
    for(int i=n-1;i>=0;--i) suffixSum[i]=(suffixSum[i+1]+a[i])%mod;
    ll ans=0;
    for(int i=0;i<n;++i)
        ans=(ans+a[i]*suffixSum[i+1]%mod)%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6724
#include <stdio.h>

int main(){
    int a = 0;
    int b = 0;
    int c = 0;
    int cnt = 0;

    scanf("%d%d%d",&a,&b,&c);
    
    
    for(;a<=b;a++){
        if(c%a==0){
           cnt = cnt + 1;
        }
    }
    
    printf("%d\n",cnt);
    return 0;
}


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

int a[210],n,ans;

int main()
{
	cin>>n;
	for(int i=1;i<=n*2;i++) cin>>a[i];
	sort(a+1,a+n*2+1);
	for(int i=1;i<n*2;i+=2)
		ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second 
#define ll long long 
#define _for(i,j,k) for(int i=j;i<k;i++)
#define endl  '\n'
#define inf 1<<29-1 
const int mod=1e9+7;
const int MAX=1e6+5;

int main() {
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	ll n,k,t;
 	cin>>n>>k;
 	ll MIN=n%k;
 	cout<<min(MIN,k-MIN);
 	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int n, m;;
vvll x;

ll calc() {
  vll sumx(n, 0);
  rep (i, n) {
    rep (j, 3) {
      sumx[i] += x[i][j];
    }
  }
  sort(all(sumx), std::greater<>());
  ll ret = 0;
  rep (i, m) {
    ret += sumx[i];
  }
  return ret;
}


int main() {
  scanf("%d %d", &n, &m);
  x.assign(n, vll(3, 0));
  rep (i, n) {
    rep (j, 3) {
      scanf("%lld", &x[i][j]);
    }
  }
  /*
  vi gray(8);
  rep (i, 8) {
    gray[i] = (i ^ (i >> 1));
  }
  debug(gray);
  */
  vi change = {0, 1, 0, 2, 0, 1, 0};
  ll ans = 0;
  ans = max(ans, calc());
  rep (i, 7) {
    rep (j, n) {
      x[j][change[i]] *= (-1);
    }
    ans = max(ans, calc());
  }
  printf("%lld\n", ans);

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int shain[n - 1];
  int ans[n-1];
  rep(i, n-1) cin >> shain[i];
  rep(i, n-1) ans[i] = 0;
  rep(i, n-1) {
    ans[shain[i]-1]++;
  };
  rep(i, n-1) cout << ans[i] << endl;
  cout << 0 << endl;
}

Measured memory_bytes: 5200
#include<cstdio>
#define orz 2333
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<=orz;i++){
		if(a*i%b==c){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 128
/*
	*#*#*#* Author GaryMr *#*#*#*
	是否可以简化问题：
	字符串问题是否可以用数学模拟递归过程（取c[i]或不取来算结果）
	二分？左闭右开？
	long long？
	逆向思维？
	dp？
	贪心？
	匹配括号 左减右>=0
	多组数据清空？
	dp优化用g？
	线段树：左闭右开！
	线段树：find： if(l>=b||r<=a) return 0x3f3f3f3f; if(r<=b&&l>=a) return tree[k];
	线段树：满二叉树 
	循环跳出条件 
	代数设出每个值寻找关系？
	优先队列：priority_queue<类型> q;   
	priority_queue<类,vector<类>, less<类> > pq1; 　　　 // 使用递减	
	priority_queue<类，vector<类>, greater<类> > pq2; 　　// 使用递增
	判断括号，判断是否长度为偶数
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define IT iterator
#define FIR first
#define SEC second
using namespace std;
const int MAX=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
long long a,b,c;
long long LIVE;
long long ans;
int main(){
	scanf("%I64d%I64d%I64d",&a,&b,&c);
	LIVE=a+b;
	ans=b;
	ans+=min(LIVE+1,c);
	printf("%I64d\n",ans);
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d %d', $cnt, $ref);
$ans = 0;
for ($i=0; $i < $cnt; $i++) { 
    fscanf(STDIN, '%d %d', $x, $y);
    $sqrt = sqrt($x **2 + $y ** 2);
    if ($sqrt <= $ref) {
        $ans++;
    }
}
echo $ans;

Measured memory_bytes: 15840
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
# S=numpp.assaray(S)=="#"
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LLS(): return [list(sys.stdin.readline().rstrip()) for _ in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()



def main():
    X, A = list(map(int,input().split()))
    if X<A:
        print("0")
    else:
        print("10")

    
    
if __name__ == "__main__":
    main()

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 N,D;
    cin >> N >> D;
    
    vector<i64> d(N);
    rep(i,0,N) cin >> d[i];

    vector<i64> pos(N+1);
    pos[0]=D;
    rep(i,1,N+1){
        i64 next=abs(pos[i-1]-d[i-1]);
        if(next<pos[i-1]) pos[i]=next;
        else pos[i]=pos[i-1];
    }

    i64 Q;
    cin >> Q;

    vector<vector<i64>> queries(500000);
    rep(i,0,Q){
        i64 q;
        cin >> q;
        queries[q-1].push_back(i);
    }

    vector<bool> ans(Q);
    i64 x=0;
    for(int i=N-1; i>=0; --i){
        if(!queries[i].empty()){
            bool ok=pos[i]>x;
            rep(j,0,queries[i].size()) ans[queries[i][j]]=ok;
        }

        if(x>=d[i]/2) x+=d[i];
    }

    rep(i,0,Q) if(ans[i]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 37248
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

#define ll long long // -2^63 to +2^63-1 (upper limit ~ 9*(10^18))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//code
	string s1,s2;
	cin>>s1>>s2;
	cout<<s2<<s1;
	return 0;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> a(n), b(n);
	map<int, int> mp;
	rep(i, n)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(all(b));
	rep(i, n)mp[b[i]] = i;
	int cnt = 0;
	rep(i, n)
	{
		if ((i - mp[a[i]]) % 2)++cnt;
	}
	cout << cnt / 2 << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v_ac(N);
  vector<int> v_wa(N);
  int p;
  string s;
  for (int i = 0; i < M; i++) {
    cin >> p >> s;
    --p;
    if (s == "AC") {
      ++v_ac[p];
    } else {
      if (!v_ac[p]) {
        ++v_wa[p];
      }
    }
  }
  int ans = 0;
  int penalty = 0;
  for (int i = 0; i < N; i++) {
    bool ac = v_ac[i] > 0;
    ans += (int)ac;
    if (ac) {
      penalty += v_wa[i];
    }
  }
  cout << ans << ' ' << penalty << endl;
  return 0;
}

Measured memory_bytes: 1024
a, b, c, x, y = map(int, input().split())
case1 = a * x + b * y
if x >= y:
    case2 = c * 2 * y + a * (x - y)
    case3 = c * 2 * x
else:
    case2 = c * 2 * x + b * (y - x)
    case3 = c * 2 * y
print(min(case1, case2, case3))

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

using namespace std;

int N;

int main() {
	int a, b, totalA, totalB;

	while (cin >> N, N) {
		totalA = totalB = 0;
		for (int i = 0; i < N; ++i) {
			cin >> a >> b;
			if (a > b) {
				totalA += a + b;
			}
			else if (a < b) {
				totalB += a + b;
			}
			else {
				totalA += a;
				totalB += b;
			}
		}
		cout << totalA << " " << totalB << endl;
	}

	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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


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

const int N = 1e6 + 19, Mod = 1e9 + 7;
ll n;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ll tot = 0;
    ll m = n - 1;
    for (ll i = 1; i * i <= m; i ++)
        if (m % i == 0)
        {
            if (i != 1)
                tot ++;
            if (m / i != i)
                tot ++;
        }
    vector < ll > A;
    for (ll i = 1; i * i <= n; i ++)
        if (n % i == 0)
        {
            A.push_back(i);
            if (n / i != i)
                A.push_back(n / i);
        }
    for (ll a : A)
    {
        if (a == 1)
            continue;
        ll tmp = n, c = 0;
        while (tmp % a == 0)
            tmp /= a, c = 1;
        if (c == 0)
            continue;
        if (tmp % a == 1)
            tot ++;
    }
    cout << tot;
    return 0;
}

Measured memory_bytes: 384
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy
# from fractions import gcd

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


n = int(input())
x = input()
nx = int(x, 2)
c = x.count("1")

numa = 0
numb = 0
p = 0
for i in reversed(range(len(x))):
    if x[i] == "1":
        if c > 1:
            numa += pow(2, p, c - 1)
        numb += pow(2, p, c + 1)
    p += 1

# print(c-1, c+1, numa, numb)

for i in range(n):
    if x[i] == "0":
        val = (numb + pow(2, n-i-1, c + 1)) % (c+1)
        # print(i, val)
        if val == 0:
            print(1)
            continue
        count = 1
        while val > 0:
            val = val % bin(val).count("1")
            count += 1
        print(count)
    else:
        if c == 1:
            print(0)
            continue
        val = (numa - pow(2, n - i - 1, c - 1)) % (c - 1)
        # print(i, val)
        if val == 0:
            print(1)
            continue
        count = 1
        while val > 0:
            val = val % bin(val).count("1")
            count += 1
        print(count)



Measured memory_bytes: 82096
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		int[][]A = new int[N][2];
		
		for(int i=0; i<N; i++) {
			A[i][0] = i+1;
			A[i][1] = keyboard.nextInt();
		}
		Arrays.sort(A, (l,r) -> {return r[1]-l[1];});
		
		for(int j=1; j<N+1; j++) {
			if(j == A[0][0]) {
				System.out.println(A[1][1]);
			}else {
				System.out.println(A[0][1]);
			}
		}
		keyboard.close();	
	}
}


Measured memory_bytes: 99020
#include <bits/stdc++.h>
using namespace std;
#define test() int t; cin>>t; while(t--)
#define ll long long int
int mod = 1e9 + 7;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int p = 0;
	int b_rank = 1;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'a') {
			if (p < (a + b))	{
				cout << "Yes\n";
				p++;
			}
			else	cout << "No\n";
			continue;
		}
		if (s[i] == 'b') {
			if (p < (a + b) && b_rank <= b) {
				cout << "Yes\n";
				p++;
				b_rank++;
			}
			else	cout << "No\n";
		}
		else {
			cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long n,k;
	cin >> n >> k;
	long long s = 0;
	for(long long i = k;i <= n;i++){
		s += n * (n + 1) / 2;
		s -= ((n - i) * (n - i + 1) / 2);
		s -= (i * (i - 1) / 2);
		++s;
		s %= mod;
	}
	++s;
	s %= mod;
	cout << s;
	return 0;
}
 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define LIMIT_M 1000000000000000000 // 10^18
using namespace std;
static const long long LIMIT = 1000000000000000000; // 10^18


int main() {
    long long res = 1, A[100005];
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for (int i = 0; i < N; i++) {
        if (res > LIMIT / A[i]) {
            cout << -1 << endl;
            return 0;
        } else {
            res *= A[i];
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4420
#include<vector>
#include<functional>
#include<limits>
template<typename T>class segment_tree:private std::vector<T>{
private:
    using typename std::vector<T>::size_type;
    using std::vector<T>::data;
    using std::vector<T>::size;
    using std::vector<T>::resize;
    std::function<T(T,T)>operation;
    T identity;
public:
    segment_tree(size_type n,std::function<T(T,T)>opr,T id):operation(opr),identity(id)
    {
        size_type _n=1;while(_n<n)_n<<=1;
        resize(_n*2-1,identity);
    }
    T&operator[](size_type idx)
    {
        return data()[idx+size()/2];
    }
    void update()
    {
        for(size_type i=size()/2-1;i>=0;--i){
            data()[i]=operation(data()[i*2+1],data()[i*2+2]);
        }
    }
    void update(size_type idx,T val)
    {
        idx+=size()/2;
        data()[idx]=val;
        while(idx>0){
            idx=(idx-1)/2;
            data()[idx]=operation(data()[idx*2+1],data()[idx*2+2]);
        }
    }
    T query(size_type l,size_type r)const
    {
        l+=size()/2;r+=size()/2;
        T L=identity,R=identity;
        while(l<r){
            if(l%2==0)L=operation(L,data()[l++]);
            if(r%2==0)R=operation(data()[--r],R);
            l>>=1;
            r>>=1;
        }
        return operation(L,R);
    }
    static segment_tree<T>sum(size_type n)
    {
        return segment_tree<T>(n,std::plus<T>(),static_cast<T>(0));
    }
    static segment_tree<T>product(size_type n)
    {
        return segment_tree<T>(n,std::multiplies<T>(),static_cast<T>(1));
    }
    static segment_tree<T>max(size_type n,T id=std::numeric_limits<T>::min())
    {
        return segment_tree<T>(n,static_cast<const T&(*)(const T&,const T&)>(std::max),id);
    }
    static segment_tree<T>min(size_type n,T id=std::numeric_limits<T>::max())
    {
        return segment_tree<T>(n,static_cast<const T&(*)(const T&,const T&)>(std::min),id);
    }
};

#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
int main()
{
    ll n=in(),q=in();
    auto st=segment_tree<ll>::sum(n);
    for(ll i=0;i<q;++i){
        ll c=in(),x=in()-1,y=in();
        if(c)cout<<st.query(x,y)<<endl;
        else st.update(x,st[x]+y);
    }
}



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

using namespace std;

int main(void) {
    int N;
    cin >> N;

    vector <string> redCards;
    for (int i = 0 ; i < N ; i++ ) {
        string temp;
        cin >> temp;
        redCards.push_back(temp);
    }

    int M;
    cin >> M;
    vector <string> blueCards;
    for (int i = 0 ; i < M ; i++ ) {
        string temp;
        cin >> temp;
        blueCards.push_back(temp);
    }

    int maxScore = 0;
    for (int baseIndex = 0 ; baseIndex < redCards.size() ; baseIndex++) {
        int score = 0;
        string baseWord = redCards[baseIndex];
        for (int radCardIndex = 0 ; radCardIndex < redCards.size() ; radCardIndex++) {
            if (baseWord == redCards[radCardIndex]) {
                score += 1;
            }
        }
        for (int blueCardIndex = 0 ; blueCardIndex < blueCards.size(); blueCardIndex++) {
            if (baseWord == blueCards[blueCardIndex]) {
                score += -1;
            }
        }
        if (score > maxScore) {
            maxScore = score;
        }
    }

    cout << maxScore;

    return 0;
}

Measured memory_bytes: 384
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int k,a,b;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>k>>a>>b;
	rep(i,a,b) if(i%k==0){
		puts("OK");
		return 0;
	}
	puts("NG");
	return 0;
}

Measured memory_bytes: 3620
# coding: utf-8
import sys
from fractions import gcd
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7

N = ir()
A = lr()
lcm = 1
for a in A:
    lcm *= a // gcd(lcm, a)

A = np.array(A)
answer = (lcm // A).sum() % MOD
print(answer % MOD)
# np.int64とint型の違いに注意


Measured memory_bytes: 272092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){

   int n, m;
   cin >> n >> m;

   // vector cnt(要素数m, 0で初期化)
   // m種類の食べ物に関するカウンターを用意
   vector<int> cnt(m,0);

   for(int i=0; i < n; i++){
      int k;
      cin >> k;
      for(int j=0; j < k; j++){
         int a;
         cin >> a;
         a--;
         cnt[a]++;
      }
   }

   int ans = 0;
   for(int i=0; i < m; i++){
      if(cnt[i] == n){
         ans++;
      }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int INF=pow(10,9);

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> plus(1,0),minus(1,0);
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        if(x<0) minus.push_back(-x);
        else plus.push_back(x);
    }
    sort(minus.begin(), minus.end());
    int ans=INF;
    for (int i=0; i<=k; i++){
        if(i<plus.size() && k-i<minus.size()){
            int t;
            t =  plus.at(i)+minus.at(k-i) +min(plus.at(i), minus.at(k-i));
            ans=min(ans, t);
        }
    }
    cout << ans << endl;
}


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

using namespace std;

const int INF = 1 << 30;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
T prim(WeightedGraph< T > &g) {
  using Pi = pair< T, int >;

  T total = 0;
  vector< bool > used(g.size(), false);
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.emplace(0, 0);
  while(!que.empty()) {
    auto p = que.top();
    que.pop();
    if(used[p.second]) continue;
    used[p.second] = true;
    total += p.first;
    for(auto &e : g[p.second]) {
      que.emplace(e.cost, e.to);
    }
  }
  return total;
}

int main() {
  int V, E;
  scanf("%d %d", &V, &E);
  WeightedGraph< int > g(V);
  for(int i = 0; i < E; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }
  printf("%d\n", prim(g));
}


Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define MAX_N 100000
using namespace std;
#define int long long
int dat[MAX_N*3],lazy[MAX_N*3];

class LazySegmentTree{
public:
    int n;
    LazySegmentTree(vector<int> v){
        n=1;
        while(n<v.size())n*=2;
        for(int i=0;i<v.size();++i)dat[i+n-1] = v[i];
        for(int i=0;i<2*n-1;++i)lazy[i] = 0;
        for(int i=n-2;i>=0;--i)dat[i] = dat[2*i+1]+dat[2*i+2];
    }

    void eval(int k,int l,int r){
        if(lazy[k]!=0){
            dat[k]+=lazy[k];
            if(r - l > 1){
                lazy[2*k+1] += lazy[k]/2;
                lazy[2*k+2] += lazy[k]/2;
            }
        }
        lazy[k] = 0;
    }

    void add(int a,int b,int x,int k,int l,int r){
        eval(k,l,r);
        if(b<=l || r<=a)return ;
        if(a<=l && r<=b){
            lazy[k] += (r-l)*x;
            eval(k,l,r);
        }
        else {
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            dat[k] = dat[2*k+1]+dat[2*k+2];
        }
    }

    int query(int a,int b,int k,int l,int r){
        eval(k,l,r);
        if(b<=l || r<=a)return 0;
        if(a<=l && r<=b)return dat[k];
        int vl = query(a,b,2*k+1,l,(l+r)/2);
        int vr = query(a,b,2*k+2,(l+r)/2,r);
        return vl + vr;
    }

};

int N,Q;

signed main(){
    cin>>N>>Q;
    vector<int> v;
    v.resize(N,0);
    LazySegmentTree seg(v);
    for(int i=0;i<Q;++i){
        int q,s,t;
        cin>>q>>s>>t;
        if(!q){
            int x;
            cin>>x;
            seg.add(s-1,t,x,0,0,seg.n);
        }
        else {
            cout<<seg.query(s-1,t,0,0,seg.n)<<endl;
        }
    }
}

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

using int64 = long long;
using uint64 = unsigned long long;

#define repeat(i, x) for (int64 i = 0; (i) < (x); (i)++)
#define rev_repeat(i, x) for (int64 i = (x) - 1; (i) >= 0; (i)--)
#define countup(i, n) for (int64 i = 0; (i) <= (n); (i)++)
#define countdown(i, n) for (int64 i = (n); (i) >= 0; (i)--)
#define range(i, a, b) for (int64 i = (a); (i) < (b); (i)++)
#define traverse(it, ctn) for (auto it = begin(ctn); (it) != end(ctn); (it)++)
#define rev_traverse(it, ctn) for (auto it = rbegin(ctn); (it) != rend(ctn); (it)++)

template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec)
{
    os << "[";
    repeat (i, vec.size())
    {
        os << (i == 0 ? "" : ", ") << vec[i];
    }
    os << "]";
    return os;
}

template<typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T>& s)
{
    os << "{";
    traverse (it, s)
    {
        if (it != s.begin()) os << ", ";
        os << *it;
    }
    os << "}";
    return os;
}

template<typename K, typename V>
ostream& operator<<(ostream& os, map<K, V>& m) 
{
    os << "{";
    traverse (it, m)
    {
        if (it != m.begin()) os << ", ";
        os << it->first << ": " << it->second;
    }
    os << "}";
    return os;
}

//
// _______  _____  _______  _____  _______ _______ _____ _______ _____ _    _ _______ 
// |       |     | |  |  | |_____] |______    |      |      |      |    \  /  |______ 
// |_____  |_____| |  |  | |       |______    |    __|__    |    __|__   \/   |______ 
//
//  _____   ______  _____   ______  ______ _______ _______ _______ _____ __   _  ______   /
// |_____] |_____/ |     | |  ____ |_____/ |_____| |  |  | |  |  |   |   | \  | |  ____  / 
// |       |    \_ |_____| |_____| |    \_ |     | |  |  | |  |  | __|__ |  \_| |_____| .  
//

string encode(int64 N)
{
    if (N == 0) return "0";
    if (N == 1) return "1";

    int q = abs(N % (-2));
    return encode((N - q) / (-2)) + to_string(q);
}

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

    int64 N;
    cin >> N;

    cout << encode(N) << endl;

    return 0;
}

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

// cl /EHsc itp1_2_d.c
// Circle in a Rectangle
int main(int arc, char *argv[])
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	
	if (((x-r) >= 0 && (y-r) >= 0) && ((x+r) <= W && (y+r) <= H)) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int n, k;   cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    vector<ll> v(k+1, 0);
    v[0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = k-a[i]; j >= 0; j--){
            v[j+a[i]] += v[j];
        }
    }
    int ans = n;
    for(int i = 0; i < n; i++){
        vector<ll> cp = v;
        for(int j = a[i]; j <= k; j++)  cp[j] -= cp[j-a[i]];
        bool flag = false;
        for(int j = max(0, k-a[i]); j <= k-1; j++){
            if(cp[j])   flag = true;
        }
        if(flag)    ans--;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int ans;
  int a,b,c;
  
  cin>>a;
  
  a = a%1000;
  
  
  
  ans= 1000-a;
  
  if(a == 0) ans = 0;
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N; 
  cin >> N;

  vector<int> A(3*N);
  REP(i, 3*N) cin >> A[i];

  int sum = 0;
  priority_queue<int, vector<int>, greater<int>> q;
  REP(i, N){
    sum += A[i];
    q.push(A[i]);
  }

  vector<int> ans(3*N, -INF);
  ans[N-1] = sum;
  FOR(i, N, 2*N){
    sum += A[i];
    q.push(A[i]);
    sum -= q.top(); q.pop();
    ans[i] = sum;
  }

  sum = 0;
  priority_queue<int> q1;
  FOR(i, 2*N, 3*N){
    sum += A[i];
    q1.push(A[i]);
  }

  int MAX = ans[2*N-1]-sum;
  RFOR(i, N, 2*N){
    sum += A[i];
    q1.push(A[i]);
    sum -= q1.top(); q1.pop();
    chmax(MAX, ans[i-1]-sum);
  }

  cout << MAX << endl;

  return 0;
}

Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
long long int mat[101][100001];
int main(){
	#ifdef EVAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int N,W;
	cin>>N>>W;
	int val[N];
	int p[N];
	for(int i=0;i<N;i++){
		cin>>p[i]>>val[i];
	}
	for(int i=p[0];i<=W;i++){
		mat[0][i]=val[0];
	}
	for(int i=1;i<N;i++){
		for(int j=0;j<=W;j++){
			mat[i][j]=max(mat[i][j],mat[i-1][j]);
			if(j+p[i]<=W)mat[i][j+p[i]]=max(mat[i][j+p[i]],mat[i-1][j]+val[i]);
		}
	}
	cout<<mat[N-1][W];
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,M,L,Q;
    int A[114514],B[114514],C[114514];
    int s[114514],t[114514];
    cin >> N >> M >> L;
    REP(i,M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;B[i]--;
    }
    cin >> Q;
    REP(i,Q){
        cin >> s[i] >> t[i];
        s[i]--;t[i]--;
    }
    
    int d1[314][314];
    int d2[314][314];
    REP(i,304){
        REP(j,304){
            d1[i][j]=INF;
            d2[i][j]=INF;
        }
    }
    REP(i,304){
        d1[i][i]=0;
        d2[i][i]=0;
    }
    REP(i,M){
        d1[A[i]][B[i]]=C[i];
        d1[B[i]][A[i]]=C[i];
    }
    
    REP(k,N){
        REP(i,N){
            REP(j,N){
                d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]);
            }
        }
    }
    
    REP(i,N){
        REP(j,N){
            if(d1[i][j]<=L){
                //cout << i MM j << endl;
                d2[i][j]=min(d2[i][j],1ll);
            }
        }
    }
    
    
    REP(k,N){
        REP(i,N){
            REP(j,N){
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]);
            }
        }
    }
    
    REP(i,Q){
        int Ans=d2[s[i]][t[i]];
        if(Ans==INF){
            cout << -1 << endl;
        }else{
            cout << Ans-1 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 6400
// https://atcoder.jp/contests/aising2020/tasks/aising2020_b
#include<iostream>
#include<vector>
#include<string>

int main() {
	int N;
	std::cin >> N;
	std::vector<int> a(N);
	for (int i = 0; i < N; i++) {
		std::cin >> a.at(i);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if ((i + 1) % 2 == 1 && a.at(i) % 2 == 1) {
			// std::cout << "ますめ " << i + 1 << std::endl;
			// std::cout << "かず " << a.at(i) << std::endl;
			ans++;
		}
	}

	std::cout << ans << std::endl;
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

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

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long K, long long N, std::vector<long long> A) {
    int ans = (K - A[N - 1]) + A[0];
    rep(i, N - 1) {
        chmax(ans, A[i + 1] - A[i]);
    }
    cout << K - ans << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long K;
    scanf("%lld", &K);
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
string input;
int main()
{
	bool ans=false;
	cin>>input;
	for(int i=0;i<input.length()-1;i++)
	{
		if(input[i]=='A'&&input[i+1]=='C')
			ans=true;
	}
	cout<<((ans)?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll x, n; cin >> x >> n;
    if(n == 0){
        cout << x << endl;
        return 0;
    }
    vector<ll> p(n); cin >> p;
    sort(p.begin(), p.end());
    //for(auto i : p) cout << i << " "; cout << endl;
    ll ansu, ansd, ud, dd;
    for(ll i = x; i <= 200; ++i){
        bool z = true;
        for(auto j : p){
            if(i == j){
                z = false;
                break;
            }
        }
        if(z){
            ansu = i;
            ud = abs(x-i);
            break;
        }
    }
    for(ll i = x; i >= -100; --i){
        bool z = true;
        for(auto j : p){
            if(i == j){
                z = false;
                break;
            }
        }
        if(z){
            ansd = i;
            dd = abs(x-i);
            break;
        }
    }
    ll ans = 0;
    if(dd <= ud) ans = ansd;
    else ans = ansu;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628