akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1)*18;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int i,n,ans=0;cin>>n;
	vector<int>c(n);for(i=0;i<n;i++){cin>>c[i];}
	c.pub(0);c.pub(0);
	SO(c);REV(c);
	for(i=0;i<n;i+=2){
		ans+=c[i];
		ans-=c[i+1];
	}
	cout<<ans<<endl;RE;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n=int(input())
edges=[[] for i in range(n)]
for i in range(n-1):
    a,s,d=map(int,input().split())
    edges[a-1].append((s-1,d));edges[s-1].append((a-1,d))
q,k=map(int,input().split())
cost=[0]*n
from collections import deque
dq=deque([])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
for to,cos in edges[k-1]:
    dq.append((k-1,to))
    cost[to]=cos
while dq:
    par,now=dq.popleft()
    
    for to,c in edges[now]:
        if to!=par:
            cost[to]=cost[now]+c
            dq.append((now,to))

for i in range(q):
    x,y=map(int,input().split())
    print(cost[x-1]+cost[y-1])

Measured memory_bytes: 47156
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int times = int.Parse(Console.ReadLine());
        while (times-- > 0)
        {
            bool flag = true;
            Stack<int> tubeA = new Stack<int>();
            Stack<int> tubeB = new Stack<int>();
            Console.ReadLine().Split().Select(x => int.Parse(x)).ToList().ForEach(delegate (int v)
            {
                if (tubeA.Count == 0 || tubeA.Peek() < v)
                    tubeA.Push(v);

                else if (tubeB.Count == 0 || tubeB.Peek() < v)
                    tubeB.Push(v);

                else
                    flag = false;
            });

            Console.WriteLine(flag ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 14616
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
int main() {
	int N, M,a;
	map<int, int>m{};
	bool flag = true;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a;
		m[a]++;
	}
	cin >> M;
	for (int i = 0; i < M; i++)
	{
		cin >> a;
		if (m[a] == 0)flag = false;
		else m[a]--;
	}
	cout << (flag ? "YES" : "NO");
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
using namespace std;
const int N=1e4+50;
const int INF=0x3f3f3f;
char s[N];
int vis[N];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len;i++)
    {
        vis[(int)s[i]]++;
    }
    for(int i=97;i<=122;i++)
    {
        if(vis[i]%2!=0)
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }
int main(){
	// in;
	// out;
	ll a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c) cout<<"No"<<endl;
	else{
		ll cha=c-a-b;
		ll xx=4*a*b;
		if(cha*cha>xx) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<ll> a(n + 1); rep(i, n + 1)cin >> a[i];
	if (n == 0)
	{
		if (a[0] == 1)cout << 1 << endl;
		else cout << -1 << endl;
		return 0;
	}
	if (n != 0 && a[0] != 0)
	{
		cout << -1 << endl;
		return 0;
	}
	if (n == 1)
	{
		if (a[1] == 1)cout << 2 << endl;
		else if (a[1] == 2)cout << 3 << endl;
		else cout << -1 << endl;
		return 0;
	}
	vector<ll> b(n + 1);
	b[0] = 1;
	rep(i, n)
	{
		ll mx = b[i] * 2;
		if (mx < 0)b[i + 1] = 1e18;
		else b[i + 1] = mx - a[i + 1];
		if (b[i + 1] < 0)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	vector<ll> v(n + 1);
	ll res = a[n] + 1;
	v[n] = a[n];
	for (int i = n; i >= 2; --i)
	{
		if (b[i - 2] >= 1e18)v[i - 1] = v[i] + a[i - 1];
		else v[i - 1] = min(v[i] + a[i - 1], b[i - 2] * 2);
		res += v[i - 1];
	}
	cout << res << endl;
}

Measured memory_bytes: 5592
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        double d = 0.0;
        
        for(int i = 0; i < n; i++){
            x[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
            y[i] = sc.nextInt();
        }
        
        //p=1
        for(int i = 0; i < n; i++){
            d += Math.abs((double)x[i] - (double)y[i]);
        }
        System.out.println(d);
        
        //p=2
        d = 0.0;
        for(int i = 0; i < n; i++){
            d += Math.pow(Math.abs((double)x[i] - (double)y[i]), 2);
        }
        System.out.println(Math.sqrt(d));
        
        //p=3
        d = 0.0;
        for(int i = 0; i < n; i++){
            d += Math.pow(Math.abs((double)x[i] - (double)y[i]), 3);
        }
        System.out.println(Math.cbrt(d));
        
        //p=∞
        d = 0.0;
        for(int i = 0; i < n; i++){
            d = Math.max(d,Math.abs((double)x[i] - (double)y[i]));
        }
        System.out.println(d);
    }
}


Measured memory_bytes: 26556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int x; cin >> x;
    if(x == 3 || x == 5 || x == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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


int main() {
	int N, M;
	int num;
	bool A[30] = { 0 };
	cin >> N >> M;
	
	// 入力
	for( int i = 0; i < N; i++ )
	{
		bool B[30] = { 0 }; // 比較用
		cin >> num;
		for( int j = 0; j < num; j++ )
		{
			int l;
			cin >> l;
			if( i )
			{
				B[l-1] = true;
			}
			else
			{
				A[l-1] = true;
			}
		}
		if( i )
			for( int k = 0; k < M; k++ )
				A[k] &= B[k];

	}

	int sum = 0;
	for( int i = 0; i < M; i++ )
	{
		sum += A[i];
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

int main()
{

	int N;
	int K;
	string S;
	cin >> N;
	cin >> K;
	cin >> S;

	auto c = S[0];
	int k = 0;
	bool flag = false;
	for (int i = 0; i < N; ++i) {
		//cerr << S << endl; 
		if (flag == false) {
			if (S[i] == c) {
				continue;
			}
			else {
				flag = true;
				S[i] = c;
			}
		}
		else {
			if (S[i] == c) {
				flag = false;
				k++;
			}
			else {
				S[i] = c;
			}
		}
		if (k >= K) {
			break;
		}
	}

	int v = 0;
	for (int i = 0; i < N - 1; ++i) {
		if (S[i] == S[i + 1]) {
			v++;
		}
	}
	cout << v;
	return 0;
}


int main1()
{

	int N;
	int K;
	string S;
	cin >> N;
	cin >> K;
	cin >> S;

	int idx = 0;
	for (int k = 0; k < K; ++k){
		//cerr << S << endl; 
		int s=-1;
		for (int i = idx; i < N - 1; ++i) {
			if (S[i] != S[i + 1]) {
				s = i+1;
				break;
			}
		}
		if (s == -1) {
			break;
		}
		int e = N-1;
		for (int i = s; i < N - 1; ++i) {
			if (S[i] != S[i + 1]) {
				e = i;
				break;
			}
		}	
		int w = e - s + 1;
		for (int i = 0; i < (int)((w+1)/2); ++i) {
			auto cs = S[s + i];
			auto ce = S[e - i];
				

			if (cs == 'R') {
				S[e - i] = 'L';
			}
			else {
				S[e - i] = 'R';
			}
			if (ce == 'R') {
				S[s + i] = 'L';
			}
			else {
				S[s + i] = 'R';
			}
			
		}
		idx = e;
	}
	//cerr << S << endl;
	int v = 0;
	for (int i = 0; i < N - 1; ++i) {
		if (S[i] == S[i + 1]) {
			v++;
		}
	}
	cout << v;
	return 0;
}


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

x1, x2, y1, y2 = (0, W, 0, H)
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = min(y2, y)
ans = max(0,x2-x1) * max(0,y2-y1)
print(ans)


Measured memory_bytes: 3064
/***************************************** START OF TEMPLATE *********************************************/

#include<bits/stdc++.h>

using namespace std;

#define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  newl           cout<<"\n";
#define  f              first
#define  s              second
#define  pb             push_back
#define  mp             make_pair
#define  sym(s)         s="#"+s+"#";
#define  sqr(v)         v*v;
#define  all(x)         (x).begin(),(x).end()
#define  alll(x, n)     x+1, x+n+1
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  mset1d(a,n,v)  foo(i,0,n+5)a[i]=v;
#define  mset2d(a,n,m,v)foo(i,0,n+5)foo(j,0,m+5)a[i][j]=v;
#define  INP(a,n)       foo(i,1,n) cin>>a[i];
#define  deb1d(a,n)     foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)   foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}    
#define  debm(a)        for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  debp(a,n)      foo(i,1,n)cout<<"{"<<a[i].f<<","<<a[i].s<<"}, ";newl;
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<" ";newl;
#define  deb2(a,b)      cout<<a<<" "<<b;newl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c;newl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d;newl;
#define  ll             long long
#define  ld             long double
#define  pll            pair<ll,ll>
#define  vll            vector<ll>
#define  vpll           vector<pll>

const ld   PI    =  3.14159265358979323846; 
const ll   MOD   =  1e+9+7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5+8;

vll adj[N]; ll vis[N];
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll l, r, d;


/***************************************** FUNCTION IMPLEMENTATIONS **************************************/



/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc){
    cin>>l>>r>>d;
    cout<<r/d - (l-1)/d;
}

int main(){
    SPEED;

    //cin>>test_cases;
    foo(i,1,test_cases){
    MAIN(i);
    }
}

Measured memory_bytes: 8216
// Problem : D - Friends
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 2*100001; //check the limits, dummy
int n,m;
vector<int> conn[MX];
vector<bool> vis(MX);
int cnt;
void dfs(int node)
{
	vis[node]=1;
	cnt++;
	trav(i,conn[node])
	if(!vis[i])
	dfs(i);
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	cin>>n>>m;
	loop(i,m)
	{
		int q,w;
		cin>>q>>w;
		q--,w--;
		conn[q].pb(w);
		conn[w].pb(q);
	}
	int ans=0;
	loop(i,n)
	{
		if(!vis[i])
		{
			cnt=0;
			dfs(i);
			ckmax(ans,cnt);
		}
	}
	cout<<ans;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 20824
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
using namespace std;


int digitdf(long long a, long long b){
  int ac = 0;
  int bc = 0;
  while(a > 0){
    a/=10;
    ac++;
  }
  while(b > 0){
    b/=10;
    bc++;
  }
  //cout << "[" << ac << "," << bc << "]" << endl;
  return max(ac, bc);
}
int main(){
  long long n;
  cin >> n;
  for(long long i = sqrt(n); i >= 1; i--){
    if((n/i)*i == n){
      cout << digitdf(i, n/i) << endl;
      break;
    }
  }

  return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
using ll = long long;

int main() {
	ll N, K;
	cin >> N >> K;
    string S;
    cin >> S;
    if (N-1 <= K) {
        cout << N-1 << endl;
        return 0;
    }
    // 最初のスコア + 改善可能スコア
    int score = 0;
    int cluster_count = 1;
    vector<int> X(N,0);
    for (int i=1; i<S.size(); ++i) {
        if (S[i] == S[i-1]) {
            score++;
        } else {
            cluster_count++;
        }
    }
    for (int i=0; i<K; ++i) {
        if (cluster_count == 1) {
            break;
        }
        if (cluster_count > 2) {
            score+=2;
            cluster_count -= 2;
        } else {
            score++;
            cluster_count--;
        }
    }
    cout << score << endl;
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int sum = 0;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    sum += x;
  }

  cout << (N - sum >= 0 ? N - sum : -1) << endl;
}


Measured memory_bytes: 3588
def resolve():
    k = int(input())
    ans = 1
    ct = 0
    num = 7
    while ct <= 2*10**6:
        num %= k
        if num == 0:
            print(ans)
            exit()
        else:
            num = (num * 10 + 7)%k
            ans += 1
            ct += 1
    print(-1)
resolve()

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
#include<bits/stdc++.h>
using namespace std;
int cnt;
int main(){
 	int n,a[200010];
 	cin>>n; 
 	for(int i=1;i<=n;i++){
 		cin>>a[i];
	 }
	 sort(a+1,a+1+n);
	 long long min=100000000;
	 for(int i=a[1];i<=a[n];i++){
	 	cnt=0;
	 	for(int j=1;j<=n;j++){
	 		cnt+=(a[j]-i)*(a[j]-i);
		}
		if(cnt<=min)
			min=cnt;
	 }
	 cout<<min;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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; }

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (auto& e : a) {
        cin >> e;
    }
    vector<ll> dp(n, INF);
    for (int i = 0; i < n; i++)
    {
        *lower_bound(dp.begin(), dp.begin() + n, a[i]) = a[i];
        //fill(upper_bound(dp.begin(), dp.begin() + n, a[i]), dp.end(), INF);
    }

    if (dp[0] != 1) {
        cout << -1 << endl;
        return 0;
    }

    //ll ans = dp.end() - lower_bound(dp.begin(), dp.begin() + n, INF);
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        if (dp[i] == i + 1ll) {
            ans++;
        }
        else {
            break;
        }
    }
    cout << n - ans << "\n";
    return 0;
}

Measured memory_bytes: 3328
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))


def lcm(x, y):
    return (x * y) // gcd(x, y)


lcmA = A[0]
for i in range(1, N):
    lcmA = lcm(lcmA, A[i])

cnt = 0

for a in A:
    b = lcmA // a
    cnt += b

print(cnt % (10 ** 9 + 7))

Measured memory_bytes: 6200
// https://atcoder.jp/contests/agc037/submissions/6956246
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define ceil(a, b) a / b + !!(a % b)
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    
    int n = (int) s.size();
    const int K = 2;
    vector<vector<int>> dp(n + 1, vector<int>(K + 1, -1));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= K; j++) {
            if (dp[i][j] == -1) {
                continue;
            }
            for (int k = 1; k <= K && i + k <= n; k++) {
                if (s.substr(i - j, j) != s.substr(i, k)) {
                    dp[i + k][k] = max(dp[i + k][k], dp[i][j] + 1);
                }
            }
        }
    }
    int ans = 0;
    for (int j = 0; j <= K; j++) {
        ans = max(ans, dp[n][j]);
    }
    cout << ans << '\n';
    
    // rep(i, n + 1) { rep(j, K + 1) cout << dp[i][j] << " "; cout << endl; }
}


Measured memory_bytes: 11412
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j,k,l;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		sc.close();
		int[][] nc = new int[10][10];
		for (i = 1; i <= 9; i++) {
			if(i<=n) {
				nc[i][i]++;
			}
		}
		for (i = 1; i <= 9; i++) {
			for (j = 1; j <= 9; j++) {
				for (k = 1; k <= 200000; k*=10) {
					for (l = 0; l < k; l++) {
						if(i * 10 *k + l*10 + j<=n) {
							nc[i][j]++;
						}
					}
				}
			}
		}
//		out.println(Arrays.deepToString(nc));
		int cnt=0;
		for (i = 1; i <= 9; i++) {
			for (j = 1; j <= 9; j++) {
				cnt+=nc[i][j]*nc[j][i];
			}
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 24148
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int n,a[100005]={},cnt=1,next_i;
  cin>>n;
  rep(i,0,n){
    cin>>a[i];
  }
  next_i=0;
  while(1){
    if(n==cnt)break;
    if(a[next_i]==2){
      cout<<cnt<<endl;
      return 0;
    }else{
      next_i=a[next_i]-1;
      cnt++;
    }
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 640
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

void bfs(vector<bool> &vis, vector<vector<int>> &v, vi &sum) {
	queue<pair<int,int>> q;
	q.PU({0,0});
	while(!q.empty()) {
		pair<int,int> p = q.front();
		q.PO();
		if(!vis[p.F]) {
			vis[p.F]=1;
			sum[p.F]+=p.S;
			for(auto i:v[p.F]) q.PU({i, sum[p.F]});
		}
	}
}

void solve(int test_case) {//209
	int n,q;
	cin>>n>>q;
	vector<vector<int>> v(n, vi());
	REP(i,1,n-1) {
		int a,b;
		cin>>a>>b;
		a--;b--;
		v[a].PUB(b);
		v[b].PUB(a);
	}
	vi sum(n,0);
	while(q--) {
		int p,x;
		cin>>p>>x;
		p--;
		sum[p]+=x;
	}
	vector<bool> vis(n, 0);
	bfs(vis, v, sum);
	REP(i,0,n-1)cout<<sum[i]<<" ";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 17308
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

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

    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i];
    int avg1 = SUM(a,0LL)/n , avg2 = SUM(a,0LL)/n+1;
    int ans1 = 0 , ans2 = 0;
    REP(i,n){
        ans1 += (avg1-a[i])*(avg1-a[i]);
        ans2 += (avg2-a[i])*(avg2-a[i]);
    }
    out(min(ans1,ans2));

    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
from operator import mul
from functools import reduce
if M==1:
  print(1)
else:
  def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

  def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

  a=factorization(M)
  A=[]
  for i in range(len(a)):
    A.append(a[i][1])
  ans=1
  for i in A:
    d=cmb(i+N-1,i)
    ans*=d%(10**9+7)
  print(ans%(10**9+7))

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

const ll INF = 1e10;;

int main(){
    int n;
    cin >> n;
    vector<ll> h(n+5);
    rep(i,n) cin >> h[i];

    vector<ll> c(n+5,INF);
    c[0] = 0;
    rep(i,n){
        chmin(c[i+1],c[i]+abs(h[i]-h[i+1]));
        chmin(c[i+2],c[i]+abs(h[i]-h[i+2]));
    }
    // chmin(c[n-1], c[n-2]+abs(h[n-1]-h[n-2]));

    cout << c[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
h, w = gets.split.map(&:to_i)
cm = Array.new(h + 2){Array.new(w + 2, 0)}
que = []
1.upto(h) do |i|
  s = gets.chomp
  1.upto(w) do |j|
    if s[j - 1] == '.'
      cm[i][j] = -1
    else
      que << i << j
      cm[i][j] = 0
    end
  end
end
ans = 0
while que.size > 0
  y, x = que.shift(2)
  ans = cm[y][x] + 1
  if cm[y + 1][x] == -1
    cm[y + 1][x] = ans
    que << y + 1 << x
  end
  if cm[y - 1][x] == -1
    cm[y - 1][x] = ans
    que << y - 1 << x
  end
  if cm[y][x + 1] == -1
    cm[y][x + 1] = ans
    que << y << x + 1
  end
  if cm[y][x - 1] == -1
    cm[y][x - 1] = ans
    que << y << x - 1
  end
end
puts ans - 1

Measured memory_bytes: 27132
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const int INF = 1 << 30;
const int MOD = 1e9 + 7;


int main() {
    string l; cin >> l;
    vector<vector<ll>> dp(l.size()+1, vector<ll>(2, 0));
    dp[0][0] = 1;
    rep(i, l.size()) rep(j, 2) {
        if (j == 0) {
            if (l[i] == '0') {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            } else {
                dp[i+1][1] += dp[i][j];
                dp[i+1][0] %= MOD;
                dp[i+1][0] += dp[i][j] * 2;
                dp[i+1][0] %= MOD;
            }
        } else {
            dp[i+1][1] += dp[i][j] * 3;
            dp[i+1][1] %= MOD;
        }
    }

    ll ans = 0;
    rep(i, 2) {
        ans += dp[l.size()][i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

int main() {
    const int MAX = 60 * 60 * 24;
    int n;
    while (scanf("%d", &n), n) {
        vector<int> imos(MAX + 1);
        while (n--) {
            int h1, m1, s1, h2, m2, s2;
            scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
            int s = h1 * 3600 + m1 * 60 + s1;
            int t = h2 * 3600 + m2 * 60 + s2;
            imos[s]++, imos[t]--;
        }
        for (int i = 1; i <= MAX; i++) imos[i] += imos[i - 1];
        int ma = 0;
        for (int i = 0; i < MAX; i++) ma = max(ma, imos[i]);
        printf("%d\n", ma);
    }
    return 0;
}


Measured memory_bytes: 2900
import bisect
from operator import itemgetter
import math
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

X,A = IL()

if X < A:
  print(0)
else:
  print(10)

Measured memory_bytes: 21608
#include <iostream>
using namespace std;
#define INF 2000000001
int heap[500500];
int H;

void swap(int a, int b) {
  int c = heap[a];
  heap[a] = heap[b];
  heap[b] = c;
}

int left(int p) {
  return p*2;
}

int right(int p) {
  return p*2+1;
}

int parent(int p) {
  return p/2;
}

void heapify(int p) {
  int l = left(p);
  if (l > H) l = 0;
  int r = right(p);
  if (r > H) r = 0;
  int largest;
  if (heap[r] > heap[l] && heap[r] > heap[p]) {
    largest = r;
  } else if (heap[l] > heap[r] && heap[l] > heap[p]) {
    largest = l;
  } else {
    largest = p;
  }
  if (largest != p) {
    swap(p, largest);
    heapify(largest);
  }
}

void build() {
  for (int i = H/2; i > 0; i--) {
    heapify(i);
  }
}

int main() {
  heap[0] = -INF;
  cin >> H;
  for (int i = 1; i <= H; i++) {
    cin >> heap[i];
  } 
  build();
  for (int i = 1; i <= H; i++) {
    cout << " " << heap[i];
  }
  cout << endl;
}




Measured memory_bytes: 4972
N = int(input())
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)

from operator import mul
from functools import reduce
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
ans = 0
for i in a:
    if  a[i] > 1:
        ans += combinations_count(a[i],2) 
for i in A:
    n = a[i]
    if n > 2:
        print(ans+combinations_count(n-1,2)-combinations_count(n,2))
    elif n == 2:
        print(ans-1)
    else:
        print(ans)

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

int acs(const void* a, const void* b){
	
	return *(int *)a - *(int *)b;	
}
int main(){
	int N;
	int p[12],i,ans=0;
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",p+i);
	qsort(p,N,sizeof(int),acs);
	
	for(i=0;i<N-1;i++){
		ans += p[i]; 
	}
	printf("%d\n",ans+p[N-1]/2);

	return 0;	
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

int acc(vector<int> a, int len) {
	int n = (int)a.size();
	int s = 0;
	for (auto t : a) {
		s += t;
	}
	int ans = s * (len / n);
	len %= n;
	for (int i = 0; i < len; i++) {
		ans += a[i];
	}
	return ans;
}

void solve(vector<int> d) {
	int x, len, mod;
	cin >> len >> x >> mod;
	vector<int> zr;
	for (auto &t : d) {
		t %= mod;
		zr.push_back((t == 0));
	}
	x %= mod;
	int bg = (x + acc(d, len - 1)) / mod;
	int eq = acc(zr, len - 1);
	cout << len - 1 - eq - bg << endl;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int k, q;
	cin >> k >> q;
	vector<int> d(k);
	for (auto &t : d) {
		cin >> t;
	}
	while (q--) {
		solve(d);
	}
}


Measured memory_bytes: 564
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
A,P = map(int,input().split())
num = 3*A+P
ans = num // 2
print(ans)

Measured memory_bytes: 5052
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int INF = 1001001001;

int main() {
    ll N;
    cin >> N;
    vl n(N);
    bool is_zero = false;
    rep (i, N) {
        cin >> n[i];
        if (n[i] == 0) is_zero = true;
    }

    ll max = 1000000000000000000;
    ll ans = 1;
    rep (i, N) {
        if (max/ans < n[i]) {
            ans = -1;
            break;
        } else {
            ans *= n[i];
        }
    }

    if (is_zero) ans = 0;

    cout << ans << endl;
}


Measured memory_bytes: 4052
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		
		while (sc.hasNext()) {
			String[] inputData = sc.next().split(",");
			
			double xa = Double.parseDouble(inputData[0]);
			double ya = Double.parseDouble(inputData[1]);
			double xb = Double.parseDouble(inputData[2]);
			double yb = Double.parseDouble(inputData[3]);
			double xc = Double.parseDouble(inputData[4]);
			double yc = Double.parseDouble(inputData[5]);
			double xd = Double.parseDouble(inputData[6]);
			double yd = Double.parseDouble(inputData[7]);
			boolean flag = true;
			
			double z1 = (xc - xb) * (ya - yb) - (yc - yb) * (xa - xb);
			double z2 = (xb - xd) * (ya - yd) - (yb - yd) * (xa - xd);
			double z3 = (xc - xb) * (ya - yb) - (yc - yb) * (xa - xb);
			
			if (z1 > 0 && z2 > 0 && z3 > 0 || z1 < 0 && z2 < 0 && z3 < 0) {
				flag = false;
			}
			
			z1 = (xd - xc) * (yb - yc) - (yd - yc) * (xb - xc);
			z2 = (xc - xa) * (yb - ya) - (yc - ya) * (xb - xa);
			z3 = (xd - xc) * (yb - yc) - (yd - yc) * (xb - xc);
			
			if (z1 > 0 && z2 > 0 && z3 > 0 || z1 < 0 && z2 < 0 && z3 < 0) {
				flag = false;
			}
			z1 = (xa - xd) * (yc - yd) - (ya - yd) * (xc - xd);
			z2 = (xd - xb) * (yc - yb) - (yd - yb) * (xc - xb);
			z3 = (xa - xd) * (yc - yd) - (ya - yd) * (xc - xd);
			if (z1 > 0 && z2 > 0 && z3 > 0 || z1 < 0 && z2 < 0 && z3 < 0) {
				flag = false;
			}
			
			z1 = (xb - xa) * (yd - ya) - (yb - ya) * (xd - xa);
			z2 = (xa - xc) * (yd - yc) - (ya - yc) * (xd - xc);
			z3 = (xb - xa) * (yd - ya) - (yb - ya) * (xd - xa);
			
			if (z1 > 0 && z2 > 0 && z3 > 0 || z1 < 0 && z2 < 0 && z3 < 0) {
				flag = false;
			}
			
			System.out.println(flag ? "YES" : "NO");
		}
	}
}

Measured memory_bytes: 26384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

class unionfind {
	vector<int> par;
	vector<int> sz;
public:
	unionfind(int n) {
		par = vector<int>(n);
		for (int i = 0; i < n; i++) par[i] = i;
		sz = vector<int>(n, 1);
	}
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	int si(int x) { return sz[find(x)]; }
	bool same(int x, int y) { return find(x) == find(y); }
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (sz[x] < sz[y]) {
			par[x] = y;
			sz[y] += sz[x];
		}
		else {
			par[y] = x;
			sz[x] += sz[y];
		}
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	unionfind uni(n);
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		uni.unite(u, v);
	}
	set<int> st;
	rep(i, n) st.insert(uni.find(i));
	int ans = st.size();
	cout << ans - 1 << '\n';
}

Measured memory_bytes: 7784
from heapq import heappop as hpp, heappush as hp
import sys
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
stx = [(s-x, t-x, x) for s, t, x in stx]
stx.sort(reverse = True)

D = [int(sys.stdin.readline()) for _ in range(Q)] 
H = []
ans = [None]*Q

for i, d in enumerate(D):
    while stx and stx[-1][0] <= d:
        hp(H, stx.pop()[1:][::-1])    
    while H and H[0][1] <= d:
        hpp(H)
    if not H:
        ans[i] = -1
    else:
        ans[i] = H[0][0]

for a in ans:
    print(a)

Measured memory_bytes: 123744
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

ll ans, a[200005];
int n;

int main(void) {
    cin >> n;
    rep(i, 0, n) scanf("%lld", &a[i]);

    if (a[0]>0) {
        puts("-1");
        return 0;
    }

    rep(i, 1, n) if (a[i]>0) {

        if (a[i-1]==a[i]-1) ans++;
        else if (a[i-1]>=a[i]) ans += a[i];
        else if (a[i-1]<a[i]-1) {
            puts("-1");
            return 0;
        }
        
    }
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in(),k=in();
    vector<ll>a(n);for(ll i=0;i<n;++i)a[i]=in();
    ll s=accumulate(a.begin(),a.end(),0ll);
    ll l=s/(n+k),r=*max_element(a.begin(),a.end());
    while(r-l>1){
        ll mid=(l+r)/2;
        ll foo=0;for(ll j=0;j<n;++j)foo+=(a[j]+mid-1)/mid-1;
        if(foo<=k){
            r=mid;
        }else{
            l=mid;
        }
    }
    cout<<r<<endl;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i,n) {
        cin>>a[i];
    }
    vector<ll> cnt(64,0);
    rep(i,n) {
        rep(j,64) {
            cnt[j] += a[i]>>j&1;
        }
    }
    ll res = 0;
    DEBUG{
        rep(i,64) {
            cout << cnt[i] << " ";
        }
    }
    rep(i,63) {
        ll add = ll(pow(2, i)) % MOD;
        add = add * cnt[i] % MOD;
        add = add * (n-cnt[i]) % MOD;
        res = (res + add) % MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2560