akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, t;
  cin >> n >> t;
  ll a[100010];
  rep(i, n) cin >> a[i];
  ll Max_a = 0, Max_d = 0;
  for (int i = n - 1; i >= 0; --i)
  {
    Max_a = max(Max_a, a[i]);
    Max_d = max(Max_d, Max_a - a[i]);
  }
  set<ll> st;
  ll cnt = 0;
  for (int i = n - 1; i >= 0; --i)
  {
    st.insert(a[i]);
    if (st.count(a[i] + Max_d))
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 5760
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
 ll n;
 cin>>n;
 cout<<(n+1)/2<<endl;
}

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

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

Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#define INF (1e9+1)

typedef struct state{
  int pos,cost;
} state;

state A[2000001];
int N=0;
 
int parent(int i){return i/2;}
int left(int i){return i*2;}
int right(int i){return i*2+1;}
 
void exchange(state* a,state* b){
  state tmp=*a;
  *a=*b;
  *b=tmp;
}
 
void minHeapify(int i){
  int l=left(i);
  int r=right(i);
  int small;
  
  if( l<=N && A[l].cost<A[i].cost )small=l;
  else small=i;
  
  if( r<=N && A[r].cost<A[small].cost)small=r;
  
  if(small!=i){
    exchange(&A[i],&A[small]);
    minHeapify(small);
  }
  
}
 
state heapExtractMin(){
  if(N<1)return (state){0,0};
  state min=A[1];
  A[1]=A[N];
  N--;
  minHeapify(1);
  return min;
}

 
void heapIncreaseKey(int i,state key){
  if(key.cost>A[i].cost)return;
 
  A[i]=key;
  while(i>1&&A[parent(i)].cost>A[i].cost){
    exchange(&A[i],&A[parent(i)]);
    i=parent(i);
  }
}
 
void minHeapInsert(state key){
  N++;
  A[N]=(state){INF,INF};
  heapIncreaseKey(N,key);
}


typedef struct edge{
  int to,cost;
} edge;

edge* G[10000];
int size[10000];
int n;
int d[10000];
edge e;
state s;
int main(){
  int i,j,a,b;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    G[a] = malloc( sizeof( edge ) *b );
    size[a]=b;
    for(j=0;j<b;j++){
      scanf("%d %d",&G[a][j].to,&G[a][j].cost);
    }
    d[i]=INF;
  }
  d[0]=0;
  minHeapInsert( (state){0,0} );
  while(N!=0){
    s = heapExtractMin();
    if(s.cost>d[s.pos])continue;
    for(i=0;i<size[s.pos];i++){
      e=G[s.pos][i];
      if(d[e.to]<=d[s.pos]+e.cost)continue;
      d[e.to]=d[s.pos]+e.cost;
      minHeapInsert((state){e.to,d[e.to]});
    }
  }
  for(i=0;i<n;i++)
    printf("%d %d\n",i,d[i]);
  
  return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> xs(h, vector<int>(w));
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            xs[i][j] = s[j] == '1';
        }
    }

    auto calc_split = [&](int split) {
        vector<int> mapping(h, 0);
        for (int i = 1; i < h; ++i) {
            if (split & (1 << (i - 1))) {
                mapping[i] = mapping[i - 1] + 1;
            } else {
                mapping[i] = mapping[i - 1];
            }
        }
        int split_size = mapping.back() + 1;
        vector<vector<int>> new_board(split_size, vector<int>(w, 0));
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                new_board[mapping[i]][j] += xs[i][j];
                if (new_board[mapping[i]][j] > k) {
                    return h + w;
                }
            }
        }
        int num_cuts = split_size - 1;
        vector<int> current(split_size, 0);
        for (int j = 0; j < w; ++j) {
            bool too_big = false;
            for (int i = 0; i < split_size; ++i) {
                if (current[i] + new_board[i][j] > k) {
                    too_big = true;
                }
            }
            if (too_big) {
                ++num_cuts;
                for (int i = 0; i < split_size; ++i) {
                    current[i] = 0;
                }
            }
            for (int i = 0; i < split_size; ++i) {
                current[i] += new_board[i][j];
            }
        }
        return num_cuts;
    };
    
    int best = h + w;
    for (int split = 0; split < (1 << (h - 1)); ++split) {
        best = min(best, calc_split(split));
    }
    cout << best << endl;
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int a = 0;
    int b = 0;
    int c = 0;
    rep(i, S.size()) {
        if (S[i] == 'a') {
            a++;
        }
        else if (S[i] == 'b') {
            b++;
        }
        else {
            c++;
        }
    }
    if (abs(a-b)>1 || abs(b-c)>1 || abs(a-c)>1) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 512
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define reppe(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)
#define repme(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)

typedef long long ll;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    return GCD(b, a % b);
}

int main() {
    string N; cin >> N;
    if (N[0] == '7' || N[1] == '7' || N[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){
    int n,tmp=0,ans=0;
    cin >> n;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        if(a==b){tmp++;}
        else{tmp=0;}
        if(ans<=tmp)ans=tmp;
    }
    if(ans>=3)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
ll n, m, x, arr[15][15], cost[15], mins=inf;

int main(){
	IOS
	cin >> n >> m >> x;
	for(int i=0;i<n;i++){
		cin >> cost[i];
		for(int j=0;j<m;j++){
			cin >> arr[i][j];
		}
	}
	for(int mask=0;mask<(1<<n);mask++){
		unordered_map<ll, ll>cnt;
		ll tmp=0;
		for(int i=0;i<n;i++){
			if((mask>>i)&1){
				tmp+=cost[i];
				for(int j=0;j<m;j++){
					cnt[j]+=arr[i][j];
				}
			}
		}
		bool cek=1;
		for(int j=0;j<m;j++){
			if(cnt[j]<x){
				cek=0;
				break;
			}
		}
		if(cek){
			mins=min(mins, tmp);
		}
	}
	if(mins==inf){
		cout << -1 << '\n';
	}
	else{
		cout << mins << '\n';
	}
}


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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    vector<int> a(n),a2(n);
    rep(i,n) cin >> a[i],a2[i]=a[i];

    ::sort(a2.rbegin(),a2.rend());
    int first_max = a2[0];
    int second_max = a2[1];
    rep(i,n){
        if(a[i] == first_max){
            cout << second_max <<endl;
        }else{
            cout <<first_max <<endl;
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  string S, ans = "Three";
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "Y") {
      ans = "Four";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int X,N;
    cin >> X >> N;
    vector<int> P(N);
    for(int i=0; i<N; i++)
    {
        cin >> P.at(i);
    }
    bool eqchk=true;
    for(int i=0; i<N; i++)
    {
        if(X==P.at(i))
        {
            eqchk=false;
        }
    }
    if(eqchk)
    {
        cout << X << endl;
        return 0;
    }
    int min=X;
    bool chk=true;
    for(int i=1 ;;i++)
    {
        for(int j=0; j<N; j++)
        {
            if(X-i==P.at(j))
            {
                chk=false;
            }
        }
        if(chk)
        {
            min=X-i;
            break;
        }
        chk=true;
        for(int j=0; j<N; j++)
        {
            if(X+i==P.at(j))
            {
                chk=false;
            }
        }
        if(chk)
        {
            min=X+i;
            break;
        }
        chk=true;
    }
    cout << min << endl;
}

Measured memory_bytes: 3616
s = input()
K = int(input())
subs = []
for i in range(0, len(s)):
    for j in range(i+1, K+i+1 if i + K <= len(s) else len(s)+1):
        subs.append(s[i:j])
        if len(subs)==K:
            break;
subs = list(set(subs))
subs.sort()
print(subs[K-1])

Measured memory_bytes: 5068
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

int main() {
	int N; cin >> N;
	vector<ll> v(N);
	map<ll, ll> mp;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		if (mp.find(v[i]) == mp.end()) {
			mp.insert({ v[i], 1 });
		}
		else {
			mp[v[i]]++;
		}
	}
	ll ans = 0;
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		ans += itr->second * (itr->second - 1);
	}
	ans /= 2;
	for (int i = 0; i < N; i++) {
		cout << ans - mp[v[i]] + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000007

int main() {
	string s;
	cin >> s;
	s.replace(0,4,"2018");
	cout << s;
}

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

r1,c1,r2,c2=map(int,input().split())

# MOD combination
def cmb(n, r, mod=10**9+7):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**6*2+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def g(r,c):
    tmp=cmb(r+1+c+1,r+1)-cmb(0+c+1,0)
    return tmp%mod

ans=0
ans+=g(r2,c2)
ans-=g(r2,c1-1)
ans-=g(r1-1,c2)
ans+=g(r1-1,c1-1)
ans%=mod
print(ans)

Measured memory_bytes: 224892
#include <stdio.h>
int main()
{
	int i,n,a[200],s,k=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	while(1) 
	{
		s=0;
		for(i=0;i<n;i++)
		{
			if(a[i]%2==0)
			{
				s++;
				a[i]=a[i]/2;
			}
		}
	    if(s<n)
		break;
		k++;
	}
	printf("%d\n",k);
	return 0; 
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int64 gcd(int64 a,int64 b){
  int64 r=a%b;
  while(r>0){
    a=b;b=r;r=a%b;
  }
  return b;
}

int cond(int64 a,int64 b,int64 c,int64 d){
  if(a<b) return 0;
  if(d<b) return 0;
  //a>=b, d>=b
  if(c>=b) return 1;
  //c<b<=a,d
  if(d%b==0){
    a=a-(a-c+b-1)/b*b;
    return a>=0;
  }
  int64 g=gcd(b,d);
  return (b-1)/g==c/g;
  /*
  a-=(a-c+b-1)/b*b;
  if(a<0) return 0;
  a+=d;
  int64 s=a;
  //c<b<=a, b<d
  //a=d..c+d
  do{
    a-=(a-c+b-1)/b*b;
    if(a<0) return 0;
    a+=d;
  } while(a!=s);
  return 1;
  */
}

void run(void){
  int t;
  scanf("%d",&t);
  while(t--){
    int64 a,b,c,d;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    printf("%s\n",cond(a,b,c,d)?"Yes":"No");
  }
}

int main(void){
  run();
  return 0;
}


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

int main()
{
 int n;
  cin>>n;
  char ch='1';
  set<string> mp;
  while(n--)
  {
    string s;
    cin>>s;
    /*for(auto i:mp)
      cout<<i<<"\n";*/
    if(ch=='1')
      {
      	 ch = s[s.length()-1];
    mp.insert(s);
    continue;
      }
      
    if(ch!=s[0]||mp.find(s)!=mp.end())
    {
      cout<<"No\n";return 0;
    }
    ch = s[s.length()-1];
    mp.insert(s);
  }
  cout<<"Yes\n";
  
  
  
  return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
s = lc()

le = 0
lw = 0
re = s[1:].count("E")
rw = s[1:].count("W")

ans = lw + re

for i in range(1,n):
    if s[i-1] == "E":
        le += 1
    else:
        lw += 1
        
    if s[i] == "E":
        re -= 1
    else:
        rw -= 1
        
    ans = min(ans, lw+re)

print(ans)

Measured memory_bytes: 8144
#include <bits/stdc++.h>
#define C(n,m) (1ll*ml[n]*ny[m]%mo*ny[(n)-(m)]%mo)
#define cal(a,b) ((a+=b)%=mo)
using namespace std;
const int mo=1e9+7;
int f[2050][2050],ml[4000050],ny[4000050];
int fap(int a,int b){
  int s=1;
  while(b){
    if (b&1) s=1ll*a*s%mo;
    b>>=1,a=1ll*a*a%mo;
  }
  return s;
}
int main(){
  int n,k; cin>>n>>k;
  if (k==1) return puts("1"),0;
  ml[0]=ny[0]=1;
  for (int i=1; i<=n*k; ++i) ml[i]=1ll*ml[i-1]*i%mo;
  ny[n*k]=fap(ml[n*k],mo-2);
  for (int i=n*k-1; i; --i) ny[i]=1ll*(i+1)*ny[i+1]%mo;
  f[0][0]=1;
  for (int i=0; i<n; ++i)
    for (int j=0; j<=i; ++j){
      cal(f[i+1][j],1ll*f[i][j]*C((i+1)*(k-1)+j-1,k-2)%mo);
      if (j!=i) cal(f[i][j+1],f[i][j]);
    }
  for (int i=0; i<n; ++i) cal(f[n][i+1],f[n][i]);
  for (int i=1; i<=n; ++i) f[n][n]=1ll*f[n][n]*i%mo;
  cout<<f[n][n];
  return 0;
}


Measured memory_bytes: 47488
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();
		int c = sc.nextInt();
		if(a == b && b == c)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}


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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	long long m ;
	cin>>n>>m ;
	long long a[n] , b[n] ;
	for(int i = 0 ; i < n ; ++i)
		cin>>a[i]>>b[i] ;
	long long pref[n] , suff[n] ;
	long long sum = 0 ;
	long long prv = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		sum += b[i] ;
		sum -= (a[i] - prv) ;
		if(i == 0)
			pref[i] = max(0ll , sum) ;
		else
			pref[i] = max(pref[i-1] , sum) ;
		prv = a[i] ;
	}
	sum = 0 ;
	prv = m ;
	for(int i = n-1 ; i >= 0 ; --i)
	{
		sum += b[i] ;
		sum -= (prv - a[i]) ;
		if(i == n-1)
			suff[i] = max(0ll , sum) ;
		else
			suff[i] = max(suff[i+1] , sum) ;
		prv = a[i] ;
	}
	sum = 0ll , prv = 0ll ;
	long long ans = 0ll ;
	for(int i = 0 ; i < n ; ++i)
	{
		sum += b[i] ;
		sum -= (a[i] - prv) ;
		long long x = 0 ;
		if(i != n-1)
			x = suff[i+1] - a[i] ;
		ans = max(ans , max(sum , sum+x)) ;
		prv = a[i] ;
	}
	sum = 0ll , prv = m ;
	for(int i = n-1 ; i >= 0 ; --i)
	{
		sum += b[i] ;
		sum -= (prv - a[i]) ;
		long long x = 0 ;
		if(i != 0)
			x = pref[i-1] - (m - a[i]) ;
		ans = max(ans , max(sum , sum+x)) ;
		prv = a[i] ;
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 3328
N = list(input())

ans1 = 0
expected = N[0]
for n in N[1:]:
    if expected == n:
        ans1 += 1
        if n == '0':
            expected = '1'
        else:
            expected = '0'
    else:
        expected = n

N.reverse()
ans2 = 0
expected = N[0]
for n in N[1:]:
    if expected == n:
        ans2 += 1
        if n == '0':
            expected = '1'
        else:
            expected = '0'
    else:
        expected = n


print(min(ans1, ans2))

Measured memory_bytes: 4652
import bisect
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  l = list(int(i) for i in input().split())
  l = sorted(l)
  ans = 0
  #print(l)
  for i in range(n):
    for j in range(i+1,n):
        a = l[i]
        b = l[j]
        c_max = bisect.bisect_left(l,a+b)
        if c_max <= j+1:
          continue
        else:
          ans += c_max-j-1
          #print(c_max-2)
        #print(c_max,i,j)

  print(ans)
  
solve()

Measured memory_bytes: 42588
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n,m;
vector<pll> A;

bool judge(ll r){
    for(int i=0;i<n && r>0;i++){
        if(A[i].F>=r){r--;}
    }
    return r==0;
}



int main(){
    cin>>n>>m;
    A.resize(n);
    for(auto &I:A){cin>>I.F>>I.S;}
    sort(A.begin(),A.end(),greater<pll>());
    ll l=1,r=m+1;
    while(r-l>0){
        ll m=l+(r-l)/2;
        if(judge(m)){l=m+1;}
        else{r=m;}
    }
    l--;
    ll w=0;
    priority_queue<ll> Q;
    ll cnt=0;
    for(;l>0;l--){
        while(w<n && A[w].F>=l){Q.push(A[w].S); w++;}
        assert(!Q.empty());
        Q.pop();
        cnt++;
    }
    while(w<n){Q.push(A[w].S); w++;}
    w=m;
    while(!Q.empty() && w>=r){
        ll a=Q.top(); Q.pop();
        if(a<=w){w--; cnt++;}
    }
    cout<<n-cnt<<endl;
    
    
    return 0;
}


Measured memory_bytes: 5492
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,K;
	while(cin>>N>>M>>K) {
		bool ans=0;
		REP(i, N+1) REP(j, M+1) {
			ll co = i*M - 2*i*j + j*N;
			if(co==K) ans=1;
		}
		
		cout<<(ans?"Yes":"No")<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cctype>
#include <vector>
using namespace std;
typedef string::const_iterator State;


vector<int> term(State &begin);
vector<int> formula(State &begin);
vector<int> factor(State &begin);

string data[2];
vector<int> g[2];

vector<int> formula(State &begin){
	vector<int> del(1<<11,0);
	int flag=1;
	if(*begin=='-'){
		flag=0;
		begin++;
	}
	if(*begin>='a' && *begin<='k'){
		for(int i=0;i<(1<<11);i++){
			del[i]=1-flag;
			if(i>>(*begin-'a') & 1)del[i]=flag;
		}
	}
	if(*begin=='T'){
		for(int i=0;i<(1<<11);i++){
			del[i]=flag;
		}
	}
	if(*begin=='F'){
		for(int i=0;i<(1<<11);i++){
			del[i]=1-flag;
		}
	}
	begin++;
	return del;
}

vector<int> factor(State &begin){
	int flag=0;
	while(*begin=='-'){
		flag=1-flag;
		begin++;
	}
	if(*begin=='('){
		begin++;
		vector<int> ret=term(begin);
		if(flag){
			for(int i=0;i<(1<<11);i++){
				ret[i]=1-ret[i];
			}
		}
		begin++;
		return ret;
	}else{
		vector<int> ret=formula(begin);
		if(flag){
			for(int i=0;i<(1<<11);i++){
				ret[i]=1-ret[i];
			}	
		}
		return ret;
	}
}

vector<int> term(State &begin){
	vector<int> ret=factor(begin);
	while(1){
		if(*begin=='+'){
			begin++;
			vector<int> ret2=factor(begin);
			for(int i=0;i<(1<<11);i++){
				ret[i]=ret[i]|ret2[i];
			}
		}
		if(*begin=='*'){
			begin++;
			vector<int> ret2=factor(begin);
			for(int i=0;i<(1<<11);i++){
				ret[i]=ret[i]&ret2[i];
			}
		}
		if(*begin=='-'){
			begin++;
			if(*begin=='>'){
				begin++;
				vector<int> ret2=factor(begin);
				for(int i=0;i<(1<<11);i++){
					ret[i]=(ret[i]==0)|ret2[i];
				}
			}else{
				printf("error\n");
				return ret;
			}
		}else{
			break;
		}
	}
	return ret;
}

int main(void){
	while(1){
		string str;
		cin >> str;
		if(str=="#")break;
		data[0]=data[1]="";
		int v=0;
		for(int i=0;i<str.size();i++){
			if(str[i]=='=')v++;
			else data[v]+=str[i];
		}
		for(int i=0;i<2;i++){
			State begin=data[i].begin();
			g[i]=term(begin);
		}
		bool flag=true;
		for(int i=0;i<1<<11;i++){
			if(g[0][i]!=g[1][i])flag=false;
		}
		printf("%s\n",flag?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 1312
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	string s;
	ll k;
	
	cin >> s >> k;
	
	REP(i,k){
		if (s[i]-'0'>1){
			cout << s[i] << endl;
			return 0;
		}
	}
	
	cout << 1 << endl;
	
	return 0;
}


Measured memory_bytes: 256
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

int cost[3005][3005];

bool Compare(pii a, pii b)
{
   return cost[a.ff][a.ss] > cost[b.ff][b.ss];
}
priority_queue<pii, vector<pii>, function<bool(pii, pii)>> pq(Compare);

vi pr;
void seive(){
	int p[100005]={0};
	f(i,2,100005){
		if(p[i]==0){
			pr.pb(i);
			for(int j=i*2;j<100005;j+=i) p[j]=1;
		}
	}
}

// https://codeforces.com/blog/entry/79048



void solve(){
	int h,w,m;  cin>>h>>w>>m;
	mpi x,y;
	mpii ss;
	int a[m][2];
	f(i,0,m){
		cin>>a[i][0]>>a[i][1];
		x[a[i][0]]++; y[a[i][1]]++;
		ss[{a[i][0],a[i][1]}]++;
	}
	int mx,my;
	int cx=-1,cy=-1;
	for(auto it : x){
		if(it.ss>cx){
			cx=it.ss;
			mx=it.ff;
		}
	}
	for(auto it : y){
		if(it.ss>cy){
			cy=it.ss;
			my=it.ff;
		}
	}
	vi d,dd; 
	for(auto it : y)
		if(it.ss==cy) d.pb(it.ff);
	for(auto it : x)
		if(it.ss==cx) dd.pb(it.ff);
	int cnt=0;
	for(auto it : d){
		int th=x[mx] + y[it] - 	ss[{mx,it}]++;
		cnt=max(cnt,th);
	}
	for(auto it : dd){
		int th=x[it] + y[my] - 	ss[{it,my}]++;
		cnt=max(cnt,th);
	}
	cout<<cnt;
}

void D(){
	int h,w; cin>>h>>w;
	int ch,cw; cin>>ch>>cw; --ch; --cw;
	int dh,dw; cin>>dh>>dw; --dh; --dw;
	int dx[]={-1,1,0,0};
	int dy[]={0,0,1,-1};
	string s[h]; f(i,0,h) cin>>s[i];
	if(s[ch][cw]=='#' || s[dh][dw]=='#') {
		cout<<"-1\n";
		return ;
	}
    f(i,0,3005) f(j,0,3005) cost[i][j]=INT_MAX;
	cost[ch][cw]=0;
	priority_queue<pii, vector<pii>, function<bool(pii, pii)>> p(Compare);
	p.push({ch,cw});
	while(!p.empty()){
		pii tp=p.top(); p.pop();
		f(i,0,4){
			int cx=tp.ff+dx[i];
			int cy=tp.ss+dy[i];
			if(cx<0 || cy<0 || cx>=h || cy>=w) continue;
			if(s[cx][cy]=='#' )continue;
			if(cost[cx][cy] > cost[tp.ff][tp.ss]) {
				cost[cx][cy]=cost[tp.ff][tp.ss];
				p.push({cx,cy});
			}
		}
		// use magic
		f(i,-2,3) f(j,-2,3){
			int cx=tp.ff+i;
			int cy=tp.ss+j;
			if(cx<0 || cy<0 || cx>=h || cy>=w) continue;
			if(s[cx][cy]=='#') continue;
			if(cost[cx][cy] > cost[tp.ff][tp.ss]+1) {
				cost[cx][cy]=cost[tp.ff][tp.ss]+1;
				p.push({cx,cy});
			}
		}
	}
	if(cost[dh][dw]>=INT_MAX)	cost[dh][dw]=-1;
	cout<<cost[dh][dw]<<"\n";
}


int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) D();
  return 0;
}
// check for overflows dummy !!!

Measured memory_bytes: 75300
#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 print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
int dp[3333][3333];

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

    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> ab;
    rep(i,N){
        int a, b;
        cin >> a >> b;
        ab.push_back({a, b});
    }
    sort(all(ab));
    rep(i,N+1)rep(j,T)dp[i][j] = 0;

    rep(i,N)rep(j,T){
        int a = ab[i].first;
        int b = ab[i].second;
        chmax(dp[i+1][j], dp[i][j]);
        if(j + a >= T)continue;
        chmax(dp[i+1][j+a], dp[i][j] + b);
    }
    int ans = 0;
    rep(i,N){
        chmax(ans, dp[i][T-1] + ab[i].second);
    }
    cout << ans << endl;
}

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

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

	if(abs(a-c)<=d){
		cout<<"Yes"<<endl;
	}else{
		if((abs(b-c)<=d)&&(abs(a-b)<=d)){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n, x, m = map(int, input().split())
mn = min(n, m)
P = [] # (x,pre_sum)
sum_p = 0 # sum of pre + cycle
X = [-1] * m # for cycle check
for i in range(mn):
    if X[x] > -1:
        cyc_len = len(P) - X[x]
        pre = P[X[x]][1]
        cyc = (sum_p - pre) * ((n - X[x]) // cyc_len)
        nxt = P[X[x] + (n - X[x]) % cyc_len][1] - P[X[x]][1]
        print(pre + cyc + nxt)
        exit()
    P.append([x, sum_p])
    sum_p += x
    X[x] = i
    x = x*x % m
print(sum_p)


Measured memory_bytes: 19256
c = [[int(x) for x in input().split()] for _ in range(3)]
for i in range(3):
    for j in range(3):
        ni = (i+1) % 3
        nj = (j+1) % 3
        if c[i][j] + c[ni][nj] != c[i][nj] + c[ni][j]:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(ll i = (m); i < (ll)(n); i++)
#define rrep(i,m,n) for(ll i=(ll)(m); i>=(ll)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<ll>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFFFFFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////


const int MAX_V = 100000;
typedef struct edge_{ll to,cost;}edge;
typedef pair<ll,ll> P; 	//firstは最短経路,secondは頂点番号
int V; 										//頂点数
vector<vector<edge>> G(MAX_V);
ll dp[MAX_V];
void dijkstra( int s ){
	//最短経路の値の小さいものから取り出せる
	priority_queue<P,vector<P>,greater<P>> que;
	for(int i = 0 ; i < V ; i++ ) dp[i] = INF;
	dp[s] = 0;
	que.push(pair<int,int>(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		ll v = p.second;
		if( dp[v] > p.first ) continue;
		for(int i = 0 ; i < G[v].size() ; i++ ){
			edge e = G[v][i];
			if( dp[e.to] > dp[v] + e.cost ){
				dp[e.to] = dp[v] + e.cost;
				que.push(pair<ll,ll>(dp[e.to],e.to));
			}
		}
	}
	return;
}

//input:G[from].push_back( edge { to , cost } );
//output:dp[to] = sum of journey cost
int main(){
	cin >> V;

	rep(i,0,V-1){
		ll a,b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back( edge{b,c} );
		G[b].push_back( edge{a,c} );
	}
	
	ll q,k;
	cin >> q >> k;
	
	k--;
	dijkstra(k);
	

	rep(i,0,q){
		ll x,y;
		cin >> x >> y;
		x--; y--;
		cout << dp[x] + dp[y] << endl;
	}

	ret 0;
}

Measured memory_bytes: 11120
#include <stdio.h>

/* prototype declaration */
int getSum();

int main(int argc, const char *argv[])
{
	printf("%d\n", getSum());	
	return 0;
}

int getSum()
{
	int ch, num=0, sum=0;
	while((ch=getchar())!=EOF){
		if(ch < '0' || '9' < ch) continue;
		
		while('0'<=ch && ch<='9'){
			num = num*10+(ch-'0');
			ch = getchar();
		}
		sum += num; num = 0;
	}

	return sum;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define pb push_back
#define fi first
#define se second
map<string,int> m;
int x[999999];
int main(){
    //fflush(stdout)
    m["Male"]=1;
    m["Female"]=0;
    int n;
    scanf("%d",&n);
    string ret;
    cout<<0<<endl;
    fflush(stdout);
    cin>>ret;
    if(ret=="Vacant")
        return 0;
    int lval=m[ret];
    cout<<n-1<<endl;
    fflush(stdout);
    cin>>ret;
    if(ret=="Vacant")
        return 0;
    int rval=m[ret];
    int l=0,r=n-1;
    while(true)
    {
        int mid=(l+r)/2;
        cout<<mid<<endl;
        fflush(stdout);
        cin>>ret;
        if(ret=="Vacant")return 0;
        int val=m[ret];
        if((mid-l+1)%2==0 && val==lval){
            r=mid;
            rval=val;
        }else if((mid-l+1)%2==1 && val!=lval){
            r=mid;
            rval=val;
        }else if((r-mid+1)%2==0 && val==rval){
            l=mid;
            lval=val;
        }else if((r-mid+1)%2==1 && val!=rval){
            l=mid;
            lval=val;
        }
    }
    return 0;
}


Measured memory_bytes: 852
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] a = new int[n];
    int[] a_sort = new int[n];
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(in.readLine());
      a_sort[i] = a[i];
    }
    
    Arrays.sort(a_sort);
    
    for(int i=0; i<n; i++) {
      if(a_sort[n-1]!=a[i])
        System.out.println(a_sort[n-1]);
      else
        System.out.println(a_sort[n-2]);
    }
  }
}

Measured memory_bytes: 59292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define SORT(c) sort(ALL((c)))
#define debug(x)                 \
    do {                         \
        std::cout << #x << ": "; \
        view(x);                 \
    } while (0)

template <typename T>
void view(T e) {
    std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
    for (const auto& e : v) {
        std::cout << e << ", ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
    for (const auto& v : vv) {
        view(v);
    }
}

struct UnionFind {
    vector<ll> size, parents;
    UnionFind() {}
    UnionFind(ll n) {
        size.resize(n, 0);
        parents.resize(n, 0);
        for (ll i = 0; i < n; i++) {
            make(i);
        }
    }
    void make(ll x) {
        parents[x] = x;
        size[x] = 1;
    }
    bool same(ll x, ll y) { return root(x) == root(y); }
    bool union_(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
        return true;
    }
    int root(ll x) {
        if (x != parents[x]) {
            parents[x] = root(parents[x]);
        }
        return parents[x];
    }
    ll size_(ll x) { return size[root(x)]; }
};

int main() {
    ll N;
    cin >> N;
    vector<ll> L(N);
    rep(i, N) { cin >> L[i]; }
    ll ans = 0;
    rep(i, N) {
        for (ll j = i + 1; j < N; j++) {
            for (ll k = j + 1; k < N; k++) {
                if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) {
                    continue;
                }
                if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] &&
                    L[k] + L[i] > L[j]) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
import math
def combo(a):
    return (math.factorial(a))/(math.factorial(a-2)*2)

from collections import Counter
n = int(input())
count = 0
string = [input() for i in range(n)]
string2 = [''.join(sorted(x)) for x in string]

'''for i in range(n-1):
    for j in range(i+1, n):
        if string2[i] == string2[j]:
            count += 1'''
li = Counter(string2)
li1=[[key,value] for key, value in li.items()]
for i in range(len(li1)):
    if li1[i][1] == 1:
        li1[i][1] = 0
for i in range(len(li1)):
    if li1[i][1] != 0:
        li1[i][1] = combo(li1[i][1])
for i in range(len(li1)):
    count += li1[i][1]
print(int(count))


Measured memory_bytes: 34064
require 'set'; require 'prime'
INF=Float::INFINITY
n = gets.chomp.to_i

ct, ca = gets.split.map(&:to_i)
(n-1).times do
  t, a = gets.split.map(&:to_i)
  l=0; r = 10**18
  mid = 0
  while l < r
    mid = (l + r) /2
    if ct <= t * mid && ca <= a * mid
      r = mid
    else
      l = mid + 1
    end
  end
  ct = t * l
  ca = a * l
  # p [ct, ca]
end

puts ct + ca

Measured memory_bytes: 2684
import java.util.Scanner;
 
public class Main {
 
	public static void main (String[] args)  {
 
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long m = sc.nextLong();
		
		System.out.println(n==m ? "Yes" : "No");
	}
 
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    char u[6][5] = {
        'a','b','c','d','e','f',
        'g','h','i','j','k','l',
        'm','n','o','p','q','r',
        's','t','u','v','w','x',
        'y','z','.','?','!',' ' };
    string s;
    while(cin>>s){
        bool flag=true;
        if(s.length()%2){cout<<"NA"<<endl; flag=false;}
    if(flag){
    vector<pii>v(1000);
    rep(i,s.length()/2){
        v[i]=pii(s[2*i]-48,s[2*i+1]-48);
        if(v[i].first>6||v[i].second>5||v[i].first<=0||v[i].second<=0){cout<<"NA"<<endl;goto E;}
    }
    rep(i,s.length()/2)
    cout<<u[v[i].first-1][v[i].second-1];
    cout<<endl;
    }
    E:;
        s.clear();
    }
}

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

#define N 8
#define F -1
#define NF 1

int r[N],c[N],dp[2*N-1],dn[2*N-1],Z[N][N];


void A()
{
  int i;
  
  for(i=0;i<N;i++)
    {
      r[i]=F;
      c[i]=F;
    }

  for(i=0;i<2*N-1;i++)
    {
      dp[i]=F;
      dn[i]=F;
    }
}

void B()
{
  int i,j;
  
  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  if(Z[i][j])
	    {
	      if(r[i]!=j)
		{
		  return;
		}
	    }
	}
    }

  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  printf("%s",(r[i]==j)?"Q":".");
	}
      
      putchar('\n');
    }
}

void C(int i)
{
  int j;
  
  if(i==N)
    {
      B();
	  
      return;
    }

  for(j=0;j<N;j++)
    {
      if(NF==c[j]||NF==dp[i+j]||NF==dn[i-j+N-1])
	{
	  continue;
	}

      r[i]=j;
      c[j]=dp[i+j]=dn[i-j+N-1]=NF;

      C(i+1);

      r[i]=c[j]=dp[i+j]=dn[i-j+N-1]=F;
    }
}



int main(void)
{
  int i,j,n,a,b;
  
  
  A();

  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  Z[i][j]=0;
	}
    }

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d%d",&a,&b);

      Z[a][b]=1;
    }

  C(0);
}



Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int n, m, q;
int a[55], b[55], c[55];
ll d[55];
ll ans = 0;

void dfs(vector<int> v) {
    int vs = v.size();
    if (vs == n) {
        ll cur = 0;
        rep(i, q) {
            if (v[b[i]] - v[a[i]] == c[i]) cur += d[i];
        }
        chmax(ans, cur);
        return;
    }
    int last = v[vs-1];
    for (int i = last; i <= m; i++) {
        vector<int> v1 = v;
        v1.push_back(i);
        dfs(v1);
    }
}


int main() {
    cin >> n >> m >> q;
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    for (int i = 1; i <= m; i++) {
        vector<int> v = { i };
        dfs(v);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.1415926535
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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

main(){
  int n;
  cin>>n;
  while(n--){
    int xp[3],yp[3],xm[2],ym[2];
    rep(i,3)cin>>xp[i]>>yp[i];

    rep(i,2)cin>>xm[i]>>ym[i];

    bool fe[2];
    fe[0]=fe[1]=true;

    rep(i,3){
      int nx1=xp[(i+1)%3]-xp[i],ny1=yp[(i+1)%3]-yp[i];
      int nx2=xp[(i+2)%3]-xp[i],ny2=yp[(i+2)%3]-yp[i];
      double nx1ab=sqrt(nx1*nx1+ny1*ny1),nx2ab=sqrt(nx2*nx2+ny2*ny2);
      double ang=(1.0*(nx1*nx2+ny1*ny2)/nx1ab/nx2ab);
      //cout<<"ang "<<ang;
      rep(j,2){
	int nxm=xm[j]-xp[i],nym=ym[j]-yp[i];
	double nxmab=sqrt(nxm*nxm+nym*nym);
	double nang=(1.0*(nxm*nx1+nym*ny1)/nxmab/nx1ab);
	//cout<<" "<<nang<<" ";
	if(nang<ang)fe[j]=false;
	nang=(1.0*(nxm*nx2+nym*ny2)/nxmab/nx2ab);
	if(nang<ang)fe[j]=false;
	//cout<<nang<<endl;
      }
    }
    //cout<<fe[0]<<fe[1];
    if(fe[0]==fe[1])cout<<"NG";
    else cout<<"OK";
    cout<<endl;
  }
}
      

Measured memory_bytes: 864
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
  cin >> h >> w;
  char a[8][8];
  rep(i,h){
    rep(j,w){
      cin >> a[i][j];
    }
  }
 
  int di = 0;
  rep(i,h){
    int count = 0;
    rep(j,di){
      if(a[i][j] == '#'){
        cout << "Impossible" << endl;
        return 0;
      }
    }
    if(i == h-1) break;
    for(int j=di;j < w;j++){
      if(count != 0 && a[i][j] == '#'){
        cout << "Impossible" << endl;
        return 0;
      }
      if(a[i][j] == '#' && a[i+1][j] == '#'){
        di = j;
        count++;
      }
    }
    if(count != 1){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  cout << "Possible" << endl;
	return 0;
}


Measured memory_bytes: 256
/*
ID: C4551DY
TASK: dualpal
LANG: C++14
*/
/*  CF_CC
        4U7H0R:_C4551DY */

#include <bits/stdc++.h>
#include <fstream>

using namespace std;

#define IC ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define lb lower_bound
#define ll long long
#define pii pair<int,int>
#define vec vector<ll>
#define fir first
#define sec second
#define pb push_back

const int mxi=1e7+7;
const int mod=1e9+7;

int l,r;string s;bool f;


int main(){
	IC
    //ofstream cout ("dualpal.out");
    //ifstream cin ("dualpal.in");
    cin >> s;
    int b=s.length();
    l=0;r=b-1;
    while(l<r){
        if(s[l]!=s[r]){
            cout << "No";
            return 0;
        }
        l++;r--;
    }
    l=0;r=((b-1)/2)-1;
    while(l<r){
        if(s[l]!=s[r]){
            cout << "No";
            return 0;
        }
        l++;r--;
    }
    l=((b+3)/2)-1;r=b-1;
    while(l<r){
        if(s[l]!=s[r]){
            cout << "No";
            return 0;
        }
        l++;r--;
    }
    cout << "Yes";
}


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

int main()
{
    ll n,W,i,j;
    cin>>n>>W;

    ll A[n+1][2];
    for(i=1;i<=n;i++)
        cin>>A[i][0]>>A[i][1];

    ll dp[W+1][n+1];

    for(i=1;i<=W;i++)
        dp[i][0]=0;

    for(i=0;i<=n;i++)
        dp[0][i]=0;

    for(j=1;j<=n;j++)
    {
        for(i=1;i<=W;i++)
        {
            if(i>=A[j][0])
                dp[i][j]=max(dp[i][j-1],dp[i-A[j][0]][j-1]+A[j][1]);
            else
                dp[i][j]=dp[i][j-1];
        }
    }

    cout<<dp[W][n]<<"\n";
}


Measured memory_bytes: 79104