akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

__int128 gcd(__int128 a,__int128 b){return (a==0 ? b : gcd(b%a,a));}

int main(){
  long long int n,m;
  cin>>n>>m;
  vector<long long int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int> p(n);
  for(int i=0;i<n;i++) cin>>p[i];
  
  auto val=[&](int comb){
    if(comb==0) return 0LL;
    __int128 res=1;
    for(int i=0;i<n;i++){
      if(comb&(1<<i)){
	res=(res*a[i]/gcd(res,a[i]));
	if(res>1e18+3){
	  return 0LL;
	}
      }
    }
    return static_cast<long long int>(m/res);
  };
  
  double res=0;
  for(int i=0;i<(1<<n);i++){
    int cnt=0;
    double pos=1;
    for(int j=0;j<n;j++){
      if(i & (1<<j)){
	pos*=double(p[j])/100;
	cnt++;
      }
    }
    res+=pos*val(i)*((cnt%2)*2-1);
  }
  cout<<fixed<<setprecision(10);
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };

int N = 1e3 + 7;


int main() {
	fastIO;
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == b && b != c) || (a == c && c != b) || (b == c && c != a)) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}

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

    string s;
    cin >> s;
    const int n = s.size();

    int total_sum = 0;
    for (int i = 0; i < (1 << n - 1); i++)
    {
        int now_sum = 0;
        int reg = s[0] - '0';
        for (int j = 0; j < n - 1; j++)
        {
            if (i & 1 << j)
            {
                now_sum += reg;
                reg = 0;
            }
            reg *= 10;
            reg += s[j + 1] - '0';
        }
        now_sum += reg;
        total_sum += now_sum;
    }
    cout << total_sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m],b[m],c[n];
    for(int i=0;i<n;i++) c[i]=0;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        for(int j=0;j<n;j++){
            if(a[i]==j+1) c[j]+=1;
            if(b[i]==j+1) c[j]+=1;
        }
    }
    for(int i=0;i<n;i++) cout<<c[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
#define LONGINF 1000000000000000000
int main(){
	int n;
	cin >> n;
	string ans_top_second, ans_top_first, ans_bot_first, ans_bot_second;
	string returnings;
	while (true) {
	rooped:;
		cout << ans_top_second + '.' << endl;
		cout << ans_bot_second + '.' << endl;
		cin >> returnings;
		if (returnings == "end") return 0;
		if (returnings == "T") {
			ans_top_second.push_back('.');
			ans_bot_second.push_back('.');
			goto rooped;
		}
		cout << ans_top_second + '#' << endl;
		cout << ans_bot_second + '.' << endl;
		cin >> returnings;
		if (returnings == "end") return 0;
		if (returnings == "T") {
			ans_top_second.push_back('#');
			ans_bot_second.push_back('.');
			goto rooped;
		}
		cout << ans_top_second + '#' << endl;
		cout << ans_bot_second + '#' << endl;
		cin >> returnings;
		if (returnings == "end") return 0;
		if (returnings == "T") {
			ans_top_second.push_back('#');
			ans_bot_second.push_back('#');
			goto rooped;
		}
		cout << ans_top_second + '.' << endl;
		cout << ans_bot_second + '#' << endl;
		cin >> returnings;
		if (returnings == "end") return 0;
		if (returnings == "T") {
			ans_top_second.push_back('.');
			ans_bot_second.push_back('#');
			goto rooped;
		}
		goto right_over;
	}
right_over:;
	while (true) {
	loool:;
		cout << '.' + ans_top_first + ans_top_second << endl;
		cout << '.' + ans_bot_first + ans_bot_second << endl;
		cin >> returnings;
		if (returnings == "end") return 0;
		if (returnings == "T") {
			ans_top_first.insert(0, ".");
			ans_bot_first.insert(0, ".");
			goto loool;
		}
		cout << '.' + ans_top_first + ans_top_second << endl;
		cout << '#' + ans_bot_first + ans_bot_second << endl;
		cin >> returnings;
		if (returnings == "end") return 0;
		if (returnings == "T") {
			ans_top_first.insert(0, ".");
			ans_bot_first.insert(0, "#");
			goto loool;
		}
		cout << '#' + ans_top_first + ans_top_second << endl;
		cout << '.' + ans_bot_first + ans_bot_second << endl;
		cin >> returnings;
		if (returnings == "end") return 0;
		if (returnings == "T") {
			ans_top_first.insert(0, "#");
			ans_bot_first.insert(0, ".");
			goto loool;
		}
		cout << '#' + ans_top_first + ans_top_second << endl;
		cout << '#' + ans_bot_first + ans_bot_second << endl;
		cin >> returnings;
		if (returnings == "end") return 0;
		if (returnings == "T") {
			ans_top_first.insert(0, "#");
			ans_bot_first.insert(0, "#");
			goto loool;
		}
	}
}


Measured memory_bytes: 596
import heapq
n, m = [int(item) for item in input().split()]
ab = []
for i in range(n):
    a, b = [int(item) for item in input().split()]
    ab.append([-a, b])
ab.sort(reverse = True)

st = []
newday = -1 
ans = 0
itr = 0
for day in range(1, m+1):
    if itr < n:
        while day == -ab[itr][0]:
            heapq.heappush(st, -ab[itr][1])
            itr += 1
            if itr >= n:
                break
    if not st:
        continue
    ans += heapq.heappop(st)
print(-ans)

Measured memory_bytes: 24168
import java.util.Scanner;

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

		long a = sc.nextLong();
		long v = sc.nextLong();
		long b = sc.nextLong();
		long w = sc.nextLong();
		long t = sc.nextLong();

		long ab = Math.abs(a - b);

		if (ab > (v - w) * t)
			System.out.println("NO");
		else
			System.out.println("YES");
	}

}


Measured memory_bytes: 35720
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  long long a, b, x;
  scanf("%lld", &a);
  scanf("%lld", &b);
  scanf("%lld", &x);
  long long ans = (b/x+1) - ((a>0)?((a-1)/x+1):0);
  printf("%lld\n", ans);
  return 0;
}


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

using namespace std;

vector<vector<pair<int, int>>> a(100001);
vector<int> ans(100001);

void dfs(int n, int p, long long t);

int main()
{
	int n;
	cin >> n;
	
	int u, v, w;
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v >> w;
		u--;
		v--;
		a[u].push_back(make_pair(v, w));
		a[v].push_back(make_pair(u, w));
	}
	
	dfs(0, 0, 0);

	for (int i = 0; i < n; i++) {
		cout << (ans[i] % 2 == 0 ? "0" : "1") << endl;
	}

	return 0;
}

void dfs(int n, int p, long long t)
{
	ans[n] = t;
	for (auto &u : a[n]) {
		if (u.first != p) {
			dfs(u.first, n, t + u.second);
		}
	}
}

Measured memory_bytes: 8448
using System;

class A
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

		var dp = new int[n + 1];
		dp[2] = Math.Abs(h[0] - h[1]);
		for (int i = 3; i <= n; i++)
			dp[i] = Math.Min(dp[i - 2] + Math.Abs(h[i - 3] - h[i - 1]), dp[i - 1] + Math.Abs(h[i - 2] - h[i - 1]));
		Console.WriteLine(dp[n]);
	}
}


Measured memory_bytes: 16864
#149_D
from itertools import groupby
n, k = map(int, input().split())
r, s, p = map(int, input().split())
point = {'s':r, 'p':s, 'r':p}
t = input()
ans = 0
for i in range(k):
    t_ = t[i::k]
    cnt = groupby(list(t_))
    for te, c in cnt:
        ans += point[te] * -(-len(list(c)) // 2)
print(ans)

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

int main(){
  int N; cin >> N;
  int A[100][2];
  for(int i=0; i<N; i++){
    cin >> A[i][0];
  }
  for(int i=0; i<N; i++){
    cin >> A[i][1];
  }
  int amemax=0,sum;
  for(int i=0; i<N; i++){
    sum=0;
    //A[0][0]～A[i][0]とA[i][1]～A[N-1][1]
    for(int j=0; j<N; j++){
      if(j<=i){
        sum+=A[j][0];
      }
      if(j>=i){
        sum+=A[j][1];
      }
    }
    amemax=max(amemax,sum);
  }
  cout << amemax << endl;
}

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

int main(){
    int r = 0;
    int a;
    cin >> a;
    if (a % 10 == 1) r++;
    if (a / 10 % 10 == 1) r++;
    if (a / 100 == 1) r++;
    cout << r;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int x, y;
    double c, t;
    scanf("%d%d", &x, &y);
    c=(4*x-y)/2.0;
    t=(y-2*x)/ 2.0;
    if(c>=0 && t >=0 && c-(int)c==0 && t-(int)t==0){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1732
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    string s;
    cin >> s;

    if (s.size() == 3) reverse(s.begin(), s.end());

    cout << s << endl;

}













































Measured memory_bytes: 256
#include<stdio.h>
#include <stdbool.h>
struct Card{
	char c;
	int a;
};

void bubble(struct Card A[],int N){
	for(int i=0;i<N-1;i++){
		for(int j=N-1;j>i;j--){
			if(A[j].a<A[j-1].a){
				Card t=A[j];
				A[j]=A[j-1];
				A[j-1]=t;
			}
		}
	}
}

void select(struct Card A[],int N){
	for(int i=0;i<N-1;i++){
		int k=i;
		for(int j=i+1;j<N;j++){
			if(A[j].a<A[k].a)	k=j;
		}
		if(k!=i){
			Card t=A[i];
			A[i]=A[k];
			A[k]=t;
		}
	}
}

bool stable(struct Card A[],struct Card B[],int N){
	for(int i=0;i<N;i++){
		if(A[i].c!=B[i].c) return false;
	}
	return true;
}

int main(){
	int i,n,j,k;
	Card c1[37],c2[37];
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++){
		scanf("%c%d",&c1[i].c,&c1[i].a);
		getchar();
		c2[i]=c1[i];
	}
	bubble(c1,n);
	select(c2,n);
	for(i=0;i<n;i++){
		printf("%c%d",c1[i].c,c1[i].a);
		if(i!=n-1) printf(" ");
	}
	printf("\nStable\n");
	for(i=0;i<n;i++){
		printf("%c%d",c2[i].c,c2[i].a);
		if(i!=n-1) printf(" ");
	}
	printf("\n");
	if(stable(c1,c2,n)){
		printf("Stable\n");
	}
	else printf("Not stable\n");
}


Measured memory_bytes: 2760
#include <stdio.h>

int main(void){
  int i = 0,retu = 0,result = 0,m = 0;
  char s[11];
  
  scanf("%s",s);
  
  while(s[i] != '\0'){
    retu = 0;
    m = i;
    while(s[m] != '\0'){
      if(s[m] == 'A' || s[m] == 'T' || s[m] == 'C' || s[m] == 'G'){
       retu++;
        if(result < retu){
         result = retu;
        }
      }else{
        break;
      }
      m++;
   }
    i++;
  }
  
  printf("%d\n",result);
  return 0;
}

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

using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
using ld = long double;
const ld EPS = 1e-9;
const ld PI = 3.141592653589793;
const int maxn = 2e5 + 1;
using pt = array<ld, 2>;

array<vector<int>, 3> dp[maxn];
int p[maxn];
vector<int> g[maxn];
int h[maxn];
int cnt[maxn];

ll mul(ll a, ll b) {
    return a * b % MOD;
}

int add(int a, int b) {
    a += b;
    if (a >= MOD) {
        a -= MOD;
    }
    return a;
}

void dfs(int v) {
//    cout << "DFS " << v << endl;
    for (int to:g[v]) {
        h[to] = h[v] + 1;
        cnt[h[to]]++;
        dfs(to);
    }
    int bg = -1;
    for (int to:g[v]) {
        if (bg == -1 || dp[to][0].size() > dp[bg][0].size()) {
            bg = to;
        }
    }
    if (bg != -1) {
        dp[v] = move(dp[bg]);
    }
    int mx = 0;
    int sz = dp[v][0].size() - 1;
    for (int to:g[v]) {
        if (to == bg) {
            continue;
        }
        mx = max<ll>(mx, dp[to][0].size());
        int cur_sz = dp[to][0].size() - 1;

        for (int e = 0; e < dp[to][0].size(); ++e) {
            ll one = add(mul(dp[to][0][cur_sz - e], dp[v][1][sz - e]), mul(dp[to][1][cur_sz - e], dp[v][0][sz - e]));
            ll two = add(mul(dp[v][2][sz - e], dp[to][1][cur_sz - e]), mul(dp[v][2][sz - e], dp[to][0][cur_sz - e]));
            two = add(two, mul(dp[v][1][sz - e], dp[to][1][cur_sz - e]));
            ll zero = mul(dp[to][0][cur_sz - e], dp[v][0][sz - e]);
            dp[v][0][sz - e] = zero;
            dp[v][1][sz - e] = one;
            dp[v][2][sz - e] = two;
        }
        for (int j = 0; j < 3; ++j) {
            dp[to][j].clear();
            dp[to][j].shrink_to_fit();
        }
    }
    for (int i = 0; i < mx; ++i) {
        dp[v][0][sz - i] = add(dp[v][0][sz - i], dp[v][2][sz - i]);
        dp[v][2][sz - i] = 0;
    }
    dp[v][0].push_back(1);
    dp[v][1].push_back(1);
    dp[v][2].push_back(0);
}

ll pw(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

int main() {
#ifdef zxc
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    freopen("green.in", "r", stdin);
    //    freopen("green.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(6);
    cout << fixed;
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        g[p[i]].push_back(i);
    }

    dfs(0);
    int mxh = dp[0][0].size() - 1;
    cnt[0]++;
    ll ans = 0;
    assert(dp[0][0].size() == dp[0][1].size());
    for (int i = 0; i < dp[0][1].size(); ++i) {
//        cout << i << " " << cnt[mxh - i] << endl;
        ans = add(ans, mul(dp[0][1][mxh - i], pw(2, n + 1 - cnt[i])));
    }
    cout << ans;
}

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

/* --------------- template start --------------- */
template <typename T> 
struct BinaryIndexTree { // [1, n]
    vector<T> array;
    int n;

    BinaryIndexTree(int _n) {
        array.resize(_n + 1, 0);
        n = _n;
    }

    T cumsum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i;
        }

        return s;
    }

    T sum(int i, int j) {
        T ret_i = cumsum(i - 1);
        T ret_j = cumsum(j);

        return ret_j - ret_i;
    }

    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

template<typename T>
struct UnionFind {
    vector<int> par;
    vector<T> sz;

    UnionFind(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }

    T size_of_tree(int x) {
        return sz[find_root(x)];
    }
};
/* --------------- template end --------------- */

/* --------------- function start --------------- */
llong my_gcd(llong a, llong b) {
    return (a ? my_gcd(b % a, a) : b);
}
llong my_lcm(llong a, llong b) {
    return a * b / my_gcd(a, b);    
}

llong facmod(llong n) {
    if (n == 0) return 1;

    llong res = n;
    for (int i = n - 1; i > 0; --i) {
        res = (res * i) % MOD;
    }

    return res;
}
llong powmod(llong a, llong n) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }

    return res;
}
llong modinv(llong n) {
    return powmod(n, MOD - 2);
}
llong combmod(llong n, llong k) {
    llong res = 1;
    for (int i = 0; i < k; ++i) {
        res = (res * (n - i)) % MOD;
    }
    res = (res * modinv(facmod(k))) % MOD;

    return res;
}
/* --------------- function end --------------- */

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong a, b, c;
    cin >> a >> b >> c;
    llong left = 4LL * a * b;
    llong right = (c - a - b) * (c - a - b);
    if (left < right) {
        if (c - a - b <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 384
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);
    static final String KEYENCE = "keyence";
    static int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        Prep[] P = new Prep[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i = 0; i < N; i++) {
            B[i] = sc.nextInt();
            int diff = A[i] - B[i];
            P[i] = new Prep(A[i], B[i], diff < 0 ? INF : diff);
        }
        
        Arrays.sort(P, (p1, p2) -> p1.d - p2.d);
        
        long sumA = sum(A);
        long sumB = sum(B);
        long sumDiff = sumA - sumB;
        if (sumDiff < 0) {
            so.println(-1);
            return;
        }
        
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (sumDiff < P[i].d) {
                break;
            }
            sumDiff -= P[i].d;
            ans++;
        }
        so.println(N - ans);
    }
    static long sum(int[] a) {
        return Arrays.stream(a).mapToLong(i -> i).sum();
    }
    
    static class Prep {
        int a;
        int b;
        int d;
        public Prep(int a, int b, int d) {
            this.a = a;
            this.b = b;
            this.d = d;
        }
        
        @Override
        public String toString() {
            return "(a: " + a + ", b: " + b + ", d: " + d + ")";
        }
    }
}


Measured memory_bytes: 88304
program prob1
    implicit none
    integer(8)::N, i, j, ans, candy
    integer, allocatable::A(:), B(:), Asum(:), Bsum(:)
    read(*,*) N
    allocate(A(N))
    allocate(B(N))
    allocate(Asum(N))
    allocate(Bsum(N))
    read(*,*) A
    read(*,*) B
    Asum(1) = A(1)
    Bsum(1) = B(1)
    ans = sum(B) + A(1)

    if(N == 1) then
        write(*,*) ans
    else
        do i = 2, N
            Asum(i) = Asum(i-1) + A(i)
            Bsum(i) = Bsum(i-1) + B(i)
        end do

        do i = 2, N
            candy = Asum(i) + sum(B) - Bsum(i-1)
            if(candy > ans) then
                ans = candy
            end if
        end do
        write(*,*) ans
    end if

    deallocate(A)
    deallocate(B)
    deallocate(Asum)
    deallocate(Bsum)
    stop
end program prob1

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

#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 

#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

const int N =1e5+5;

int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};

void solve(){
int n;
cin>>n;

int nl=n-1;
int tt=nl*(nl+1)/2;

cout<<tt<<endl;
}

int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
		solve();


	return 0;	  
}

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

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

  int sum = 0;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    sum += num;
  }

  cout << (sum % 2 == 0 ? "YES" : "NO") << endl;
  return 0;
}

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

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

    long long ans=0,tmp=0;
    for(int i=0; i<N; ++i){
        tmp = max(tmp, A[i]);
        ans += tmp - A[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4840
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

bool compare_P(pair<string, int> a, pair<string, int> b) {
	if (a.first == b.first) {
		return a.second > b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {
	int N; cin >> N;
	vector<pair<string, int>> p1(N);
	vector<pair<string, int>> p2(N);
	for (int i = 0; i < N; i++) {
		string S; int P; cin >> S >> P;
		p1.at(i) = make_pair(S, P);
		p2.at(i) = make_pair(S, P);
	}

	sort(p1.begin(), p1.end(), compare_P);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (p1[i].first == p2[j].first && p1[i].second == p2[j].second) {
				cout << j + 1 << endl;
			}
		}
	}
}

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

int main()
{
  int N;cin>>N;
  tuple<int,int,int> txy[N];
  for(int t,x,y,i=0;i<N;i++)
  {
    cin>>t>>x>>y;
    txy[i]={t,x,y};
    if(x+y>t||(t-x-y)%2==1){cout<<"No"<<endl;return 0;}
    if(i>0)if(t-get<0>(txy[i-1])<abs(x-get<1>(txy[i-1]))+abs(y-get<2>(txy[i-1]))||(t-get<0>(txy[i-1])-abs(x-get<1>(txy[i-1]))-abs(y-get<2>(txy[i-1])))%2==1){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
}

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

const ll mod=1e9+7;
int main()
{

    int n;
    cin>>n;
    vector<ll>dp(n+1,0);
    ll sum=0;
    for(int i=3;i<=n;i++)
    {
        dp[i]=(dp[i-3]+1)%mod;
        sum=dp[i];
        dp[i]=(dp[i-1]+dp[i])%mod;
        
    }
    cout<<sum<<endl;




    return 0;

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 200005

int N,M,K,num_query;
int O[45],X[10005];
bool secret_table[SIZE],can_make[SIZE];
bool dp[45][SIZE],without[45][SIZE];


int main(){

	scanf("%d %d %d %d",&N,&M,&K,&num_query);

	scanf("%d",&O[0]);
	int tmp_sum = O[0];
	int secret_max = O[0]-1;

	for(int i = 1; i < N; i++){

		scanf("%d",&O[i]);
		tmp_sum += O[i];
	}

	for(int i = 0; i < num_query; i++){

		scanf("%d",&X[i]);
	}

	int secret_total = K-tmp_sum;
	if(secret_max == 0 && M > 0){ //制約に反する

		for(int i = 0; i < num_query; i++){
			printf("-1\n");
		}
		return 0;
	}

	for(int i = 0; i <= N; i++){
		for(int sum = 0; sum <= K; sum++){

			dp[i][sum] = false; //dp[openを何個目まで見たか][合計] = 作れるかどうか
		}
	}


	//secret集合で数iが作れるか
	for(int i = 0; i <= secret_total; i++){

		secret_table[i] = false;
	}

	//数iを作れるかどうか
	for(int i = 0; i <= K; i++){

		can_make[i] = false;
	}

	if(secret_max == 0){ //M == 0

		secret_table[0] = true;
		can_make[0] = true;
		dp[0][0] = true;

	}else{

		//secret集合で部分和を作れるか調べる
		for(int S = 0; S <= secret_total; S++){

			int tmp = S/secret_max;
			if(S%secret_max != 0){

				tmp++;
			}
			if(secret_max*(M-tmp)+S >= secret_total){

				secret_table[S] = true;
				can_make[S] = true;
				dp[0][S] = true;
			}
		}
	}

	//作れる数を調べる
	for(int i = 1; i <= N; i++){
		for(int pre_sum = 0; pre_sum <= K; pre_sum++){
			if(!dp[i-1][pre_sum])continue;

			dp[i][pre_sum] = true; //O[i-1]を使わない

			if(pre_sum+O[i-1] <= K){
				dp[i][pre_sum+O[i-1]] = true;
				can_make[pre_sum+O[i-1]] = true;
			}
		}
	}

	//O[i-1]を使わずにsumが作れるか調べる
	for(int i = 0; i <= N; i++){
		for(int sum = 0; sum <= K; sum++){

			without[i][sum] = false; //sumが作れるならtrue
		}
	}

	for(int dont_use = 1; dont_use <= N; dont_use++){
		for(int i = 0; i <= N; i++){
			for(int sum = 0; sum <= K; sum++){

				dp[i][sum] = false;
			}
		}
		//secretの結果を反映
		for(int i = 0; i <= secret_total; i++){

			dp[0][i] = secret_table[i];
			without[dont_use][i] = secret_table[i];
		}

		for(int i = 1; i <= N; i++){
			for(int pre_sum = 0; pre_sum <= K; pre_sum++){
				if(!dp[i-1][pre_sum])continue;

				dp[i][pre_sum] = true; //O[i-1]を使わない

				if(i == dont_use)continue;

				if(pre_sum+O[i-1] <= K){

					dp[i][pre_sum+O[i-1]] = true;
					without[dont_use][pre_sum+O[i-1]] = true;
				}
			}
		}
	}

	vector<int> V;

	for(int loop = 0; loop < num_query; loop++){

		if(!can_make[X[loop]]){

			printf("-1\n");
			continue;
		}

		V.clear();

		for(int i = 1; i <= N; i++){

			if(!without[i][X[loop]]){

				V.push_back(i);
			}
		}

		if(V.size() == 0){

			printf("-1\n");
			continue;
		}

		printf("%d",V[0]);
		for(int i = 1; i < V.size(); i++){

			printf(" %d",V[i]);
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 19532
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n);
    map<ll,ll> mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    ll ans=0;
    ll mx;
    priority_queue<ll> que;
    sort(all(a),greater<ll>());
    que.push(a[0]);
    ll c=0;
    for(ll i=1;i<n;i++){
        ll v=que.top();
        ans+=que.top();
        if(a[i]<que.top()){
            que.pop();
            que.push(a[i]);
            que.push(a[i]);
        }else{
            que.push(a[i]);
        }
        //que.pop();
        
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 19388
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n,m;
    cin>>n>>m;
    vector<pll> seito,check;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        seito.push_back({a,b});
    }
    for(int i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        check.push_back({a,b});
    }
    vector<vector<pll>> where(seito.size());
    for(int i=0;i<seito.size();i++){
        for(int t=0;t<check.size();t++){
            ll dist=abs(seito[i].F-check[t].F)+abs(seito[i].S-check[t].S);
            where[i].push_back({dist,t+1});
        }
        sort(where[i].begin(),where[i].end());
    }
    for(int i=0;i<where.size();i++){
        cout<<where[i][0].S<<endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int n, sum=0;
    cin >> n;
    vector<int> s_z;
    for(int i=0; i<n; i++){
        int s;
        cin >> s;
        sum+=s;
        if(s%10!=0) s_z.push_back(s);
    }
    if(sum%10!=0) cout << sum << endl;
    else{
        if(s_z.empty()) cout << 0 << endl;
        else{
            sort(s_z.begin(), s_z.end());
            cout << sum-s_z[0] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
	int a=0,b=0,c=0,i;
	char s[4];
	scanf("%s",s);
	for(i=0;i<3;i++){
		if(s[i]=='a') a=1;
		if(s[i]=='b') b=1;
		if(s[i]=='c') c=1;
	}
	if(a&&b&&c){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int N=500000;
int n,k,f[N+10];
char s[N+10],ans[N+10];
int Calc(int x) {
    x++;
    if (x<=n) return f[x]+x-1;
    if (n%2) return f[n]+x*2-n-1;
    return f[n]+x-1;
}
void work(int x) {
    x++;
    for (int i=1;i<=n;i++) {
	int kx=x+i-1;
	if (kx<=n) {
	    if (x%2) ans[i]=s[kx];
	    else {
		if (s[kx]=='A') ans[i]='B';
		else ans[i]='A';
	    }
	}
	else {
	    if ((n-i+1)%2) ans[i]='A';
	    else ans[i]='B';
	}
    }
    ans[1]='B';
}
void work2() {
    for (int i=1;i<n;i++)
	if (ans[i+1]=='A') ans[i]='B';
	else ans[i]='A';
    ans[n]='A';
}
int main() {
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    for (int i=1;i<=n;i++) {
	f[i]=f[i-1];
	if (s[i]=='A'&&i%2) f[i]++;
	if (s[i]=='B'&&i%2==0) f[i]++;
    }
    int l=0,r=k;
    while (l<r) {
	int mid=(l+r+1)/2;
	int now=Calc(mid);
	if (now<=k) l=mid;
	else r=mid-1;
    }
    int nowx=Calc(l);
    work(l);
    if (nowx!=k) work2();
    for (int i=1;i<=n;i++) putchar(ans[i]);
    putchar('\n');
    return 0;
}


Measured memory_bytes: 1664
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,M,P = LI()

import collections

class BellmanFord():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.e = collections.defaultdict(list)
    def add(self,u,v,d,directed = False):
        if directed is False:  # 無向グラフの場合
            self.e[u].append((v,d))
            self.e[v].append((u,d))
        else:  # 有向グラフの場合
            self.e[u].append((v,d))
    def BellmanFord_search(self,s):  # sから各点までの最短距離
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        while True:
            update = False
            for u in self.e.keys():
                for v,c in self.e[u]:
                    if d[v] > d[u] + c:
                        d[v] = d[u] + c
                        update = True
            if not update:
                break
        return d
    def BellmanFord_negative_bool(self,s):  # sから辿り着ける負の閉路が存在するか
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        for i in range(self.N):
            for u in self.e.keys():
                for v,c in self.e[u]:
                    if d[v] > d[u] + c:
                        if i != self.N - 1:
                            d[v] = d[u] + c
                        else:
                            d[v] = -float('inf')
                            for i in range(self.N):
                                for u in self.e.keys():
                                    for v, c in self.e[u]:
                                        if d[v] > d[u] + c:
                                            d[v] = d[u] + c
                            if d[N] == -float('inf'):
                                return True, d
                            else:
                                return False, d
        return False,d

G = BellmanFord(N)

for i in range(M):
    a,b,c = LI()
    G.add(a,b,P-c,directed=True)

a,d = G.BellmanFord_negative_bool(1)

if not a:
    print(max(0,-d[N]))
else:
    print(-1)

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

int main(){
    int n,k;
    cin >> n >> k;
    long long h[n];
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    sort(h,h+n);
    long long ans = 0;
    for(int i=0; i<n-k; i++){
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	while(true)
	{
		c-=b;
		if(c<=0)
		{
			cout<<"Yes";
			break;
		}
		a-=d;
		if(a<=0)
		{
			cout<<"No";
			break;
		}
	}
}

Measured memory_bytes: 3604
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        s: [Chars; n]
    }
    let (mut m, mut a, mut r, mut c, mut h) = (0, 0, 0, 0, 0);
    for i in 0..n {
        if s[i][0] == 'M' {
            m += 1
        }
        if s[i][0] == 'A' {
            a += 1
        }
        if s[i][0] == 'R' {
            r += 1;
        }
        if s[i][0] == 'C' {
            c += 1;
        }
        if s[i][0] == 'H' {
            h += 1;
        }
    }
    let d = vec![m, a, r, c, h];
    let p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2];
    let q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3];
    let t = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4];
    let mut ans: u128 = 0;
    for i in 0..10 {
        ans += d[p[i]] * d[q[i]] * d[t[i]];
    }
    println!("{}", ans);
}


Measured memory_bytes: 10456
// vim:ts=4:sts=4:sw=4:et
// MOSCOW IPT JINOTEGA
// Table #14
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef long long i64;

string s;
ll n;

void read() {
    cin >> s;
}

void kill() {
    n = s.length();
    ll ans = 0;
    map<char, int> cnt;
    for (char c : s)
        cnt[c]++;
    for (auto e : cnt)
        ans += e.second * (n - e.second);
    ans /= 2;
    ++ans;
    cout << ans << "\n";
}

int main() {
#ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
#endif
    //ios_base::sync_with_stdio(false);

    read();
    kill();

    return 0;
}



Measured memory_bytes: 640
import glob
import os

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        N = int(self.input_data())
        A = list(map(int, self.input_data().split()))

        a_len = len(A)
        max = A[0]
        result = 0
        for i in range(1, a_len):
            if A[i] < max:
                result += (max - A[i])
            else:
                max = A[i]
        print(str(result))

solver = Solver(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 33776
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for _ in range(q)]

ac = [0]*(n+1)

for i in range(1,n+1):
  if s[i-1:i+2-1]=='AC':  
    ac[i]=ac[i-1] + 1
  else:
    ac[i]=ac[i-1]
    
for l,r in lr:
  print(ac[r-1]-ac[l-1])    

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

using namespace std;

int main(void)
{
    int N, K;
    string S;

    cin >> N >> K;
    cin >> S;

    if(S[K-1] == 'A'){
        S[K-1] = 'a';
    }

    else if(S[K-1] == 'B'){
        S[K-1] = 'b';
    }

    else{
        S[K-1] = 'c';
    }

    cout << S << endl;

    return 0;
}

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

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

  for(int i; i < (int)s.length(); i++){
    if(s[i] == '+')
      output++;
    else
      output--;
  }
  
  cout << output << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long a, b;
    cin >> a >> b;
    bitset<32> bit_a(a), bit_b(b);
    cout << (bit_a & bit_b) << endl;
    cout << (bit_a | bit_b) << endl;
    cout << (bit_a ^ bit_b) << endl;
}


Measured memory_bytes: 3152
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for (ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VLL               vector<vector<ll>>
#define VLLL              vector<vector<vector<ll>>>
#define INF               2e9;
#define INF_LL            1LL<<60;
#define MOD               1000000007;

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 処理
void Solve()
{
	ll N;
	cin >> N;
	vector<ll> A(N);
	for (auto i : irange<ll>(0, N, 1)) { 
		cin >> A[i];
	};
	sort(ALL(A));

	ll idx = 0;
	ll sum = A[0];
	vector<P> ans(N - 1);
	REPN(i, 1, A.size() - 1) {
		if (0 <= A[i]) {
			ans[idx++] = { sum, A[i] };
			sum -= A[i];
		}
	}

	ans[idx++] = { A.back(), sum };
	sum = A.back() - sum;

	REPN(i, 1, A.size() - 1) {
		if (0 > A[i]) {
			ans[idx++] = { sum, A[i] };
			sum -= A[i];
		}
	}

	cout << sum << endl;
	for (auto &one : ans) {
		cout << one.first << " " << one.second << endl;
	}
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 1e5 + 5;
int n , mod = 1e9 + 7;
int black[N] , white[N];
vector < int > g[N];

void DFS(int i , int j)
{
    black[i] = white[i] = 1;
    REP(s , g[i].size())
    {
        int u = g[i][s];
        if(u != j)
        {
            DFS(u , i);
            black[i] = (black[i] * white[u]) % mod;
            white[i] = (white[i] * (black[u] + white[u])) % mod;
        }
    }
}

main()
{
    //freopen("P.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    FOR(i , 1 , n - 1)
    {
        int u , v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    DFS(1 , -1);
    cout << (black[1] + white[1]) % mod;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	unordered_map<string, ll> mp1, mp2, mp3, mp4, mp5;
	FOR(i, n) {
		string s;
		cin >> s;
		char c = s.front();
		if (c=='M') mp1[s]++;
		else if (c=='A') mp2[s]++;
		else if (c=='R') mp3[s]++;
		else if (c=='C') mp4[s]++;
		else if (c=='H') mp5[s]++;
	}
	ll cnt[5];
	cnt[0]=mp1.size();
	cnt[1]=mp2.size();
	cnt[2]=mp3.size();
	cnt[3]=mp4.size();
	cnt[4]=mp5.size();
	ll ans = 0;
	FOR(i, 5) {
		for (int j = i+1; j < 5; j++) {
			for (int k = j+1; k < 5; k++) ans += cnt[i]*cnt[j]*cnt[k];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10880
#include<stdio.h>
#include<string.h>

int main(){
	char str[1001];
	scanf("%s",str);
	int len=strlen(str);
	int total=0;
	int spc=0;
	for(int i=0;i<len;i++){
		if(str[i]=='R'){
			total+=90;
		}else{
			total-=90;
		}
		if(total==360){
			spc++;
			total=0;
		}else if(total==-360) total=0;
	}
	printf("%d\n",spc);
	return 0;
}


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

def cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

print(cf(A,B)[-(K)])

Measured memory_bytes: 9088
S = input()
T = input()

max_match = 0

n = len(T)
m = len(S)

for i in range(m-n+1):
    tmp = 0
    for j in range(i,i+n):
        if S[j] == T[j-i]:
            tmp += 1
    if tmp > max_match:
        max_match = tmp

ans = n - max_match



print(ans)

Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}

int main(){
    int n;cin >> n;
    vector<int> d(n);
    vector<LL> k(n+1,0);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
        k[d[i]]++;
    }
    if(d[0]!=0||k[0]!=1){
        cout << 0 << endl;
        return 0;
    }
    LL ans = 1;
    bool f = false;
    for (int i = 1; i < n; i++) {
        if(f&&k[i]){
            cout<<0<< endl;
            return 0;
        }
        if(k[i]==0){
            f = true;
            continue;
        }
        ans = (ans * fpow(k[i-1],k[i]))%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 500009
ll n,m,i,j,k,l,t[4*sz],arr[sz],brr[sz],crr[sz],ans,hi,lo,mi,tt;
vector<pair<ll,ll> >v[sz];
void update(ll node,ll l,ll r,ll ind)
{
    if(ind<l || ind>r)
        return;
    if(l==r)
    {
        t[node]^=1;
        return;
    }
    ll mid=(l+r)/2;
    if(ind<=mid)
    update(2*node,l,mid,ind);
    else
    update(2*node+1,mid+1,r,ind);
    t[node]=t[2*node]+t[2*node+1];
    return;
}
ll query(ll node,ll l,ll r,ll le,ll ri)
{
    if(l>r || le>ri || le>r || ri<l)
        return 0;
    if(le<=l&& ri>=r)
    {
       return t[node];
    }
    ll mid=(l+r)/2;
    return query(2*node,l,mid,le,ri)+query(2*node+1,mid+1,r,le,ri);
}
int main()
{
    scanf("%lld %lld",&n,&m);
    for(i=1;i<=n;i++)
        scanf("%lld",&arr[i]);
    for(i=1;i<=m;i++)
    {
        scanf("%lld %lld",&j,&k);
        v[k].push_back({j,i});
    }
    for(i=1;i<=n;i++)
    {
        k=arr[i];
        if(brr[k]>0)
        {
            update(1,1,n,brr[k]);
        }
        update(1,1,n,i);
        brr[k]=i;
        while(!v[i].empty())
        {
            k=v[i].back().first;
            j=v[i].back().second;
            tt=query(1,1,n,k,i);
            v[i].pop_back();
            crr[j]=tt;
        }
    }
    for(i=1;i<=m;i++)
        printf("%lld\n",crr[i]);
}


Measured memory_bytes: 48496
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import functools
N = int(input())
x = [int(i) for i in input().split()]
mod = 10**9+7
start = 1
st = 1
st_list = [0] * N
st_rev = [0] * N
for i in range(N-1):
    st *= (i+1)
    st %= mod
    st_list[i] = st
    st_rev[i] = pow(st,mod-2,mod)
all_dis = 0
for i in range(N-1):
    far = x[i+1]-x[i]
    all_dis += far*start*st_list[N-2]*st_rev[i]
    start = (start*(i+2)+st_list[i])%mod
    all_dis %= mod
print(all_dis)

Measured memory_bytes: 89196