akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<unordered_set>
#include<stack>
#include<queue>
#include<unordered_map>
using namespace std;
typedef long long int ll;
#define EPS 1e-9
#define pb push_back
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
void DSUinit(vector<ll>&a,vector<ll>&size,ll n)
{
    FOR(i,0,n)
    {
        a[i]=i;
        size[i]=1;
    }
    return;
}
ll root(vector<ll>&a,ll i)
{
    return (i==a[i])?i:a[i]=root(a,a[i]);
}
bool DSUfind(vector<ll>a,ll x,ll y)
{
    if(root(a,x)==root(a,y))
    {
        return true;
    }
    return false;
}
void DSUunion(vector<ll>&a,vector<ll>&size, ll x,ll y)
{
    x=root(a,x);
    y=root(a,y);
    if(x==y)
    {
        return;
    }
    if(size[x]<size[y]) swap(x,y);
    a[y]=x;
    size[x]+=size[y];
}
void dfs(vector<vector<ll> >&graph,vector<bool>&visited,ll start)
{
    visited[start]=true;
    FOR(i,0,graph[start].size())
    {
        if(!(visited[graph[start][i]]))
        {
            dfs(graph,visited,graph[start][i]);
        }
    }
    return;
}
bool isPrime(int n) 
{
    if (n <= 1)  return false; 
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
          return false;
    return true; 
}
ll power(ll x,ll y,ll p)
{
    ll ans=1;
    x = x%p;
    if(x==0) return 0;
    while(y)
    {
        if(y&1) ans=(ans*x)%p;
        y>>=1;
        x=(x*x)%p;
    }
    return ans;
}

ll knapsack(vector<ll>&wt, vector<ll>&val, ll n, ll mw)
{
    vector<vector<ll> >dp(n,vector<ll>(mw+1,0));
    FOR(i,1,mw+1)
    {
        dp[0][i]=(i-wt[0]>=0)?val[0]:0;
    }
    FOR(i,1,n)
    {
        FOR(j,0,mw+1)
        {
            dp[i][j]=(j-wt[i]>=0)?max(val[i]+dp[i-1][j-wt[i]],dp[i-1][j]):dp[i-1][j];
        }
    }
    return dp[n-1][mw];

}
    
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, mw;
    cin>>n>>mw;
    vector<ll>wt(n,0);
    vector<ll>val(n,0);
    FOR(i,0,n)
    {
        cin>>wt[i]>>val[i];
    }
    cout<<knapsack(wt,val,n,mw);
    return 0;
}

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

vector<bool> check(50,false);
vector<vector<int>> graph(50);

void dfs(int ima,int a,int b){
    check[ima] = true;
    for(int x : graph[ima]){
        if(check[x] == false && !(ima == a && x == b) && !(x == a && ima == b)){
            dfs(x,a,b);
        }
    }
}

int main(){
    int n,m; cin >> n >> m;
    vector<P> vec;
    rep(i,m){
        int a,b; cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        vec.push_back(P(a,b));
    }
    int ans = 0;
    rep(i,m){
        int s = vec[i].first,g = vec[i].second;
        fill(ALL(check),false);
        dfs(s,s,g);
        if(check[g] == false) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

for i, d in enumerate(itertools.permutations(range(1, N+1), N)):
    if d == P:
        a = i
    if d == Q:
        b = i

print(abs(a-b))

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

int main(){
	int n,a;
	cin >> n >> a;
	
	if (n%500 > a){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}

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

signed main(){
	int n,a,b,c,d;
	cin>>n;
	a=(n-n%1000)/1000,b=(n%1000-n%100)/100,c=(n%100-n%10)/10,d=n%10;
	if(a+b+c+d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
		return 0;
	}
	if(a-b+c+d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
		return 0;
	}
	if(a-b-c+d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
		return 0;
	}
	if(a-b+c-d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
		return 0;
	}
	if(a+b-c+d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
		return 0;
	}
	if(a+b+c-d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
		return 0;
	}
	if(a+b-c-d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
		return 0;
	}
	if(a-b-c-d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

	int t,n,s,f,sum;

	while(1){
		cin>>t;
		if(t==0) break;
		cin>>n;
		sum=0;
		for(int i=0;i<n;i++){
			cin>>s>>f;
			if(f>s) sum+=f-s;
			else sum+=24-s+f;
		}
		if(t<=sum) cout<<"OK"<<endl;
		else cout<<t-sum<<endl;
	}

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pll = pair<ll, ll>;
using pss = pair<string, string>;
using pdd = pair<ld, ld>;
using graph = vector<vector<int>>;

const ll MOD = 1000000007;
const ld EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ex[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ey[8] = {0, 1, 1, 1, 0, -1, -1, -1};

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

ll intabs(ll a)
{
    if (a >= 0)
        return a;
    else
        return -a;
}

ll intpow(ll a, ll b, ll p = LLONG_MAX)
{
    ll ret = 1;
    while (b != 0)
    {
        if ((b & 1) == 1)
            ret *= a;
        a *= a;
        if (a >= p)
            a %= p;
        if (ret >= p)
            ret %= p;
        b = b >> 1;
    }
    return ret;
}

int digit(ll a, ll b = 10)
{
    int ret = 0;
    while (a != 0)
    {
        a /= b;
        ret++;
    }
    return ret;
}

ll gcd(ll x, ll y)
{
    while (y != 0)
    {
        ll cnt = x % y;
        x = y;
        y = cnt;
    }
    return x;
}

ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

class UnionFind
{
    vector<int> par, sz;

public:
    UnionFind(int n) : par(n), sz(n)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            sz[i] = 1;
        }
    }
    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
        sz[ry] += sz[rx];
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x)
    {
        return sz[root(x)];
    }
};

vector<bool> seen;
void dfs(const graph &g, int v)
{
    seen[v] = true;
    for (auto i : g[v])
    {
        if (seen[i])
            continue;
        dfs(g, i);
    }
}

int main()
{
    int i, j, k, cnt;
    int a, b;
    cin >> a >> b;
    if (a < b)
    {
        for (i = 0; i < b; i++)
            cout << a;
    }
    else
    {
        for (i = 0; i < a; i++)
            cout << b;
    }
    cout << endl;
}

Measured memory_bytes: 256
/*
    Code written by Talant I.D.
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9	
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353

inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
 
bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2) 
		if(n % i == 0) return false;
	return true;
}

int main(){
    do_not_disturb
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int a[2];
	cin >> a[0] >> a[1];
	sort(a, a+2);
	if(a[1] < 3)cout << 3;
	else if(a[0] > 1)cout << 1;
	else cout << 2;
	
    return 0;
} // What is to be written here?


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int n;
		int count=0;
		Scanner scan = new Scanner(System.in);
		n=scan.nextInt();
		for(int i=0;i<n;i++){
			if(PrimeNumber(scan.nextInt())){
				count++;
			}
		}
		scan.close();
		System.out.println(count);
	}
	public static Boolean PrimeNumber(int m){
		Boolean PN = true;
		for(int i=2;i*i<=m;i++){
			if(m%i==0){
				PN=false;
				break;
			}
		}
		return PN;
	}
}


Measured memory_bytes: 41532
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;


int main(){
    int N;
    ll T;
    cin >> N >> T;
    vector<ll> A(N + 1);
    A[0] = 0;
    for(int i = 1; i < N + 1; i++) cin >> A[i];

    ll sum = A.back() + T;
    for(int i = 0; i < N; i++){
        if(A[i] + T < A[i + 1]){
            sum -= (A[i + 1] - (A[i] + T));
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
fun readInt(): Int {
    val N: Int = readLine()!!.toInt()
    return N
}

fun readString(): String {
    val N: String = readLine()!!
    return N
}

fun getSeqList(): List<Int>{
    return (1..5).toList()
}

fun solveB_bk(): Long{
    val N: Int = readLine()!!.toInt()
    var An: Array<Int?> = arrayOfNulls(N)
    var ans: Long = 0
    for (i in An.indices) {
        val num: Int = (i + 1)
        if (num%3 == 0 || num%5 == 0 ){
            continue
        }
        ans += num
    }
    return ans
}

fun solveA(): String{
    val N: Int = readLine()!!.toInt()
    for (i1 in (1..9).toList()){
        for (i2 in (1..9).toList()){
            if (N == i1*i2){
                return "Yes"
            }
        }
    }
    return "No"
}

fun solveB(): String{
    val S: String = readLine()!!
    for (i in (0..(S.length-1)).toList()){
        val num: Int = i + 1
        val subS: String = S.substring(i,i+1)
        if (subS == "U" || subS == "D"){
            continue
        }
        if (num%2 == 1){
            if(subS == "R"){
                continue
            }
        } else {
            if(subS == "L"){
                continue
            }
        }
        return "No"
    }
    return "Yes"
}

fun main(args: Array<String>) {
    //Practice
    //println(getSeqList())
    // 20200421 A problem
    /*
    if (readString().contains('7')){
        println("Yes")
    } else {
        println("No")
    }
    */

    // 20200421 B problem
    //println(solveB_bk())

    // masui#4 A problem
    //println(solveA())

    // masui#4 B problem
    println(solveB())
}


Measured memory_bytes: 33688
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
class Solve {
private:
public:
    bool is_last_;
    Solve()
    {
        
        int h,w;
        int dx[4]={0,1,0,-1};
        int dy[4]={1,0,-1,0};
        cin >> w>>h;
        if (h == 0)
        {
            is_last_ = true;
            return;
        }
        vector<vector<int>> b=vector<vector<int>> (h+2,vector<int>(w+2,mod));
        queue<array<int,3>> q;
        FOR(i,0,h){
            string s;
            cin>>s;
            FOR(j,0,w){
                if(s[j]=='.'){
                    b[i+1][j+1]=0;
                }else if(s[j]=='B'){
                    q.push({i+1,j+1,1});
                }else if(s[j]=='W'){
                    q.push({i+1,j+1,2});
                }   
            }
        }
        //cerr<<"test"<<endl;
        while(q.size()){
            auto tpl=q.front();
            q.pop();
            FOR(d,0,4){
                int ni=tpl[0]+dx[d];
                int nj=tpl[1]+dy[d];
                int c=tpl[2];
                if(b[ni][nj]>5)continue;
                if(b[ni][nj]&c)continue;
                b[ni][nj]|=c;
                q.push({ni,nj,c});
            }
        }
        vector<int> v(3,0);
        FOR(i,1,h+1){
            FOR(j,1,w+1){
                if(b[i][j]==1)v[1]++;
                if(b[i][j]==2)v[2]++;
            }
        }
        cout<<v[1]<<" "<<v[2]<<endl;
    }
};

int main()
{
    while (!Solve().is_last_);
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
using namespace std;
const int maxn = 200100;
ll moves[30], n, q;
string code;

char l[maxn], d[maxn];
bool checkleft(int x) {
    for(int i=0;i<q;i++) {
        if(x == 0) return true;
        if(l[i] == code[x-1]) {
            if(d[i] == 'R') x++;
            else x--;
        }
    }

    if(x == 0) return true;
    else return false;
}

bool checkright(int x) {
    for(int i=0;i<q;i++) {
        if(x == n+1) return true;
        if(l[i] == code[x-1]) {
            if(d[i] == 'R') x++;
            else x--;
        }
    }

    if(x == n+1) return true;
    else return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>q;
    cin>>code;

    for(int i=0;i<q;i++) {
        cin>>l[i]>>d[i];
    }

    int l_most = 0;
    for(int cekor=n/2;cekor>0;cekor/=2) {
        while(l_most + cekor <= n && checkleft(l_most+cekor)) l_most += cekor;
    }

    int r_most = n+1;
    for(int cekor=n/2;cekor>0;cekor/=2) {
        while(r_most - cekor >= 0 && checkright(r_most-cekor)) r_most -= cekor;
    }
    cout<<r_most-l_most-1<<"\n";
    return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;



//メモリ置き場


//inputします
void input() {
	
}

//ライブラリ置き場


//main
int main() {
	input();
	long double l;
	cin >> l;
	long double a = l / 3.0;
	cout <<setprecision(16)<< a * a * a << endl;
	return 0;
}

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

int main(){
    cin>>x>>y;
    if(x<y&&x>1){
        cout<<"Bob"<<endl;
    }
    else if(x>y&&y>1){
        cout<<"Alice"<<endl;
    }
    else if(x<y&&x==1){
        cout<<"Alice"<<endl;
    }
    else if(x>y&&y==1){
        cout<<"Bob"<<endl;
    }
    else if(x==y){
        cout<<"Draw"<<endl;
    }
}


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

using namespace std;


void solve() {
    int n,m,A,B,C;
    cin >> n >> m >> A >> B >> C;
    vector<int> a(A),b(B),c(C);
    for (auto& x: a) cin >> x;
    for (auto& x: b) cin >> x;
    for (auto& x: c) cin >> x;
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());
    a.resize(n);
    b.resize(m);
    for (int x:a)c.push_back(x);
    for (int x:b)c.push_back(x);
    sort(c.begin(), c.end(), greater<int>());
    long long res = 0;
    for (int i = 0; i < n+m; i++) {
        res += c[i];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long 
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pii pair <int,  int>
#define pll pair <long long , long long>  
#define FAST ios::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const int maxn = 2e5 + 10 , INF = 1e9;

ll a[maxn];

int main() {
    FAST
    int n , k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a , a + n);
    ll sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += a[i];
    }
    cout << sum <<endl;
}

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

int main(){
  double r;
  cin >> r;
  cout << fixed << setprecision(6);
  cout << r*r*3.14159265358979 << " " << r*2*3.14159265358979 << endl;
}





Measured memory_bytes: 3280
/*
AuThOr Gwj
*/
#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 LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	int k,a,b;
	cin>>k>>a>>b;
	int i=k;
	while(i<a){
		i+=k;
	}
	if(i<=b){
		cout<<"OK";
	}
	else{
		cout<<"NG";
	}
	return 0;
}


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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;

	cin >> n >> k;

	vector<bool> km(10, false);
	ll tmp;
	rep(i, k) {
		cin >> tmp;
		km[tmp] = true;
	}

	ll now = n;
	ll d;
	bool is_ok;
	while (1) {
		d = now;
		is_ok = true;
		while (d > 0) {
			if (km[d % 10]) {
				is_ok = false;
				break;
			}
			d /= 10;
		}
		if (is_ok) {
			l_ans = now;
			break;
		}
		now++;
	}

	cout << l_ans << "\n";
}

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

	solve_abc_c();

	return 0;
}


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

int main() {
    ll n, x;
    cin >> n;
    ll minimum = 1001001001001001001;
    ll maxi = -1001001001001001001;
    ll sum = 0;
    for (ll i = 0; i < n; ++i) {
        cin >> x;
        minimum = min(minimum, x);
        maxi = max(maxi, x);
        sum += x;
    }
    cout << minimum << " " << maxi << " " << sum << endl;
}



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

using namespace std;
typedef long long ll;

const int mx = 2e5+5;

int main()
{
	//int n;
	//cin>>n;
	string s;
	string t;

	cin>>s;
	cin>>t;

	int cnt =0;

	for(int i=0;i<3;i++)
	{
		cnt+=(s[i]==t[i]);
	}


	cout<<cnt<<'\n';


	return 0;		
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define all(x) x.begin(), x.end()
#define ed cout << "\n"
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define ar array
#define sz(x) (int)x.size()
#define forn(a,b,c) for(int a = b; a < c; a++)
#define rfor(a,b,c) for(int a = b; a >= c; a--)
#define fors(a,b,c,d) for(int a = b; a < c; a+=d)
#define rfors(a,b,c,d) for(int a = b; a >= c; a-=d)
#define yes cout << "Yes"
#define no cout << "No"
#define NAME ""
bool isFile = 0;
 
typedef long long ll;
typedef long double ld;
 
const ll INF=1e9+1234;                                                   
const int N = 4e5 + 5; 
const ll MOD=998244353;
const ll mod=1e9+7;                                            
double EPS = 3e-18;
const double PI = acos(-1);  
 
 
void faster()
{
	if(isFile)
	{
		freopen(NAME".in","r",stdin);
		freopen(NAME".out","w",stdout);
	}
	ios_base::sync_with_stdio(false);        
    cin.tie(NULL);                                         
    cout.tie(NULL);                                
}                                                     
 
int q[N],w[N],e[N];
 
 
void solve() 
{			  			 																	 									 	  	                      
	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	forn(i,0,a)
		cin >> q[i];
	forn(i,0,b)
		cin >> w[i];
	forn(i,0,c)
		cin >> e[i];
	sort(q,q+a);
	reverse(q,q+a);

	sort(w,w+b);
	reverse(w,w+b);

	sort(e,e+c);
	reverse(e,e+c);
	vpll v;
	ll sum = 0;
	forn(i,0,x)
	{
		v.pb({q[i],1});
		sum += q[i];
	}
	forn(i,0,y)
	{
		v.pb({w[i],2});
		sum += w[i];
	}
	sort(all(v));
	int r = 0;
	forn(i,0,c)
	{
		if(e[i] <= v[i].F) break;
		sum -= v[i].F;
		sum += e[i];
	}
	cout << sum;
}                         
                           
int main()                                     
{                            
	faster();                 
	int t = 1;
	//cin >> t;	
	while(t--)
	{               	
		solve();
		ed;
	}
	return 0;
}

Measured memory_bytes: 8816
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, K, i, x[100001], a, b, ans=INF, sum;

    cin >> N >> K;
    
    for(i=1; i<=N; i++){
        cin >> x[i];
    }

    for(i=1; i<=N-K+1; i++){
        a = x[i];
        b = x[i+K-1];

        if(abs(a) >= abs(b)){ // b→a
            sum = abs(b) + abs(a-b);
        }
        else{
            sum = abs(a) + abs(a-b);
        }

        chmin(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

ll a[110],b[110];

int main(){
	ll n,m;
	while(scanf("%lld%lld",&n,&m),n){
		ll sn=0,sm=0;
		ll id1=-1,id2,min=200;
		rep(i,0,n){
			scanf("%lld",a+i);
			sn+=a[i];
		}
		rep(i,0,m){
			scanf("%lld",b+i);
			sm+=b[i];
		}
		rep(i,0,n)rep(j,0,m){
			if(sn-a[i]+b[j]==sm-b[j]+a[i]){
				if(a[i]+b[j]<min){
					min=a[i]+b[j];
					id1=a[i];
					id2=b[j];
				}
			}
		}
		if(id1==-1)puts("-1");
		else printf("%lld %lld\n",id1,id2);
	}
}



Measured memory_bytes: 2036
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

#define MAX 100100
#define rep(i,n) for(long long i = 0;i<n;i++)
#define REP(i,k,n) for(long long i=k;i<n;i++)
using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long a[MAX];
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  double m;
  if(a[n-1]==0){
    m = 0;
  }else m = (double)a[n-1]/2;
  double mi = 1000000000;
  int ans;
  rep(i,n-1){
    if(abs(m-a[i]) < mi){
      mi = abs(m-a[i]);
      ans = a[i];
    }
  }

  cout << a[n-1] << " " << ans << endl;
  return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    fastio;
    ll ans=0;
    ll n, k;
    cin >> n >> k;
    if (n > k) {
        n %= k;
    }
    if (n > k/2)
        n = abs(n-k);
    ans = n;
    cout << ans << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int T=1;
    //cin >> T;
    while(T--){
        ll x,y,a,b,c;
        cin>>x>>y>>a>>b>>c;
        ll p[a], q[b], r[c];
        vector<ii>v;
        rep(i,a){
            cin>>p[i];
            v.pb(mp(p[i],0));
        }
        rep(i,b){
            cin>>q[i];
            v.pb(mp(q[i],1));
        }
        rep(i,c){
            cin>>r[i];
            v.pb(mp(r[i],2));
        }
        sort(all(v));
        ll d=0,z=0,x1=0,y1=0;
        rev(i,v.size()-1){
            if(v[i].ss==2) d+=v[i].ff, z++;
            if(v[i].ss==0 && x1<x) d+=v[i].ff, x1++;
            if(v[i].ss==1 && y1<y) d+=v[i].ff, y1++; 
            if(x1+y1+z==x+y) break; 
        }
        cout<<d<<el;

    }

    return 0;
}

Measured memory_bytes: 12268
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=110;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int a[N],s[N];
inline void wrong() {
	puts("Impossible");
	exit(0);
}
int main()
{
	int n=gi(),i;
	for (i=1;i<=n;i++) s[gi()]++;
	while (!s[n]) n--;
	if (n==1) { puts(s[1]==2?"Possible":"Impossible"); return 0; }
	if (s[(n+1)/2]!=1+(n&1)) wrong();
	for (i=n/2+1;i<=n;i++)
		if (s[i]<2) wrong();
	for (i=n/2-1;i;i--) if (s[i]) wrong();
	puts("Possible");
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::io::{stdin, stdout, Read, Write};
use std::str::FromStr;

#[derive(Default)]
struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner {
            reader,
        }
    }

    fn scan<T: FromStr>(&mut self) -> Option<T> {
        let s = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok()
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.scan() {
            s
        } else {
            std::process::exit(1);
        }
    }
}

fn max_heapify(a: &mut[i32], i: usize) {
    let l = i * 2;
    let r = i * 2 + 1;
    let mut largest = i;
    if l < a.len() && a[l] > a[i] {
        largest = l;
    }
    if r < a.len() && a[r] > a[largest] {
        largest = r;
    }
    if largest != i {
        a.swap(i, largest);
        max_heapify(a, largest);
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let out = stdout();
    let mut out = out.lock();

    let n: usize = sc.next();
    let mut a = vec![0; n+1];
    for i in 1..n+1 {
        a[i] = sc.next();
    }
    for i in (1..(n/2+1)).rev() {
        max_heapify(a.as_mut_slice(), i);
    }
    for i in 1..n+1 {
        write!(out, " {}", a[i]).ok();
    }
    writeln!(out).ok();
}


Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const int N = 1e2+9, M = 1e5+9, OO = 0x3f3f3f3f,MOD = 1e9 + 7;
int n,k,a[N];
LL memo[N][M];
LL solve(int i=0,int rem=k)
{
  if(rem==0) return 1;
  if(rem<0 || i==n) return 0;
  
  LL &ret = memo[i][rem];
  if(~ret) return ret;

  ret =(solve(i+1,rem)%MOD+solve(i,rem-1)%MOD-solve(i+1,rem-a[i]-1)%MOD+MOD)%MOD;
  return ret; 
}
//return dp[i][j] = ((solve(i - 1, j) + solve(i, j - 1)) % mod_num - solve(i - 1, j - a[i] - 1) + mod_num) % mod_num;
int main()
{
  memset(memo,-1,sizeof memo);
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;++i) scanf("%d",a+i);
  printf("%lld",solve());
  
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 91776
#include <iostream>

#define MAX_WH 20

using namespace std;

void solve();
void dfs(int x, int y);

int W,H,count;
char field[MAX_WH][MAX_WH+1];

int main()
{
    while (1) {
        cin>>W>>H;
        if (W==0&&H==0) break;
        for (int i=0; i<H; i++) cin>>field[i];
        solve();
    }
    return 0;
}

void solve()
{
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (field[i][j]=='@') {
                count=1;
                dfs(i,j);
                cout<<count<<endl;
                return ;
            }
        }
    }
}

void dfs(int x, int y)
{
    field[x][y]='#';
    
    
    if (x-1>=0&&field[x-1][y]=='.') {
        count++;
        dfs(x-1,y);
    }
    if (y-1>=0&&field[x][y-1]=='.') {
        count++;
        dfs(x,y-1);
    }
    if (x+1<H&&field[x+1][y]=='.') {
        count++;
        dfs(x+1,y);
    }
    if (y+1<W&&field[x][y+1]=='.') {
    	count++;
        dfs(x,y+1);
    }
}

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-
 
tmp = input()
n = int(tmp.split(" ")[0])
m = int(tmp.split(" ")[1])
 
cake0 = []
cake1 = []
cake2 = []
cake3 = []
cake4 = []
cake5 = []
cake6 = []
cake7 = []


for x in range(n):
    tmp = input()
    cake0.append(int(tmp.split(" ")[0]) + int(tmp.split(" ")[1]) + int(tmp.split(" ")[2]))
    cake1.append(int(tmp.split(" ")[0]) + int(tmp.split(" ")[1]) - int(tmp.split(" ")[2]))
    cake2.append(int(tmp.split(" ")[0]) - int(tmp.split(" ")[1]) + int(tmp.split(" ")[2]))
    cake3.append(int(tmp.split(" ")[0]) - int(tmp.split(" ")[1]) - int(tmp.split(" ")[2]))
    cake4.append(-int(tmp.split(" ")[0]) + int(tmp.split(" ")[1]) + int(tmp.split(" ")[2]))
    cake5.append(-int(tmp.split(" ")[0]) + int(tmp.split(" ")[1]) - int(tmp.split(" ")[2]))
    cake6.append(-int(tmp.split(" ")[0]) - int(tmp.split(" ")[1]) + int(tmp.split(" ")[2]))
    cake7.append(-int(tmp.split(" ")[0]) - int(tmp.split(" ")[1]) - int(tmp.split(" ")[2]))
 
cake0.sort()
cake0.reverse()
cake1.sort()
cake1.reverse()
cake2.sort()
cake2.reverse()
cake3.sort()
cake3.reverse()
cake4.sort()
cake4.reverse()
cake5.sort()
cake5.reverse()
cake6.sort()
cake6.reverse()
cake7.sort()
cake7.reverse()
 
i = [0,0,0,0,0,0,0,0]
x = int(0)

for x in range(m):
    i[0] = i[0] + cake0[x]
    i[1] = i[1] + cake1[x]
    i[2] = i[2] + cake2[x]
    i[3] = i[3] + cake3[x]
    i[4] = i[4] + cake4[x]
    i[5] = i[5] + cake5[x]
    i[6] = i[6] + cake6[x]
    i[7] = i[7] + cake7[x]

print(max(i))

Measured memory_bytes: 3444
#include<cstdio>

int main(void) {
    int r,g,b,n;
    scanf("%d%d%d%d", &r,&g,&b,&n);

    long long int res = 0;

    for(int rr=0; rr<=3000; rr++)
        for(int gg=0; gg<=3000; gg++) {
            if(rr*r+gg*g<=n && (rr*r+gg*g-n) % b == 0) {
                res++;
            }
        }
    printf("%lld\n",res);
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
L, R = map(int, input().split())
end = min(R, L + 637*2)

ans = 2018
for i in range(L, end+1):
    for j in range(i+1, end+1):
        x = i*j%2019
        ans = min(ans, x)
print(ans)

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int prize = 100000;
int x, y;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> x >> y;

    int ans = 0;
    if(x <= 3) {
        ans += (4-x)*prize;
    }
    if(y <= 3) {
        ans += (4-y)*prize;
    }
    if(ans == prize*6) {
        ans += prize*4;
    }

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


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split(' ')))
ans=1
key=0
for x in a:
    if key==0:
        ans*=x
    if key==0 and ans>10**18:
        ans=-1
        key=1
    if x==0 and key==1:
        ans=0
        break
print(ans)

Measured memory_bytes: 21704
#include <bits/stdc++.h>
using namespace std;
#define INF 100005

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
	int n;
	cin >> n;
	int cc=0;
	for(int i=1;i<=n;i++)
	{
		int num;
		cin >> num;
		if(i%2!=0 && num%2!=0)
		{
			cc++;
		}
	}
	cout << cc << "\n";
}


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

int main(){
  int N, M;
  vector<int64_t> A(100010);
  vector<pair<int64_t, int64_t>> CB(100010, make_pair(0,0));

  cin >> N >> M;
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<M; i++) cin >> CB[i].second>> CB[i].first;
  
  vector<int64_t> D(100010, 0);
  sort(CB.begin(), CB.begin()+M, greater<pair<int64_t, int64_t>>());
  int cnt = 0;
  for(int i=0; i<M; i++){
    if(cnt == N) break;
    for(int j=0; j<CB[i].second; j++){
      if(cnt == N) break;
      D[cnt] = CB[i].first;
      cnt++;
    }
  }

  int64_t ans = 0;
  sort(A.begin(), A.begin()+N);
  for(int i=0; i<N; i++){
    //cout << A[i] << " " <<  D[i] << endl;
    if(A[i] < D[i]) ans += D[i];
    else ans += A[i];
  }

  cout << ans << endl;
}

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

int main(){
    int N, M;
    long long result = 0;
    cin >> N >> M;
    priority_queue<int> q;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        q.push(a);
    }
    for(int i = 0; i < M; i++){
        int a = q.top();
        q.pop();
        q.push(a/2);
    }
    for(int i = 0; i < N; i++){
        result += q.top();
        q.pop();
    }
    cout << result << endl;
}

Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>

using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef vector < vector < pair <ll,ll> > > vvp_ll;
typedef pair <ll,ll> p_ll;

ll N,M;
vv_ll G;
vector<bool> D;

int main(){
  cin >>N>>M;
  G.assign(N+10,v_ll());
  D.assign(N+10,true);
  for(ll i=1;i<=M;i++){
    ll x,y,z;
    cin >> x >> y >> z;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  queue<ll> que;
  ll f=1;
  ll ans=0;
  while (f<=N){
    //cout << f << endl;
    if(D[f]!=true){f++;continue;}
    ans++;
    que.push(f);
    while(!que.empty()){
      ll x=que.front();
      que.pop();
      D[x]=false;
      for (ll i=0;i<G[x].size();i++){
        //cout << "hog!!!!e" <<endl;
        ll y=G[x][i];
        if (D[y]){
          que.push(y);
          //cout << "hoge" <<endl;
        }
      }
    }
    //cout << "hoge!" << endl;
    f++;

  }
  //cout << "hoge!!" << endl;
  cout << ans << endl;
}


Measured memory_bytes: 7284
n = int(input())
a = [int(_) for _ in input().split()]
count = 0
for i in range(n-1):
    tmp_index = i
    for j in range(i+1, n):
        # 最小の値探索
        # print("# temp", tmp_index, "j", j)
        if a[j] < a[tmp_index]:
            tmp_index = j
    if tmp_index != i:
        count += 1
        # 最小と左端入れ替え
        a_tmp = a[i]
        a[i] = a[tmp_index]
        a[tmp_index] = a_tmp
for i in range(n-1):
    print(a[i], end=" ")
print(a[n-1])
print(count)



Measured memory_bytes: 5608
let n = readInt()
let a = readArray().lazy.map { Int($0)! }

var acc = 0
var min = 0

for num in a {
  if min > num {
    acc = acc &+ (min - num)
  } else {
    min = num
  }
}

print(acc)

@inlinable @inline(__always) func readInt() -> Int { Int(readLine()!)! }
@inlinable @inline(__always) func readArray(_ separator: Character = " ") -> [String] { readLine()!.split(separator: separator).map(String.init) }


Measured memory_bytes: 21220
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

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

	int n;
	cin>>n;
	cout<<n*(n-1)/2<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
  }
int count=0;
  for(int i=0;i<n;i++){
    if(a[i]==b[i]) count++;
    else count=0;
    if(count==3){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
int main(int argc, char *argv[])
{
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF)
	 {int t;
	 if(a>b){
 		t=a;a=b;b=t;
 	}
 	if(a>c){
	 	t=a;a=c;c=t;
	 }
	 if(b>c){
 		t=b;b=c;c=t;
 	}
 	int sum=0;
 	sum=c-a;
	printf("%d\n",sum);
	 }
	return 0;
}

Measured memory_bytes: 128
H, W = list(map(int, input().split()))
A = [input() for i in range(H)]

header = ''
for _ in range(W+2):
    header += '#'

B = []
for i in range(H):
    B.append('#' + A[i] + '#')

print(header)
print(*B, sep="\n")
print(header)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		ll N, X, M;
		cin >> N >> X;
		if (cin.fail()) break;

		ll min = INF;
		for (int i = 0; i < N; i++) {
			cin >> M;
			if (min > M) min = M;
			X -= M;
		}

		cout << (N + X / min) << endl;
	}

	return 0;
}


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

// マクロ
// forループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x)begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
// 出力
#define PRINT(x) cout<<(x)<<endl
#define PRINTA(x,n) REP(i,n)PRINT(x[i])
// 定数
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
// 略記
#define PB push_back
#define MP make_pair

int N, A[200009];

ll L[200009], R[200009];

int main() {
    cin >> N;
    FOR(i, 1, N) {
        L[i] = 0;
        R[i] = 0;
    }
    FOR(i, 1, N) {
        cin >> A[i];
        int l = i + A[i];
        int r = i - A[i];
        if (l >= 1 && l <= N) L[l]++;
        if (r >= 1 && r <= N) R[r]++;
    }
    ll ans = 0;
    FOR(i, 1, N) ans += L[i] * R[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7528
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int K, N;
	vector<int> A;
	int ans = INF;
	
	cin>>K>>N;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		if(i) ans = min(ans, K - (A[i] - A[i-1]));
	}
	
	ans = min(ans, K - (K - A[N-1] + A[0]));
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int p,j,x,y,z,i,k;
	x=2000;
	y=2000;
	for(i=0;i<3;i++) {
		scanf("%d",&p);
			if(x > p) {
			x=p;
			}
	}
	for(k=0;k<2;k++) {
		scanf("%d",&j);
			if(y > j) {
			y=j;
			}
	}
	z=x+y-50;
	printf("%d\n",z);
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, x;
  cin >> n >> x;
  ll d = 0, res = 1;
  rep(i, n) {
    ll l;
    cin >> l;
    d += l;
    if (d <= x) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <tuple>
#include <unordered_set>

using namespace std;
typedef long long ll;

priority_queue<pair<ll,tuple<ll,ll,ll>>> q;
ll x,y,z,k;
vector<ll> a;
vector<ll> b;
vector<ll> c;
unordered_set<ll> us;

int main(){
    ll d;
    cin >> x >> y >> z >> k;
    for(int i=0;i<x;i++){
        cin >> d;
        a.push_back(d);
    }
    for(int i=0;i<y;i++){
        cin >> d;
        b.push_back(d);
    }
    for(int i=0;i<z;i++){
        cin >> d;
        c.push_back(d);
    }
    sort(a.begin(),a.end(),greater<ll>());
    sort(b.begin(),b.end(),greater<ll>());
    sort(c.begin(),c.end(),greater<ll>());
    q.push(make_pair(a[0]+b[0]+c[0],make_tuple(0,0,0)));
    tuple<ll,ll,ll> t;
    long long uu;
    for(int i=0;i<k;i++){
        cout << q.top().first << endl;
        ll xx = get<0>(q.top().second);
        ll yy = get<1>(q.top().second);
        ll zz = get<2>(q.top().second);
        q.pop();
        t = make_tuple(xx+1,yy,zz);
        uu = xx * 10e6 + (yy-1) * 10e3 + zz-1;
        if(xx+1 < x && us.find(uu) == us.end()){
            q.push(make_pair(a[xx+1]+b[yy]+c[zz],t));
            us.insert(uu);
        }
        t = make_tuple(xx,yy+1,zz);
        uu = (xx-1) * 10e6 + yy * 10e3 + zz-1;
        if(yy+1 < y && us.find(uu) == us.end()){
            q.push(make_pair(a[xx]+b[yy+1]+c[zz],t));
            us.insert(uu);
        }
        t = make_tuple(xx,yy,zz+1);
        uu = (xx-1) * 10e6 + (yy-1) * 10e3 + zz;
        if(zz+1 < z && us.find(uu) == us.end()){
            q.push(make_pair(a[xx]+b[yy]+c[zz+1],t));
            us.insert(uu);
        }
    }
    return 0;
}

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

map<string, int> dp;
int direction[4] = { 1, -1, 4, -4 };
void bfs()
{
	queue<string> que;
	que.push("01234567");
	dp["01234567"] = 0;
	while (!que.empty())
	{
		string now = que.front(); que.pop();
		// p是'0'的位置
		int p = 0;
		for (int j = 0; j < 8; ++j)
		{
			if (now[j] == '0')
			{
				p = j;
				break;
			}
		}

		for (int i = 0; i < 4; ++i)
		{
			int n = p + direction[i];
			if (0 <= n && n < 8 &&
				!(p == 3 && i == 0) && 
				!(p == 4 && i == 1))
			{
				string next = now;
				swap(next[p], next[n]);
				if (dp.find(next) == dp.end())
				{
					dp[next] = dp[now] + 1;
					que.push(next);
				}
			}
		}
	}
}

int main() {
	bfs();
	string a="        ";
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> a[7]) {
		cout << dp[a] << endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 3436
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
bool is_prime[55559];
vector<llong> ans;

int main() {
    fill(is_prime, is_prime + sizeof(is_prime) / sizeof(bool), true);
    cin >> n;

    is_prime[0] = is_prime[1] = false;
    for (llong i = 2; i * i <= 55555; i++) {
        if (is_prime[i]) {
            for (llong j = i + i; j <= 55555; j += i) is_prime[j] = false;
        }
    }

    llong i = 1;
    while (ans.size() < n) {
        if (is_prime[i]) {
            ans.push_back(i);
        }
        i += 5;
    }

    for (auto a:ans) {
        cout << a << ' ';
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256