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

using namespace std;
using ll = long long int;
using lc = complex<double>;

template<typename T>
struct Convex {
    using P = complex<T>;
    ll n;
    vector<ll> conv;
    vector<P> v;

    T cross(P a, P b) {
        return (a * conj(b)).imag();
    }

    Convex(const vector<P> &_v) {
        // incremental method
        n = _v.size();
        v = _v;

        auto comp = [&](P a, P b) {
            return make_tuple(real(a),imag(a)) < make_tuple(real(b), imag(b));
        };
        sort(v.begin(), v.end(), comp);

        ll k = 0;
        conv.resize(n+1);
        for(ll i=n-1; i>=0; conv[k++] = i--) // up
            while(k>=2 && cross(v[i] - v[conv[k-1]], v[conv[k-2]] - v[conv[k-1]]) > 0) k--;
        for(ll i=1, t=k+1; i<n; conv[k++] = i++) // dn
            while(k>=t && cross(v[i] - v[conv[k-1]], v[conv[k-2]] - v[conv[k-1]]) > 0) k--;
        conv.resize(k-1);
    }

    P operator[](ll i) {
        return v[conv[i]];
    }
    ll size() {
        return conv.size();
    }

    double diam() {
        ll i=0, j=0;
        for(ll k=0; k<size(); k++) {
            if(imag((*this)[i]) < imag((*this)[k])) i = k;
            if(imag((*this)[j]) > imag((*this)[k])) j = k;
        }
        ll si = i, sj = j;

        T res = 0;
        do {
            res = max(res, norm((*this)[i] - (*this)[j]));
            if(cross((*this)[(i+1)%size()] - (*this)[i], (*this)[(j+1)%size()] - (*this)[j]) <= 0)
                j = (j+1) % size();
            else
                i = (i+1) % size();
        } while(!(si == i && sj == j));
        return sqrt(res);
    }
};

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    cin >> n;

    vector<complex<double>> a(n);
    for(ll i=0; i<n; i++) {
        double x, y;
        cin >> x >> y;
        a[i] = complex<double>(x, y);
    }
    Convex<double> cva(a);

    cout << cva.diam() << endl;
}



Measured memory_bytes: 5972
n, m = map(int, input().split())
a = list(map(int, input().split()))
matches = [100, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [""]
for i in range(1, n + 1):
    dp.append(None)
    for d in a:
        m = matches[d]
        if i - m >= 0 and dp[i - m] is not None:
            r = max(dp[i - m] + str(d), str(d) + dp[i - m])
            if dp[i] is None or len(r) > len(dp[i]) or len(r) == len(dp[i]) and r > dp[i]:
                dp[i] = r
print(dp[n])


Measured memory_bytes: 28896
import java.util.Scanner;
 
public class Main {

	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String[] day = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for(int i = 0; i < 7; i++) {
        if(s.equals(day[i])) {
            System.out.println(7 - i);
        }
    }		
	}
}

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

const ll INF = pow(10, 9) + 7;
int f(int x) {
	int aa = 0;
	while (x) {
		aa = x;
		x /= 10;
	}
	return aa;
};

int main() {
	int N;
	cin >> N;
	vector<vector<int>> a(10, vector<int>(10));

	for (int i = 1; i <= N; i++) {
		int A = f(i);
		int B = i % 10;
		a[A][B]++;
	}

	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		int A = f(i);
		int B = i % 10;
		ans += a[B][A];
	}
	cout << ans;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,A,B;
    cin >> N >> A >> B;
    if(abs(A-B)%2 == 0) {
        cout << abs(A-B)/2 << endl;
    }
    else {
        cout << min((A+B-1)/2,(N*2-A-B+1)/2) << endl;
    }
}


Measured memory_bytes: 3636
/*
 * https://atcoder.jp/contests/abc154/tasks/abc154_b
 */
#include <bits/stdc++.h>
 
using namespace std;

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll long long

/* 
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/*
 * 正規表現系
 */
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

const int MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;

    cout << REPLACE(s, ".", "x");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,c;
	while(scanf("%d %d",&a,&b),a!=0){
		if(a>2 && a<=8){
			if(a%2==0)c=a/2*31+(a/2-1)*30+b-1;
			else c=a/2*61+b-1;
		}
		if(a>8){
			if(a%2==0)c=a/2*31+(a/2-1)*30+b-1;
			else c=(a/2+1)*31+(a/2-1)*30+b-1;
		}
		if(a==2)c=a/2*31+b;
		if(a==1)c=b;
		c%=7;
		if(c==0)printf("Wednesday\n");
		if(c==1)printf("Thursday\n");
		if(c==2)printf("Friday\n");
		if(c==3)printf("Saturday\n");
		if(c==4)printf("Sunday\n");
		if(c==5)printf("Monday\n");
		if(c==6)printf("Tuesday\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    map<int, int> mp;
    bool ok = true;
    for(int i=0; i<n; i++){
        int a; cin >> a;
        mp[a]++;
        if(mp[a] > 1) ok = false;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.size(); ++i)
  {
    if (S == T)
    {
      cout << "Yes" << endl;
      return 0;
    }
    S = S.back() + S.substr(0, S.size() - 1);
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
lst1 = list(map(int,input().split()))
mod = 10**9+7

#高速に二項係数を求める
def cmb(n, r, mod=mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = 10 ** 5+1  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod mod)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod mod)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)


"""
その数が最大値に選ばれる回数と、最小値に選ばれる回数をすべて求め、その差が答え
"""
num_mins = 0
num_maxs = 0

lst1.sort()

for i in range(n):
    if n-k >= i:
        num_mins += lst1[i] * cmb(n-1-i,k-1)
    if i >= k-1:
        num_maxs += lst1[i] * cmb(i,k-1)

print((num_maxs-num_mins)%mod)

Measured memory_bytes: 20304
N,W = map(int,raw_input().split())
dp = [0]*(W+1)
for loop in range(N):
    v,w = map(int,raw_input().split())
    dp[w] = max(dp[w],v)
    for i in range(W-w+1):
        if dp[i]:
            dp[i+w] = max(dp[i+w],dp[i]+v)
print max(dp)

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;
typedef vector <int> vi;
typedef pair <int, int> ii;

const int INF = (int)1e9;

#define maxn 100010



int main() {
#ifdef BZ
    freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(6);

    int n, k;
    cin >> n >> k;

    vi a(n), b(n);

    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    auto e = lower_bound(a.begin(), a.end(), 0) - a.begin();

    for(int i = 0; i < n; i++) {
        b[i] = abs(a[i]);
    }

    int ans = min((e + k - 1 < n) ? b[e + k - 1] : INF, (e - k >= 0) ? b[e - k]: INF);
    //cout << ans << "\n";
    for(int i = 0; i + k - 1 < n; i++) {
        if(i + k - 1 >= e) {
            int f = b[i + k - 1] * 2 + b[i];
            int s = b[i] * 2 + b[i + k - 1];
            //cout << f << " " << s << "\n";
            ans = min(ans, min(f, s));
        }
    }

    cout << ans << "\n";


}

Measured memory_bytes: 1024
def exe_grading():
    
    grade_list=[]
    
    while True:
        
        m,f,r=tuple(map(int,input().split()))

        if m==-1 and f==-1 and r ==-1:
            break
        
        
        grade_list.append((m,f,r))
        
    for m,f,r in grade_list:
        score=m+f
        if m==-1 or f ==-1:
            print("F")
        elif score>=80:
            print("A")
        elif 80>score>=65:
            print("B")
        elif 65>score>=50:
            print("C")
        elif 50>score>=30:
            if r>=50:
                print("C")
            else:
                print("D")
        else:
            print("F")
        
exe_grading()




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

int main()
{
	int n;
	cin>>n;
	vector<int> a;
	for(int i=0;i<2*n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	long int ans=0;
	for(int i=0;i<a.size();i+=2)
	{
		ans+=a[i];
	}
	cout<<ans;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define N_MAX 1000000

int main(){
  vl tetra;
  ll i = 1;
  while(i*(i+1)*(i+2)/6 < N_MAX){
    tetra.push_back( i*(i+1)*(i+2)/6 );
    ++i;
  }
  vl alldp(N_MAX,1e18);
  alldp[0] = 0;
  REP(x,tetra.size()){
    ll tt = tetra[x];
    ll t = 1;
    ll b = tt*t;
    while(b<N_MAX){
      REP(_a,N_MAX){
        ll a = N_MAX-1-_a;
        if(a+b>=N_MAX)continue;
        alldp[a+b] = min(alldp[a+b],alldp[a]+t);
      }
      t<<=1;
      b = tt*t;
    }
  }
  vl odddp(N_MAX,1e18);
  odddp[0] = 0;
  REP(x,tetra.size()){
    ll tt = tetra[x];
    if(tt%2==0)continue;
    ll t = 1;
    ll b = tt*t;
    while(b<N_MAX){
      REP(_a,N_MAX){
        ll a = N_MAX-1-_a;
        if(a+b>N_MAX)continue;
        odddp[a+b] = min(odddp[a+b],odddp[a]+t);
      }
      t<<=1;
      b = tt*t;
    }
  }
  while(true){
    ll n;
    cin>>n;
    if(n==0)break;
    cout << alldp[n] << " " << odddp[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 16704
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/

int main() {
	ll X;cin >> X;
	for (ll i = sqrt(X);i >= 0;i--) {
		if (X % i == 0) {
			if (i > X / i) {
				cout << keta(i) << endl;
				break;
			}
			else {
				cout << keta(X / i) << endl;
				break;
			}
		}
		if (i == 0) {
			cout << keta(X) << endl;
		}
	}
}


Measured memory_bytes: 256
count = 0
n = int(input())
d = [list(map(int,input().split())) for _ in range(n)]
ans = 'No'
for d1,d2 in d:
    if d1==d2:
        count+=1
        if count==3:
            ans = 'Yes'
            break
    else:
        count = 0
        
print(ans)

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

char buf[200000+10];
int fromLeft[200000+10];
int fromRight[200000+10];
int main(void) {
  int n, k, c;
  cin >> n >> k >> c >> buf;
  {
    int id = 1;
    int last = -1e8;
    REP(i, n) {
      if(buf[i] == 'x') {
        continue;
      }
      if(i <= last + c) {
        continue;
      }
      fromLeft[i] = id++;
      last = i;
    }
  }
  {
    int id = k;
    int last = 1e8;
    for(int i = n-1; i >= 0; --i) {
      if(buf[i] == 'x') {
        continue;
      }
      if(i >= last - c) {
        continue;
      }
      fromRight[i] = id--;
      last = i;
    }
  }

  REP(i, n) {
    if(fromLeft[i] > 0 && fromRight[i] > 0 && fromLeft[i] == fromRight[i]) {
      printf("%d\n", i+1);
    }
  }
  return 0;
}


Measured memory_bytes: 3328
#![allow(unused)]

use std::cmp::{max, min};
use std::io::stdin;
use std::str::FromStr;

fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse()
}

fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|x| x.parse()).collect()
}

fn main() {
    let v: Vec<i32> = input_vec().unwrap();

    let ans = if v[1] >= v[2] {"delicious"} else if v[0] + v[1] >= v[2] {"safe"} else {"dangerous"};
    println!("{}", ans);
}


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

long long cnt;
int l, A[1000000],n,Gsize;
int * G;

void insertionSort(int A[], int n , int g) {
  int i,j,v;
  for(i = g ; i <= n-1;i++) {
    v = A[i];
    j = i - g;
    while(j >= 0 && A[j] > v ) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n) {
  int i = 0, j , h;
  for(h = 1;;) {
    if(h > n) break;
    G[i++] = h;
     h = h * 3 + 1;
  }
  Gsize = i;
  for(i = Gsize - 1; i >= 0; i--) {
    insertionSort(A, n , G[i]);
  }
   }

int main() {
  int i;
  scanf("%d",&n);
  for(i = 0;i<n;i++) scanf("%d\n",&A[i]);
  G = (int *)malloc(sizeof(int) * n);
  cnt = 0;

  shellSort(A,n);
  printf("%d\n",Gsize);
  for(i = Gsize - 1; i >=0 ; i--) {
    printf("%d",G[i]);
    if(i) printf(" ");
  }
  printf("\n" );
  printf("%lld\n", cnt);
  for (i = 0; i < n ; i++) printf("%d\n",A[i] );

  return 0;
}

Measured memory_bytes: 4516
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int a=0;
    int X;
    cin>>X;
    int ans=0;
    while(1){
        a+=X;
        a%=360;
        ans++;
        if(a==0)break;
        //cout<<a<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef unsigned long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)2e5+5;
const int Q = 301;

int a[N];
void solve() {
    ll n;
    cin>>n;
    if (n&1 || n<10) {
        cout<<0;
    }
    else {
        ll sum2 = 0;
        ll m = n;
        ll p = 2;
        while (n>=p) {
            sum2 += n/p;
            p *= 2;
        }
        n = m/2;
        ll sum5 = 0;
        p = 5;
        while (n>=p) {
            sum5 += n/p;
            p *= 5;
        }
        cout<<min(sum2, sum5);
    }
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 256
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;

int bs_cnt_less(vl& A, const ll X, bool equal) {
    if (equal) return upper_bound(A.begin(), A.end(), X) - A.begin();
    else return lower_bound(A.begin(), A.end(), X) - A.begin();
}

int bs_cnt_greater(vl& A, const ll X, bool equal) {
    if (equal) return A.end() - lower_bound(A.begin(), A.end(), X);
    else return A.end() - upper_bound(A.begin(), A.end(), X);    
}

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


  ll N,M; cin>>N>>M;
  vl A(N); REP(i,N) cin>>A[i];

  sort(A.begin(), A.end());

  ll l = 2, r = 1e5*2+1;

  while(l < r-1) { // [l,r)
    ll m = (l+r)/2;
    
    ll num = 0;
    REP(i,N) {
      num += bs_cnt_greater(A, m-A[i], true);
    }

    if (num>=M) {
      l = m;
    } else {
      r = m;
    }
  }

  vl sum(N+1,0);
  REP(i,N) sum[i+1] = sum[i] + A[i];

  ll ans = 0, num = 0;
  REP(i,N) {
    //int lle = bs_cnt_less(A, l-A[i], true);
    int lgt = bs_cnt_greater(A, l-A[i], false);
    //assert(l+1 == r);
    //assert(lle + lgt == N);
    int lle = N - lgt;

    num += lgt;
    ans += A[i]*lgt + (sum[N] - sum[lle]);
  }
  while (num<M) {
    ll cnt = 0;
    REP(i,N) {
      ll cntr = bs_cnt_less(A, l-A[i], true);
      ll cntl = bs_cnt_less(A, l-A[i], false);
      cnt += cntr - cntl;
    }
    ll dc = min(cnt, M-num);
    ans += l * dc;
    num += dc;

    if (l>2) l--;
    else break;
  }  
 
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
N = gets.chomp.to_i
T = gets.chomp.split(" ").map(&:to_i)
M = gets.chomp.to_i

P = []
X = []
M.times do
  p, x = gets.chomp.split(" ").map(&:to_i)
  P << p
  X << x
end

M.times do |i|
  t = T.clone
  t[P[i]-1] = X[i]
  puts t.inject(:+)
end

Measured memory_bytes: 1916
s = input()
if len(s) == 2:
    if s[0] == s[1]:
        print(1, 2)
    else:
        print(-1, -1)
    exit()
for i in range(len(s) - 2):
    if s[i] == s[i + 1] or s[i + 1] == s[i + 2] or s[i + 2] == s[i]:
        print(i + 1, i + 3)
        exit()
print(-1, -1)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main() {
ll N,K,Q;
cin >> N >> K >> Q;
vector<ll> Aq(Q);
for(ll i = 0;i<Q;i++){
    cin >> Aq[i];
}
vector<ll> ansN(N,K);//i+1番目にA[k]の正解回数+Kがメモしてある
for(ll i = 0;i<Q;i++){
    ansN[Aq[i]-1]++;
}
for(ll i = 0;i<N;i++){
    if(ansN[i] - Q >0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = scanner.nextInt();
		}
		int m = scanner.nextInt();
		int count = 0;
		while (m-- > 0) {
			int a = scanner.nextInt();
			for (int i = 0; i < n; i++) {
				if (a == num[i]) {
					count++;
					break;
				}

			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 30988
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int[] a = new int[n];
        Arrays.fill(a, q);
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt() - 1;
            a[x]--;
        }
        for (int i = 0; i < n; i++) {
            if (a[i] >= k) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

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

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

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

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

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 54356
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import Control.Arrow
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import Data.Char
import Data.Function
import Data.List
import Data.Maybe
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString.Unsafe as B

type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
 
parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
 
parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

main = do
  !n <- readLn :: IO Int
  !a <- U.unfoldrN n parseInt <$> C.getContents :: IO (U.Vector Int)
  let !ans = recip $ U.foldl (\ttl x -> ttl + recip (fromIntegral x)) 0.0 a :: Double
  print ans


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

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

    int H, W; cin >> H >> W;
    int N; cin >> N;
    vi a(N);
    REP(i, N) cin >> a[i];
    vvi ans(H, vi(W));
    int k = 0;
    REP(i, H)
    {
        if(i % 2 == 0)
        {
            REP(j, W)
            {
                while(a[k] == 0) k++;
                ans[i][j] = k+1;
                a[k]--;
            }
        }
        else
        {
            RREP(j, W)
            {
                while(a[k] == 0) k++;
                ans[i][j] = k+1;
                a[k]--;
            } 
        }
    }

    REP(i, H)
    {
        REP(j, W) cout << ans[i][j] << " ";
        cout << endl;
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
const int mod = 1e9+7, A = 1e5+5;
using namespace std;
ll fact[A], inv[A];
ll fp(ll x, ll y)
{
	if (!y)
		return 1;
	ll acc = fp(x, y/2) %mod;
	acc = (acc * acc) %mod;
	if (y & 1)
		return ((acc %mod) * (x %mod)) %mod;
	return acc;
}
void fact_inv(ll n)
{
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = (fact[i-1] * i) %mod;
		inv[i] = fp(fact[i], mod-2);
	}
}
ll ncr(ll n, ll r)
{
	return ((fact[n]*inv[r]) %mod * inv[n-r]) %mod ;
}
ll npr(ll n, ll r)
{
	return (fact[n] * inv[n-r]) %mod ;
}
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	fact_inv(1e5+2);
	sort(a, a + n);
	ll sum_mx = 0, sum_mn = 0;
	for (ll i = k-1; i < n; i++)
		sum_mx = (sum_mx %mod + ((a[i] %mod) * (ncr(i, k-1) %mod)) %mod) %mod;
	reverse(a, a + n);
	for (ll i = k-1; i < n; i++)
		sum_mn = (sum_mn %mod + ((a[i] %mod) * (ncr(i, k-1) %mod)) %mod) %mod;
	ll ans = (sum_mx %mod - sum_mn %mod) %mod;
	cout << ans;
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vl>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

void solve() {
  int n; cin >> n;
  Graph parts(3, vl(n));
  rep(i,3) rep(j,n) cin >> parts[i][j];

  rep(i,3) sort(all(parts[i]));

  Graph dp(3, vl(n, 1));

  rep(i,2) {
    int idx = 0;
    ll sum = 0;
    rep(j,n) {
      while (idx < n && parts[i][idx] < parts[i+1][j]) {
        sum += dp[i][idx];
        ++idx;
      }
      dp[i+1][j] = sum;
    }
  }

  cout << accumulate(all(dp[2]), 0LL) << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 5744
#include<bits/stdc++.h>
using namespace std;
int main(){
  string w;
  cin>>w;
  int ans=0;
  for(int i=0;i<w.size();i++){
    int x=0;
    for(int j=0;j<w.size();j++){
      if(w[i]==w[j]){
        x++;
      }
    }
    if(x%2!=0){
      ans++;
      break;
    }
  }
  if(ans==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
data = list(input().split(" "))
stack = []
for d in data:
    if d == '+':
        stack.append(stack.pop() + stack.pop())
    elif d == '-':
        stack.append(- stack.pop() + stack.pop())
    elif d == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(d))
print(stack[0])

Measured memory_bytes: 7544
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000001;
const ll MOD = 1000000007;
//  In 0-1 knapsack if we choose an item we can do it only once so look in the dp table in the above
// row when it was not selected.
ll v[101], w[101], dp[101][100001];
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1,W, V = 100001, ans = 0;
    cin>>n>>W;    
    for(i=1;i<=n;i++){
        cin>>w[i];
        cin>>v[i];
    }    
    for(i=0;i<=n;i++){
        for(j=0;j<V;j++){
            dp[i][j] = 9999999999;
        }
    }
    dp[0][0] = 0;
    for(i=1;i<=n;i++){
        for(j=1;j<V;j++){                        
            if(j > v[i]){
                x = dp[i-1][j - v[i]] + w[i];
                dp[i][j] = min(dp[i-1][j], x);                                
            }else{
                dp[i][j] = min(dp[i-1][j], w[i]);
            }
         }       
    }
    // for(i=0;i<=n;i++){
    //     for(j=0;j<=20;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    for(i=1;i<V;i++){
        if(dp[n][i] <= W)
            ans = max(ans, i);
    }
    cout<<ans;
}    

Measured memory_bytes: 79232
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
s = 0
for i in range(n):
    if s+a[i]==x or (i<n-1 and s+a[i]<=x):
        s += a[i]
#         print(s)
    else:
        i -= 1
        break
print(i+1)

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	string n;
	cin >> n;

	int judge=0;
	rep(i,n.size()){
		judge += (n[i] - '0');
	}
	if(judge % 9 == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

}

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

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

using namespace std;

using Number = double;
const Number EPS = 1e-10;

inline int sign(Number x) { return (x < -EPS) ? -1 : (x > EPS) ? +1 : 0; }
inline bool equal(Number a, Number b) { return sign(a - b) == 0; }

class Point {
public:
    Number x, y;

    Point() {}
    Point(Number x, Number y) : x(x), y(y) {}

    Point operator+(const Point &rhs) const {
        return Point(this->x + rhs.x, this->y + rhs.y);
    }
    Point operator-(const Point &rhs) const {
        return Point(this->x - rhs.x, this->y - rhs.y);
    }
};

inline Number abs_cross(const Point &p1, const Point &p2) {
    return p1.x * p2.y - p1.y * p2.x;
}

class Line : public std::array<Point, 2> {
public:
    Line() {}
    Line(const Point &p1, const Point &p2) {
        (*this)[0] = p1;
        (*this)[1] = p2;
    }
};
inline bool IsParallel(const Line &l1, const Line &l2) {
    return equal(abs_cross(l1[0] - l1[1], l2[0] - l2[1]), 0.0);
}

int Search(const int i, const int m, vector<int> &idx, const vector<Point> &p) {
    if (i == m - 2) {
        int sum = 0;
        vector<bool> check(m / 2, false);

        for (int j = 0; 2 * j < m; ++j) {
            if (check[j]) continue;

            check[j] = true;
            int num = 1;
            Line l(p[idx[2 * j]], p[idx[2 * j + 1]]);
            for (int k = j + 1; 2 * k < m; ++k)
                if (IsParallel(l, Line(p[idx[2 * k]], p[idx[2 * k + 1]]))) {
                    ++num;
                    check[k] = true;
                }
            sum += num * (num - 1) / 2;
        }
        return sum;
    }

    int res = 0;
    int min_idx = distance(idx.begin(), min_element(idx.begin() + i, idx.end()));
    swap(idx[i], idx[min_idx]);
    for (int j = i + 1; j < m; ++j) {
        swap(idx[i + 1], idx[j]);
        res = max(res, Search(i + 2, m, idx, p));
        swap(idx[i + 1], idx[j]);
    }
    swap(idx[i], idx[min_idx]);

    return res;
}

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

    int m;

    cin >> m;
    vector<Point> p(m);
    for (auto &pp : p) cin >> pp.x >> pp.y;

    vector<int> idx(m);
    iota(idx.begin(), idx.end(), 0);

    cout << Search(0, m, idx, p) << endl;

    return 0;
}



Measured memory_bytes: 3232
ip = input()
ip = ip.split(" ")
n = int(ip[0])
h = int(ip[1])

dmg = []

for i in range(n):
  ip = input()
  ip = ip.split(" ")
  dmg.append([int(ip[0]), 0])
  dmg.append([int(ip[1]), 1])

dmg_sorted = sorted(dmg, reverse=True)

rs = 0
i = 0
j = 0
while i <= len(dmg_sorted):
  if dmg_sorted[i][1] == 1:
    h = h - dmg_sorted[i][0]
    rs = rs + 1
    i = i + 1
    j = j + 1
  elif dmg_sorted[i][1] == 0:
    rs = rs + h // dmg_sorted[i][0]
    if(h % dmg_sorted[i][0] != 0):
      rs = rs + 1
    else:
      pass
    j = j + 1
    break
  else:
    raise ValueError("hoge")
  
  if h <= 0:
    break
  else:
    pass
  
print(rs)

Measured memory_bytes: 32232
N,M = map(int,input().split())
H = input().split()
good = [1]*N
import collections

for i in range(M):
  a,b = map(int,input().split())
  if int(H[a-1]) > int(H[b-1]):
    good[b-1] = 0
  elif int(H[a-1]) < int(H[b-1]):
    good[a-1] = 0
  else:
    good[a-1] = 0
    good[b-1] = 0
    
c = collections.Counter(good)
print(c[1])


Measured memory_bytes: 17696
d, g = map(int, input().split())
p = []
c = []

for i in range(d):
    _p, _c = map(int, input().split())
    p.append(_p)
    c.append(_c)
cnt = 10 ** 5
for i in range(2**d):
    tmp = 0
    ans = 0
    for j in range(d):
        if i >> j & 1:
            tmp += p[j]
            ans += c[j] + p[j] * 100 * (j + 1)
    for j in range(d-1, -1, -1):
        if ans >= g:
            break
        if i >> j & 1:
            continue
        for k in range(p[j] - 1):
            ans += 100 * (j + 1)
            tmp += 1
            if ans >= g:
                break
    if ans >= g:
        cnt = min (tmp, cnt)
print(cnt)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

#define INF 1<<29

template <typename T>
struct BipartiteMatching {
  struct Edge {
    int to, rev; T cap;
    Edge(int to, int rev, T cap) : to(to), rev(rev), cap(cap) { }
  };

  typedef vector<Edge> Edges;
  vector<Edges> G;
  int V, source, sink;
  vector<int> level, iter;
  
  BipartiteMatching(int V1, int V2) {
    V = V1 + V2 + 2, source = V-2, sink = V-1;
    G.resize(V);
    add_sink_source(V1, V2);
  }

  void add_edge(int from, int to) {
    G[from].push_back(Edge(to, (int)G[to].size(), 1));
    G[to].push_back(Edge(from, (int)G[from].size()-1, 0));
  }

  void add_sink_source(int V1, int V2) {
    for (int i = 0; i < V1; i++) add_edge(source, i);
    for (int i = V1; i < V1+V2; i++) add_edge(i, sink);
  }

  void bfs(int source) {
    level.assign(V, -1);
    queue<int> que;
    que.push(source);
    level[source] = 0;
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int i = 0; i < (int)G[v].size(); i++) {
	Edge &e = G[v][i];
	if (e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[v] + 1;
	  que.push(e.to);
	}
      }
    }
  }

  T dfs(int v, int sink, T flow) {
    if (v == sink) return flow;
    for (int &i = iter[v]; i < (int)G[v].size(); i++) {
      Edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
	T d = dfs(e.to, sink, min(e.cap, flow));
	if (d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }

  T dinic() {
    T flow = 0;
    while (true) {
      bfs(source);
      if (level[sink] < 0) return flow;
      iter.assign(V, 0);
      T f;
      while ((f = dfs(source, sink, INF)) > 0) {
	flow += f;
      }
    }
  }
};


int main() {
  // use scanf in CodeForces!

  while (true) {
    int M, N;
    scanf("%d %d", &M, &N);
    if (M == 0 && N == 0) break;
    BipartiteMatching<int> bp(M, N);
    int blue[501], red[501];
    REP(i, M) scanf("%d", blue+i);
    REP(i, N) scanf("%d", red+i);
    REP(i, M) REP(j, N) {
      if (__gcd(blue[i], red[j]) > 1) {
	bp.add_edge(i, M+j);
      }
    }
    printf("%d\n", bp.dinic());
  }

  return 0;
}

Measured memory_bytes: 7488
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heapify, heappush 
def main():
    N, M = map(int, readline().split())
    tasks = [[] for _ in range(M)]
    for _ in range(N):
        a, b = map(int, readline().split())
        if M-a<0:
            continue
        tasks[M-a].append(b)
    s = 0
    h = []
    for i in reversed(range(M)):
        for b in tasks[i]:
            heappush(h, -b)
        if len(h)>0:
            s+=-heappop(h)
    print(s)
if __name__ == '__main__':
    main()


Measured memory_bytes: 64176
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long



int main() {
	int n, a[100010], b[100010];
	ll ans = 0;
	cin >> n;
	for (int i = 0; i < n + 1; i++)cin >> a[i];
	for (int i = 0; i < n; i++)cin >> b[i];
	for (int i = n; i > 0; i--) {
		if (a[i] > b[i - 1]) {
			ans += b[i - 1];
			a[i] -= b[i - 1];
			b[i - 1] = 0;
		}
		else {
			b[i - 1] -= a[i];
			ans += a[i];
			a[i] = 0;
			if (a[i - 1] > b[i - 1]) {
				ans += b[i - 1];
				a[i - 1] -= b[i - 1];
				b[i - 1] = 0;
			}
			else {
				ans += a[i - 1];
				b[i - 1] -= a[i - 1];
				a[i - 1] = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int n, mx, sum;

int main()
{
	scanf("%d", &n);
	for (int i = 1, x; i <= n; i ++)
	{
		scanf("%d", &x);
		mx = max(mx, x);
		sum += x;
	}
	puts(mx * 2 < sum ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
#define MOD 1000000007

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> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const int INF=1e9;
const double eps=0.0000000001;


int main(){
  ll n;
  cin >> n;
  ll sum=0,v=(1+n)*n/2,a[1000000];
  FOR(i,n){
    cin >> a[i];
    sum+=a[i];
  }

  if(sum%v!=0){
    cout << "NO" << endl;
    return 0;
  }
  ll kaisuu=sum/v,m=0;

  ll b[1000000],sumi=0;
  bool c=0;
  FOR(i,n){
    if(i==n-1)b[i]=a[0]-a[i];
    else b[i]=a[i+1]-a[i];

    if((b[i]-kaisuu)%(n)!=0){
      c=1;
    }else{
      m+=abs((b[i]-kaisuu)/n);
    }
  }
  if(m!=kaisuu){
    c=1;
  }

  if(c){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }

  

  

  
  
  
  
}


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

int main() {
  int n;
  cin >> n;
  
  bool can = false;
  for(int i=0; ; i++) {
    if(7*i > n) {
      break;
    }
    for(int j=0; ; j++) {
      if(7*i+4*j == n) {
        can = true;
        break;
      }
      else if(7*i+4*j > n) break; 
    }
  }
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,x;
    cin>>n>>m;
    vector<int>vi[n+3];
    for(i = 0 ;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        vi[a].push_back(b);
        vi[b].push_back(a);
    }
    for(i = 1;i<=n ;i++)
    {
        cout<<vi[i].size()<<endl;
    }
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
//#define INF             1000000000
//#define INF             100000000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

void init(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int N = 1000;

char arr[N][N];

int mr[N], mc[N];

int main()
{
	int h, w;
	cin >> h >> w;
	lp(i, h)
		lp(j, w){
			cin >> arr[i][j];
			if(arr[i][j] == '.'){
				++mr[i];
				++mc[j];
			}
		}
	lp(i, h){
		lp(j, w)
			if(mr[i] < w && mc[j] < h)
				cout << arr[i][j];
		if(mr[i] < w)
			cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 384
r, c = [int(i) for i in input().split()]

data = []
sum_row = [0]*(c+1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c+1):
        sum_row[ci] += data[ri][ci]
print(" ".join([str(s) for s in sum_row]))

Measured memory_bytes: 7696
#include <bits/stdc++.h>
  
int main(){
 long long int n,m;
 scanf("%lld%lld",&n,&m);

 if(n>1&&m>1){
        printf("%lld\n",(n-2)*(m-2));
 }else if(n==1){
        if(m==1){
                printf("1\n");
                return 0;
        }else{
                printf("%lld\n",m-2);
                return 0;
        }
 }else{
        printf("%lld\n",n-2);
        return 0;
 }
}

Measured memory_bytes: 256
#AIsing2020 c

import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
ans = [0]*N

for x in range(1,101):
    for y in range(x+1,101):
        for z in range(y+1,101):
            n = x**2+y**2+z**2+x*y+y*z+z*x
            if n <= N:
                ans[n-1] +=6
                
for x in range(1,101):
    y = x
    for z in range(1,101):
        if z == x:
            continue
        else:
            n = x**2+y**2+z**2+x*y+y*z+z*x
            if n <= N:
                ans[n-1] +=3

for x in range(1,101):
    y = x
    z = x
    n = x**2+y**2+z**2+x*y+y*z+z*x
    if n <= N:
        ans[n-1] +=1
        
for i in range(N):
    print(ans[i])
        


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

int main() {
    int a, b;
    cin >> a >> b;

    int diff = b - a;
    int sum = 0;
    for(int i=diff; i>0; --i) {
        sum += i;
    }

    int diff2 = sum - b;

    cout << diff2 << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] d = new int[N];
		for(int i = 0;i < N;i++){
			d[i] = sc.nextInt();
		}
		sc.close();

		int sum = 0;
		for(int i = 0;i < N-1;i++){
			for(int j = i+1;j < N;j++){
				sum += (d[i]*d[j]);
			}
		}
		System.out.println(sum);

	}

}

Measured memory_bytes: 22228
#include <stdio.h>

int main()
{
  int x,y,a,to;

  scanf("%d %d",&x,&y);

  if(y > x)
    {
      a = x;
      x = y;
      y = a;
    }

  to = x % y;
  while(to != 0)
    {
      x = y;
      y = to;
      to = x % y;
    }

  printf("%d\n",y);

  return 0;
}



Measured memory_bytes: 2068
import sys
import collections
import itertools
import math
from collections import Counter
from collections import deque
MOD = 10 ** 9 + 7


N, x = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

B = A.copy()


for i in range(1, N):
    s = B[i - 1] + B[i]
    if s > x:
        B[i] -= s - x
        if B[i] < 0:
            B[i - 1] += B[i]
            B[i] = 0


# print(A)
# print(B)

total = 0
for i in range(N):
    total += A[i] - B[i]

print(total)

sys.exit(0)


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

int p[100100];
int li[100100];
map<int,int> mp;

int fi(int nw)
{
	if(li[nw]==nw)return nw;
	return li[nw]=fi(li[nw]);
}

void uni(int l1,int l2)
{
	li[l1]=l2;
}

main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)li[i]=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		mp[p[i]]=i;
	}
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		if(fi(a)!=fi(b))
		{
			uni(fi(a),fi(b));
		}
	}
	for(int i=1;i<=n;i++)fi(i);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(li[mp[i]]==li[i])
		{
			ans++;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++) 
#define S(v) sort(v.begin(),v.end());


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin>>n>>k;
    vector<ll> v(n);
    loop(i,0,n)cin>>v[i];
    loop(i,k,n){
        if(v[i] > v[i-k])cout<<"Yes";
        else cout<<"No";
        cout<<"\n";
    }
    
    

}

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

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

int main() {
  int n;
  cin >> n;
  
  int s = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    s = gcd(s, a);
  }
  cout << s << endl;
}

Measured memory_bytes: 256