akhauriyash/Code-Regression huggingface dataset:
N, x = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

ans = 0

1.upto(N-1) do |i|
  tmp = a[i-1] + a[i]
  if tmp > x
    ans += [tmp - x, a[i]].min
    a[i] -= [tmp - x, a[i]].min
  end

  # 右を減らしても、まだ大きい場合は左を減らす
  if a[i-1] > x
    ans += a[i-1] - x
    a[i-1] -= a[i-1] - x
  end
end

p ans


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

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)

using namespace std;

const int inf = (int)1e9 + 7;
const int N = (int)2e6 + 7;

int n,m,q;
int l,r;
pair<int,int> a[N];
int nn;

vector <int> t[N * 4];

void build (int v = 1,int tl = 1,int tr = nn) {
      if (tl == tr)
            t[v].pb(a[tl].sc);
      else {
            int tm = (tl + tr) >> 1;
            build (v + v,tl,tm);
            build (v + v + 1,tm + 1,tr);
            merge(t[v + v].begin(),t[v + v].end(),t[v + v + 1].begin(),t[v + v + 1].end(),back_inserter(t[v]));
      }
}
int get (int l,int r,int val,int v = 1,int tl = 1,int tr = nn) {
      if (tl > r || tr < l) return 0;
      if (l <= tl && tr <= r) {
            int pos = upper_bound(t[v].begin(),t[v].end(),val) - t[v].begin();
            return pos;
      }
      int tm = (tl + tr) >> 1;
      return get(l,r,val,v + v,tl,tm) + get(l,r,val,v + v + 1,tm + 1,tr);
}
main () {
      cin >> n >> m >> q;

      for (int i = 1; i <= m; i ++) {
            cin >> l >> r;
            a[++nn] = mk(l,r);
      }
      a[++nn] = mk(inf,inf);
      sort (a + 1,a + nn + 1);

      build ();

      while (q --) {
            cin >> l >> r;

            int pos = lower_bound(a + 1,a + nn + 1,mk(l,0)) - a;
            int pos1 = upper_bound(a + 1,a + nn + 1,mk(r,n)) - a;
            pos1 --;
            cout << get(pos,pos1,r) << endl;
      }
}


Measured memory_bytes: 218612
#include<iostream>
#include<stdio.h>

using namespace std;

string X;
int main () {
    cin >> X;
    int l = X.size();
    int d = 0;
    int cnt = 0;
    for(int i=0; i<l; i++) {
        if( X[i] == 'S' ) cnt++;
        if( X[i] == 'T') {
            if( cnt ) {
                cnt = max( 0, cnt-1);
                d += 2;
                }
        }
    }
    cout << l - d<< endl;
    return 0;
}


Measured memory_bytes: 640
N,M = map(int,input().split())
INF = 10**10
AB = []
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
AB.sort()
count = 0
count_money=0
for i in range(N):
    if count==M:
        break
    if count+AB[i][1]>M:
        count_money += (AB[i][0]*(M-count))
        count = M
    else:
        count += AB[i][1]
        count_money += AB[i][0]*AB[i][1]
print(count_money)

Measured memory_bytes: 20072
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BCountBalls solver = new BCountBalls();
        solver.solve(1, in, out);
        out.close();
    }

    static class BCountBalls {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long a = in.nextLong();
            long b = in.nextLong();

            long are = n / (a + b);
            long mod = n % (a + b);
            long amari = Math.min(mod, a);

            out.println(are * a + amari);


        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        private byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            byte b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 23636
import java.util.*;

public class Main {
    private static final int N_MAX = 1000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] in = sc.next().chars().map(i -> i -'0').toArray(); int n = in.length;
        long ans = 0;
        for (int i=0; i<(1<<n-1); i++) {
            long last = in[0];
            for (int j=1; j<n; j++) {
                if (((i>>(j-1) & 1) == 1)) {
                    ans += last;
                    last = 0;
                }
                last = 10 * last + in[j];
            }
            ans += last;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 28364
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }

    ll ok(ll mid , vector<ll>& a){
        int n=a.size();
        ll ans=0;
        for(int i=0;i<n;i++){
            ans+=(ll)(mid^a[i]);
        }
        return ans;
    }
 
    void solve (){
        string s;
        cin>>s;
        if(s.back()=='s'){
            s+=("es");
        }
        else{
            s+=("s");
        }
        cout<<s;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const int N = 51;
const int M = 2500;
ll c[N], d[N], a[N][N], b[N][N];
vector<v32> adj(N, v32());
int vis[N][M];
ll dp[N][M];

void solve()
{
	ll n, m, s;
	cin >> n >> m >> s;
	ll mx = 0;
	for (int i = 0; i < m; i++)
	{
		ll u, v, ai, bi;
		cin >> u >> v >> ai >> bi;
		adj[u].push_back(v);
		adj[v].push_back(u);
		a[u][v] = a[v][u] = ai;
		b[u][v] = b[v][u] = bi;
		mx = max(mx, ai);
	}
	s = min(s, (ll)M);
	for (int i = 1; i < n + 1; i++)
		cin >> c[i] >> d[i];
	priority_queue<pair<ll, p64>, vector<pair<ll, p64>>, greater<pair<ll, p64>>> Q;
	for (int i = 1; i < n + 1; i++)
		for (int j = 0; j < M; j++)
			dp[i][j] = 1e18, vis[i][j] = 0;
	Q.push({0, {s, 1}});
	while (sz(Q))
	{
		ll u = Q.top().se.se, lambda = Q.top().se.fi, tym = Q.top().fi;
		Q.pop();
		if (vis[u][lambda])
			continue;
		vis[u][lambda] = 1;
		for (int v : adj[u])
		{
			ll tmp_tym = tym + b[u][v];
			if (lambda >= a[u][v] && tmp_tym < dp[v][lambda - a[u][v]])
			{
				dp[v][lambda - a[u][v]] = tmp_tym;
				Q.push({dp[v][lambda - a[u][v]], {lambda - a[u][v], v}});
			}
		}
		if (dp[u][min((ll)M - 1, lambda + c[u])] > tym + d[u])
		{
			Q.push({tym + d[u], {min((ll)M - 1, lambda + c[u]), u}});
			dp[u][min((ll)M - 1, lambda + c[u])] = tym + d[u];
		}
	}
	for (int i = 2; i < n + 1; i++)
	{
		ll mn = 1e18;
		for (int j = 0; j < 2500; j++)
			mn = min(mn, dp[i][j]);
		cout << mn << ln;
	}
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 7740
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	sort(A.begin(), A.end());
	vector<pair<int, int>> xy;
	for (int i = 1; i < N - 1; ++i) {
		if (A[i] > 0) {
			xy.emplace_back( A[0], A[i] );
			A[0] -= A[i];
		} else {
			xy.emplace_back( A.back(), A[i] );
			A.back() -= A[i];
		}
	}
	cout << A.back() - A[0] << "\n";
	for (auto p : xy) {
		cout << p.first << " " << p.second << "\n";
	}
	cout << A.back() << " " << A[0] << "\n";

	return 0;
}


Measured memory_bytes: 4712
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
typedef long long ll;
typedef long double ld;
#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;



int main(){
    string S,T;
    cin >>S>>T;
    cout <<T<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main() {
	int a, b, ab, i, xb;
	double j;

	cin >> a >> b;

	xb = b;
	a *= 10;

	while (xb/10 > 0) {
		a *= 10;
		xb /= 10;
	}

	ab = a + b;

	i = j = sqrt((double)ab);
	
	if (i == j)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  string s;
  string ans = "Heisei";
  cin >> s;
  int m = s[6] - '0';

  if(s[5] == '1') ans = "TBD";
  else if(m > 4) ans = "TBD";

  cout << ans << endl;
  
}


Measured memory_bytes: 256
//shara's here
#include<bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
int main(){
    //costs A, has B, at most C
    s ss;
    cin>>ss;
    if(ss<="2019/04/30"){cout<<"Heisei";}else{cout<<"TBD";}
return 0;}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
const int N=105;
int ab[N][N],u[N],nx[N],n;
bool f(int q)
{
    for(int i=1;i<=n;i++)
    {
        if(ab[q][i]&&u[i]==0)
        {
            u[i]=1;
            if(nx[i]==0||f(nx[i]))
            {
                nx[i]=q;
                return true;
            }
        }
    }
    return false;
}
int main()
{
    cin>>n;
    int a[n+2][2],b[n+2][2];
    for(int i=1;i<=n;i++)
        cin>>a[i][0]>>a[i][1];
    for(int i=1;i<=n;i++)
        cin>>b[i][0]>>b[i][1];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        if(a[i][0]<b[j][0]&&a[i][1]<b[j][1])ab[i][j]=1;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        memset(u,0,sizeof(u));
        if(f(i))sum++;
    }
    cout<<sum;
    return 0;
}


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

using namespace std;
int main()
{
	string a;
	cin >> a;
	string b;
	cin >> b;
	
	if (a.size() > b.size())
		cout << "GREATER" << endl;
	else if (a.size() < b.size())
	    cout << "LESS" << endl;
	else if (a > b)
		cout << "GREATER" << endl;
	else if (a < b)
		cout << "LESS" << endl;
	else
		cout << "EQUAL" << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		Map<String, Integer> map = new HashMap<String, Integer>();
		Set<String> set = new HashSet<String>();
		String[] kanc = new String[38];
		for (int i = 0; i < 26; i++) {
			kanc[i] = Character.toString((char) ('a' + i));
		}
		// "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", and
		// "ts".
		kanc[26] = "ld";
		kanc[27] = "mb";
		kanc[28] = "mp";
		kanc[29] = "nc";
		kanc[30] = "nd";
		kanc[31] = "ng";
		kanc[32] = "nt";
		kanc[33] = "nw";
		kanc[34] = "ps";
		kanc[35] = "qu";
		kanc[36] = "cw";
		kanc[37] = "ts";
		for (int i = 0; i < 38; i++) {
			map.put(kanc[i], i);
		}

		while (sc.hasNext()) {
			int n = sc.nextInt();
			sc.nextLine();
			int[][] count = new int[38][38];
			// count[i][j] : j番目の韓文字の前に出現するi番目の韓文字の数
			while (n != 0) {
				String[] ws = sc.nextLine().split(" ");
				for (int i = 0; i < ws.length; i++) {
					String[] cs = ws[i].split("");
					int k = 0;
					String str = "";
					String pre = "";
					while (true) {
						if (k == cs.length) {
							if (!pre.equals("")&&!str.equals(""))
								count[map.get(pre)][map.get(str)]++;
							break;
						}
						if (map.containsKey(str + cs[k])) {
							str += cs[k];
						} else {
							if (!pre.equals("")) {
								count[map.get(pre)][map.get(str)]++;
							}
							pre = str;
							str = cs[k];
						}
						k++;
					}
				}
				n--;
			}
			for (int i = 0; i < 38; i++) {
				int max = 0;
				int index = 0;
				for (int j = 0; j < 38; j++) {
					if (max < count[i][j]) {
						max = count[i][j];
						index = j;
					}
				}
				String fst = kanc[i];
				String snd = max == 0 ? "a" : kanc[index];
				int thd = max;
				System.out.println(fst + " " + snd + " " + thd);
			}
		}
	}
}

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

int main(void) {
	int num,op;
  cin>>num;
  vector<int> vec(num,0);
  for(int i=0;i<num-1;i++){
    cin>>op;
    vec.at(op-1)+=1;
  }
  for(int i=0;i<num;i++){
    cout<<vec.at(i)<<endl;
  }
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
const int INF = (int) 1e9;
#define REP(i,m,n) for(int i = m; i < (int)(n); ++i)
#define rep(i,n) REP(i, 0, n)

class SegmentTree {
public:
    int N; //要素数
    vector<int> dat;

    SegmentTree(int n_) {
        N = 1;
        while (N < n_) N *= 2;
        dat.assign(2 * N - 1, 0);
    }

    void update(int k, int a) { //k番目(0-indexed)をaに変更
        k += N - 1; //一番下
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2; //1つ上がる
            //更新
            dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
        }
    }

    //[a, b)の値（最小値/和/etc.）を求める
    //kは節点の番号、l, rはその節点が[l,r)に対応づいていることを表す
    //外からはquery(a, b, 0, 0, N)と呼ぶ

    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = N;
        if (r <= a || b <= l) return 0;
        //[a, b)が[l,r)を完全に含む
        if (a <= l && r <= b) return dat[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return vl + vr;
        }
    }
};

void make_primes(set<int> &primes, int s = 100010) {

    for (int i = 2; i <= s; ++i) {
        bool is_prime = true;
        for (auto p : primes) {
            if (i % p == 0) {
                is_prime = false;
                break;
            }
        }
        if (is_prime) primes.insert(i);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> primes;
    make_primes(primes);
    SegmentTree seg(100010);
    for (int i = 1; i <= 100000; ++i) {
        seg.update(i, i % 2 == 1 && primes.count(i) && primes.count((i + 1) / 2));
    }

    int q;
    cin >> q;

    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << seg.query(l, r + 1) << endl;
    }

    return 0;
}

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



int main(){

	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);

	if(C >= A && C <= B){

		printf("Yes\n");

	}else{

		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 3808
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll mod=1e9+7;
pair<ll,ll> v[2010];
vector<ll> fenwick(5000,0);
vector<ll> p;
void upd(ll pos){
	for(ll i=pos;i<5000;i+=(i&-i))fenwick[i]++;
}
ll somma(ll pos){
	ll tot=0;
	for(ll i=pos;i>0;i-=(i&-i))tot+=fenwick[i];
	return tot;
}
ll sum(ll pos){
	return somma(4500)-somma(pos);
}
int main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		ll N,K;
		cin>>N>>K;
		for(ll i=0;i<N;i++){
			ll a;
			cin>>a;
			upd(a);
			v[i].first=sum(a);
			p.push_back(a);
		}
		for(ll i=0;i<N;i++){
			upd(p[i]);
			v[i].second=sum(p[i])-v[i].first;
		}
		ll sol=0;
		for(ll i=0;i<N;i++){
			sol+=v[i].first*K+v[i].second*(((K)*(K-1)/2)%mod);
			sol%=mod;
		}
		cout<<sol;
		return 0;
}


Measured memory_bytes: 384
import scala.io.StdIn

object Main {

  case class Point(x: Double = 0, y: Double = 0) {

    def +(p: Point) = Point(this.x + p.x, this.y + p.y)

    def -(p: Point) = Point(this.x - p.x, this.y - p.y)

    def *(a: Double) = Point(this.x * a, this.y * a)

    def /(a: Double) = {
      assert(a == 0)
      Point(this.x / a, this.y / a)
    }

    def norm() = this.x * this.x + this.y * this.y

    def abs() = scala.math.sqrt(norm())

    def <(p: Point) = this.x < p.x && this.y < p.y

    private val EPS = 1 ^ (-10)

    def ==(p: Point) = scala.math.abs(this.x - p.x) < EPS && scala.math.abs(this.y - p.y) < EPS

  }

  case class Segment(p1: Point, p2: Point)
  type GeoVector = Point

  object Cgl0A {
    
    // 内積
    def dot(a: Point, b: Point) = a.x * b.x + a.y * b.y

    def isOrthogonal(a: GeoVector, b: GeoVector): Boolean = dot(a, b) == 0.0

    def isOrthogonal(a1: Point, a2: Point, b1: Point, b2: Point): Boolean = {
      isOrthogonal(a1-a2, b1-b2)
    }

    def isOrthogonal(s1: Segment, s2: Segment): Boolean = {
      dot(s1.p2 - s1.p1, s2.p2 - s2.p1) == 0.0
    }

    // 外積
    def cross(a: Point, b: Point) = a.x * b.y - a.y * b.x
    
    def isParallel(a: GeoVector, b: GeoVector) = cross(a, b) == 0.0

    def isParallel(a1: Point, a2: Point, b1: Point, b2: Point): Boolean = {
      isParallel(a1-a2, b1-b2)
    }

    def isParallel(s1: Segment, s2: Segment): Boolean = {
      cross(s1.p2 - s1.p1, s2.p2 - s2.p1) == 0.0
    }

  }


  def main(args: Array[String]): Unit ={
    
    val n = StdIn.readLine().toInt
    val list = (0 until n).map{ i =>
      val a = StdIn.readLine().split(' ').map(_.toDouble)
      (new Point(a(0), a(1)),
        new Point(a(2), a(3)),
        new Point(a(4), a(5)),
        new Point(a(6), a(7)))
    }
    
    list.foreach{ ls => 
      if(Cgl0A.isParallel(ls._1, ls._2, ls._3, ls._4)){
        println("2")
      } else if(Cgl0A.isOrthogonal(ls._1, ls._2, ls._3, ls._4)){
        println("1")
      } else {
        println("0")
      }
    }
  }
  
}




Measured memory_bytes: 49148
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, Q = MAP()
S = list(input())
lr = [LIST() for _ in range(Q)]

lis = [0]*N

for i, x in enumerate(S):
    if (i == N-1):
        break
    else:
        if x == 'A' and S[i + 1] == 'C':
            lis[i+1] = lis[i]+1
        else:
            lis[i+1] = lis[i]


for i in range(Q):
    print(lis[lr[i][1]-1]-lis[lr[i][0]-1])


Measured memory_bytes: 32056
<?php
$n = trim(fgets(STDIN));
$arr = array();

for ($i = 1; $i <= 4; $i++)
  for ($j = 1; $j <= 3; $j++)
    for ($k = 1; $k <= 10; $k++)
      $arr[$i][$j][$k] = 0;

for ($i = 0; $i < $n; $i++) {
  list($b, $f, $r, $v) = explode(" ", trim(fgets(STDIN)));
  $arr[$b][$f][$r] += $v;
}

for ($i = 1; $i <= 4; $i++) {
  for ($j = 1; $j <= 3; $j++) {
    for ($k = 1; $k <= 10; $k++) echo " " . $arr[$i][$j][$k];
    echo "\n";
  }
  if ($i != 4) echo "####################\n";
}



Measured memory_bytes: 9320
#include <stdio.h>
int main(void){
    // Your code here!
    int n, k, r, s, p;
    char t[100001];
    int tmp[100001];
    int score=0;
    
    scanf("%d %d", &n, &k);
    scanf("%d %d %d", &r, &s, &p);
    scanf("%s", t);
    
    for(int i = 0; i < n; i++){
        tmp[i]=0;
        if(k <= i && t[i-k] == t[i] && tmp[i-k] == 1){
            continue;
        }
        if(t[i]=='r') score += p;
        else if(t[i]=='s') score += r;
        else if(t[i]=='p') score += s;
        tmp[i] = 1;
    }
    
    printf("%d", score);
}


Measured memory_bytes: 640
import java.io.*
import java.util.InputMismatchException
import java.io.IOException
import kotlin.system.measureTimeMillis
var out = PrintWriter(System.out)
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/


fun solve() {
    var N = ni()
    var A = na(N)
    A.sort()

    var ans = A.last() - A.first()
    out.println(ans)
}









//---------------------------------------------------------------------------------------------------
fun main(args: Array<String>) {
    var time = measureTimeMillis {
        solve()
        out.flush()
    }
    //println("$time ms")
}
//---------------------------------------------------------------------------------------------------
private var inbuf = ByteArray(1024)
private var lenbuf = 0
var ptrbuf = 0

var `is` = System.`in`

fun readByte(): Byte {
    if (lenbuf === -1) throw InputMismatchException()
    if (ptrbuf >= lenbuf) {
        ptrbuf = 0
        try {
            lenbuf = `is`.read(inbuf)
        } catch (e: IOException) {
            throw InputMismatchException()
        }

        if (lenbuf <= 0) return -1
    }
    return inbuf[ptrbuf++]
}


private fun isSpaceChar(c: Byte): Boolean {
    return !(c >= 33 && c <= 126)
}

private fun skip(): Byte {
    var b: Byte
    while (true) {
        b = readByte()
        if(b < 0 && isSpaceChar(b)) break
    }
    return b
}

private fun ns(): String {
    var b = skip()
    val sb = StringBuilder()
    while (!isSpaceChar(b)) {
        sb.appendCodePoint(b.toInt())
        b = readByte()
    }
    return sb.toString()
}

fun na(n: Int) = IntArray(n, {ni()})

fun ni(): Int {
    var num = 0
    var b: Byte
    var minus = false
    while (true) {
        b = readByte()
        if(b < 0) break
        if(b >= '0'.toByte() && b <= '9'.toByte() || b == '-'.toByte()) break

        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
    }

    while (true) {
        if (b >= '0'.toByte() && b <= '9'.toByte()) {
            num = num * 10 + (b - '0'.toByte())
        } else {
            return if (minus) -num else num
        }
        b = readByte()
    }
}

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

int main(int argc, char **argv)
{
	int n, i, j, x, y, tmp, nn, t = 1;
	int **array;
	
	while(1){
		scanf("%d", &n);
		nn = n*n;
		if(n == 0){
			break;
		}
		
		array = (int **)calloc(n, sizeof(int));
		for(i = 0; i < n; i++){
			array[i] = (int *)calloc(n, sizeof(int));
		}
		x = j = array[0][0] = 1;
		tmp = 2;
		y = 0;
		i = -1;
		while(tmp <= nn){
			array[y][x] = tmp++;
			x += i;
			y += j;
			
			if(x < 0 || y < 0 || y >= n || x >= n){
				x -= i;
				y -= j;
				i = -i;
				j = -j;
				
				if((y == 0 || y == n-1)&& x < n-1){
					x++;
				} else {
					y++;
				}
			}
		}
		
		printf("Case %d:\n", t++);
		for(i = 0; i < n; i++){
			for(j = 0; j < n; j++){
				printf("%3d", array[i][j]);
			}
			printf("\n");
		}
		
		for(i = 0; i < n; i++){
			free(array[i]);
		}
		free(array);
	}
	
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  map<ll, int> mp;
  mp[0] = 1;
  ll sum = 0;
  ll ans = 0;
  rep(i, N) {
    sum += A[i];
    ans += mp[sum]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14336
def solve(n):
    if n in memo:
        return memo[n]

    ans = INF
    for i in (-1, 0, 1):
        res = n + i
        if res % 2 == 0:
            tmp = res - (res // 2)
            ans = min(solve(res // 2) + abs(i) * d + min(a, tmp * d), ans)

    for i in (-2, -1, 0, 1, 2):
        res = n + i
        if res % 3 == 0:
            tmp = res - (res // 3)
            ans = min(solve(res // 3) + abs(i) * d + min(b, tmp * d), ans)
          
    for i in (-4, -3, -2, -1, 0, 1, 2, 3, 4):
        res = n + i
        if res % 5 == 0:
            tmp = res - (res // 5)
            ans = min(solve(res // 5) + abs(i) * d + min(c, tmp * d), ans)

    memo[n] = ans
    return ans

INF = 10 ** 30
t = int(input())

for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    memo = {0: 0, 1: d}
    print(solve(n))

Measured memory_bytes: 84844
import java.util.*;
import java.io.FileInputStream;
import java.io.InputStream;
 
public class Main {
 
	public static Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {
		
		int a = scan.nextInt();
      	int b = scan.nextInt();
      
      if(a > 8 || b > 8)
        System.out.println(":(");
      else 
        System.out.println("Yay!");
		
	}
	
}

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

int main() {
  int64_t N, D;
  cin >> N >> D;
  int count=0;
  for (int i=0; i<N; i++) {
    int64_t x, y;
    cin >> x >> y;
    if (x*x+y*y<=D*D) count++;
  }
  cout << count << endl;
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> v;
    long s=0;
    for(int i=0; i<m; i++){
        int t;
        cin >> t;
        s+=t;
    }
    if(s>n) cout << -1;
    else cout << n-s;
    return 0;
}


Measured memory_bytes: 3636
N, W = map(int, input().split())

dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
# dp[n][w] = n番目までの品物による重量w以下の価値の総和の最大値

for i in range(1, N + 1):
    w, v = map(int, input().split())
    for j in range(W + 1):
        if j - w >= 0:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
        else:
            dp[i][j] = dp[i - 1][j]

print(dp[N][W])

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

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	
	long long n, k; cin >> n >> k;

	vector<long long> a(n);
	for(long long &x : a) cin >> x;

	vector<bool> dp(k + 1, false);
	for(long long stones = 0; stones <= k; stones++){
		for(long long x : a){
			if(stones >= x && !dp[stones - x]){
				dp[stones] = true;
			}
		}
	}

	puts(dp[k] ? "First" : "Second");

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	long long int N, ret, three, five, fifteen;
	scanf("%lld", &N);
	ret = three = five = fifteen = 0;
	if(N - N%3 > 0){
		three = (N - N%3) / 3;
		three = three*(three + 1) / 2;
		three *= 3;
	}
	if(N - N%5 > 0){
		five = (N - N%5) / 5;
		five = five*(five + 1) / 2;
		five *= 5;
	}
	if(N - N%15 > 0){
		fifteen = (N - N%15) / 15;
		fifteen = fifteen*(fifteen + 1) / 2;
		fifteen *= 15;
	}
	ret = N*(N+1) / 2 - three - five + fifteen;
	printf("%lld\n", ret);
	return 0;
}

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

int main(){
    string s;
    map<char, int> mp;
    cin >> s;
    for(int i = 0; i < 4; i++){
        mp[s[i]]++;
    }
    
    if(mp.size() == 2 & mp[s[0]] == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
  int mas[3][3];
  for(int i = 0;i < 3;i++){
    for(int j = 0;j < 3;j++){
      cin >> mas[i][j];
    }
  }


  int min1 = mas[0][1] - mas[0][0];
  int min2 = mas[0][2] - mas[0][1];

  if(mas[1][1] - mas[1][0] == min1 && mas[1][2] - mas[1][1] == min2 && mas[2][1] - mas[2][0] == min1 && mas[2][2] - mas[2][1] == min2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;

}

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

int sort_asc(const void *a, const void *b);

int main()
{
	const int N = 3;
	int x[N];
	cin >> x[0] >> x[1] >> x[2];
	qsort(x, N, sizeof(int), sort_asc);
	cout << x[0] << " " << x[1] << " " << x[2] << endl;

	return 0;
}

int sort_asc(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

Measured memory_bytes: 3072
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,m;
    int arr[100001];
    for(int i=0;i<100001;i++)arr[i]=-1;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
    	cin>>arr[i];
    }
    bool arr2[100001];
    for(int i=0;i<100001;i++)arr2[i]=true;
    for(int i=0;i<m;i++){
    	int a,b;
    	cin>>a>>b;
    	if(arr[a]<=arr[b])arr2[a]=false;
    	if(arr[b]<=arr[a])arr2[b]=false;
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    	if(arr2[i])cnt++;
    	
    cout<<cnt<<endl;
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll MRINF = 5000000000000000;

int main() {

  ll N;
  cin >> N;
  cout << N * 2 / __gcd(N, (ll)2) << endl;


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

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

using namespace std;

#define F first
#define S second
#define int long long

typedef long long ll;
typedef long double ld;

const int maxn = 510;
const int mod = 998244353;
const int M = 1e6+10;

ll n, m;

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

    cin>> n >> m;
    ll x = __gcd(n,m);
    n = n/x;
    cout<< (3*n-3) * x;
}


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

using namespace std;


int main()
{
	/*ifstream input("input.txt");
	ofstream output("output.txt");*/

	int N = 0;
	cin >> N;

	string s = to_string(N);
	vector<int> v(3);
	v[0] = s[0];
	v[1] = s[1];
	v[2] = s[2];

	bool ok = true;
	for (int a = 0, b = 2; a < 2; ++a, --b)
	{
		if (v[a] != v[b])
			ok = false;
	}

	if (ok)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import deque
import copy

def main():
  H, W = list(map(int, input().split()))
  field = [[i=='#' for i in input()] for _ in range(H)]
  count = 0
  q = deque([(i, j) for i in range(H) for j in range(W) if field[i][j]])
  while True:
    nq = deque()
    while q:
      y, x = q.popleft()
      if x > 0 and not field[y][x-1]:
        field[y][x-1] = True
        nq.append((y,x-1))
      if y > 0 and not field[y-1][x]:
        field[y-1][x] = True
        nq.append((y-1,x))
      if x<W-1 and not field[y][x+1]:
        field[y][x+1] = True
        nq.append((y,x+1))
      if y<H-1 and not field[y+1][x]:
        field[y+1][x] = True
        nq.append((y+1, x))
    if nq:
      q = copy.copy(nq)
    else:
      break
    count += 1
  print(count)
      
if __name__ == "__main__":
  main()

Measured memory_bytes: 115492
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>


using namespace std;

typedef pair<int, int> P;

int n;
vector<P> edge[110000];
bool ans[110000];
bool done[110000];

void dfs(int u) {
  done[u] = true;
  for (P p: edge[u]) {
    int v = p.first;
    int w = p.second;
    if (done[v]) continue;
    ans[v] = w % 2 ? (ans[u]+1) % 2 : ans[u];
    dfs(v);
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n-1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    edge[u].push_back(P(v, w));
    edge[v].push_back(P(u, w));
  }
  
  dfs(0);
  
  for (int i = 0; i < n; i++) {
    cout << (int)ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n;
ll dis[1001];
bool vis[1001];
vector<pair<pair<ll, ll>, ll>>v[1001];
set<ll>st;
void dijkstra(ll k)
{
	multiset<pair<ll, pair<ll, ll> > > s;
	s.insert({0, {k, 0}});
	for (ll i = 0; i <= 1000; i++)
	{
		vis[i] = 0;
		dis[i] = INT_MAX;
	}
	dis[k] = 0;
	while (!s.empty())
	{
		pair<ll, pair<ll, ll>>p = *s.begin();
		s.erase(s.begin());
		ll wei = p.first;
		ll node = p.second.first;
		ll edge = p.second.second;

		if (vis[node])
			continue;
		vis[node] = 1;
		st.insert(edge);
		for (ll i = 0; i < v[node].size(); i++)
		{
			if (dis[node] + v[node][i].first.second < dis[v[node][i].first.first])
			{
				dis[v[node][i].first.first] = dis[node] + v[node][i].first.second;
				s.insert({dis[v[node][i].first.first], { v[node][i].first.first, v[node][i].second}});
			}
		}
	}
}
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt" , "r" , stdin);
// 	freopen("output.txt" , "w" , stdout);
// #endif

	ll  m;
	cin >> n >> m;
	for (ll i = 1; i <= m; i++)
	{
		ll a, b, c;
		cin >> a >> b >> c;
		v[a].push_back({{b, c}, i});
		v[b].push_back({{a, c}, i});
	}
	for (ll i = 1; i <= n; i++)
	{
		dijkstra(i);
	}
	cout << m + 1 - st.size() << endl;
	// while (!st.empty())
	// {
	// 	cout << *st.begin() << " ";
	// 	st.erase(st.begin());
	// }



}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
itn H, W, A, B;
int c[1010][1010];
int sw[1010], sh[1010];
int SW[1010], SH[1010];
void solve()
{
    int x = -1, y = -1;
    FOR(i, 0, H)
    {
        if (x != -1) {
            break;
        }
        FOR(j, 0, W)
        {
            if (i * (W - 2 * A) + A * H == j * (H - 2 * B) + B * W) {
                x = i;
                y = j;
            }
        }
    }
    if (x == -1) {
        cout << "No" << endl;
        return;
    }
    FOR(i, 0, H)
    {
        if (i < x)
            sh[i] = A;
        else
            sh[i] = W - A;
    }
    FOR(i, 0, W)
    {
        if (i < y)
            sw[i] = B;
        else
            sw[i] = H - B;
    }

    FOR(i, 0, H)
    {
        FOR(j, 0, W)
        {
            if (SH[i] < sh[i] && SW[j] < sw[j]) {
                c[i][j] = 1;
                SH[i]++;
                SW[j]++;
            }
        }
    }

    /*
    int a = INF, b = INF;
    int h = 0, w = 0;
    FOR(i, 0, H)
    {
        FOR(j, 0, W)
        {
            c[i][j] =
        }
    }*/


    FOR(i, 0, H)
    {
        FOR(j, 0, W)
        {
            cout << c[i][j];
        }
        cout << endl;
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> H >> W >> A >> B;
    solve();
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct L {
	int64_t i;
	int64_t j;
	int64_t s;
};
int64_t lval(const L& l, const vector<int64_t>& as) {
	return  as[l.i] + as[l.j];
}

int64_t calcn(vector<int>& bs, int64_t v)
{
	if (v < 0) return bs[0];
	return bs[v];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t n, m; cin >> n >> m;
	vector<int64_t> as(n);
	FOR_LT(i, 0, n) {
		cin >> as[i];
	}
	sort(as.begin(), as.end());
	vector<int> bs(200001);
	{
		int c = 0;
		auto it = as.rbegin();
		FOR_DW(i, 200000, 0) {
			while (it != as.rend() && *it == i) {
				c++;
				it++;
			}
			bs[i] = c;
		}
	}

	vector<int64_t> ss(n);
	{
		int64_t s = 0;
		FOR_LT(i, 0, n) {
			s += as[i];
			ss[i] = s;
		}
	}

	int64_t low = 0;
	int64_t high = 200000;

	int cc = 0;
	while (true) {
		if (low == high) break;

		int64_t mid = (low + high) / 2;
		if (low == mid) mid++;

		int64_t cn = 0;
		FOR_LT(i, 0, n) {
			cn += calcn(bs, mid - as[i]);
		}

		if (cn >= m) {
			low = mid;
		}
		else {
			if (high == mid) high--;
			else {
				high = mid;
			}
		}
	}

	int64_t ans = 0;
	int64_t sumn = 0;
	FOR_LT(i, 0, n) {
		int cn = calcn(bs, low - as[i]);
		sumn += cn;
		ans += ss[n - 1];
		if (cn != n) {
			ans -= ss[n - 1 - cn];
		}
		ans += cn * as[i];
	}
	ans -= low * (sumn - m);
	cout << ans << endl;

	return 0;
}


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

int main()
{
    int K, X;
    int min_num,max_num;
    cin >> K >> X;
    
    min_num = max({-1000000,X-K+1});
    max_num = min({1000000,X+K-1});
    
    for(int i=0; i<max_num-min_num+1; i++){
        cout << min_num+i << " ";
    }
    cout << endl;
    return 0;
}


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

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

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)


int main() {

  const ll MOD = 1e9 + 7;
  ll N, M;
  cin >> N >> M;
  vector<ll> v1(N), v2(M);
  REP(i, N) cin >> v1[i];
  REP(i, M) cin >> v2[i];

  //ll dp[N][M] = {{0}};
  vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0LL));
  vector<vector<ll>> sum(N + 1, vector<ll>(M + 1, 0LL));
  //ll sum[N][M] = {{0}};

  REP(i, N){
    REP(j, M){
      if (v1[i] == v2[j]){
        dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD;
      }
      //sum[i + 1][j + 1] = (((((sum[i + 1][j] - sum[i][j]) % MOD)  + sum[i][j + 1]) % MOD) + dp[i + 1][j + 1]) % MOD;
      sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= MOD;
      sum[i + 1][j + 1] = (sum[i + 1][j + 1] + MOD - sum[i][j]) % MOD;
    }
  }
  //ll ans = (sum[N][M] + 1) % MOD;
  ll ans = 1;
  REP(i, N)REP(j, M) ans = (ans + dp[i + 1][j + 1]) % MOD;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 62976
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n; cin >> n;
    int out = 0, temp = 0;
    for(int i = 1; i <= n; i++) {
        cin >> temp;
        if(i&1 && temp&1)
            out++;
    }
    cout << out;
}

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

#define FOR(i,b,e) for (int i = (b); i <= (e); i++)
#define FORD(i,b,e) for (int i = (b); i >= (e); i--)
#define SIZE(c) ((int) (c).size())

#define pb push_back
#define st first
#define nd second

using namespace std;


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

typedef vector <int> VI;
typedef vector <ll> VL;
typedef vector <bool> VB;
typedef vector <pii> VP;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    VVI g(n);

    FOR(i,0,n-1) {
        string s;
        cin >> s;

        FOR(j,0,n-1) {
            if (s[j] == '1') {
                g[i].pb(j);
            }
        }
    }

    int kMax = 0;

    FOR(v,0,n-1) {
        queue <int> q;
        q.push(v);

        VI dist(n, -1);
        dist[v] = 0;

        while (!q.empty()) {
            int x = q.front(); q.pop();

            for (int y : g[x]) if (dist[y] == -1) {
                dist[y] = dist[x] + 1;
                q.push(y);
            }
        }

        FOR(x,0,n-1) for (int y : g[x]) if (dist[x] == dist[y]) {
            cout << -1;
            return 0;
        }

        kMax = max(kMax, *max_element(dist.begin(), dist.end()) + 1);
    }

    cout << kMax;

    return 0;
}

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

int main(){
  int N; 
  cin >> N;
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  
  vector<string> s(N);
  for(int i=0; i<N; i++){
    cin >> s.at(i);
    if(s.at(i)=="AC") ac++;
    if(s.at(i)=="WA") wa++;
    if(s.at(i)=="TLE") tle++;
    if(s.at(i)=="RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " <<wa << endl;
  cout << "TLE x " <<tle << endl;
  cout << "RE x " <<re << endl;

}


Measured memory_bytes: 6368
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
const int N = 1005;
using namespace std;
typedef long long ll;
int a[N];

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    int la=0,lb=0,a1=a,b1=b,sum;
    while(a1)
    {
        la++;
        a1/=10;
    }
    while(b1)
    {
        lb++;
        b1/=10;
    }
    // cout<<la<<lb;
    if(lb==1)
        sum=a*10+b;
    if(lb==2)
        sum=a*100+b;
    if(lb==3)
        sum=a*1000+b;
    int s=(int)sqrt(sum);
    if(s*s==sum)
        printf("Yes\n");
    else
    {
        if(la==1)
            sum=b*10+a;
        if(la==2)
            sum=b*100+a;
        if(la==3)
            sum=b*1000+a;
        int s=(int)sqrt(sum);
        if(s*s==sum)
            printf("Yes\n");
        else
            printf("No\n");
    }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,a[N],b[N];
struct node
{
    int x,pos;
    node(int x=0,int pos=0):x(x),pos(pos){}
    bool operator<(const node&o)const
    {
        return x<o.x;
    }
};
priority_queue<node>q;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]),q.push(node(b[i],i));
    long long ans=0;
    while(!q.empty())
    {
        int u=q.top().pos;q.pop();
        if(b[u]==a[u]) continue;
        int l=u-1,r=u+1;
        if(l==0) l=n;
        if(r==n+1) r=1;
        if((b[u]-a[u])%(b[l]+b[r])==0)
        {
            ans+=(b[u]-a[u])/(b[l]+b[r]);
            b[u]=a[u];continue;
        }
        int now=max(a[u],max(b[l],b[r]));
        if((b[u]-now)/(b[l]+b[r])>0)
        {
            ans+=(b[u]-now)/(b[l]+b[r]);
            b[u]-=(b[u]-now)/(b[l]+b[r])*(b[l]+b[r]);
        }
        else
        {
            b[u]-=b[l]+b[r];
            ans++;
        }
        if(b[u]<a[u])
        {
            printf("-1\n");return 0;
        }
        if(b[u]!=a[u])
            q.push(node(b[u],u));
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4724
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	while(true){
		int n,q,cnt[100]={};
		scanf("%d%d",&n,&q);
		if(n==0) break;
		rep(i,n){
			int m;
			scanf("%d",&m);
			rep(j,m){
				int d;
				scanf("%d",&d);
				cnt[d-1]++;
			}
		}
		int ok=0,now=q-1;
		rep(i,100) if(cnt[i]>now) ok=i+1,now=cnt[i];
		printf("%d\n",ok);
	}
	return 0;
}

Measured memory_bytes: 1012