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

template<class T, class E, typename F, typename G, typename H, typename P>
struct LazySegmentTree {
private :
    int n;
    F f;
    G g;
    H h;
    P p;
    T id1;
    E id0;
    vector<T> node;
    vector<E> lazy;
public :

    LazySegmentTree () { }

    LazySegmentTree (int sz, const F &f, const G &g, const H &h, T id1, E id0, const P &p)
            : f(f), g(g), h(h), id1(id1), id0(id0), p(p) {
        n = 1; while (n < sz) n *= 2;
        node.resize(2*n-1, id1);
        lazy.resize(2*n-1, id0);
    }

    LazySegmentTree (vector<T> v, const F &f, const G &g, const H &h, T id1, E id0, const P &p)
            : f(f), g(g), h(h), id1(id1), id0(id0), p(p) {
        n = 1; while (n < (int)v.size()) n *= 2;
        node.resize(2*n-1, id1);
        lazy.resize(2*n-1, id0);
        for (int i = 0; i < (int)v.size(); i++){
            node[i+n-1] = v[i];
        }
        for (int i = n-2; i >= 0; i--) {
            node[i] = f(node[2*i+1], node[2*i+2]);
        }
    }

    inline void eval (int len, int k) {
        if (lazy[k] == id0) return;
        if (k*2+1 < n*2-1) {
            lazy[2*k+1] = h(lazy[2*k+1], lazy[k]);
            lazy[2*k+2] = h(lazy[2*k+2], lazy[k]);
        }
        node[k] = g(node[k], p(lazy[k], len));
        lazy[k] = id0;
    }

    T update (int a, int b, E x, int k, int l, int r) {
        eval(r-l, k);
        if (r <= a || b <= l) return node[k];
        if (a <= l && r <= b) {
            lazy[k] = h(lazy[k], x);
            return g(node[k], p(lazy[k], r-l));
        }
        return node[k] = f(update(a, b, x, 2*k+1, l, (l+r)/2),
                           update(a, b, x, 2*k+2, (l+r)/2, r));
    }

    T update (int a, int b, E x) { return update(a, b, x, 0, 0, n); }

    T query (int a, int b, int k, int l, int r) {
        eval(r-l, k);
        if (r <= a || b <= l) return id1;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }

    T query (int a, int b) { return query(a, b, 0, 0, n); }

};


int main() {
    int n, q;
    cin >> n >> q;
    
    auto f = [](int a, int b) { return min(a, b); };
    auto g = [](int a, int b) { return (b == -1 ? a : b); };
    auto h = [](int a, int b) { return (b == -1 ? a : b); };
    auto p = [](int a, int b) { return a; };
    LazySegmentTree<int, int, decltype(f), decltype(g), decltype(h), decltype(p)>
        seg(n, f, g, h, INT_MAX, -1, p);

    while (q--) {
        int op;
        cin >> op;
        if (op == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            seg.update(s, t+1, x);
        } else {
            int s, t;
            cin >> s >> t;
            cout << seg.query(s, t+1) << endl;
        }
    }
    return 0;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    string a,b;
    cin >> a >> b;

   	if(a=="D"){
   		if(b=="H"){
   			cout << "D";
   			return 0;
   		}
   		else{
   			cout << "H";
   			return 0;
   		}
   	}

   	cout << b << endl;

    return 0;
}

Measured memory_bytes: 256
def ok(P):
    cnt = 0
    truck = 0
    for w in W + [0]:
        if w > P:
            return False
        if truck + w <= P:
            truck += w
        else:
            truck = w
            cnt += 1
    if cnt + 1 <= K:
        return True
    else:
        return False


N, K = map(int, input().split())
W = [int(input()) for _ in range(N)]
l, r = 0, 10**10
while r - l > 1:
    c = (l + r) // 2
    if ok(c):
        r = c
    else:
        l = c
print(r)



Measured memory_bytes: 10352
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
        if(a%(2*b+1)==0){System.out.println(a/(2*b+1));}
		else{System.out.println(a/(2*b+1)+1);}
	}
}


Measured memory_bytes: 21844
A,B,C,D,E,F=map(int,input().split())
a=b=d=0
m=lambda:100*(A*a+B*b)+D*d
l=[]
while m()<=F:
 while m()<=F:
  while m()<=F:
   c=min((E*(A*a+B*b)-D*d)//C,(F-m())//C)
   if(a+b>0)&(c>=0):l+=[(m()+C*c,C*c+D*d,E-(C*c+D*d)/(A*a+B*b))]
   d+=1
  b+=1;d=0
 a+=1;b=0
l.sort(key=lambda x:x[2])
print(*l[0][:2])

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

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

    int n;
    cin >> n;
    vector<vector<ll>> a(10, vector<ll>(10));
    rep(i, 1, n + 1) {
        int x = i;
        int s = x % 10;
        int t = 0;
        while (x) {
            t = x % 10;
            x /= 10;
        }
        a[s][t]++;
    }
    ll ans = 0;
    rep(i, 1, 10) rep(j, 1, 10) {
        ans += (ll)(a[i][j] * a[j][i]);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int q, ope, tmp;
    vector<int> p = {};

    cin >> q;

    for (int i = 0; i < q; i++){
        cin >> ope;
        if (ope == 0){
            cin>>tmp;
            p.push_back(tmp);
        }else if (ope == 1){
            cin>>tmp;
            cout << p[tmp]<<"\n";
        }else{
            p.pop_back();
        }

        //for(int j=0;j<p.size();j++){
        //   cout<<p[j]<<" ";
        //}
    }
    return 0;
}


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

struct Node {
  long key;
  Node *parent, *left, *right;
};

Node *root, *nil;

void insert(long k) {
  Node *y = nil;
  Node *x = root;

  Node *z;
  z = (Node*)malloc(sizeof(Node));
  z->key = k;
  z->parent = nil;
  z->left = nil;
  z->right = nil;

  while (x != nil) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if (y == nil) {
    root = z;
  } else if (z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void in(Node* n) {
  if (n == nil) return;
  in(n->left);
  cout << ' ' << n->key;
  in(n->right);
}

void pre(Node* n) {
  if (n == nil) return;
  cout << ' ' << n->key;
  pre(n->left);
  pre(n->right);
}

void find(long k) {
  Node* x = root;
  while (x != nil && x->key != k) {
    if (k < x->key) x = x->left;
    else x = x->right;
  }
  if (x == nil) cout << "no";
  else cout << "yes";
  cout << endl;
}

void print() {
  in(root); cout << endl;
  pre(root); cout << endl;
}

int main() {

  long l; cin >> l;

  while (l--) {
    string s; cin >> s;

    if (s == "insert") {
      long k; cin >> k;
      insert(k);
    } else if (s == "find") {
      long k; cin >> k;
      find(k);
    } else {
      print();
    }
  }

  return 0;
}

Measured memory_bytes: 19964
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
vector <int> G[MAXN], path;
bool vis[MAXN];
void dfs(int pos)
{
	vis[pos] = true;
	path.push_back(pos);
	for (int i = 0; i < G[pos].size(); ++i)
	{
		if(!vis[G[pos][i]])
		{
			dfs(G[pos][i]);
			break;
		}
	}
}
int main()
{
	int n,m;
	cin>>n>>m;
	for (int i = 0; i < m; ++i)
	{
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1);
	reverse(path.begin(), path.end());
	path.pop_back();
	dfs(1);
	cout<<path.size()<<"\n";
	for (int i = 0; i < path.size(); ++i)
	{
		cout<<path[i]<<" ";
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 9720
import bisect
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
a.sort()
b.sort()
b=b[::-1]
c.sort()
ans=tmp=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c, i)
    ans+=x*(n-y)
print(ans)

Measured memory_bytes: 23232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    LL N,M; cin >> N >> M;
    VL A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    VL racc(N+1);
    for(int i = N-1; i >= 0; i--){
        racc[i] = racc[i+1] + A[i];
    }
    
    LL ok = 0;
    LL ng = 1e5 * N + 10;
    while(abs(ok-ng) > 1){
        LL mid = (ok+ng) / 2;
        LL m = 0;
        REP(i,N){
            m += A.end() - lower_bound(A.begin(),A.end(),mid-A[i]);
        }
        if(m >= M) ok = mid;
        else ng = mid;
    }
    LL ans = 0;
    LL cnt = 0;
    REP(i,N){
        LL idx = lower_bound(A.begin(),A.end(),ok-A[i]) - A.begin();
        LL pcnt =A.end() - lower_bound(A.begin(),A.end(),ok-A[i]);
        cnt += pcnt;
        ans += racc[idx];
        ans += pcnt * A[i];
    
    }
    ans -= (cnt-M) * ok;
    cout << ans << endl;

}

Measured memory_bytes: 1792
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int q = int.Parse(cin[1]);
        string s = Console.ReadLine();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++)
        {
            cin = Console.ReadLine().Split();
            l[i] = int.Parse(cin[0]);
            r[i] = int.Parse(cin[1]);
        }

        int[] c = new int[n];
        c[0] = 0;
        for (int i = 1; i < n; i++)
        {
            c[i] = c[i - 1];
            if (s[i - 1] == 'A' && s[i] == 'C') c[i]++;
        }

        for (int i = 0; i < q; i++)
        {
            Console.WriteLine(c[r[i] - 1] - c[l[i] - 1]);
        }
    }
}

Measured memory_bytes: 17100
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N=200005;
const LL inf=(LL)1e16;

int n,m,a,b;
LL sum[N],x[N],f[N];

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;
}

struct Segment_Tree
{
	struct tree{LL mn;}t[N*4];
	
	void build(int d,int l,int r)
	{
		t[d].mn=inf;
		if (l==r) return;
		int mid=(l+r)/2;
		build(d*2,l,mid);build(d*2+1,mid+1,r);
	}
	
	void ins(int d,int l,int r,int x,LL y)
	{
		if (l==r) {t[d].mn=y;return;}
		int mid=(l+r)/2;
		if (x<=mid) ins(d*2,l,mid,x,y);
		else ins(d*2+1,mid+1,r,x,y);
		t[d].mn=min(t[d*2].mn,t[d*2+1].mn);
	}
	
	LL query(int d,int l,int r,int x,int y)
	{
		if (l==x&&r==y) return t[d].mn;
		int mid=(l+r)/2;
		if (y<=mid) return query(d*2,l,mid,x,y);
		else if (x>mid) return query(d*2+1,mid+1,r,x,y);
		else return min(query(d*2,l,mid,x,mid),query(d*2+1,mid+1,r,mid+1,y));
	}
}t1,t2;

void dp()
{
	t1.ins(1,1,m,x[0],f[1]-x[0]-sum[1]);
	t2.ins(1,1,m,x[0],f[1]+x[0]-sum[1]);
	for (int i=2;i<=n;i++)
	{
		f[i]=min(t1.query(1,1,m,1,x[i])+x[i],t2.query(1,1,m,x[i],m)-x[i])+sum[i-1];
		t1.ins(1,1,m,x[i-1],f[i]-x[i-1]-sum[i]);
		t2.ins(1,1,m,x[i-1],f[i]+x[i-1]-sum[i]);
	}
}

int main()
{
	m=read();n=read();a=read();b=read();
	for (int i=1;i<=n;i++) x[i]=read();
	for (int i=2;i<=n;i++) sum[i]=sum[i-1]+abs(x[i]-x[i-1]);
	LL ans=inf;
	f[1]=abs(a-x[1]);x[0]=b;
	t1.build(1,1,m);t2.build(1,1,m);
	dp();
	for (int i=1;i<=n;i++) ans=min(ans,f[i]+sum[n]-sum[i]);
	f[1]=abs(b-x[1]);x[0]=a;
	t1.build(1,1,m);t2.build(1,1,m);
	dp();
	for (int i=1;i<=n;i++) ans=min(ans,f[i]+sum[n]-sum[i]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 17408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
// const ll mod=1e9+7 ;
const ll MOD=998244353;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string s;
    cin >> s;

    int rgb[3];
    rgb[0] = 0;
    rgb[1] = 0;
    rgb[2] = 0;
    int maze[3*n];
    rep(i,3*n) maze[i] = 0;

    rep(i, 3*n)
    {
        if (s[i] == 'R')
        {
            rgb[0]++;
        }
        else if (s[i] == 'G')
        {
            rgb[1]++;
        }
        else
        {
            rgb[2]++;
        }

        if (rgb[0]>=1 && rgb[1]>=1 && rgb[2]>= 1)
        {
            maze[i] = 1;
            rgb[0]--;
            rgb[1]--;
            rgb[2]--;
        }
    }
    for (int i=3*n-1;i>=0;i--)
    {
        if (s[i] == 'R')
        {
            rgb[0]++;
        }
        else if (s[i] == 'G')
        {
            rgb[1]++;
        }
        else
        {
            rgb[2]++;
        }

        if (rgb[0]>=1 && rgb[1]>=1 && rgb[2]>= 1)
        {
            maze[i] = -1;
            rgb[0]--;
            rgb[1]--;
            rgb[2]--;
        }
    }
    // rep(i, 3*n)
    // {
    //     cout << maze[i];
    // }
    int snum=0;
    ll ans = 1;
    rep(i, 3*n)
    {
        if (maze[i] == -1)
        {
            snum++;
        }
        else if (maze[i] == 0)
        {
            ans *= snum;
            ans = ans % MOD;
            snum--;
        }
    }
    int m = 0;
    rep(i, 3*n)
    {
        if (maze[i] == 0)
        {
            m++;
        }
        else if (maze[i] == 1)
        {
            ans *= m;
            ans = ans % MOD;
            m--;
        }
    }
    REP(i,1,n+1)
    {
        ans *= i;
        ans = ans % MOD;
    }
    cout << ans << endl;
}


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

int gcd(int x,int y) {
    if (x % y == 0) return y;
    else return gcd(y, x % y);
}

int main() {
    int n;
    long int sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                sum += gcd(i, gcd(k, j));
            }
        }
    }
    cout << sum << endl;   
    return 0; 
}

Measured memory_bytes: 3620
x, y = map(int, input().split())
group1 = [1, 3, 5, 7, 8, 10, 12]
group2 = [4, 6, 9, 11]
if x == 2 or y == 2:
    print('No')
elif (x in group1 and y in group1) or (x in group2 and y in group2):
    print('Yes')
else:
    print('No')

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

using namespace std;

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

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

const int inf = 2000000000;

main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b, c, d; 
    cin >> a >> b >> c >> d;
    for(int i = 0; i < 1000 && a > 0 && c > 0; i++){
        if(i % 2 == 0){
            c -= b;
        } else {
            a -= d;
        }
    }
    cout << (a > 0 ? "Yes" : "No");
}


Measured memory_bytes: 3652
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    int N;
    cin >> N;
    ll A[N]; ll s= 0;  ll sum = 0;

    rep(i, N) cin >> A[i]; for (int i = 0; i < N; i++) {s += A[i];}
    for (int i = 0; i < N - 1; i++) {
        s -= A[i];
        sum += (A[i] * (s % 1000000007LL)) % 1000000007LL;
        sum = (sum % 1000000007LL);
        
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 5116
#include<stdio.h>
int main(void)
{
	int n,p[100],i,j,jb,pon;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;;i++){
		jb=0;
		for(j=0;j<n;j++){
			if(p[j]>=i){
				jb++;
			}
		}
		if(jb<i){
			pon=i-1;
			break;
		}
	}
	printf("%d\n",pon);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;

int main() {
    fastIO;
    int n;
    cin >> n;
    vector<int> ans(n);
    for (int i = 1; i < n; i++) {
        int x;
        cin >> x;
        ans[x-1]++;
    }
    for (auto i : ans) {
        cout << i << '\n';
    }
}


Measured memory_bytes: 3952
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>

using namespace std;
typedef long long ll;

const int maxn=500+10;
int a[maxn][maxn];
int b[maxn][maxn];
int p[maxn*maxn];
int n,ans;
int go[4][2]={0,1,0,-1,1,0,-1,0};

bool check(int x,int y)
{
    return !(x<0||x>=n||y<0||y>=n);
}

void init()
{
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int cost = min(i, min(n - 1 - i, min(j, n - 1 - j)));
            a[i][j]=cost;
            b[i][j]= 0;
        }
    }
}

void update(int x,int y)
{
    for(int i=0;i<4;i++){
        int xx=x+go[i][0];
        int yy=y+go[i][1];
        if(check(xx,yy)){
            if(b[x][y]){
                if(a[x][y]<a[xx][yy]){
                    a[xx][yy]=a[x][y];
                    update(xx,yy);
                }
            }
            else{
                if((a[x][y]+1)<a[xx][yy]){
                    a[xx][yy]=a[x][y]+1;
                    update(xx,yy);
                }
            }
        }
    }
}

int main() {
    cin>>n;
    init();
    for(int i=0;i<n*n;i++){
        cin>>p[i];
        p[i]--;
        int x=p[i]/n;
        int y=p[i]%n;
        ans+=a[x][y];
        b[x][y]= 1;
        update(x,y);
        /*for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)cout<<a[i][j];
            cout<<"   ";
            for(int j=0;j<n;j++)cout<<b[i][j];
            cout<<endl;
        }
        cout<<endl;*/
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n, m;
	cin >> n >> m;
	int a[n];
	REP(i, n) cin >> a[i];
	map<int, int> mp;
	REP(i, n) mp[a[i]]++;
	vector<P> oc;
	for(auto it = mp.begin(); it != mp.end(); it++){
		oc.pb({it->first, it->second});
	}
	REP(i, m){
		int b, c;
		cin >> b >> c;
		oc.pb({c, b});
	}
	sort(ALL(oc), greater<P>());
	ll ans = 0, taken = 0, cur = 0;
	for(P p: oc){
		if(taken + p.second <= n){
			taken += p.second;
			ans += p.second * p.first;
		}
		else if(taken < n){
			ans += p.first * ((ll)n - taken);
			taken = n;
		}
	}
	cout << ans << endl;
	return 0;
} 


Measured memory_bytes: 11504
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		int[] x = new int[n];
		int[] y = new int[n];
		for(int i = 0 ; i < n ; i++) {
			t[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		int dist = x[0] + y[0];
		int time = t[0];
		boolean ok = true;
		for(int i = 0 ; i < n ; i++) {
			if(i != 0) {
				dist = Math.abs(x[i] - x[i - 1]) + Math.abs(y[i] - y[i - 1]);
				time = Math.abs(t[i] - t[i - 1]);
			}
			if(time < dist) {
				ok = false;
			} else if(time > dist && time % 2 != dist % 2) {
				ok = false;
			}
		}
		if(ok) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 94388
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int N=1e5+5;
ll dp[N]={-1},v[N],n;
const int inf=0x3f3f3f3f;
ll check(int index);


int main(){
ll i,j,k,m;
memset(dp,-1,sizeof(dp));
    cin>>n;
    for(i=0;i<n;i++)
        cin>>v[i];
    cout<<check(0)<<"\n";

    return 0;
}

ll check(int index){
    if(dp[index]!=-1)return dp[index];

    if(index==n-1)return dp[index]=0;
    else if(index==n-2)return dp[index]=abs(v[index]-v[index+1]);

    return dp[index]=min(abs(v[index]-v[index+1])+check(index+1),
                abs(v[index]-v[index+2])+check(index+2));
}

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

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

using namespace std;

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){
			if(p[v]<p[u]) swap(u,v);
			p[u]+=p[v]; p[v]=u; n--;
		}
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size()const{ return n; }
	int size(int u){ return -p[find(u)]; }
};

int main(){
	int n,m,k; scanf("%d%d%d",&n,&m,&k);

	vector<int> ans(n,-1);
	union_find U(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		U.unite(u,v);
		ans[u]--;
		ans[v]--;
	}
	rep(u,n) ans[u]+=U.size(u);

	rep(i,k){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		if(U.is_same(u,v)) ans[u]--, ans[v]--;
	}

	rep(u,n) printf("%d%c",ans[u],u<n-1?' ':'\n');

	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    REP(i,N){
        cin >> H[i];
    }

    int ans = 0;
    REP(i,N){
        bool ok = true;
        REP(j,i){
            if(H[i] < H[j]){
                ok = false;
            }
        }
        if(ok){
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }
  
  reverse(H.begin(), H.end());
  int ans = 0;
  int val = 0;
  for(int i = 1; i < N; i++){
    if(H[i-1] <= H[i]){
      val++;
    }else{
      val = 0;
    }
    ans = max(ans, val);
  }

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


Measured memory_bytes: 640
#include<iostream>
#define ll long long int
#include<bits/stdc++.h>

using namespace std;

int main()
{
ll n,k,cursum=0,res=0;
  cin>>n>>k;
  vector<ll> arr(n);
  vector<ll> sum(n+1);
  sum[0]=0;
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
    sum[i+1]=sum[i]+arr[i];
  }
  queue<ll> q;
  map<ll,ll> count;
  for(int i=0;i<=n;i++)
  {
    cursum=(sum[i]-i)%k;
    q.push(cursum);
    res+=count[cursum];
    count[cursum]++;
    if(q.size()>=k)
    {
      count[q.front()]--;
    	q.pop();
  	}
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 17536
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	string s;
	cin >> s;
	int len = (int)s.size();

	int Aindex;
	int Zindex = 0;
	REP(i, len){
		if (s[i] == 'A'){
			Aindex = i;
			break;
		}
	}

	FOR(i, Aindex, len){
		if (s[i] == 'Z'){
			if (i > Zindex) Zindex = i;
		}
	}

	cout << Zindex - Aindex + 1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
long long int fac(long int n)
{
	long long int res=1;
	for(int i=1;i<=n;i++)
	{
		res=(res*i)%(1000000007);
	}
	return res;
}
int main()
{
	long int n,m;
	cin>>n>>m;
	if((n>m+1) || (m>n+1))
	{
		cout<<"0\n";
		return 0;
	}
	else
	{
		if(n-m==1 || m-n==1)
		cout<<(fac(n)*fac(m))%(1000000007);
		else
			{
				cout<<(((2*fac(n))%1000000007)*fac(m))%(1000000007);
			}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int c1,c2;
  int i,j,n;
  int ans,temp;
  int num[100000];

  while(1){

    scanf("%d %d",&c1,&c2);
    if(c1 == 0 && c2 == 0){
      break;
    }

    for(i = 0;i <= c1-1;i++){
      scanf("%d",num+i);
    }

    temp = 0;
    for(i = 0;i < c2;i++){
      temp += num[i];
    }
    ans = temp;

    for(i = c2;i <c1;i++){
      temp-=num[i-c2];
      temp+=num[i];
      
      if(temp > ans){
	ans = temp;
      }
    }

    printf("%d\n",ans);  
  
 
  }
 return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  
  cin >> a;
  
  if (a >= 111) {
    cout << 3 << endl;
  } else if (a >= 101) {
    cout << 2 << endl; // Both 110 or 101 will be 2.
  } else if (a >= 100) {
  	cout << 1 << endl;
  } else if (a >= 11)  {
    cout << 2 << endl;
  } else if (a >= 1)  {
    cout << 1 << endl; // Both 010 or 001 will be 1.
  } else {
    cout << 0 << endl;
  }
  
  return 0;
}

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

typedef long long int ll;
ll powk(ll a, ll n){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll a, b;
    vector<ll> s(100000);
    cin >> a >> b;
    ll ae = a, be = b;
    for(ll i = 2;i <= ae;i++){
        while(a % i == 0){
            a = a / i;
            s[i - 1]++;
        }
    }

    for(ll i = 2;i <= be;i++){
        ll t = 0;
        while(b % i == 0){
            b = b / i;
            t++;
        }
        if(t > s[i - 1]){
            s[i - 1] = t;
        }
    }

    ll ans = 1;
    for(ll i = 0;i < 100000;i++){
        if(s[i] != 0){
            ans *= powk(i + 1,s[i]);
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
 
int uruu(int i)
{
    if (i % 400 == 0) {
        return 1;
    } else if (i % 100 == 0) {
        return 0;
    } else if (i % 4 == 0) {
        return 1;
    } else {
        return 0;
    }
}
 
int main(void)
{
    int first, end;
    int count = 0;
    int dataset = 0;
    while(1) {
        scanf("%d %d", &first, &end);
        if (first == 0 && end == 0) {
            break;
        }
        if (dataset > 0) {
            printf("\n");
        }
        for (int i = first; i < end + 1; i++) {
            if (uruu(i) == 1){
                printf("%d\n", i);
                count++;
            }
        }
        if (count == 0) {
            printf("NA\n");
        }
        dataset = dataset++;        
        count = 0;
    }
    return 0;
}

Measured memory_bytes: 1044
#include <iostream>

int
main(int argc, char** argv) {
    int N, M, L, R;
    std::cin >> N >> M;


    int l = 1, r = N;
    for (int i = 0; i < M; i++) {
        std::cin >> L >> R;
        //std::printf("%d, %d, %d %d\n", l, r, L, R);
        if (l < L) {
            l = L;
        }
        if (r > R) {
            r = R;
        }
        //std::printf("%d, %d, %d %d\n", l, r, L, R);
    }
    int ans = r - l + 1;
    std::printf("%d\n", ans < 0 ? 0 : ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n,m; cin >> n >> m;
    vector<int> num(m, 0);
    for(int i=0; i<n; i++){
        int k; cin >>k;
        for(int j=0; j<k; j++){
            int a; cin >> a; --a;
            ++num[a];
        }
    }
    int ans=0;
    for(int i=0; i<m; i++){
        if(num[i]==n) ++ans; 
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    std::string str;
    std::cin >> str;
    int order_num = 0;
    std::cin >> order_num;

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

        std::string order = "";
        std::cin >> order;
        /*****************/

        if (order == "replace") {
            int a = 0;
            int b = 0;
            std::string rpl = "";
            std::cin >> a;
            std::cin >> b;
            std::cin >> rpl;

            for (int i = 0; i < b - a + 1; i++) {
                str[a + i] = rpl[i];
            }

        }

        /******************/

        if (order == "reverse") {
            int a = 0;
            int b = 0;
            std::string stock = "";
            std::cin >> a;
            std::cin >> b;
            for (int i = b; i >= a; i--) {
                stock += str[i];
            }

            for (int i = a; i <= b; i++) {
                str[i] = stock[i - a];
            }
        }

        /******************/
        if (order == "print") {
            int a = 0;
            int b = 0;
            std::cin >> a;
            std::cin >> b;
            for (int i = a; i <= b; i++) {
                std::cout << str[i];
                if (i == b) {
                    std::cout << std::endl;
                }
            }
        }

        /******************/
    }



    return 0;
}

Measured memory_bytes: 1216
S=input()
a=list(S)
for i in range(len(a)):
    if a[i] != 'A' and a[i] != 'G' and a[i] != 'C' and a[i] != 'T':
        a[i]='/'
b=''.join(a)
c=b.split('/')
ans=0
for j in range(len(c)):
    if ans<=len(c[j]):
        ans=len(c[j])
print(ans)

Measured memory_bytes: 3064
def saiki(N,M,X,check,book,cost):
	if len(check) == N:
		u = [0] * M
		c = 0
		for i in range(N):
			if check[i] == 1:
				b = book[i]
				c += b[0]
				for j in range(1,M+1):
					u[j-1] += b[j]
		if min(u) >= X:
			if cost[0] == -1 or cost[0] > c:
				cost[0] = c
	else:
		C = check[:]
		saiki(N,M,X,C+[0],book,cost)
		C = check[:]
		saiki(N,M,X,C+[1],book,cost)

if __name__ == '__main__':
	N,M,X = map(int, input().split())
	book = []
	for _ in range(N):
		book.append([int(a) for a in input().split()])

	cost = [-1]
	saiki(N,M,X,[],book,cost)

	print(cost[-1])

Measured memory_bytes: 69868
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M;
	int A[310][310];
	cin >> N >> M;

	vector<bool> F(M, false);
	bool f = false;
	int ans = INF;

	REP(i, N) {
		REP(j, M) {
			cin >> A[i][j];
			A[i][j]--;
		}
	}
	while (!f) {
		f = true;
		vector<VI> join(M);
		REP(i, N) {
			REP(j, M) {
				if (F[A[i][j]] == false) {
					join[A[i][j]].push_back(i);
					break;
				}
			}
		}
		int res = 0, tmp = 0,k;
		REP(i, M) {
			int b = join[i].size();
			res = max(res, b);
		}
		ans = min(ans, res);
		REP(i, M) {
			//cout << join[i].size() << " ";
			if (tmp < join[i].size()) {
				tmp = join[i].size();
				k = i;
			}
		}
		F[k] = true;
		REP(i, M) {
			//cout << F[i] << " ";
			if (F[i] == false) {
				f = false;
				//break;
			}
		}
		//cout << endl;
	}
	
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1024
N = int(input())
if N==3:
    print(61)
    exit()

MOD = 10**9+7
dp = [[0]*64 for i in range(N-2)]

A,C,G,T = 0,1,2,3
for i in range(4):
    for j in range(4):
        for k in range(4):
            if i==A and j==G and k==C: continue
            if i==A and j==C and k==G: continue
            if i==G and j==A and k==C: continue
            dp[0][i*16 + j*4+ k] = 1

for i in range(N-3):
    for j in range(64):
        a,b = divmod(j,16)
        b,c = divmod(b,4)
        for d in range(4):
            if b==A and c==G and d==C: continue
            if b==A and c==C and d==G: continue
            if b==G and c==A and d==C: continue
            if a==A and b==G and d==C: continue
            if a==A and c==G and d==C: continue
            dp[i+1][b*16+c*4+d] += dp[i][j]
            dp[i+1][b*16+c*4+d] %= MOD
print(sum(dp[-1]) % MOD)

Measured memory_bytes: 3188
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
dist = sum([abs(a[i] - a[i + 1]) for i in range(n + 1)])
for i in range(1, n + 1):
    print(dist - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]))


Measured memory_bytes: 14048
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var n = parseInt(input[0], 10);
    var values = input[1].split(' ');
    var p = new Array(n);
    for (var i = 0; i < n; i++) {
        p[i] = parseInt(values[i], 10);
    }

    var swapCount = 0;
    for (var i = 0; i < n; i++) {
        if (p[i] == i + 1) {
            if (i == n - 1) {
                swap(p, i, i - 1);
                swapCount++;
            }
            else {
                swap(p, i, i + 1);
                swapCount++;
            }
        }
    }

    console.log(swapCount);
}

function swap(array, src, dest) {
    var temp = array[src];
    array[src] = array[dest];
    array[dest] = temp;
}


Measured memory_bytes: 16960
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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


int main(){
  ll a,b,c; cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  else if(a == c) cout << b << endl;
  else cout << a << endl;
  
  
}

Measured memory_bytes: 3564
#pragma GCC optimize("Ofast", "unroll-loops")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	string S; cin >> S;
	ll K; cin >> K;
	for (int i = 0; i < K - 1; ++i) {
		if (S[i] != '1') {
			cout << S[i] << endl;
			return 0;
		}
	}
	cout << S[K - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <stack>
#include <queue>

typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,n;
  ll a,b,q;
  cin >> a >> b >> q;
  vector<ll> t(a),x(b);
  for(i=0;i<a;i++)cin >> t[i];
  //sort(t.begin(),t.end());
  for(i=0;i<b;i++)cin >> x[i];
  //sort(x.begin(),x.end());
  vector<ll> ans(q);
  for(i=0;i<q;i++){
    ll ret = 0,ret2=0;
    cin >> j;
    vector<ll>::iterator it,it2;
    it = lower_bound(t.begin(),t.end(),j);//j以上の神社
    ll c = it-t.begin();

    it2 = lower_bound(x.begin(),x.end(),t[c]);
    ll d = it2-x.begin();
    if(d!=0&&abs(x[d]-t[c])>abs(x[d-1]-t[c]))d--;
    ret = abs(t[c]-j)+abs(t[c]-x[d]);

    if(c!=0){
      c--;
      it2 = lower_bound(x.begin(),x.end(),t[c]);
      d = it2-x.begin();
      if(d!=0&&abs(x[d]-t[c])>abs(x[d-1]-t[c]))d--;
      ret = min(ret,abs(t[c]-j)+abs(t[c]-x[d]));
    }

    it = lower_bound(x.begin(),x.end(),j);//j以上の寺
    c = it-x.begin();
    it2 = lower_bound(t.begin(),t.end(),x[c]);
    d = it2-t.begin();
    if(d!=0&&abs(t[d]-x[c])>abs(t[d-1]-x[c]))d--;
    ret = min(ret,abs(x[c]-j)+abs(x[c]-t[d]));

    if(c!=0){
      c--;
      it2 = lower_bound(t.begin(),t.end(),x[c]);
      d = it2-t.begin();
      if(d!=0&&abs(t[d]-x[c])>abs(t[d-1]-x[c]))d--;
      ret = min(ret,abs(x[c]-j)+abs(x[c]-t[d]));
    }
    ans[i]=ret;
  }
  for(i=0;i<q;i++)cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;
import java.awt.image.BandedSampleModel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
    public static int binarySearch(long[] arr,long n)
    {
        //#aaRJae
        //This is a basic  binary search code(return -1 if not found)
        //returns index of number
        // binary search has infinite variation so beware
        //To make search for number just greater than the value "n" decomment comment just below "1&&3"
        //return -1 if value greater than last integer
        //To make search for number just less than the value "n" decomment comment just below "2&&3"
        //returns -1 if value less than last integer
        int len =arr.length;
        int l = 0;
        int r = len-1;
        int mid;
        //3
        int ans =-1;


        while(r>=l)  //"=" lagana hai bhai
        {
            mid = l+(r-l)/2;  //never (l+r)/2 kyunki integer overflow
            if(arr[mid]==n)
            {
                //3
                ans =mid;
                return mid;

            }
            if(arr[mid]>n)
            {
                r =mid-1;
                //1
                //ans = mid;
            }
            else
            {
                l =mid+1;
                //2
                ans = mid;
            }
        }
        //3 make return -1 commented
        return ans;
        //return -1;
    }

    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int k=sc.nextInt();
        long arrn[]=new long[n];
        long prefn[]=new long[n+1];
        for(int i=0;i<n;i++)
        {
            arrn[i]=sc.nextLong();
            prefn[i+1]=prefn[i]+arrn[i];
        }
        long arrm[]=new long[m];
        long prefm[]=new long[m+1];
        for(int i=0;i<m;i++)
        {
            arrm[i]=sc.nextLong();
            prefm[i+1]=prefm[i]+arrm[i];
        }

        long ans=0;
        for(int i=0;i<n+1;i++)
        {
            long search=k-prefn[i];
            if(search>=0) {
                long s = binarySearch(prefm, search);
                if(s>=0) {
                    ans = Math.max(s + i, ans);
                }
            }
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 67376
import           Control.Applicative
import           Control.Monad
import           Data.List

printInts :: [Int] -> IO ()
printInts = putStrLn . intercalate " " . fmap show

mult :: [[Int]] -> [[Int]] -> [[Int]]
mult xss yss = [[sum (zipWith (*) xs ys) | ys <- yss'] | xs <- xss]
  where
    yss' = transpose yss

main :: IO ()
main = do
    [n, m, _] <- fmap read . words <$> getLine :: IO [Int]
    xss <- fmap (fmap read . words) . lines <$> getContents :: IO [[Int]]
    let (mat1, xss') = splitAt n xss
    let mat2 = take m xss'
    let answer = mult mat1 mat2
    mapM_ printInts answer



Measured memory_bytes: 12212
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n, k = read_ints()
    if k % 2:
        print((n // k)** 3)
    else:
        print((n // k)** 3 + ((n + k // 2) // k)** 3)     

if __name__ == '__main__':
    Main()

Measured memory_bytes: 9232
let content = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => { content += buf; });
process.stdin.on('end', () => {
  const { hour, minute, sec } = parseTime(parseInt(content, 10));
  console.log([hour, minute, sec].join(':'));
});


const SEC_IN_HOUR = 60 * 60;
const parseTime = time => {
  const hour = Math.floor(time / SEC_IN_HOUR);
  const minute = Math.floor(time % SEC_IN_HOUR / 60);
  const sec = time % 60;
  return { hour, minute, sec };
};


Measured memory_bytes: 15516
#![allow(non_snake_case)]

use std::collections::HashMap;

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let mut S: HashMap<char, Vec<char>> = HashMap::new();
    let SA: String = read();
    let SB: String = read();
    let SC: String = read();
    S.insert('a', SA.chars().rev().collect());
    S.insert('b', SB.chars().rev().collect());
    S.insert('c', SC.chars().rev().collect());
    let mut turn = 'a';
    loop {
        if S.get(&turn).unwrap().is_empty() {
            println!(
                "{}",
                match turn {
                    'a' => 'A',
                    'b' => 'B',
                    'c' => 'C',
                    _ => panic!(),
                }
            );
            return;
        } else {
            let entry = S.entry(turn).or_insert_with(|| vec![]);
            turn = entry.pop().unwrap();
        }
    }
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;
import java.math.*;
class Main{
	static int mod1 = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();	
		int n = sc.nextInt();
		int m = sc.nextInt();
		System.out.println(6-n-m);

    }
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mp;
int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		string s = to_string(i);
		++mp[{s[0] - '0', s.back() - '0'}];
	}
	int ans = 0;
	for (auto i : mp) {
		int x = i.first.first;
		int y = i.first.second;
		ans += mp[{x, y}] * mp[{y, x}];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3696
#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    priority_queue<int> que;

    FOR(i, N) {
        ll tmp;
        cin >> tmp;
        //A.push_back(tmp);
        que.push(tmp);
    }
    //sort(A.begin(), A.end());
    FOR(i, M) {
        ll tmp = que.top();
        que.pop();
        tmp /= 2;
        que.push(tmp);
        //auto itr = lower_bound(A.begin(), A.end(), tmp);
        //A.insert(itr, tmp);
    }
    ll sum = 0;
    FOR(i, N) { 
        sum += que.top();
        que.pop();
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1660
import math
import collections
import fractions
import itertools

def solve():
    s = input()
    n = len(s)
    ans = [0]*n
    cnt = 0
    for i, moji in enumerate(s):
        if moji == "R":
            cnt += 1
            continue
        else:
            even_num = cnt//2
            odd_num = cnt - even_num
            ans[i] += even_num
            ans[i-1] += odd_num
            cnt = 0
    for i in range(n-1, -1, -1):
        if s[i] == "L":
            cnt += 1
            continue
        else:
            even_num = cnt // 2
            odd_num = cnt - even_num
            ans[i] += even_num
            ans[i+1] += odd_num
            cnt = 0
    print(*ans)
    return 0

if __name__ == "__main__":
    solve()


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

#define rep(a,b) for(int a=0; a<b; ++a)

int main(void){
	map<int,int> mp; bool able=true;
	rep(i,4){
		int e; cin>>e; ++mp[e];
	}
	switch((int)mp.size()){
		case 1 :
			cout<<"yes"<<endl; break;
		case 2 :
			for(auto &e:mp){
				able&=e.second==2;
			}
			if(able) cout<<"yes"<<endl;
			else cout<<"no"<<endl;
			break;
		default :
			cout<<"no"<<endl;
			break;
	}
}


Measured memory_bytes: 3088