akhauriyash/Code-Regression huggingface dataset:
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define pb emplace_back
#define mp make_pair
#define eps 1e-8
#define lson (curpos<<1)
#define rson (curpos<<1|1)
/* namespace */
using namespace std;
/* header end */

const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
ll fac[maxn + 1], inv[maxn + 1], dp[maxn + 1], n, k;

ll qp(ll x, ll y = mod - 2) {
    ll ret = 1;
    for (; y; y >>= 1, x = x * x % mod)
        if (y & 1) ret = ret * x % mod;
    return ret;
}

ll C(int x, int y) {
    return fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int main() {
    fac[0] = fac[1] = 1;
    for (int i = 1; i <= maxn; i++) fac[i] = fac[i - 1] * i % mod;
    inv[maxn] = qp(fac[maxn]);
    for (int i = maxn - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
    cin >> n >> k;
    k = min(n - 1, k);
    ll ans = 1;
    for (int i = 1; i <= n; i++) dp[i] = C(n - 1, i - 1);
    for (int i = 1; i <= k; i++) ans = (C(n, i) * dp[n - i] % mod + ans) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
import java.util.*;
public class Main{
	static long y=1;
	static long l=1;
	static Scanner cs=new Scanner(System.in);
	public static void main(String args[]){
		while(true){
			int n=cs.nextInt();
			if (n==0)break;
			long x=cs.nextLong();
			y=cs.nextLong();
			l=1;
			for(int i=0;i<n;i++){
				l=l*2;
			}
			x=l-x+1;
			System.out.println(solve(l,x));
			}
	}
	static String solve(long h,long x){
		String res="";
		if (h==1)return("");
		if (x<=h/2) {
			res=solve(h/2,x);
			if (y<=l/2){
				res=res+"R";
				l=l/2;
			}
			else {
				res=res+"L";
				y=y-l/2;
				l=l/2;
			}
		}else{
			res=solve(h/2,h-x+1);
			if (y<=l/2){
				res=res+"L";
				y=l/2-y+1;
				l=l/2;
			}
			else {
				res=res+"R";
				y=l-y+1;
				l=l/2;
			}
		}
		return(res);
	}
}


Measured memory_bytes: 28384
#include <stdio.h>
int main(void){
    // Your code here!
    int N;
    scanf("%d",&N);
    
  	int ct,tmp;
  	tmp = N%100;
  	ct = (N-tmp)/100;
  	//printf("%d %d\n",ct,tmp);
  	if(ct>=20)	printf("1\n");
  	else if(ct*5>=tmp)	printf("1\n");
  	else				printf("0\n");
    
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    if (n < 0)return 0;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

ll merge_cnt(vector<ll>& a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin() + n / 2);
    vector<ll> c(a.begin() + n / 2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
            a[ai++] = b[bi++];
        }
        else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll m = s.size();
    vector<ll> z(n+1);
    z[0] = 1;
    for (int i = 0; i < n; i++) {
        vector<ll> x(n + 1);
        for (int i = 0; i < n; i++) {
            x[i + 1] += z[i]*2;
            x[max(i - 1, 0)] += z[i];
        }
        for (int i = 0; i < n+1; i++) {
            x[i] %= 1000000007;
        }
        z = x;
    }
    cout << z[m] * modinv(modpow(2, m, 1000000007), 1000000007) % 1000000007 << endl;
}

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

using int64 = long long;

const int64 mod = 998244353LL;

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

    vector<int> x(N), y(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    static int64 pat[210];
    pat[0] = 1;
    for (int i = 0; i < N; i++) (pat[i + 1] = 2 * pat[i]) %= mod;
    int64 ans = (pat[N] + mod - N - 1 - N * (N - 1) / 2) % mod;
    // 3頂点以上
    static bool used[210][210];
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (used[i][j]) continue;
            vector<int> vec = {i, j};
            for (int k = 0; k < N; k++) {
                if (k == i or k == j) continue;
                if ((y[i] - y[j]) * (x[k] - x[j]) == (y[k] - y[j]) * (x[i] - x[j])) {
                    vec.emplace_back(k);
                }
            }
            for (int k = 0; k < vec.size(); k++) {
                for (int l = k + 1; l < vec.size(); l++) {
                    used[vec[k]][vec[l]] = used[vec[l]][vec[k]] = true;
                }
            }
            int64 num = vec.size();
            if (num < 3) continue;
            ans = (ans - pat[num] + num + 1 + num * (num - 1) / 2 + mod * mod) % mod;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String li[] = S.split("");
    int count = 0;
    
    for(int i=0;i<li.length;i++){
      if(i%2==0){
        if (li[i].equals("R") || li[i].equals("U") || li[i].equals("D")){
        }else{
          count++;
          break;
        }
      }else{
        if(li[i].equals("L") || li[i].equals("U") || li[i].equals("D")){
        }else{
          count++;
          break;
        }
      }
    }
    if(count == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}      

Measured memory_bytes: 22996
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+5;
const int M = 555;

int n;
int a[N];

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    long long sum = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            sum += a[i] * a[j];
        }
    }
    cout << sum << endl;
}


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

int main() {
  map<char, ll> counts;
  int N;
  cin >> N;

  rep (i, N) {
    string s;
    cin >> s;
    if (counts.count(s[0])) {
      counts[s[0]] += 1;
    } else {
      counts[s[0]] = 1;
    }
  }

  ll ans = 0;
  rep (i, 5) {
    rep2 (j, i + 1, 5) {
      rep2 (k, j + 1, 5) {
        char c1 = "MARCH"[i];
        char c2 = "MARCH"[j];
        char c3 = "MARCH"[k];
        if (counts.count(c1) && counts[c1] &&
            counts.count(c2) && counts[c2] &&
            counts.count(c3) && counts[c3]) {
          ans += counts[c1] * counts[c2] * counts[c3];
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())

b=list(map(int,input().split()))

a=[0]*(n)

for i in range(n-1):
  if i==0:
    a[i]=b[i]
    a[i+1]=b[i]
  else:
    a[i]=min(a[i],b[i])
    a[i+1]=b[i]

print(sum(a))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while(b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if(u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}

	bool operator==(ModInt that) const { return x == that.x; }
	bool operator!=(ModInt that) const { return x != that.x; }
	ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1;
	while(k) {
		if(k & 1) r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}
typedef ModInt<mod> mint;

int n,m,_,x,y,q;
string s,sb;
bool ok;
map<int,int> p;

void dic(int n){
    for (int i = 2; i*i <= n; i++){
        if(!(n%i)){p[i]++; dic(n/i); return;}
    }
    if(n!=1)p[n]++;
    return;
}

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

  cin>>n; map<int,int> fac;
  rer(i,2,n+1){
    dic(i);
  }
  mint ans=1;
  for(auto e:p)ans*=(e.second+1);
  pri1(ans.get());
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

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

static int mod = 1000000007;
static int large = 1000000000;

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


int N, K;
int h[100000];

int dp[1000000];

int main() {
	cin >> N >> K;
	rep(i, N) {
		cin >> h[i];
		dp[i] = large;
	}
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int k = 1; k <= K; k++) {
			if (k + i <= N - 1) {
				dp[i + k] = min(dp[i + k], dp[i] + abs(h[k + i] - h[i]));
			}
		}
	}
	cout << dp[N - 1] << endl;
	return 0;
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int dp[1010][20010] = {};
// dp[i+1][j] i番目までの魔法で、与えたダメージjの時の使った魔力の最小値

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }

    for (int i = 0; i < 1010; ++i) {
        for (int j = 0; j < 20010; ++j) {
            if(j == 0) dp[i][j] = 0;
            else dp[i][j] = INF;
        }
    }


    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 20010; ++j) {
            if(j < a[i]) dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            else dp[i+1][j] = min(dp[i+1][j], min(dp[i][j], dp[i+1][j - a[i]] + b[i]));
        }
    }

    int res = INF;
    for (int i = h; i < 20010; ++i) {
        res = min(res, dp[n][i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 79232
def readinput():
    n=int(input())
    x=input()
    return n,x

poptbl=[0]*(2*10**5+1)
def popcount(x):
    global poptbl
    if poptbl[x]!=0:
        return poptbl[x]
    
    poptbl[x]=bin(x).count('1')
    return poptbl[x]

ftbl=[0]*(2*10**5+1)
def f(x):
    global ftbl

    #if ftbl[x]!=0:
    #    return ftbl[x]
    
    #print('f(x), x: {}'.format(x))
    if x==0:
        return 0
    else:
        ans=f(x%popcount(x))+1
        #print(ans)
        ftbl[x]=ans
        return ans    

def main():
    n=int(input())
    x=input()
    m=x.count('1')
    #print('m: {}'.format(m))
    xint=int(x,2)
    #print('xint: {}'.format(xint))
    if m!=1:
        xmodm1=xint%(m-1)
    else:
        xmodm1=1
    xmodp1=xint%(m+1)
    pow2mod1=[0]*n
    pow2mod2=[0]*n
    pow2mod1[0]=1
    pow2mod2[0]=1
    for i in range(1,n):
        if m!=1:
            pow2mod1[i]=pow2mod1[i-1]*2 % (m-1)
        pow2mod2[i]=pow2mod2[i-1]*2 % (m+1)

    ans=[]
    #b=2**(n-1)
    for i in range(n):
        if x[i]=='1':
            if m==1:
                a=0
                ans.append(a)
            else:
                xx=( xmodm1 + (m-1) -pow2mod1[n-i-1] )%(m-1)
                #ans.append(f(xx)+1)
                a=f(xx)+1
                ans.append(a)
        else:
            xx=( xmodp1 + pow2mod2[n-i-1] )%(m+1)
            #ans.append(f(xx)+1)
            a=f(xx)+1
            ans.append(a)
        #b=b//2
        print(a)
    return ans

if __name__=='__main__':
    #n,x=readinput()
    ans=main()
    #for a in ans:
    #    print(a)



Measured memory_bytes: 29720
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

N = int(input())
dist = [[float("inf") if i != j else 0 for i in range(N)] for j in range(N)]

for i in range(N):
    dist[i] = list(map(int, input().split()))

ans = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                print(-1)
                exit()

for i in range(N):
    for j in range(i + 1, N):
        for k in range(N):
            if k == i or k == j:
                continue
            if dist[i][j] == dist[i][k] + dist[k][j]:
                break
        else:
            ans += dist[i][j]
print(ans)

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var result = 1000000000;
            for (var i=1; i<=N/2; i++)
            {
                var a = i;
                var b = N - i;
                var digitsSumA = a.ToString().ToCharArray().Select(x => int.Parse(Convert.ToString(x))).Sum();
                var digitsSumB = b.ToString().ToCharArray().Select(x => int.Parse(Convert.ToString(x))).Sum();

                if (digitsSumA + digitsSumB < result) result = digitsSumA + digitsSumB;
            }

            Console.WriteLine(result);
        }
    }

}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

string N;
ll dfs(int depth,int three,int five,int seven,bool exact,bool delay){
	if(depth==N.size()){
		if(three && five && seven){
			return 1LL;
		}
		return 0;
	}

	ll V=0;
	if(!exact || N[depth]>='7'){
		V += dfs(depth+1,three,five,1,(N[depth]=='7') && exact,false);
	}
	if(!exact || N[depth]>='5'){
		V += dfs(depth+1,three,1,seven,(N[depth]=='5') && exact,false);
	}
	if(!exact || N[depth]>='3'){
		V += dfs(depth+1,1,five,seven,(N[depth]=='3') && exact,false);
	}
	if(delay){
		V += dfs(depth+1,three,five,seven,false,true);
	}
	return V;
}

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

	N=in<string>();
	
	out(dfs(0,0,0,0,true,true));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int getday(int, int, int);

int main(void)
{
  int y1, m1, d1, y2, m2, d2;
  int day1, day2;
  int year;
  
  while(1) {
    cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
    if(y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0) break;
    day1 = getday(y1, m1, d1);
    day2 = getday(y2, m2, d2);
    
    cout << day2 - day1 << endl;
  }
  return 0;
}

int getday(int y, int m, int d)
{
  int day = 0,u;

  u = (y % 4 == 0 && y % 100 != 0 || y % 400 == 0);

  for(int i = 1 ; i < y ; i++) {
    day += 365;
    if(i % 4 == 0 && i % 100 != 0 || i % 400 == 0) day += 1;
      }

  for(int i = 1 ; i < m ; i++) {
    day += 30;
    if(i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) day++;
    if(i == 2) { day -= 2; if(u) day++; }
  }
  for(int i = 0 ; i < d ; i++) {
    day++;
  }
  return day;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		// solver.solve();
	}
}

class Solver {
	int N;
	int K;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		K = Integer.parseInt(strArr[1]);
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		String[] strArr = str.split(" ");
		ArrayList<Integer> nums = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			int l = Integer.parseInt(strArr[i]);
			nums.add(l);
		}
		nums.sort(new Comparator<Integer>() {
			public int compare(Integer v1, Integer v2) {
				return v2 - v1;
			}
		});
		int sum = 0;
		int cnt = 0;
		for (int i : nums) {
			// System.out.println(i);
			sum += i;
			cnt++;
			if (cnt >= K)
				break;
		}
		System.out.println(sum);
	}

	public void solve() {

	}
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int mod2 = 998244353;

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
string a;
int dir[4];
int main() {
	cin >> a;
	for (int i = 0, n = a.size(); i < n; ++i) {
		if (a[i] == 'N') dir[0]++;
		else if (a[i] == 'S')dir[1]++;
		else if (a[i] == 'E')dir[2]++;
		else  if(a[i] == 'W') dir[3]++;
	}
	if ((dir[0] && dir[1] && (!(dir[2])) && (!(dir[3]))) || (!(dir[0]) && (!(dir[1])) && dir[2] && dir[3]) || dir[0] && dir[1] && dir[2] && dir[3]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
from fractions import gcd
def lcm(a,b):
    return a*b // gcd(a,b)

N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
l = 1
for a in A:
    l = lcm(l,a)
ans = 0
for a in A:
    ans += l//a
print(ans%M)


Measured memory_bytes: 6200
import java.util.Scanner;

public class Main {

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

        final double x = sc.nextDouble();

        for (int i = -128; i <= 128; i++) {
            for (int j = -128; j <= 128; j++) {
                if (x == (Math.pow(i, 5) - Math.pow(j, 5))) {
                    System.out.println(i + " " + j);
                    return;
                }
            }
        }
    }
}


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

int main() {
	int x = 0;
	int n;
	string s; cin >> n >> s;

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') x++;
		else x--;
		ans = max(ans, x);
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

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

#define int ll


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

	queue<ll> q;
	for(int i=1;i<=9;i++) q.push(i);
	int ans;
	for(int i=0;i<k;i++){
		ll t = q.front();
		if(i==k-1) ans = t;
		q.pop();
		if(t%10!=0) q.push(10*t+(t%10)-1);
		q.push(10*t+(t%10));
		if(t%10!=9) q.push(10*t+(t%10)+1);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main(){
	 int a,b;
	 char op;
	 while (cin>>a>>op>>b){
	if(op=='+' && op!='?'){
		cout<<a+b<<endl;
	}else if(op=='-' && op!='?'){
		cout<<a-b<<endl;
	}else if(op=='*' && op!='?'){
		cout<<a*b<<endl;
	}else if(op=='/' && '?'){
		cout<<a/b<<endl;
}
}
}



Measured memory_bytes: 3096
N, W = map(int, input().split())
WEIGHTS = list(list(map(int, input().split())) for _ in range(N))
M = len(WEIGHTS)

DP = [[0 for _ in range(W + 1)] for _ in range(M + 1)]

for i, (weight, value) in enumerate(WEIGHTS):
    for w in range(W + 1):
        if w - weight >= 0:
            DP[i+1][w] = max(DP[i][w - weight] + value, DP[i][w])
        else:
            DP[i+1][w] = DP[i][w]

print(DP[M][W])

# dp_ij := 1~jまでのアイテムからいくつかを選んで総重量iを超えないようにしたときの最大価値

# 0 1 2 3  4  5  6  7  8
# 0 0 0 0  0  0  0  0  0
# 0 0 0 30 30 30 30 30 30
# 0 0 0 30 50 50 50 80 80
# 0 0 0 30 50 60 60 80 90


Measured memory_bytes: 171656
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        s: String,
        t: String
    }

    let s_vec: Vec<char> = s.as_str().chars().collect();
    let t_vec: Vec<char> = t.as_str().chars().collect();
    let mut count = 0;

    for i in 0 .. s.len() {
        if s_vec[i] != t_vec[i] {
            count += 1;
        }
    }

    println!("{}", count);
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int C[6]={1,5,10,50,100,500};
int P;
int N[6];

const int T=10000;
int dp[2][T];

int calc(int v){
    int ans=0;
    for(int i=5;i>=0;i--){
        ans+=v/C[i];
        v%=C[i];
    }
    return ans;
}

signed main(){
    while(cin>>P){
        rep(i,6)cin>>N[i];
        if(P==0)break;
        fill_n(*dp,2*T,1001001001);
        int cnt=0;

        for(int i=5;i>=0;i--){
            while(P-C[i]>=2500&&N[i]){
                cnt++;
                N[i]--;
                P-=C[i];
            }
            if(N[i])break;
        }

        dp[0][0]=0;
        rep(i,6){
            rep(j,C[i]){
                deque<pint>deq;
                for(int k=j;k<T;k+=C[i]){
                    int w=T-k/C[i];
                    chmin(dp[(i+1)&1][k],dp[i&1][k]);
                    while(deq.size()&&deq.front().se+C[i]*N[i]<k)deq.pop_front();
                    if(deq.size())chmin(dp[(i+1)&1][k],deq.front().fi-w);
                    if(deq.size()&&deq.front().se+N[i]*C[i]<=k)deq.pop_front();
                    deq.pb(pint(dp[i&1][k]+w,k));
                }
            }
        }
        int mi=1001001001;
        for(int i=P;i<T;i++){
            chmin(mi,dp[0][i]+calc(i-P));
        }
        cout<<mi+cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1396
#include <bits/stdc++.h>
using namespace std;
int main(){
   double  a,b;
   cin >> a >> b;
   double d = (a+b)/2;
   if(d == (int)(a+b)/2){
      cout << (int)(a+b)/2;
   }else {
      cout << (int)(a+b)/2+1;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   int a[4];
   for(int i=0;i<4;i++){
      cin>>a[i];
   }
   sort(a,a+4);
   if(a[0]==1 and a[1]==4 and a[2]==7 and a[3]==9){
      cout<<"YES"<<endl;
   }else{
      cout<<"NO"<<endl;
   }
   return 0;   
}

Measured memory_bytes: 256
#include<stdio.h>
#define INFTY (1<<21)
#define MAX 100
int min(int x, int y){
	if(x<y) return x;
	else return y;
} 

void floyd(int m, int C[MAX][MAX], int T[MAX][MAX]){
int i,j,k;
 for(k = 0;k<m;k++)
 for(i = 0;i<m;i++)
	for(j = 0;j<m;j++){
		C[i][j] = min( C[i][j], C[i][k] + C[k][j] );
		T[i][j] = min( T[i][j], T[i][k] + T[k][j] );
	}
}
int main(void){
 int n, m, a, b, c, t, i,j,k, q, C[MAX][MAX], T[MAX][MAX];
 do{
	scanf("%d %d",&n,&m);
	if(n==0&&m==0)
	break;
	for(i = 0;i<m;i++)
 	for(j = 0;j<m;j++){
			 C[i][j] = T[i][j] = INFTY;
	}
	for(i = 0;i<n;i++){
 			scanf("%d %d %d %d",&a,&b,&c,&t);
			C[a-1][b-1] = C[b-1][a-1] = c; T[a-1][b-1] = T[b-1][a-1] = t;
	}
	floyd(m, C, T);
	scanf("%d",&k);
	for(i = 0;i<k;i++){
 			scanf("%d %d %d",&a,&b,&q);
			if (q){
			 printf("%d\n",T[a-1][b-1]);
			}else{
			 printf("%d\n",C[a-1][b-1]);
			 }
 	}
 }while(1);
 return 0;
}

Measured memory_bytes: 676
N, Y = map(int, input().split())

for i in range(N+1):
  y1 = 10000 * i
  for j in range(N+1-i):
    y2 = 5000 * j
    if y1 + y2 > Y:
      break
    
    k = (Y - y1 - y2) // 1000
    if i + j + k == N:
      print(i, j, k)
      quit()

print(-1, -1, -1)

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char str[1005];
int main(){
        while(cin>>str){
                int k=0;
                if(str[strlen(str)-1]=='s'){
                        str[strlen(str)]='e';
                        k=1;
                }
                else{
                        str[strlen(str)]='s';
                }
                for(int i=0;i<strlen(str);i++){
                        cout<<str[i];
                }
        if(k==1)cout<<'s';
                cout<<endl;
        }
}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n;cin>>n;
  if(n<2){cout<<0<<endl;return 0;}
  ll ans=1;
  rep(i,n){
    ans*=10;
    ans%=mod;
  }
  ll x9=1;
  rep(j,n){
    x9*=9;x9%=mod;
  }x9*=2;
  ll x8=1;
  rep(k,n){
    x8*=8;x8%=mod;
  }ans=ans-x9+x8;
  ans+=2*mod;
  ans%=mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n,a[20],tot=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        a[i]=i;
        tot*=i;
    }
    for(int i=0;i<tot;i++){
        printf("%d",a[1]);
        for(int j=2;j<=n;j++)printf(" %d",a[j]);
        printf("\n");
        next_permutation(a+1,a+n+1);
    }
}


Measured memory_bytes: 2712
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		  Scanner sc = new Scanner(System.in);
		  int X = sc.nextInt();
		  sc.close();
		  
		  if(X == 1) {
			  System.out.println("1");
		      System.exit(0);
		  }
		  
		  int answer = 1;
		  
		  for(int base = 2; base <= Math.sqrt(X); base++) {
			  int i = 2;
			  while(Math.pow(base, i) <= X) {
				  answer = Math.max(answer, (int)Math.pow(base, i));
				  i++;
			  }
		  }
		 
		  System.out.println(answer);
	      System.exit(0);
	    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    vs d{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    rep(i, 7) {
        if (d[i] == s) {
            cout << 7-i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

day = 0
for i in range(N):
    if i < day:
        continue
    for j in range(i+1, N):
        if stock == 0:
            if A[i] < A[j]:
                stock += money // A[i]
                money -= stock * A[i]
                break
            else:
                break
        else:
            if A[j-1] > A[j]:
                money += stock * A[j-1]
                stock = 0
                day = j
                break
if stock > 0:
    money += stock * A[-1]
    stock = 0

print(money)





Measured memory_bytes: 9136
S=input()
K=int(input())
S1=""
if K==1:
	print(int(S[0:1]))
elif K>100:
	print(S.replace("1","")[0:1])
else:
	for i in range(K):
		S1=S1+"1"
	if S[0:K]==S1:
		print(1)
	else:
		print(S.replace("1","")[0:1])

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; 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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int N;
int p[20];

int main()
{
    cin >> N;
    int maxP = 0;
    int sum = 0;
    rep(i, 0, N)
    {
        cin >> p[i];
        sum += p[i];
        chmax(maxP, p[i]);
    }
    cout << sum - maxP / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX (ll)(5e3 + 4)
#define MOD (ll)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false), cin.tie (nullptr);

using namespace std;
using ll = long long;
using ld = long double;

int main () {
	int k, x;
	cin >> k >> x;
	if (k * 500 >= x) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}


Measured memory_bytes: 256
N,M = [ int(it) for it in input().split() ]
li = [ [i,[ int(it) for it in input().split() ]] for i in range(M) ]
li = [ (it[0],it[1][0],it[1][1]) for it in li]

sor = [ [] for i in range(N+1) ]
for i,p,y in li:
  sor[p].append((i,y))
[ it.sort(key = lambda x:x[1]) for it in sor]

coo = [0]*M
for so in sor:
  for j in range(len(so)):
    i,y = so[j]
    coo[i] = j+1
for i in range(M):
  print ( "{0:06d}{1:06d}".format(li[i][1], coo[i]) ) 
  

Measured memory_bytes: 45572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main() {
    int h, w; cin >> h >> w;
    char c[h][w], ans[2*h][w];
    rep(i,h) rep(j,w) cin >> c[i][j];

    rep(i,h){
        rep(j,w){
            ans[i*2][j] = c[i][j];
            ans[i*2+1][j] = c[i][j];
        }
    }
    rep(i,2*h) {
        rep(j,w){
            cout << ans[i][j];
        }cout << endl;
    }
}


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

//繰り返し自乗法(modなし)
int mypow(int x, int n){
  if(n == 0)
    return 1;
 
  if(n % 2 == 0)
    return mypow(x * x, n / 2);
  else
    return x * mypow(x, n - 1);
}

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0;
  double coin = 0.5;
  for (int i = 1; i <= n; i++){
    double per = (double)1 / (double)n;
    int v = i;
    int c = 0;
    while(v < k){
      v *= 2;
      c++;
    }
    ans += per * (double)pow(coin, c);
  }
  cout << fixed << setprecision(12) << ans << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int x, t;
	cin >> x >> t;

	cout << (x - t <= 0 ? 0 : x - t) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <functional>
#include <cstdint>
#include <cstdio>

#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

using namespace std;

typedef int64_t ll;

const int INF = 1e9 + 10;

int n;
stack<int> s;
vector<int> a;

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

  cin >> n;
  a.resize(n);

  int c = 0;

  /*
  for (int i = 0; i < 2 * n; i++) {
    string str; int idx;
    cin >> str;
    if (str[0] == 'a') {
      cin >> idx;
      s.push(idx);
    } else {
      a[c++] = s.top();
      s.pop();
    }
  }*/
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<int> dp(n, INF);
  for (int i = 0; i < n; i++) {
    *lower_bound(dp.begin(), dp.begin() + n, a[i]) = a[i];
  }

  cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
  //cout << n - (lower_bound(dp.begin(), dp.end(), INF) - dp.begin()) << endl;

  return 0;
}

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

int selectionSort(int target[], int count) {
  int total = 0;
  for (int i = 0; i < count; i++) {
    int minj = i;
    for (int j = i; j < count; j++) {
      if (target[j] < target[minj]) {
        minj = j;
      }
    }
    if (i != minj) {
      total++;
      swap(target[i], target[minj]);
    }
  }
  return total;
};

int main() {
  int count;
  cin >> count;
  int result[count];
  for (size_t i = 0; i < count; i++) {
    cin >> result[i];
  }

  int total = selectionSort(result, count);
  for (size_t i = 0; i < count; i++) {
    cout << result[i];
    if (i == count - 1) cout << endl;
    if (i != count - 1) cout << " ";
  }
  cout << total << endl;
  return 0;
}


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

const int MAX_n = 1e5 + 5;
int n,mingcd;
int num[MAX_n];
int gcd_b[MAX_n];
int gcd_a[MAX_n];

int main()
{
	scanf("%d",&n);
	for ( int i = 0 ; i < n ; i++ )
		scanf("%d",&num[i]);
	gcd_b[0] = num[0];
	for ( int i = 0+1 ; i <= n-1 ; i++ )
		gcd_b[i] = __gcd(gcd_b[i-1],num[i]);
	gcd_a[n-1] = num[n-1];
	for ( int i = n-1-1 ; i >= 0 ; i-- )
		gcd_a[i] = __gcd(gcd_a[i+1],num[i]);
	mingcd = gcd_a[0+1];
	for ( int i = 0+1 ; i <= n-1-1 ; i++ )
		mingcd = max(mingcd,__gcd(gcd_b[i-1],gcd_a[i+1]));
	mingcd = max(mingcd,gcd_b[n-1-1]);
	printf("%d",mingcd);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,0,n-1) cin>>a[i];
    double ans=0.0;
    rep(i,0,n-1){
        ans += 1.0/a[i];
    }
    ans = 1.0/ans;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int solve(char s[], long long k) {
    for (int i = 0; i < k && s[i] != 0; i++) {
        if (s[i] != '1')
            return s[i] - '0';
    }
    return 1;
}


int main() {
    char s[101];
    long long k;
    scanf("%s", s);
    scanf("%lld", &k);
    printf("%d\n", solve(s, k));
    return 0;
}


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

using namespace std;

int main(){
 long a,b,c; 
  cin >> a >> b >> c;
 
  if(a%2||b%2||c%2) {cout << 0 << endl;
                     return 0;
                    }
   
  if(a==b&&b==c) { cout << -1 << endl;
                   return 0;
                 }          
  long res=0;
  long cnt=0;
  
  while(1){
    res++;
    long tmp=a,tmp2=b;
    a=(b+c)/2;
    b=(tmp+c)/2;
    c=(tmp+tmp2)/2;
    if(a%2||b%2||c%2) break;
  }
  
  cout << res << endl;
  
}

Measured memory_bytes: 256
import heapq


X,Y,A,B,C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))


rg = [(p, "r") for p in P] + [(q, "g") for q in Q]
rg.sort()
nc = R
nc.sort()

ans = 0
cnt_r, cnt_g, cnt_nc = 0, 0, 0


while cnt_r + cnt_g + cnt_nc < X + Y:

    if cnt_r == X:
        while rg[-1][1] == "r":
            rg.pop()

    if cnt_g == Y:
        while rg[-1][1] == "g":
            rg.pop()


    if len(nc) > 0 and nc[-1] > rg [-1][0]:
        tmp = nc.pop()
        cnt_nc += 1
    else:
        tmp, c = rg.pop()
        if c == "r":
            cnt_r += 1

        else:
            cnt_g += 1


    ans += tmp

print(ans)

Measured memory_bytes: 31920
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll MOD = 1e9 + 7;
    ll n;
    cin >> n;
    vector<vector<ll>> a(n, vector<ll>(n, 0));
    rep(i, n) rep(j, n) cin >> a[i][j];

    vector<vector<ll>> dp(22, vector<ll>(1<<21, 0));
    dp[0][0] = 1;
    rep(i, n) rep(mask, 1<<n) if(i == __builtin_popcount(mask)) {
        rep(j, n) if (!(mask & (1<<j))) if (a[i][j] == 1) {
            dp[i+1][mask | (1<<j)] += dp[i][mask];
            dp[i+1][mask | (1<<j)] %= MOD;
        }
    }
    cout << dp[n][(1<<n)-1] << endl;
}

Measured memory_bytes: 377216
#include <iostream>
#include <string>
using namespace std;
int main() {
	int n;
	cin >>n;
	int m;
	cin >>m;
	int h[n];
	for (int i=0;i < n;i++) {
		cin >> h[i];
	}
	int t1, t2;
	int s[n]={0};
	int r[n]={0};
	for (int i=0;i< m;i++) {
		cin  >>t1>>t2;
		s[t1-1]++;
		s[t2-1]++;
		if (h[t1-1] > h[t2-1]) {
			r[t1-1]++;
		}else if (h[t1-1] < h[t2-1]){
			r[t2-1]++;
		}
	}
	int res=0;
	for (int i=0;i< n;i++) {
		if (r[i]== s[i]) {
			res++;
		}
	}
	cout << res;
}

Measured memory_bytes: 4808
#define VERNIY st();int ver=0,niy=0,hbk=0
#define HIBIKI int ver=0,niy=0,hbk=0
//#pragma GCC optimize("0fast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
typedef unsigned long long LLU;
typedef long long LL;
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
typedef vector<int> vd;
typedef vector<pair<int,int> > vpd;
typedef pair<int,int> pd;
typedef queue<int> qd;
typedef queue<pair<int,int> > qpd;
typedef priority_queue<int> maxpqd;
typedef priority_queue<int, vector<int>, greater<int> > minpqd;
#define fr front
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; ++a)
#define forineq(a,b,c) for(int a=b ; a<=c ; ++a)
#define forde(a,b,c) for(int a=b ; a>=c ; --a)
#define UPC(oo) (oo>='A' && oo<='Z')
#define LWC(oo) (oo>='a' && oo<='z')
#define DGT(oo) (oo>='0' && oo<='9')
#define UPCVOC(oo) (oo=='A' || oo=='E' || oo=='I' || oo=='U' || oo=='O')
#define LWCVOC(oo) (oo=='a' || oo=='e' || oo=='i' || oo=='u' || oo=='o')
#define filein(oo) freopen(oo,"r",stdin);
#define fileout(oo) freopen(oo,"w",stdout);
#define setarr(a,b,c) memset(a,b,sizeof(c))

template<class Ver>
inline void in(Ver &a){cin>>a;}
template<class Ver,class Niy>
inline void in(Ver &a, Niy &b){cin>>a>>b;}
template<class Ver,class Niy, class Hbk>
inline void in(Ver &a, Niy &b, Hbk &c){cin>>a>>b>>c;}

template<class Ver>
inline void out(Ver a){cout<<a<<"\n";};
template<class Ver,class Niy>
inline void out(Ver a,Niy b){cout<<a<<" "<<b<<"\n";};
template<class Ver,class Niy, class Hbk>
inline void out(Ver a, Niy b, Hbk c){cout<<a<<" "<<b<<" "<<c<<"\n";};

inline void debug(){cout<<"asd"<<endl;}
template<class Ver>
inline void debug(Ver a){cout<<"--- "<<a<<endl;};
template<class Ver,class Niy>
inline void debug(Ver a,Niy b){cout<<"--- "<<a<<" "<<b<<endl;};
template<class Ver,class Niy, class Hbk>
inline void debug(Ver a,Niy b,Hbk c){cout<<"--- "<<a<<" "<<b<<" "<<c<<endl;};

#define grav 9.8
#define pi 3.14159265

void st()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

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

int main()
{
	VERNIY;
/*
	HIBIKI;
	filein("in.txt");
	fileout("out.txt");
*/
	in(hbk);
	in(niy);
	int ans=niy;
	--hbk;
	forin(i,0,hbk)
	{
		in(ver);
		ans=min(ans,gcd(ver,ans));
	}
	out(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
template <class T>bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp
const ll mod=1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll ac=0;
    ll wa=0;
    ll tle=0;
    ll re=0;
    rep(i,n){
        string s;
        cin >> s;
        if(s=="AC") ac++;
        else if(s=="TLE") tle++;
        else if(s=="WA") wa++;
        else re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;
typedef long long ll;

int main()
{

    ll n;
    cin >> n;
    
    string s;
    cin >> s;

    for (int i = 0; i < s.length(); i++)
    {

        char a = ((s[i] - 'A') + n) % 26 + 'A';

        cout << a;
    }

    cout << endl;
    
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	
	ll n, a[100010], b[100010], ans = 0;
	
	cin >> n;
	for(int i = 0; i < n + 1; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	
	for(int i = 0; i < n; i++){
		if(b[i] > a[i]){
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		else{
			a[i] -= b[i];
			ans += b[i];
			b[i] = 0;
		}
		
		if(b[i] > a[i + 1]){
			ans += a[i + 1];
			b[i] -= a[i + 1];
			a[i + 1] = 0;
		}
		else{
			ans += b[i];
			a[i + 1] -= b[i];
			b[i] = 0;
		}
	}
	
	cout << ans << endl;
	
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define il inline
#define vd void
#define rg register
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
int n,m,a,b,ans;
vector <int> V[100005];
priority_queue <int> q;
int main(){
	n=rd(),m=rd();
	rep(i,1,n) a=rd(),b=rd(),V[a].push_back(b);
	drp(i,m-1,0){
		for(rg int j=0;j<(int)V[m-i].size();++j) q.push(V[m-i][j]);
		if(!q.empty()) ans+=q.top(),q.pop();
	}
	rt(ans);
	return flush(),0;
}
il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 9472