akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

#define mod 1000000007
#define REP(i,n) for(int i=0; i<n; i++)

using namespace std;
using ll = long long;

void solve() {
    int n, x;
    ll res = 0;
    vector<int> a, b, c;
    cin >> n;
    REP(i, n) {cin >> x; a.push_back(x);}
    REP(i, n) {cin >> x; b.push_back(x);}
    REP(i, n) {cin >> x; c.push_back(x);}

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    /*
    REP(i, n) cout << a.at(i) << " ";
    cout << endl;
    REP(i, n) cout << b.at(i) << " ";
    cout << endl;
    REP(i, n) cout << c.at(i) << " ";
    cout << endl;
    */
    unsigned long up, down;
    REP(i, n){
        up = (lower_bound(a.begin(), a.end(), b.at(i))-a.begin());
        down = n-(upper_bound(c.begin(), c.end(), b.at(i))-c.begin());
        //cout << up << ", " << down << endl;
        res += up * down;
    }
    cout << res << endl;
}

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

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


int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    cin>>x;
    ll n;
    cin>>n;
    ll a[n];
    if(n==0)
    cout<<x<<endl;
    ll i,j;
    for(i=0;i<n;i++)
    {
    	cin>>a[i];
	}
    if(n==1)
    {
    	if(x<=a[0])
    	cout<<a[0]-1<<endl;
    	else
    	cout<<a[0]+1<<endl;
	}
	
	if(n>1)
	{
		vector<ll>k;
		k.clear();
		sort(a,a+n);
		for(i=1;i<n;i++)
		{
			ll z=a[i]-a[i-1];
			if(z==1)
			continue;
			else
			{
				for(j=a[i-1]+1;j<a[i];j++)
				{
					//cout<<"j ="<<j<<endl;
					k.push_back(j);
				}
			}
		}
		ll v=k.size();
		//cout<<"V="<<v<<endl;
		ll diff;ll ans=INT_MAX;diff=INT_MAX;
		//cout<<"OK"<<endl;
		for(i=0;i<v;i++)
		{
			ll s=abs(x-k[i]);
			if(s<diff)
			{
				//cout<<"Hm"<<endl;
				diff=s;
				ans=k[i];
			}
		}
		ll q=abs(x-(a[0]-1));
		if(q<diff)
		{
			ans=a[0]-1;
			diff=q;
		}
		ll w=abs(x-(a[n-1]+1));
		
		if(w<diff)
		{
			ans=a[n-1]+1;
			diff=w;
		}	
		
		cout<<ans<<endl;
		
	}
	return 0;
}
	

Measured memory_bytes: 3660
use std::io::stdin;

fn main() {
    let mut nm = String::new();
    stdin().read_line(&mut nm).unwrap();
    let nm: Vec<usize> = nm.trim().split_whitespace().flat_map(str::parse).collect();
    let (n, m) = (nm[0], nm[1]);
    let mut stores: Vec<(usize, usize)> = (0..n).map(|_| {
        let mut a = String::new();
        stdin().read_line(&mut a).unwrap();
        let a: Vec<usize> = a.trim().split_whitespace().flat_map(str::parse).collect();
        (a[0], a[1])
    }).collect();
    stores.sort();
    let mut count = m;
    let mut result = 0;
    for (yen, stock) in stores {
        let needs = if stock > count { count } else { stock };
        count -= needs;
        result += yen * needs;
        if count == 0 {
            break;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 6396
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

int main()
{
	i64 N,M,X,Y;
	cin >> N >> M >> X >> Y;
	i64 max_x = X;
	REP(i, N)
	{
		i64 x;
		cin >> x;
		if (x > max_x)
			max_x = x;
	}
	i64 min_y = Y;
	REP(i, M)
	{
		i64 y;
		cin >> y;
		if (y < min_y)
			min_y = y;
	}

	if (max_x < min_y)
		cout << "No War" << endl;
	else
		cout << "War" << endl;
	return 0;
}


Measured memory_bytes: 256
[n,m] = [int(i) for i in input().split()]
ls_st = []
ls_ch = []
for j in range(n):
    ls_st.append([int(i) for i in input().split()])
for j in range(m):
    ls_ch.append([int(i) for i in input().split()])
ans = []
for i in range(n):
    dist = 10**20;
    place = -1
    for j in range(m):
        if dist > (abs(ls_st[i][0] - ls_ch[j][0])+abs(ls_st[i][1] - ls_ch[j][1])):
            dist = (abs(ls_st[i][0] - ls_ch[j][0])+abs(ls_st[i][1] - ls_ch[j][1]))
            place = j+1
    ans.append(place)
for i in range(n):
    print(ans[i])


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
typedef long long ll;
using namespace std;
int main(){
    ll k,x,t=0;
    cin>>k;
    vector<ll> a(k+2);
    vector<ll> b(k);
    for(int i=0;i<k+1;i++) cin>>a[i];
    for(int i=0;i<k;i++) cin>>b[i];
    for(int i=0;i<k;i++) {
        if(b[i]>=a[i]){
            t+=a[i];b[i]-=a[i];
            if(b[i]>=a[i+1]) {t+=a[i+1];a[i+1]=0;}
            else {t+=b[i];a[i+1]-=b[i];}    
        }
        else t+=b[i];
    }
    cout<<t;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
    char str[100];
    int n,i,count=0;
    scanf("%d",&n);

    for(i=0; i<n+1; i++)
    {
        scanf("%c",&str[i]);
    }

    //gets(str);

    for(i=0; str[i]!='\0'; i++)
    {
        if(str[i]=='A' && str[i+1]=='B' &&str[i+2]=='C'){
            count++;
        }
    }


    printf("%d",count);


}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vll a(n), b(n);
	for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];

	ll add = 0;
	for (ll i = n - 1; i >= 0; i--) {
		a[i] += add;
		add += (a[i] + b[i] - 1) / b[i] * b[i] - a[i];
	}
	cout << add << endl;
}


Measured memory_bytes: 1920
#include<stdio.h>
#define N 100000
#define Q 50000
 
int main(){
 
  int i,j,x,y,b;
  int s[N],t[Q],a=0,mid,left,right;
 
  scanf("%d",&x);
 
  for(i=0;i<x;i++){
    scanf("%d",&s[i]);
  }
 
  scanf("%d",&y);
 
  for(j=0;j<y;j++){
    scanf("%d",&t[j]);
  }
 
 
  for(b=0;b<y;b++){
 
  left=0;
  right=x;
 
  while(left<right){
    mid=(left+right)/2;
  if(s[mid]==t[b]){
    a++;
    break;
  }
  else if(t[b]<s[mid])
    right=mid;
  else if(t[b]>s[mid])
    left=mid+1;
  }
  }
 
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
  string S; cin >> S;

  int ans = 1000; 
  for (int i = 0; i < S.size() - 2; i++) {
    int a = S[i] - '0';
    int b = S[i + 1] - '0';
    int c = S[i + 2] - '0';
    int curr = abs((a * 100 + b * 10 + c) - 753);
    if (curr < ans) ans = curr;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
array = []
for _ in range(M):
    array.append(list(map(int,input().split()))[1:])
P = list(map(int,input().split()))
count = 0
for mask in range(2**N):
    se = set()
    for i in range(N):
        if mask>>i & 1:
            se.add(i+1)
    for m in range(M):
        p = P[m]
        tmp = 0
        for j in array[m]:
            if j in se:
                tmp+=1
        if tmp%2!=p:
            break
    else:
        count+=1
print(count)

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

int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	for(auto &k:p)cin >> k;
	vector<int> a(N);
	vector<int> b(N);
	for(int i=0;i<N;i++){
		a[i]=b[N-i-1]=(i+1)*40001;
	}
	for(int i=0;i<N;i++){
		a[p[i]-1]+=i;
		b[p[i]-1]+=i;
	}
	for(int i=0;i<N;i++){
		cout << a[i];
		if(i<N-1)cout << " ";
		else cout << endl;
	}
	for(int i=0;i<N;i++){
		cout << b[i];
		if(i<N-1)cout << " ";
		else cout << endl;
	}
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
const int mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  long long a = 1, b = 1, c = 1;
  rep(i,N){
    a = 10*a % mod;
    b = 9*b % mod;
    c = 8*c % mod;
  }
  long long ans = (a-2*b+c)%mod;
  cout << (ans+mod)%mod;
  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>	
#include<functional>
#include<climits>

using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
#define pb push_back
#define PB push_back
#define lb lower_bound
#define LB lower_bound
#define ub upper_bound
#define UB upper_bound


//constant
const int MOD = 1000000007;
const int INF = INT_MAX / 3 - 1;
const double EPS = 1e-9;
const int dx4[4] = { 1,0,-1,0 };
const int dy4[4] = { 0,1,0,-1 };

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;


int main() {
	int n;
	while (cin >> n, n) {
		vector<pii> times(2*n);
		string buf;
		REP(i,n)
			REP(j, 2) {
			cin >> buf;
			times[2 * i + j].first = stoi(buf.substr(0, 2)) * 60 * 60 + stoi(buf.substr(3, 2)) * 60 + stoi(buf.substr(6, 2));
			times[2 * i + j].second = j;
		}
		sort(ALL(times),
			[](pii lef, pii rig) {
			return lef.first < rig.first ||
				lef.first == rig.first && lef.second>rig.second;
		});
		int count = 0;
		int stopping = 0;
		REP(i, 2 * n) {
			if (times[i].second)
				stopping++;
			else if (stopping > 0)
				stopping--;
			else
				count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3220
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int i, k;
		int n = sc.nextInt();
		int[] data = new int[n];
		int[] rank = new int[data.length];
		int A, B, C, D;
		for(i=0; i<data.length; i++){
			data[i] = 0;
		}
		for(i=0; i<(n*(n-1))/2; i++){
			A = sc.nextInt();
			B = sc.nextInt();
			C = sc.nextInt();
			D = sc.nextInt();
			if(C > D){
				data[A-1] += 3;
			}
			else if(C < D){
				data[B-1] += 3;
			}
			else{
				data[A-1] += 1;
				data[B-1] += 1;
			}
		}
		for(i=0; i<data.length; i++){
			int rnk = 1;
			for(k=0; k<data.length; k++){
				if(data[i] < data[k]){
					rnk++;
				}
			}
			rank[i] = rnk;
		}
		
		for(i=0; i<rank.length; i++){
			System.out.println(rank[i]);
		}
		

	}

}

Measured memory_bytes: 42220
H, W = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(H)]

ans = []
idx_list = [(i, j) if i % 2 == 0 else (i, W - j - 1)
            for i in range(H) for j in range(W)]
for i, (u, v) in enumerate(idx_list[:-1]):
    if X[u][v] % 2 == 1:
        x, y = idx_list[i + 1]
        X[x][y] += 1
        ans.append((u + 1, v + 1, x + 1, y + 1))

print(len(ans))
for t in ans:
    print(*t)


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


int main(){
  long long n;
  cin >> n;
  long long b, r;
  cin >> b >> r;

  long long ans = 0;
  long long c = 0;
  c = n / (b + r);
  ans += c * b;
  if(n - c * (b + r) >= b){
    ans += b;
  }
  else{
    ans += n - c * (r + b);
  }
  cout << ans << endl;
}

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

#define ll   long long int
#define PI 3.14159265358979
#define zig ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;


int main()
{
    zig
    string s;
    cin>>s;
    map<char, int> mp;
    bool flag=false;
    for(char a:s)
    {
        mp[a]++;
    }
    for(auto i:mp)
    {
        if(i.second%2)
        {
            flag=true;
            break;
        }
    }
    (flag)?cout<<"No":cout<<"Yes";
    return 0;
}


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

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, m;
    cin >> n >> m;

    int ans = 0;
    for(int x = sqrt(m); x >= 1; x--){
        if(m % x == 0){
            if(x >= n){
                ans = max(ans, m / x);
            }
            if(m / x >= n){
                ans = max(ans, x);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
    char[] buf = new char[0];

    public static void main(String[] args) {
        FastScanner scanner = new FastScanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> L = new ArrayList();
        for(int i=0;i<n;i++) {
            L.add(scanner.nextInt());
        }
        Collections.sort(L);

        long answer = 0;
        for(int i=0;i<n - 2;i++) {
            for(int j=i+1;j<n - 1;j++) {
                int a = L.get(i);
                int b = L.get(j);
                int lower = Math.max(a - b, b - a);
                int upper = a + b;
                int lowerResult = Math.max(~Collections.binarySearch(L, lower + 1, (x, y) -> x - y >= 0 ? 1 : -1), j + 1);
                int upperResult = Math.min(~Collections.binarySearch(L, upper - 1, (x, y) -> x.compareTo(y) > 0 ? 1 : -1), n);

                if (upperResult - lowerResult > 0) {
                    answer += (upperResult - lowerResult);
                }
            }
        }
        System.out.println(answer);
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

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

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

}


Measured memory_bytes: 47144
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	vector<string> vs;
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); i++)
	{
		for (int j = 1; i + j <= str.length() && j <= 5; j++)
		{
			vs.emplace_back(str.substr(i, j));
		}
	}
	sort(vs.begin(), vs.end());
	vs.resize(unique(vs.begin(), vs.end()) - vs.begin());
	int k;
	cin >> k;
	cout << vs[k - 1] << endl;
	return 0;
}


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

int main()
{
	int a[4],b[4];

	while(~scanf("%d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3])){
		int hit=0,blow=0;
		
		for(int i=0;i<4;++i){
			for(int j=0;j<4;++j){
				if(a[i] == b[j]){
					if(i == j)
						++hit;
					else
						++blow;
				}
			}
		}

		cout << hit << " " << blow << endl;

	}
	return 0;
}

Measured memory_bytes: 1208
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[4];
		for(int i = 0; i < str.length; i++) {
			str[i] = sc.nextLine();
		}
		sc.close();
		int lenSort = Integer.parseInt(str[0]);
		int[] sorted = stringToIntArray(str[1], lenSort);
		int lenUn = Integer.parseInt(str[2]);
		int[] unsorted = stringToIntArray(str[3], lenUn);
		int n = 0;
		for(int u: unsorted) {
			n += linearSearch(sorted, u);
		}
		System.out.println(n);
	}
	
	public static int[] stringToIntArray(String str, int len) {
		String[] strings = str.split(" ", len);
		int[] nums = new int[strings.length];
		for(int i = 0; i < strings.length; i++) {
			nums[i] = Integer.parseInt(strings[i]);
		}
		return nums;
	}
	
	public static int linearSearch(int[] sorted, int x) {
		int n = 0;
		for(int s: sorted) {
			if(x == s)
				n++;
		}
		if (n != 0) return 1;
		else return 0;
	}
}



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

int main()
{
  int n,k;
  for(;cin>>n>>k;)
    {
      int boot[n+1];
      for(int i=0;i<k;i++)
	{
	  int m;
	  cin>>m;
	  for(int j=0;j<m;j++)
	    {
	      int bu;
	      cin>>bu;
	      boot[bu]=i;
	    }
	}
      int r;
      bool check[n+1];
      memset(check,false,sizeof(check));
      cin>>r;
      for(int i=0;i<r;i++)
	{
	  int p,q;
	  cin>>p>>q;
	  if(boot[p]==boot[q])
	    {
	      check[p]=true;
	      check[q]=true;
	    }
	}
      int ans=0;
      for(int i=0;i<n+1;i++)
	{
	  if(check[i])
	    ans++;
	  
	}
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
ll a[100010];
pair<ll,ll> x[100010];
int main() {
	int n,m;
	cin >> n >> m;
	rep(i,n) cin >> a[i];
	rep(i,m) {
		ll b,c; cin >> b >> c;
		x[i] = {c,b};
	}
	sort(x,x+m, greater<pair<ll,ll>>());
	sort(a,a+n);
	int id_a = 0, id_x = 0; //aのインデックス
	while (id_a < n && id_x < m)
	{
		int cnt = 0;
		while (true)
		{
			cnt++;
			if (id_a == n || a[id_a] > x[id_x].first) break;
			if (cnt > x[id_x].second) break;
			a[id_a] = x[id_x].first;
			id_a++;
 		}
		id_x++;
	}
	
	ll sum = 0;
	rep(i,n) sum += a[i];
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 5980
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

typedef string::const_iterator State;
int ans;
string s;


ll exp(State &begin);



ll bin(State &begin){
	ll ret=0;
	
	while(isdigit(*begin)){
		ret*=2;
		ret+=*begin-'0';
		begin++;
	}
	return ret;
}


ll number(State &begin){
	if(*begin=='0'){
		begin++;
		if(isdigit(*begin))throw "number error1";
		else return 0;
	}
	else if(*begin=='1'){
		return bin(begin);
	}else throw "number error2";
	
	assert(1);
	return -1;
}


ll factor(State &begin){
	if( isdigit(*begin) )return number(begin);
	else if(*begin=='-'){
		begin++;
		if(isdigit(*begin)||*begin=='('||*begin=='-') return -1*factor(begin);
		else throw "factor error1";
	}else if(*begin=='('){
		begin++;
		ll ret = exp(begin);
		if(*begin!=')')throw "factor error2";
		begin++;
		return ret;
	}
	else throw "factor error3";
	assert(1);
	return -1;
}


ll term(State &begin){
	ll ret = factor(begin);
	
	if(*begin=='+'||*begin=='-'||*begin=='$'||*begin==')'){
		return ret;
	}
	else if(*begin=='*'){
		begin++;
		return ret*term(begin);
	}
	else throw "term error";
	
	assert(1);
	return -1;
	
}


ll exp(State &begin){
	ll ret = term(begin);
	
	while(1){
		if(*begin=='+'){
			begin++;
			ret+=term(begin);
		}else if(*begin=='-'){
			begin++;
			ret-=term(begin);
		}else if(*begin=='$'||*begin==')'){
			return ret;
		}else throw "exp error";
	}
	
	assert(1);
	return -1;
}


bool isValid(string tmp){
	int eqc=0;
	rep(i,tmp.size())if(tmp[i]=='=')eqc++;
	if(eqc!=1)return false;
	
	string str[2]={};
	bool f=false;
	rep(i,tmp.size()){
		if(tmp[i]=='=')f=true;
		else if(f)str[1]+=tmp[i];
		else str[0]+=tmp[i];
	}
	if(str[0].size()==0||str[1].size()==0)return false;
	
	State b[2];
	ll res[2];
	try{
		rep(i,2){
			str[i] +='$';
			b[i] = str[i].begin();
			res[i] = exp(b[i]);
		}
	}catch(char const* e){
		return false;
	}
	if(res[0]==res[1] && *b[0]=='$'&&*b[1]=='$'){
		return true;
	}else return false;
}

void dfs(string tmp,vector<bool> used){
	char alp='!';
	int pos=-1;
	rep(i,tmp.size()){
		if(isalpha(tmp[i]))alp=tmp[i],pos=i;
	}
	if(pos==-1){ if(isValid(tmp))ans++; return; }
	
	assert(alp!='!');
	string symbols = "01+-*()=";
	rep(i,symbols.size()){
		if(used[i])continue;
		used[i]=true;
		string ntmp = tmp;
		rep(j,ntmp.size()){
			if(ntmp[j]==alp) ntmp[j] = symbols[i];
		}
		dfs(ntmp,used);
		used[i]=false;
	}
}


int main(){
	cin>>s;
	set<char> st;
	vector<char> vs;
	
	rep(i,s.size())st.insert(s[i]);
	for(auto &e:st)vs.pb(e);
	
	int count=0;
	rep(i,vs.size())if(isalpha(vs[i]))count++;
	if(count>8){
		cout<<0<<endl;
		return 0;
	}
	
	ans=0;
	vector<bool> used(8,false);
	dfs(s,used);
	cout<<ans<<endl;
}

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

struct Card{
    char suit;
    char value;
};

vector<Card> BubbleSort(vector<Card> A, int N){
    for(int i=0;i<N;i++){
        for(int j=N-1;j>=i+1;j--){
            if(A.at(j).value < A.at(j-1).value){
                Card w=A.at(j);
                A.at(j)=A.at(j-1);
                A.at(j-1)=w;
            }
        }
    }
    return A;
}

vector<Card> SelectionSort(vector<Card> A, int N){
    for(int i=0;i<N;i++){
        int mini=i;
        Card v=A.at(i);
        for(int j=i+1;j<N;j++){
            if(A.at(j).value<A.at(mini).value) mini=j;
        }
        A.at(i)=A.at(mini);
        A.at(mini)=v;
    }
    return A;
}

void Print(vector<Card> A,int N){
    for(int i=0;i<N;i++){
        if(i>0) cout << " ";
        cout << A.at(i).suit << A.at(i).value;
    }
    cout << endl;
    return;
}

bool isStable(vector<Card> A,vector<Card> B, int N){
    for(int i=0;i<N;i++){
        if(A.at(i).suit!=B.at(i).suit || A.at(i).value != B.at(i).value) return false;
    }
    return true;
}

int main() {
	int N;
	cin >> N;
	vector<Card> C1(N),C2(N);
	for(int i=0;i<N;i++){
	    cin >> C1.at(i).suit >> C1.at(i).value;
	}
	for(int i=0;i<N;i++){
	    C2.at(i)=C1.at(i);
	}
	vector<Card> B=BubbleSort(C1,N);
	vector<Card> S=SelectionSort(C2,N);
	Print(B,N);
	cout << "Stable" << endl;
	
	Print(S,N);
	if(isStable(B,S,N)){
	    cout << "Stable" << endl;
	}
	else{
	    cout << "Not stable" << endl;
	}
	return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <string>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0, have = 1;
    while (have < b) {
        ++ans;
        have = have - 1 + a;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		if(a<b&&b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
			}
	}
}



Measured memory_bytes: 26296
#include <iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;

int main(){
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    int a_size = sa.size();
    int b_size = sb.size();
    int c_size = sc.size();
    
    int a=0;
    int b=0;
    int c=0;
    
    char turn ='a';
    char ans;
    while(a <= a_size && b <= b_size && c <= c_size){
        if(turn == 'a'){
            if(a==a_size){
                ans = 'A';
                break;
            }
            turn = sa[a];
            a++;
        }else if(turn == 'b'){
            if(b==b_size){
                ans = 'B';
                break;
            }
            turn = sb[b];
            b++;
        }else{
            if(c==c_size){
                ans = 'C';
                break;
            }
            turn = sc[c];
            c++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef double R;

ll C[51][51];

void comb_table(int N) {
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i) {
        C[i][j] = 1LL;
      } else {
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
      }
    }
  }
}

int main(int argc, const char * argv[]) {
  int N, A, B;
  cin >> N >> A >> B;
  const int NMAX = 50;
  ll v[NMAX];
  
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  
  comb_table(N);
  sort(v, v + N);
  reverse(v, v + N);
  
  R max_average = 0.0;
  for (int i = 0; i < A; i++) {
    max_average += v[i];
  }
  max_average /= A;
  
  int cnt = 0, pos = 0;
  for (int i = 0; i < N; i++) {
    if (v[i] == v[A - 1]) {
      cnt++;
      if (i < A) {
        pos++;
      }
    }
  }
  
  ll ans = 0LL;
  if (pos == A) {
    for (pos = A; pos <= B; pos++) {
      ans += C[cnt][pos];
    }
  } else {
    ans += C[cnt][pos];
  }
  
  cout.precision(20);
  cout << fixed << max_average << endl;
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll a, b;
	cin >> a >> b;
	cout << a/__gcd(a,b) * b << endl;
}



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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 55;
const int INF = 2e6;

int main() {

    int mn = 0, mx = 0;
    int n; cin >> n;
    static int a[N];
    forn(i,n) {
        cin >> a[i];
        if (a[i] < a[mn]) mn = i;
        if (a[i] > a[mx]) mx = i;
    }
    vector<pii> ans;
    if (a[mn] + a[mx] < 0) {
        forn(i,n) if (i != mn) ans.eb(mn,i);
        dforsn(i,1,n) ans.eb(i,i-1);
    }
    else {
        forn(i,n) if (i != mx) ans.eb(mx,i);
        forn(i,n-1) ans.eb(i,i+1);
    }

    cout << si(ans) << endl;
    for (auto xy : ans) {
        int x,y; tie(x,y) = xy;
        cout << x+1 << ' ' << y+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> G[2020];
int N,Z[2020]; char S[2020];

pair<int, int> go(int x, int l, int d)
{
	pair<int, int> r;
	if (S[x] == '1') r.first += d, Z[x] = 1;
	else Z[x] = 0;
	int mx = 0, sm = 0;
	for (auto &y : G[x]) if (y != l){
		auto n = go(y, x, d + 1);
		Z[x] += Z[y];
		r.first += n.first;
		mx = max(mx, n.second);
		sm += n.second;
	}
	if (mx <= sm / 2) sm %= 2;
	else sm = sm - 2 * (sm - mx);
	r.second = sm + Z[x];
	return r;
}

int main()
{
	scanf ("%d", &N);
	scanf ("%s", S + 1);
	for (int i = 1; i < N; i++){
		int x, y; scanf ("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}

	int ans = 0x7fffffff;
	for (int c = 1; c <= N; c++){
		vector<pair<int, int> > res;
		int mx = 0;
		for (auto &p : G[c]){
			auto n = go(p, c, 1);
			res.push_back(n);
			mx += n.first;
		}
		if (mx % 2 || ans < mx / 2) continue;

		int u = 0, v = 0;
		for (auto &p : res){
			u = max(u, p.second);
			v = max(v, p.first);
		}
		bool g = 0;
		for (int i = u; i <= v; i++){
			int sum = 0;
			for (int j = 0; j < res.size(); j++){
				if (res[j].first <= i) sum += res[j].first;
				else{
					if (i % 2 != res[j].first % 2) sum += i - 1;
					else sum += i;
				}
			}
			if (sum >= i * 2){
				g = 1;
				break;
			}
		}
		if (g) ans = min(ans, mx / 2);
	}
	
	if (ans == 0x7fffffff) ans = -1;
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <numeric>

int main() {
  int K, X;
  std::cin >> K >> X;

  const int min = X - K + 1;
  const int max = X + K - 1;

  for (int i = min; i <= max; ++i) {
    std::cout << i;
    if (i != max) {
      std::cout << " ";
    }
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    long long int n,x=0,y=0;
    cin>>n;
    long long int arr[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]%2==0)
        {
            x++;
        }
        else
            y++;
    }
    if(y%2==0||x==n)
    {
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 4368
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 2e9;



int main() {
	int n, t; cin >> n >> t;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	vector<P> b(n - 1);
	int mi = a[0],idx=0;
	rep(i, 0, n - 1) {
		if (mi > a[i + 1]) {
			mi = a[i + 1];
			idx = i + 1;
		}
		b[i] = { a[i+1]-mi,idx };
	}
	sort(b.begin(), b.end(),greater<P>());
	idx = 0; int ans = 0;
	while (b[idx].first == b[0].first) {
		ans++; idx++;
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i = 1 ;i<=n ;i++){
    scanf("%hd",&A[i]);
  }
  for(i = 0;i<=VMAX+1;i++){
    C[i] = 0;
  }
  for(j=1;j<=n;j++){
    C[A[j]] = C[A[j]]+1;
  }
  
  for(i = 1 ;i<=VMAX+1;i++){
    C[i] = C[i]+C[i-1];
  }
  for(j=n ;j>=1 ;j--){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]]-1;
  }
  for(j = 1;j<n+1;j++){
    if(j ==n)
    printf("%d\n",B[j]);
    else printf("%d ",B[j]);
    }
  return 0;
}



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

#define LL long long

#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) (((l)+(r))>>1)

const int MOD = (int) 1e9 + 7;
const double eps = (double) 1e-8;
const int maxn = (int) 2e5 + 20;


void work()
{
    int r, g, b, n;
    cin >>r >>g >>b >>n;

    int ans = 0;
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
        {
            int t = n - i * r - j * g;
            if(t >= 0 && t % b == 0)
            {
                ans++;
            }
        }

    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r" ,stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416

    int tc = 1;
//    scanf("%d", &tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main(){
  int n, W;
  cin >> n >> W;
  int w[n], v[n];
  int maxv = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
    maxv = max(maxv, v[i]);
  }
  ll dp[n + 1][n * maxv + 1] = {};
  fill(dp[0], dp[0] + n * maxv + 1, INF);
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n * maxv; j++) {
      if (j < v[i]) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
      }
    }
  }
  int res = 0;
  for (int i = 0; i <= n * maxv; i++) {
    if (dp[n][i] <= W) res = i;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 100001
#define ll long long
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N);
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}

vector<vector<int>> dp;
int func(string &a , string &b, int i , int j)
{
    if(i==a.size()||j==b.size())
    return 0;
    if(dp[i][j]!=-1)
    return dp[i][j];
    if(a[i]==b[j])
    return dp[i][j]=1+func(a,b,i+1,j+1);
    else
    return dp[i][j]=max(func(a,b,i+1,j),func(a,b,i,j+1));
}
void print(string &a, string &b,int n, int m)
{
    int i=0,j=0;
    while(i<n && j<m)
    {
        if(a[i]==b[j])
        cout<<a[i],i++,j++;
        else if(dp[i][j+1]>=dp[i+1][j])
        j++;
        else
        i++;
    }
}
void solve()
{
    int n,m;
    string a,b; cin>>a>>b;
    n=a.size(); m=b.size();
    dp.assign(n+1,vector<int> (m+1,-1));
    func(a,b,0,0);
    print(a,b,n,m);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 72832
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

// (B - A + 1) - (A以上B以下で、Cで割り切れる数の個数+Dで割り切れる数の個数-CかつDで割り切れる数の個数)
ll A, B, C, D;
ll f(ll x) {
  return B/x-(A-1)/x;
}
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b;}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> B >> C >> D;
  cout << B-A+1-(f(C)+f(D)-f(lcm(C,D))) << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        // input
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int K = sc.nextInt();

        String exc = S.substring(K-1, K);
        String ansS = "";

        for (int i = 0; i < N; i++) {
            if (S.charAt(i) != exc.charAt(0)) {
                ansS += "*";
            }
            else {
                ansS += S.substring(i, i + 1);
            }
        }

        System.out.println(ansS);
    }
}

Measured memory_bytes: 23508
import java.util.*;
public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int k= sc.nextInt();
		int s= sc.nextInt();
		int suces=0;
		for(int x=0;x<=k;x++) {
			for(int y=0;y<=k;y++) {
				int z=s-x-y;
				if(0<=z && z<=k) {
					suces=suces+1;
				}
			}
		}
		System.out.println(suces);

	}

}


Measured memory_bytes: 21972
import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=sc.next();
        if(a.charAt(0)==b.charAt(0)){
            System.out.println('H');
        }else{
            System.out.println('D');
        }
}
        
        
    }


Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	ll n,y;cin >> n >> y;
	
	REP(i,3000)
	{
		REP(j,5000)
		{
			if(10000*i+5000*j > y)continue;
			ll tmp = (y - (10000*i+5000*j))/1000;
			if(i+j+tmp == n)
			{
				cout << i << ' ' << j << ' ' << tmp << endl;
				return 0;
			}
		}
	}
	
	cout << -1 << ' ' << -1 << ' ' << -1 << endl;
	
	return 0;
}

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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

int n, m, k;
vector<vector<int>> adj, adj2;
vector<int> ans;

void bfs(int start)
{
	queue<int> Q;
	Q.push(start);
	set<int> component;
	component.insert(start);
	ans[start] = 0;
	int sz = 1;
	while (!Q.empty()) {
		int u = Q.front();
		Q.pop();
		for (auto v : adj[u]) {
			if (ans[v] == -1) {
				ans[v] = 0;
				component.insert(v);
				Q.push(v);
				sz++;
			}
		}
	}
	
	for (auto u : component) {
		int block = 0;
		for (auto v : adj2[u])
			if (component.find(v) != component.end())
				block++;
		ans[u] = sz - adj[u].size() - block - 1;
	}
}

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

	cin >> n >> m >> k;
	adj.resize(n);
	adj2.resize(n);
	ans.assign(n, -1);
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	for (int i = 0; i < k; ++i) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		adj2[u].pb(v);
		adj2[v].pb(u);
	}

	for (int i = 0; i < n; ++i) {
		if (ans[i] == -1)
			bfs(i);
	}
	for (int i = 0; i < n; ++i)
		cout << ans[i] << ' ';
	cout << endl;
}


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

int n;

int main() {
  cin >> n;
  bool ch = 0;
  int bf1 = 0, bf2 = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    x = x == y;
    if (bf1 && bf2 && x) ch = 1;
    bf2 = bf1;
    bf1 = x;
  }
  if (ch)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
 
int main() {
 
  int x = 1;
  int y = 1;
  int N, K;
   cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    x = x * 2;
    y = y + K;
    //cout << x << " " << y << endl;
    
   if (i < N - 1) {
    if (x <= y){
      y = x;
      //cout << y << endl;
    }
    
    else {
      x = y;
      //cout << x << endl;
    }
   }
    
    else {
      if (x <= y) {
        cout << x << endl;
      }
      
      else {
        cout << y << endl;
      }
    }
  }
      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> A(n);
    vector<int64_t> sum(n + 1, 0);
    vector<int> sign(n, 1);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        if (i < n - 1) {
            char c;
            cin >> c;
            sign[i + 1] = c == '-' ? -1: 1;
        }
        sum[i + 1] = sum[i] + A[i];
    }

    int prev = n;

    int64_t xsum = 0;
    for (int i = 0; i < n; ++i) {
        xsum += sign[i] * A[i];
    }
    int64_t ans = xsum;
    for (int i = n - 1; i >= 0; --i) {
        if (sign[i] == -1) {
            if (prev != n) {
                int64_t csum = xsum - (sum[prev] - sum[i + 1]) + sum[n] - sum[prev];
                ans = max(ans, csum);
            }
            prev = i;
        }
        xsum -= sign[i] * A[i];
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int sum = abs(a[0]);
  for (int i = 1; i < n; i++) {
    sum += abs(a[i] - a[i - 1]);
  }
  int diff[n + 1];
  diff[0] = a[0];
  for (int i = 1; i < n; i++) {
    diff[i] = a[i] - a[i - 1];
  }
  diff[n] = -a[n - 1];
  sum += abs(a[n - 1]);
  for (int i = 0; i < n - 1; i++) {
    if (diff[i] * diff[i + 1] < 0) {
      cout << sum - 2 * min(abs(diff[i]), abs(diff[i + 1])) << endl;
    } else {
      cout << sum << endl;
    }
  }
  if (diff[n - 2] >= 0 && diff[n - 1] >= 0 && diff[n] >= 0) {
    cout << sum << endl;
    return 0;
  }
  if (diff[n - 2] <= 0 && diff[n - 1] <= 0 && diff[n] <= 0) {
    cout << sum << endl;
    return 0;
  }
  if (diff[n - 1] * diff[n] < 0) {
  cout << sum - 2 * min(abs(diff[n - 1]), abs(diff[n])) << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
//#include "Header.h"

#define pi 3.14159265358979323846264

#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)

#define sp(n) setprecision(n)
#define d7 1000000007
#define mkp make_pair
#define mkt make_tuple

using namespace std;

bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}

ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++)
        {if (j == 0 || j == i) C[i][j] = 1;
            else C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);}}
    return C[n][k];
 }

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

ll srihrg(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}

ll kk=1;
void dfsi(vector<bool> &vis, vector<ll> adj1[], ll n, ll start, vector<ll> &pre, vector<ll> &pos){
    vis[start]=true;
    pre[start]=kk;kk++;
    for(ll i: adj1[start]){
        if(!vis[i]){
            vis[i]=true;
            dfsi(vis,adj1,n,i,pre,pos);
        }
    }
    pos[start]=kk;kk++;
}

void bfsi(vector<ll> &dis, vector<ll> adj[], ll s, vector<ll> &parent){
    dis[s]=-1;
    queue<ll> q;
    q.push(s);
    while(!q.empty()){
        ll z=q.front();
        q.pop();
        for(ll v:adj[z]){
            if(dis[v]==0){
            q.push(v);
            dis[v]=-dis[z];
                parent[v]=z;}
        }
    }
}

void make_set(ll v, vector<ll> &parent, vector<ll> &krank) {
    parent[v] = v;
    krank[v] = 0;
}

ll find_set(ll v,vector<ll> &parent, vector<ll> &krank) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v], parent, krank);
}

void union_sets(ll a, ll b,vector<ll> &parent, vector<ll> &krank) {
    a = find_set(a,parent,krank);
    b = find_set(b,parent,krank);
    if (a != b) {
        if (krank[a] < krank[b])
            swap(a, b);
        parent[b] = a;
        if (krank[a] == krank[b])
            krank[a]++;
    }
}

void dijkstra(ll s, vector<ll> &dist, vector<ll> &parent, ll n, vector<pair<ll,ll>> adj[]){
    dist[s]=0;
    vector<bool> u(n,false);
    fori(n){
        ll v=-1;
        forj(n){
            if(!u[j] &&(v==-1||(dist[j]<dist[v]))) v=j;
        }
        if(dist[v]==d7) break;
        u[v]=true;
        for(auto j:adj[v]){
            ll a,b;
            a=j.first;
            b=j.second;
            if(dist[v]+b<dist[a]){
                dist[a]=dist[v]+b;
                parent[a]=v;
            }
        }
    }
}


int main(int argc, const char * argv[]) {
 //cout<<"Om\n";
 //Praise to Lord
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
// code now
   
    ll n;
    cin>>n;
    ll sum=0;
    ll t=1;
    while(n!=0){
        sum+=t;
        n/=2;t=2*t;
    }
    cout<<sum;
    
//code ends
    return 0;
}


Measured memory_bytes: 256