akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

ll ncr(vll &fac,vll &finv,ll n,ll r){
	if(n<0||r<0||n<r) return 0 ;
	if(n==r||r==0) return 1 ;
	return fac.at(n)*finv.at(n-r)%mod*finv.at(r)%mod ;
}

ll modpow(ll a,ll b){
	ll res = 1 ;
	while(b>0){
		if(b&1) res = res*a%mod ;
		b >>= 1 ;
		a = a*a%mod ;
	}
	return res ;
}

int main(){
	ll n ; cin >> n ;
	if(n==1){
		ll ans ; cin >> ans ;
		cout << ans*2%mod << endl ;
		return 0 ;
	}
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	sort(all(a)) ;
	vll fac(n+10,1),inv(n+10,1),finv(n+10,1) ;
	for(int i=2;i<fac.size();i++){
		fac.at(i) = fac.at(i-1)*i%mod ;
		inv.at(i) = mod-inv.at(mod%i)*(mod/i)%mod ;
		finv.at(i) = finv.at(i-1)*inv.at(i)%mod ;
	}
	ll cnt = 0 ;
	ll d = 0 ;
	for(int i=1;i<=n;i++){
		ll sub = i*ncr(fac,finv,n-1,i-1)%mod ;
		cnt += sub ;
		cnt %= mod ;
		d += sub-(i*ncr(fac,finv,n-2,i-1)%mod+(i-1)*ncr(fac,finv,n-2,i-2));
		d %= mod ;
	}
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		ll sub = (cnt-d*i%mod+mod)%mod ;
		ans = (ans+sub*a.at(i)%mod)%mod ;
//		cout << sub << " " ;
	}
	cout << ans*modpow(2,n)%mod << endl ;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	vector<PLL> vp(n);
	for (int i = 0; i < n; i++) {
		LL a,b;
		cin >> a >> b;
		vp[i] = make_pair(a,b);
	}
	SORT(vp);
	LL ans = 0,count = 0;
	for (int i = 0; i < n; i++) {
		if (count + vp[i].second >= m) {
			ans += (m - count) * vp[i].first;
			cout << ans << endl;
			return 0;
		}
		ans += vp[i].second * vp[i].first;
		count += vp[i].second;
	}
	return 0;
}



Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
    int n;
    vector<pair<int, int>> vp;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        vp.push_back(make_pair(x, y));
    }
    double res = 0;
    for (int i = 0; i < n; i++) {
        long double r = 0;
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            r += pow((vp[i].first - vp[j].first) * (vp[i].first - vp[j].first) + (vp[i].second - vp[j].second) * (vp[i].second - vp[j].second), 0.5);
        }
        res += r / (n);
    }
    cout << setprecision(12) << res << endl;
}


Measured memory_bytes: 512
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
    int n ; 
    cin >> n ; 
    long double total = 0 ; 
    long double bit = 380000 ; 
    while(n--){
    	long double x ; 
    	string s ; 
    	cin >> x >> s ; 
    	if ( s == "JPY" ) total += x ; 
    	else total += x*bit ; 
    }
    cout << fixed << setprecision(6) << total << endl;
    return 0 ;
}


Measured memory_bytes: 256
import numpy as np

s = list(str(input()))

if len(s) % 2 == 1:
  c = len(s) // 2
  del s[c]

half_len = int(len(s)/2)
h = s[:half_len]
t = s[-half_len:]
t.reverse()

count = 0
for i in range(0, half_len):
  if h[i] != t[i]:
    count = count + 1
print(count)

Measured memory_bytes: 18872
//
// Created by sark2 on 14-07-2019.
//

#include "bits/stdc++.h"

using namespace std;
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cases int t;cin>>t;while(t--)
typedef long double ld;

int main() {
    IOS

    int n;
    cin>>n;
    int cost[n][3];

    for(int i = 0; i < n; i++){
        for(int j = 0; j<3; j++){
            cin>>cost[i][j];
        }
    }
    int dp[n][3];
    for(int i = 0; i < 3; i++){
        dp[0][i] = cost[0][i];
    }
    for(int i = 1; i < n; i++){
        dp[i][0] = cost[i][0] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = cost[i][1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = cost[i][2] + max(dp[i-1][1],dp[i-1][0]);
    }
 /*   for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/

    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#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 rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int k,a,b;cin>>k>>a>>b;
    if(b/k-a/k>0||a%k==0||b%k==0)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}

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

int main(){
  long long int sum=0;
  long long int tmp=0;
  long long int mid;
  vector <long long int> v;
  int q;
  cin >> q;
  long long int a,b,c;
  cin >> a >> b >> c;
  sum+=(b+c);
  v.push_back(b);
  tmp+=b;
  mid = b;
  for(int i=0;i<q-1;i++){
    cin >> a;
    if(a==1){
      cin >> b >> c;
      sum+=(b+c);
      v.insert(upper_bound(v.begin(),v.end(),b),b);
      if(mid>=b){
        if(v.size()%2==0)tmp -= mid;
        tmp += b;
        mid=v[(v.size()-1)/2];
      }
      else{
        if(v.size()%2)tmp += v[(v.size()-1)/2];
        mid=v[(v.size()-1)/2];
      }
    }
    else cout << v[(v.size()-1)/2] <<" "<<((long long int)v.size()%2)*v[(v.size()-1)/2]+sum - 2*tmp << endl;
  }
}

Measured memory_bytes: 3700
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, M = MAP()
a = LIST()
b = LIST()
xyc = [LIST() for _ in range(M)]

ans = min(a)+min(b)

for x, y, c in xyc:
	ans = min(ans, a[x-1]+b[y-1]-c)
print(ans)


Measured memory_bytes: 40568
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int temp = N/2+N%2;
		BigDecimal a = new BigDecimal(N);
		BigDecimal b = new BigDecimal(temp);
		b =b.divide(a, 12,RoundingMode.HALF_UP);
		System.out.println(b.toPlainString());
	}
}


Measured memory_bytes: 22740
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
rd=[True for i in range(n+1)]
mod=1000000007
for i in a:
    rd[i]=False
dp=[1]+[0 for i in range(n)]
for i in range(n):
    for j in range(i+1,min(i+3,n+1)):
        if rd[j]:
            dp[j]+=dp[i]
            dp[j]%=mod
print(dp[n])

Measured memory_bytes: 9384
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <typename T> lint gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> lint lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b) a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b) a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  string s;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> s;
      if (s == "snuke") {
        cout << char(j + 65) << i + 1 << '\n';
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc138/tasks/abc138_d

from collections import deque

def dfs(lst, start, ans):
    queue = deque([])
    queue.append(start)
    visited = [False] * len(ans)
    visited[start] = True

    while queue:
        parent = queue.pop()
        for child in lst[parent]:
            if visited[child]:
                continue
            visited[child] = True
            ans[child] += ans[parent]
            queue.append(child)

    print(*ans)

n,q = map(int, input().split())
start = 0

tree = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

ans = [0]*n
for _ in range(q):
    p, x = map(int,input().split())
    ans[p-1] += x
dfs(tree, start, ans)


Measured memory_bytes: 56188
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct segt
{
	int l,r,maxv;
}tree[2400010];
int a[300010],dp[300010];
void build(int le,int ri,int i)
{
	tree[i].l=le;
	tree[i].r=ri;
	tree[i].maxv=0;
	if(le==ri)
		return;
	int mid=(le+ri)>>1;
	build(le,mid,i<<1);
	build(mid+1,ri,i<<1|1);
}
void change(int p,int x,int i)
{
	if(tree[i].l==tree[i].r)
	{
		tree[i].maxv=max(tree[i].maxv,x);
		return;
	}
	if(tree[i<<1].r>=p)
		change(p,x,i<<1);
	else
		change(p,x,i<<1|1);
	tree[i].maxv=max(tree[i<<1].maxv,tree[i<<1|1].maxv);
}
int ask(int le,int ri,int i)
{
	if(le<=tree[i].l&&tree[i].r<=ri)
		return tree[i].maxv;
	int cnt=0;
	if(tree[i<<1].r>=le)
		cnt=ask(le,ri,i<<1);
	if(tree[i<<1|1].l<=ri)
		cnt=max(cnt,ask(le,ri,i<<1|1));
	return cnt;
}
signed main()
{
	int n,k,i,ans=1;
	cin>>n>>k;
	for(i=1;i<=n;i++)
		cin>>a[i];
	build(1,300002,1);
	for(i=1;i<=n;i++)
	{
		dp[i]=max(1ll,ask(max(0ll,a[i]-k)+1,min(300000ll,a[i]+k)+1,1)+1);
		change(a[i]+1,dp[i],1);
		ans=max(ans,dp[i]);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    int N, M;
    cin >> N >> M;
    vector<int> P(M);
    vector<string> S(M);
    REP(i, M) { cin >> P[i] >> S[i]; }
    ll ac = 0LL, wa = 0LL;
    set<int> ACed;
    vector<int> WABuf(N + 1, 0);
    REP(i, M) {
        if (ACed.find((P[i])) != ACed.end()) {
            continue;
        }
        if (S[i] == "AC") {
            ACed.insert(P[i]);
            ++ac;
            wa += WABuf[P[i]];
        } else {
            WABuf[P[i]]++;
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}

Measured memory_bytes: 11136
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ff first
#define ss second
#define sf ss.ff
#define tt ss.ss
#define input(a) scanf("%lld",&a)
#define M 1000000007
#define inf 1<<30
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

/*
 *Use abbreviation:
 *dsu ->Disjoint Set Union
 *bit ->Binary Indexed Tree
 *math ->Mathematical Functions(gcd,fact,bigMod,ncr)
 *test ->For test cases
 */

ll n,k,res;
vll a,b;

int main()
{
    cin>>n;
    a.resize(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b.push_back(a[i]);
    }
    sort(a.begin(),a.end());
    res=0;
    for(int i=0;i<n;i++){
        k=lower_bound(a.begin(),a.end(),b[i])-a.begin();
        res+=(abs(k-i)&1);
    }
    cout<<res/2<<endl;
    return 0;
}



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

using namespace std;

typedef long long LL;

const int maxn = 100000;
const int mod = 1000000007;

LL a[maxn + 10], b[maxn + 10];
LL maxa, maxb, sa, sb;
int n;

LL solve() {
    if(sa > sb) return 0;
    if(maxa != maxb) return 0;
    LL ans = 1;
    LL t = maxa;
    for(int i = sa - 1; i >= 0; i--) {
        if(a[i] != t) t = a[i];
        else ans = (ans * a[i]) % mod;
    }
    t = maxb;
    for(int i = sb + 1; i < n; i++) {
        if(b[i] != t) t = b[i];
        else ans = (ans * b[i]) % mod;
    }
    for(int i = sa + 1; i <= sb - 1; i++) ans = (ans * maxa) % mod;
    return ans;
}

int main() {
    while(~scanf("%d", &n)) {
        maxa = maxb = 0;
        for(int i = 0; i < n; i++) {
            scanf("%lld", &a[i]);
            if(a[i] > maxa) maxa = a[i], sa = i;
        }
        for(int i = 0; i < n; i++) scanf("%lld", &b[i]);
        for(int i = n - 1; i >= 0; i--) {
            if(b[i] > maxb) maxb = b[i], sb = i;
        }
        printf("%lld\n", solve());
    }
    return 0;
}


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

const int N = 1234567;
const int mod =  1e9+7;

vector<bool> prime(N, true);
vector<int> primes;
void sieve() {
	for (int i = 2; i < N; i++) {
			if (prime[i])
				primes.push_back(i);
			for (int j = i; j < N; j += i) {
				prime[j] = false;
			}
	}
}

int f(int n, int p){
	int ans = 0;
	long long int cur = 1LL*p;
	while(true) {
		int temp = n/cur;
		if (temp==0)	break;
		ans+=temp;
		cur *= (long long) p;
	}
	return ans;
}

int main() {

	int n;
	cin >> n;
	sieve();
	long long int ans = 1;
	for (int i = 0; i < primes.size(); i++) {
		int p = f(n, primes[i]);
		p++;
		ans = ((ans%mod)*((long long) p%mod))%mod;
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().solove();
    }

    public void solove() {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int distance1 = Math.abs(a - c);

        if (distance1 <= d) {
            System.out.println("Yes");
            return;
        }

        int distance2 = Math.abs(a - b);
        int distance3 = Math.abs(b - c);

        if (distance2 <= d && distance3 <= d) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
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;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}


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

    int n;
    int q;
    cin >> n >> q;
    //priority_queue<ll> que;
    priority_queue<ll> vec[n];
    

    int num,t;
    ll x;
    while (q--)
    {
        cin >>num>>t;
        if(num==0){
            cin >> x;
            vec[t].push(x);
        }
        else if(num==1){
            if(!vec[t].empty())
                cout << vec[t].top() << endl;
        }
        else{
            if(!vec[t].empty())
                vec[t].pop();   
        }
    }       
    return 0;
}


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


signed main() {
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
  int n;
  cin>>n;
 vector<int> a(n);
 map<int,int> mp;
 for(int i=0;i<n;i++)
 {
      cin>>a[i];
     
 }
 sort(a.begin(),a.end());
 int cnt=0;
 for(int i=0;i<n-2;i++)
 {
      int k=i+2;
      for(int j=i+1;j<n;j++)
      {
           while(k<n&&(a[i]+a[j]>a[k]))
           k++;//k will be inceremented extra,we can use binary search
           if(k>j)
           cnt+=(k-j-1);
      }
      
 }
 cout<<cnt;

}

Measured memory_bytes: 256
N, D = map(int, input().split())
X = [0]*N
for i in range(N):
  X[i] = list(map(int, input().split()))
cnt = 0
for i in range(N):
  for j in range(i+1,N):
    prod = 0
    for p in range(D):
      prod += (X[i][p]-X[j][p])**2
    prod **= 0.5
    if prod==int(prod):
      cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
  int i, j;
  int a[3];
  int b[3];
  int c[4] = {};
  for (i = 0; i < 3; i++) {
    scanf("%d %d", &a[i], &b[i]);
    c[a[i]-1]++;
    c[b[i]-1]++;
  }
  for (i = 0; i < 4; i++) {
    if (c[i] == 3) {
      puts("NO");
      goto end;
    }
    if (c[i] == 0) {
      puts("NO");
      goto end;
    }
  }
  puts("YES");
 end:
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <algorithm>

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

using namespace std;

typedef long double ld;

ld d;

int main(){
	scanf("%Lf", &d);
	ld ans = M_SQRT2 * d;
	for(int i = 1; i <= d; ++i){
		ld k = sqrt(d * d - i * i);
		ans = max(max<ld>(k, 1) + i, ans);
	}
	printf("%.12Lf\n", ans);
	return 0;
}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n, a, b, c;
   cin >> n >> a >> b >> c;
   vector<int> d(n);
   for (int i = 0; i < n; i++) {
      cin >> d[i];
   }
   sort(d.begin(), d.end(), greater<int>());
   int cal = c, sum = a;
   int Max = 0;
   for (int i = 0; i < n; i++) {
      Max = max(Max, cal / sum);
      cal += d[i];
      sum += b;
   }
   printf("%d\n", Max);

   return 0;
}


Measured memory_bytes: 3252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << (a+b+c >= 22 ? "bust" : "win") << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
Ai = [(i + 1) - a for i, a in enumerate(A)]
Aj = [(j + 1) + a for j, a in enumerate(A)]
cntAi = defaultdict(lambda: 0)
for ai in Ai:
    cntAi[ai] += 1

ans = 0
for ai, aj in zip(Ai, Aj):
    cntAi[ai] -= 1
    ans += cntAi[aj]
print(ans)


Measured memory_bytes: 152772
from collections import deque

def solve():
    INF = float('inf')

    N = int(input())
    Ass = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(N)]

    adjL = [[] for _ in range(N*N)]
    indegs = [0] * (N*N)
    for i, As in enumerate(Ass):
        x, y = i, As[0]
        if x > y:
            x, y = y, x
        vPrev = x*N + y
        for A in As[1:]:
            x, y = i, A
            if x > y:
                x, y = y, x
            v = x*N + y
            adjL[vPrev].append(v)
            indegs[v] += 1
            vPrev = v

    def getMaxCostsDAG(adjList, indegs, INF):
        numV = len(adjList)
        vs = [v for v in range(numV) if indegs[v] == 0]
        costs = [INF] * numV
        for v in vs:
            costs[v] = 0
        Q = deque(vs)
        while Q:
            vNow = Q.popleft()
            cost = costs[vNow]
            for v2 in adjList[vNow]:
                indegs[v2] -= 1
                if indegs[v2] == 0:
                    costs[v2] = cost + 1
                    Q.append(v2)
        return costs

    costs = getMaxCostsDAG(adjL, indegs, INF)

    ans = max(costs)
    if ans == INF:
        print(-1)
    else:
        print(ans+1)


solve()


Measured memory_bytes: 216592
#include <cstdio>

int main(void){
    int A, B, C, D;
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &C);
    scanf("%d", &D);

    int sum = 0;

    if(A > B){
        sum += B;
    }else{
        sum += A;
    }

    if(C > D){
        sum += D;
    }else{
        sum += C;
    }
    printf("%d", sum);
}

Measured memory_bytes: 128
// Author : Mahmoud Tarek

#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std ;


int main(){

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

  int a , b , c ;
  cin >> a >> b >> c ;
  if( a + b >= c ) cout << "Yes\n" ;
  else cout << "No\n" ;

  return 0 ;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static class Knapsack01 {

        int capacity;
        int n;
        int[] cost;
        int[] value;

        public Knapsack01(int n, int capacity, int[] cost, int[] value) {
            this.n = n;
            this.capacity = capacity;
            this.cost = cost;
            this.value = value;
        }

        int solve() {
            int[] rowPrev = new int[capacity + 1];
            int[] rowCurr = new int[capacity + 1];
            for (int numOfItems = 1; numOfItems <= n; numOfItems++) {
                int[] tmp = rowCurr;
                rowCurr = rowPrev;
                rowPrev = tmp;
                for (int weight = 1; weight <= capacity; weight++) {
                    if (weight < cost[numOfItems - 1]) {
                        rowCurr[weight] = rowPrev[weight];
                    } else {
                        rowCurr[weight] = Math.max(
                                rowPrev[weight - cost[numOfItems - 1]] + value[numOfItems - 1],
                                rowPrev[weight]);
                    }
                }
            }
            return rowCurr[capacity];
        }
    }

    static Scanner in = new Scanner(System.in);

    static Knapsack01 readCase() {
        while (in.hasNext()) {
            int n = in.nextInt();
            int capacity = in.nextInt();
            int[] cost = new int[n];
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = in.nextInt();
                cost[i] = in.nextInt();
            }
            Knapsack01 knapsack01 = new Knapsack01(n, capacity, cost, value);
            return knapsack01;
        }
        return null;
    }

    public static void main(String[] args) {
        Knapsack01 knapsack01 = null;
        while ((knapsack01 = readCase()) != null) {
            System.out.println(knapsack01.solve());
        }
    }

}

Measured memory_bytes: 27020
# ?????¶??????????±???????????????°??????
import sys

def main():
    n = int(sys.stdin.readline().strip())

    for _ in range(n):
        x = sys.stdin.readline().strip()
        y = sys.stdin.readline().strip()

        if len(x) > 80 or len(y) > 80:
            print('overflow')
        else:
            ans = int(x) + int(y)
            if len(str(ans)) > 80:
                print('overflow')
            else:
                print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7660
from collections import defaultdict
n, m, k = list(map(int, input().split()))
ns = defaultdict(set)
bs = defaultdict(set)
for i in range(m):
    a,b = list(map(int, input().split()))
    ns[a-1].add(b-1)
    ns[b-1].add(a-1)
for i in range(k):
    c,d = list(map(int, input().split()))
    bs[c-1].add(d-1)
    bs[d-1].add(c-1)
    
s = [0]
start = 0
parent = [None] * n
starts = defaultdict(int)
starts[0] = 0
notdone = set(list(range(n)))
notdone.remove(start)
while notdone or s:
    u = s.pop()
    parent[u] = start
    starts[start] += 1
    for v in ns[u]:
        if v in notdone:
            s.append(v)
            notdone.remove(v)
    if not s and notdone:
        start = notdone.pop()
        parent[start] = start
        s.append(start)
ans = [None] * n
for u in range(n):
    val = starts[parent[u]] - 1 - len(ns[u])
    for v in bs[u]:
        if parent[v]==parent[u]:
            val -= 1
    ans[u] = val
print(" ".join(map(str, ans)))

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

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

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

int main()
{
  int n;
  cin >> n;
  
  vi a(n);
  rep(i, n) cin >> a[i];

  vi cnt(13);
  rep(i, n){
    cnt[a[i]]++;
    if(cnt[a[i]] >= 3){
      cout << 0 << endl;
      return 0;
    }
  }

  sort(all(a));
  
  int ans = inf;
  int l = 0, r = 24;
  rep(i, n){
    if(i%2 == 0){
      ans = min(ans, a[i]-l);
      l = a[i];
    }else{
      ans = min(ans, (24-a[i])%24);
      r = 24 - a[i];
    }
  }
  ans = min(ans, (r-l)%24);

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


Measured memory_bytes: 256
from itertools import accumulate
n=int(input())
w=list(map(int,input().split()))
w=list(accumulate(w))
for i in range(n):
  if w[i]*2==w[-1]:
    print(0)
    break
  elif w[i]*2>w[-1]:
    print(min((w[i]*2-w[-1]),(w[-1]-w[i-1]*2)))
    break

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

int main(){
    for (int i = 0; i < 9; ++i)
    {
        for (int j = 0; j < 9; ++j)
        {
            cout << i+1 << "x" << j+1 << "=" << (i+1)*(j+1) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1116
#include<cstdio>
#include<bits/stdc++.h>
#define fi first
#define sc second
#define pb push_back


using namespace std;
 
 
int N, A;
vector<int> arr;
int main() { 
	
	cin >> N;
	for (int i  = 0; i < N; i++) {
		int x;
		cin >> x;
		arr.push_back(x);
	}
	sort(arr.begin(), arr.end());
	reverse(arr.begin(), arr.end());
	int ans= 0;
	for (int i = N - 1;	i >= 0; i--) {
		if (i % 2 == 0) ans += arr[i];
		else ans -= arr[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ty = [0]*n # 0:縦 1:横
s1 = input()
prev = ""
cnt = 0
for i in range(n):
    if prev == s1[i]:
        ty[i] = 1
        ty[i-1] = 1
    prev = s1[i]
ans = 1
mod = 10**9+7
f = 0
if ty[0] ==0:
    ans = 3
else:
    ans = 6
    f = 1

for i in range(1,n):
    if f==1:
        f = 0
        continue

    if ty[i] ==1:
        f = 1
        if ty[i-1] ==1:
            ans = ans*3 %mod
        else:
            ans = ans*2 %mod
    elif ty[i] == 0:
        if ty[i-1] == 0:
            ans = ans*2 %mod
        else:
            ans = ans*1
print(ans)


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(string S) {
    if (S[2] == S[3] && S[4] == S[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main() {
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
L, R = map(int, input().split())

if R-L >= 2019:
    print(0)
    exit()

for i in range(L,R+1,1):
    if i%2019 == 0:
        print(0)
        exit()

ans = 2018
for i in range(L,R+1,1):
    for j in range(i+1,R+1,1):
        x = (i*j)%2019
        if x<ans:
            ans = x

print(ans)


Measured memory_bytes: 41196
#include <iostream>
#include <complex>

using namespace std;

#define REPEAT(i,a,b)   for(int i=(a); i<(b); i++)
#define REP(i, n)       REPEAT(i, 0, n)
#define ALL(c)          (c).begin(), (c).end()

#define X real()
#define Y imag()
typedef double D;
typedef complex<double> P;
const double EPS = 1e-9;
const int INF = 1000000;
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)

int main(void){
    double x[3] ,y[3], xp, yp;
    while(cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> xp >> yp){
        P p[3];
        P target(xp,yp);
        for(int i=0; i<3; i++){
            p[i] = P(x[i],y[i]);
        }
        P a = p[1]-p[0];
        P b = p[2]-p[0];
        if(a.X*b.Y - a.Y*b.X < 0) swap(p[2],p[1]);
        bool ok = true;
        for(int i=0; i<3; i++){
            P pp = p[(i+1)%3] - p[i];
            P tar = target - p[i];
            tar/=pp;
            if(0 < tar.X && tar.X < 1 && tar.Y > 0){}
            else {
                ok = false;
                break;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }            
}

Measured memory_bytes: 1220
n=int(input())
s=[int(input())for i in range(n)]
total=sum(s)
five_path=[]
for i in s:
    if i%10!=0:
        five_path.append(i)
five_path.sort()
if total%10!=0:
    print(total)
else:
    if len(five_path)==0:
        print(0)
    else:
        print(total-five_path[0])
        

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9

using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
const db pi = acos(-1);
const int N = 1e5 + 10;
string ch;
int main()
{
	cin >> ch;
	int n = ch.size();
	int x = ch.size() - 2;
	rep(i, 1, n - 1)
		if(ch[i - 1] != ch[i + 1]) break;
		else x --;
	rrep(i, n - 2, 1)
		if(ch[i - 1] != ch[i + 1]) break;
		else x --;
	if(x <= 0) puts("Second");
	else puts(((ch.size() + (ch[0] == ch[n - 1])) % 2) == 0 ? "Second" : "First");
	return 0;
}


Measured memory_bytes: 512
sa = list(input())
sb = list(input())
sc = list(input())

turn = sa[0]
sa.pop(0)

while True:
    if turn == 'a':
        if not sa:
            print('A')
            break
        else:
            turn = sa[0]
            sa.pop(0)

    elif turn == 'b':
        if not sb:
            print('B')
            break
        else:
            turn = sb[0]
            sb.pop(0)

    elif turn == 'c':
        if not sc:
            print('C')
            break
        else:
            turn = sc[0]
            sc.pop(0)


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli a, b;
    cin>>a>>b;
    lli ans=0;
    rep(i,2){
        if(a>b){ 
            ans+=a;
            a--;
        }
        else{ 
            ans+=b;
            b--;
        }
    }
    out(ans);
}

Measured memory_bytes: 3600
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
struct Node
{
	double x;
	inline bool operator < (const Node &nt) const
	{
		return nt.x<x;
	}
};
priority_queue<Node> Q; 
signed main(void)
{
	int n;
	cin>>n;
	reg double x;
	for(int i=1;i<=n;++i)
		cin>>x,Q.push((Node){x});
	while(Q.size()!=1)
	{
		reg double a=Q.top().x;Q.pop();
		reg double b=Q.top().x;Q.pop();
		Q.push((Node){(double)((a+b)/2.0)});
	}
	cout<<Q.top().x<<endl;
	return 0;
}


Measured memory_bytes: 256
;; BEGIN_INSERTED_CONTENTS
(declaim (inline read-line-into))
(defun read-line-into (buf-str &optional (in *standard-input*) (terminate-char #\Nul))
  (declare (optimize (speed 3) (safety 1))
	   (simple-base-string buf-str))
  (loop for ch of-type base-char =
           #-swank (code-char (read-byte in nil #\Newline))
           #+swank (read-char in nil #\Newline)
        for idx = 0 then (1+ idx)
        until (char= ch #\Newline)
        do (setf (aref buf-str idx) ch)
        finally (setf (aref buf-str idx) terminate-char)
                (return buf-str)))

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil
(deftype uint nil `(integer 0 ,(expt 10 9)))
(defun main ()
  (declare (optimize (speed 3) (safety 1)))
  (let* ((n (read))
         (k (read))
         (table (make-array (list n) :element-type 'uint))
         (buf (make-string 11 :element-type 'standard-char :initial-element #\Newline)))
    (declare (uint k))
    (dotimes (idx n)
      (setf (aref table idx)
            (parse-integer (read-line-into buf *standard-input* #\Newline) :junk-allowed t)))
    (stable-sort table #'<)
    (println
     (loop for begin-idx from 0
           for end-idx from (- (min k (length table)) 1) below (length table)
           minimize (- (aref table end-idx) (aref table begin-idx))))))

#-swank(main)


Measured memory_bytes: 12776
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	int ans;
	cin>>ans;
	for(int i=2; i<=n; i++) {
		int a; cin>>a;
		ans=a xor ans;
	}

	if(ans==0) {
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}

	return 0;
}


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

#define int long long
signed main(){

    int n, k; cin >> n >> k;
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        a--;
        p[i].first = b;
        p[i].second = a;
        
    }

    //おいしさ、種類

    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    int ans = 0LL;
    vector<int> isSelect(n, 0LL);
    for(int i = 0; i < k; i++){
        ans += p[i].first;
        isSelect[p[i].second]++;
        //cout << p[i].second << endl;
    }



    int num = 0LL;

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

        //cout << i << "   " << isSelect[i] << endl;
        num += (isSelect[i] != 0);
    }

    //cout << num << endl;
      
    vector<int> tempp(n, 0LL);
    for(int i = 0; i < n; i++){
        if(isSelect[p[i].second] == 0){
            tempp[p[i].second] = max(tempp[p[i].second], p[i].first);
        }
    }
    //cout << "43" << endl;
    vector<int> vec;
    for(int i = 0; i < n; i++){
        if(tempp[i] != 0) vec.push_back(tempp[i]);
    }

    reverse(p.begin(), p.end());    
    vector<int> tmp;
    //cout << "51" << endl;
    for(int i = n - k; i < n; i++){
        //cout << i << " " << p[i].first << "   " << p[i].second << endl;
        if(isSelect[p[i].second] > 1){
            tmp.push_back(p[i].first);
            isSelect[p[i].second]--;
            //cout << "hoge" << endl;
        }
    }



    sort(tmp.begin(), tmp.end());
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    int anss = 0;
    int v = 0;
    anss = ans + num * num;
    //cout << anss << endl;
    for(int i = 0; (i < k - num) && (i < vec.size()) && (i < tmp.size()); i++){

        v += vec[i] - tmp[i];
        anss = max(anss, ans + (num + i + 1) * (num + i + 1) + v);
        //cout << ans << " " << (num + i + 1) * (num + i + 1) << " " << vec[i] << " " << tmp[i] << endl;
    }
    
    cout << anss << endl;
    return 0;
}

Measured memory_bytes: 4128
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
const int MAX = 410;
int H, W;
vector<string> fi;

ll numb = 0;
ll numw = 0;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool seen[MAX][MAX];
void dfs(int x, int y) {
    seen[x][y] = true;
    if(fi[x][y] == '#') {
        numb++;
    } else {
        numw++;
    }
    for(int dir = 0; dir < 4; dir++) {
        int nx = x + dx[dir];
        int ny = y + dy[dir];
        if(nx < 0 || nx >= H || ny < 0 || ny >= W) {
            continue;
        }
        if(fi[x][y] == fi[nx][ny]) {
            //同じ色だった
            continue;
        }
        //このif文必要ですか
        if(seen[nx][ny]) {
            //他の連結成分に含まれる
            continue;
        }
        dfs(nx, ny);
    }
}
int main() {
    cin >> H >> W;
    fi.resize(H);
    REP(i, H) { cin >> fi[i]; }
    ll res = 0;
    for(int x = 0; x < H; x++) {
        for(int y = 0; y < W; y++) {
            //黒から白へ行く回数
            if(fi[x][y] == '.') {
                continue;
            }
            if(seen[x][y]) {
                continue;
            }
            numb = numw = 0;
            dfs(x, y);
            res += numb * numw;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod (ll) 2019
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  ll L, R, m = inf;
  cin >> L >> R;
  if(R - L >= 2019) {
    cout << 0;
    exit(0);
  }
  int  x = L % mod, y = R - (L - x);
  for(int i = x; i < y; i++) {
    for(int j = i+1; j <= y; j++) {
      m = min(m, ((i % mod) * (j % mod)) % mod);
    }
  }
  cout << m;   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)	
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7  ;
#define ld long double
#define MAX (int)(330)

ll n;
ld dp[MAX][MAX][MAX];
ld solve(ll i, ll j ,ll k){
	if(dp[i][j][k] != -1)
		return dp[i][j][k];
	ld s =0 ;
	vector<ld> th({(ld)i,(ld)j,(ld)k});
	ld ans = 0;
	forx(3){
		s+=th[x];
		if(th[x]){
			th[x]--;
			if(x)
				th[x-1]++;
			ans += (ld)(th[x]+1)/((ld)n) * (solve(th[0], th[1], th[2])+1);
			if(x)
				th[x-1]--;
			th[x]++;
		}
	}
	// x = (n-s)/n * (x + 1) + ans  ==   x = (n-s)/n * x  +  (n-s)/n  + ans
	// x*s/n  = ans + (n-s)/n
	// x = ans*n / s + (n-s)/s
//	cout<<"the ans : "<<ans<<" the s: "<<s<<" the n: "<<n<<endl;
	dp[i][j][k] = (ans*(ld)n) /(ld)s  + ((ld)n-(ld)s)/(ld)s;
//	cout<<"at "<<i<<" "<<j<<" "<<k<<" we got: "<<dp[i][j][k]<<endl;
	return dp[i][j][k];
}

void deal(){
	fori(MAX)
		forj(MAX)
			fork(MAX)
				dp[i][j][k] = -1;
	dp[0][0][0] = 0;
	cin>>n;
	vector<ll> th(3,0);
	fori(n){
		ll ed;
		cin>>ed;
		th[ed-1]++;
	}
	cout<<setp(13)<<solve(th[0], th[1], th[2]);
}
 
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}
 
/*
 
5 1
1 2 3 4 5


*/

Measured memory_bytes: 562048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string atCoder;
  string contest;
  string name;  //コンテストのタイトル
  cin >> atCoder >> name >> contest;  //入力
 
  char letter;  //一文字目
  
  letter = name.at(0);  //一文字目を取り出す
  
  //出力
  cout << "A" << letter << "C" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;


void solve() {
	int n; cin >> n;
	vector<ll> l(n), r(n), len(n);
	rep(i, n)cin >> l[i] >> r[i];
	rep(i, n)len[i] = r[i] - l[i];
	ll ml = l[0], mr = l[0]; ll my = 0;
	multiset<ll> sl, sr;
	ll adle = 0, adri = 0;
	rep1(i, n - 1) {
		ml -= len[i]; mr += len[i - 1];
		if (l[i] < ml) {
			ll dif = ml - l[i];
			sl.insert(dif - adle); sl.insert(dif - adle);
			my += dif;
			sr.insert(- adri);adri += mr - ml;
			mr = ml;
			ll nl = *sl.begin(); sl.erase(sl.begin());
			nl += adle;
			ml -= nl;
			adle -= nl;
		}
		else if (l[i] > mr) {
			ll dif = l[i] - mr;
			sr.insert(dif - adri); sr.insert(dif - adri);
			my += dif;
			sl.insert(- adle); adle += mr - ml;
			ml = mr;
			ll nr = *sr.begin(); sr.erase(sr.begin());
			nr += adri;
			mr += nr;
			adri -= nr;
		}
		else {
			sl.insert(-adle), sr.insert(-adri);
			adle += l[i] - ml; adri += mr - l[i];
			ml = mr = l[i];
		}
	}
	cout << my << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 12032
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, m = LI()
    lst = []
    for _ in range(n):
        a, b = LI()
        lst.append([a,b])

    lst.sort()

    ans = 0
    for i in range(n):
        tem = lst[i][1]
        lst[i][1] = max(0, lst[i][1]-m)
        bought = tem-lst[i][1]
        m -= bought
        ans += lst[i][0]*bought
        if m == 0:
            break

    print(ans)   
main()


Measured memory_bytes: 87988