akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,p=310,maxn=200010,maxm=600010;

int n,idx[p][p],idy[p][p],m,map[p][p],S,T;
namespace nwf{
	int first[maxn],cur[maxn],tot=1,q[maxn],d[maxn];
	struct edge{int v,from,f;}e[maxm*2];
	void insert(int u,int v,int f){
		//printf("%d %d %d\n",u,v,f);
		tot++;e[tot].v=v;e[tot].f=f;e[tot].from=first[u];first[u]=tot;
		tot++;e[tot].v=u;e[tot].f=0;e[tot].from=first[v];first[v]=tot;
	}
	bool bfs(){
		memset(d,-1,sizeof(d));
		int head=0,tail=1;q[head]=S;d[S]=0;
		while(head<tail){
			int x=q[head++];
			for(int i=first[x];i;i=e[i].from)if(e[i].f&&d[e[i].v]==-1){
				d[e[i].v]=d[x]+1;
				q[tail++]=e[i].v;
			}
		}
		return d[T]!=-1;
	}
	int dfs(int x,int a){
		if(x==T||a==0)return a;
		int flow=0,f;
		for(int& i=cur[x];i;i=e[i].from)if(e[i].f&&d[e[i].v]==d[x]+1&&(f=dfs(e[i].v,min(a,e[i].f)))){
			e[i].f-=f;e[i^1].f+=f;
			a-=f;flow+=f;
			if(a==0)break;
		}
		return flow;
	}
	int dinic(){
		int ans=0;
		while(bfs()){
			for(int i=S;i<=T;i++)cur[i]=first[i];
			ans+=dfs(S,inf);
		}
		return ans;
	}
}
char s[p];
int main(){
//	freopen("trade4.in","r",stdin);
//	freopen("trade.out","w",stdout);
    n=read();m=read();
    int cnt=0;S=0;T=n*m*2+1;
    for(int i=1;i<=n;i++){
    	scanf("%s",s+1);
    	for(int j=1;j<=m;j++){
    		idx[i][j]=++cnt;idy[i][j]=++cnt;
    		if(s[j]!='.'){
    			map[i][j]=1;//printf("i=%d j=%d\n",i,j);
    			if(s[j]=='S')nwf::insert(S,idy[i][j],inf),nwf::insert(S,idx[i][j],inf);
    			if(s[j]=='T')nwf::insert(idx[i][j],T,inf),nwf::insert(idy[i][j],T,inf);
    		}
    	}
    }
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		if(map[i][j])nwf::insert(idx[i][j],idy[i][j],1),nwf::insert(idy[i][j],idx[i][j],1);
    		if(j<m)nwf::insert(idx[i][j],idx[i][j+1],inf),nwf::insert(idx[i][j+1],idx[i][j],inf);
    		if(i<n)nwf::insert(idy[i][j],idy[i+1][j],inf),nwf::insert(idy[i+1][j],idy[i][j],inf);
    	}
    }
    int ans=nwf::dinic();
    if(ans>=inf)printf("-1");else printf("%d",ans);
    return 0;
}

Measured memory_bytes: 6144
k = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[k-1])

Measured memory_bytes: 38256
import java.util.*;

class Main {
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		StringBuilder insert = new StringBuilder("2018");

		String str = sc.next();

		StringBuilder sb = new StringBuilder(str);

		sb.delete(0, 4);

		insert.append(sb.toString());

		System.out.println(insert.toString());

	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;


int main() {
    int n, y;
    cin >> n >> y;
    
    rep(i,n+1) {
        int yen = y - (10000*i);
        if (yen<0) break;
        rep(j,n+1-i) {
            if ( (i + j + (yen-5000*j)/1000) == n ) {
                cout3( i, j, (yen-5000*j)/1000);
                return 0;
            }
        }
    }
    cout3( -1, -1, -1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main() {
    auto start = chrono::system_clock::now();
    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a]++;
    }

    vi as, ts = {0};
    for (auto& p : mp) {
        if (p.first == 0 || p.first == 12) {
            ts.push_back(p.first);
        } else {
            if (p.second > 2) {
                cout << 0 << endl;
                return 0;
            }
            for (int i = 0; i < p.second; i++) {
                as.push_back(p.first);
            }
        }
    }

    if (as.empty()) {
        cout << ts.back() << endl;
        return 0;
    }

    int N = as.size();
    int nax = 0;
    for (int i = 0; i < 1 << N; i++) {
        if (chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count() > 1950) {
            cout << nax << endl;
            return 0;
        }
        vi tmp = ts;
        for (int j = 0; j < N; j++) {
            if ((i >> j) & 1) {
                tmp.push_back(as[j]);
            } else {
                tmp.push_back(24 - as[j]);
            }
        }

        int nin = 1e9;
        sort(tmp.begin(), tmp.end());
        tmp.push_back(24);
        for (int i = 0; i < tmp.size() - 1; i++) {
            nin = min(nin, tmp[i + 1] - tmp[i]);
        }
        nax = max(nax, nin);
    }

    cout << nax << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
typedef tuple<int, int, int, int> quad;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  for (int a, b, c; cin >> a >> b >> c, a;){
    const int P = a + b + c;
    vector<int> p(P + 1, 2);
    vector<quad> q;
    for (int n = in(); n--;){
      int i, j, k, r;
      cin >> i >> j >> k >> r;
      if (r == 1){
        p[i] = p[j] = p[k] = 1;
      }
      q.emplace_back(i, j, k, r);
    }
    while (1){
      bool update = false;
      for (const auto& qi : q){
        int i, j, k, r;
        tie(i, j, k, r) = qi;
        if (r == 1) continue;
        vector<pair<int,int>> vd;
        vd.emplace_back(p[i], i);
        vd.emplace_back(p[j], j);
        vd.emplace_back(p[k], k);
        sort(vd);
        if (vd[0].first == 1 && vd[1].first == 1 && vd[2].first == 2){
          p[vd[2].second] = 0;
          update = true;
        }
      }
      if (!update) break;
    }
    for (int i = 1; i <= P; i++){
      cout << p[i] << endl;
    }
  }
  return 0;
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t; cin >> t;
	string s1, s2;
	cin >> s1 >> s2;
	for (int i = 0; i < t; ++i)
	{
		cout << s1[i] << s2[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main() {

    unsigned long h;
    cin >> h;

    long ans = 0;
    long num = 1;
    while ( h > 0 ) {
        ans += num;
        num *= 2;
        h /= 2;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;
import java.io.*;

public class Main{
	String [] table = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int s = sc.nextInt();
			int n = sc.nextInt();
			int t = sc.nextInt();
			String week = sc.next();
			String time = sc.next();
			int p = sc.nextInt();
			int m = sc.nextInt();
			if((s|n|t|p|m) == 0) break;
			
			double max = 0.0;
			for(int i = 0; i < 60 * 24 * 7; i++){
				double mP = 1.0;
				for(int j = 0 ; j < m; j++){
					int nowTime = i + j * t;
					if(isOK(nowTime, week, time) && isOK(nowTime + s , week, time)){
						mP *= pow(1.0 - 1.0 / p, n);
					}
				}
				max = Math.max(1.0 - mP, max);
			}
			System.out.printf("%.10f\n",max);
		}
	}

	private double pow(double nowP, int n) {
		double res = 1;
		for(int i = 0; i < n; i++){
			res *= nowP;
		}
		return res;
	}

	private boolean isOK(int nowTime, String weekStr, String timeStr) {
		int min = nowTime % 60;
		int hour = (nowTime % (60 * 24)) / 60;
		int week = (nowTime % (60 * 24 * 7)) / (60 * 24);
		if(! (weekStr.equals("All") || weekStr.equals(table[week]))) return false;
		if(timeStr.equals("All")) return true;
		else if(timeStr.charAt(0) == 'D'){
			if((6 <= hour && hour < 18)){
				return true;
			}
		}
		else{
			if((18 <= hour && hour <= 23) || (0 <= hour && hour <= 5)){
				return true;
			}
		}
		
		return false;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 20476
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    N = int(input())
    L = list(map(int, input().split()))

    ans = -float('inf')
    for i in range(N, 2*N+1):
        tmp = sum(list(sorted(L[:i], reverse=True))[:N])\
            - sum(list(sorted(L[i:]))[:N])
        #print("first->", L[:i])
        #print("sum_f->", sum(list(sorted(L[:i], reverse=True))[:N]))
        #print("second->", L[i:])
        #print("sum_sec->", sum(list(sorted(L[i:]))[:N]))
        #print("tmp->", tmp)
        # print("----")

        ans = max(ans, tmp)

    # print(ans)


def solve():
    N = int(input())
    L = list(map(int, input().split()))

    first = L[:N]
    heapq.heapify(first)
    first_sum = [0]*(N+1)
    tmp_first = sum(first)
    first_sum[0] = tmp_first
    #print("first->", first)
    for i in range(N, 2*N):
        first_ind = i-N+1
        #print("new->", L[i])
        if L[i] > first[0]:
            rem = heapq.heappop(first)
            heapq.heappush(first, L[i])
            tmp_first += L[i]-rem
            #print("rem->", rem)
            #print("new_sum->", tmp_first)
        first_sum[first_ind] = tmp_first
        #print("first_sum->", first_sum)
        # print("--------")

    third = [-v for v in L[N*2:]]
    heapq.heapify(third)
    third_sum = [0]*(N+1)
    tmp_third = -sum(third)
    third_sum[-1] = tmp_third
    #print("third->", third)
    for i in reversed(range(N+1, 2*N+1)):
        #print("cand->", L[i:])
        third_ind = i-N-1
        #print("new->", L[i-1])
        #print("last->", third[0])
        if -L[i-1] > third[0]:
            rem = heapq.heappop(third)
            #print("rem->", rem)
            heapq.heappush(third, -L[i-1])
            tmp_third = tmp_third + rem+L[i-1]
        #print("new_sum->", tmp_third)
        third_sum[third_ind] = tmp_third
        # print("----")
    # print(third_sum)
    # print(first_sum)
    # print(L)

    ans = max([f-l for f, l in zip(first_sum, third_sum)])
    print(ans)


# brute_force()
solve()


Measured memory_bytes: 39644
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    int N,M;cin>>N>>M;
    int a[10],c[10];
    rep(i,0,M){
        cin>>a[i]>>c[i];
        if(N!=1&&a[i]==1&&c[i]==0){
            cout<<-1<<endl;
            return 0;
        }
    }
    if(N==1&&M==0){
        cout<<0<<endl;
        return 0;
    }
    int ans[10];rep(i,0,10)ans[i]=-1;
    rep(i,0,M){
        if(ans[a[i]]==-1){
            ans[a[i]]=c[i];
        }
        else if(ans[a[i]]!=-1&&ans[a[i]]!=c[i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    
    rep(i,1,N+1){
        if(i==1&&ans[1]==-1)cout<<1;
        else if(ans[i]==-1)cout<<0;
        else cout<<ans[i];
    }
    cout<<endl;
}






Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define ll long long
int main(){
    int a,b;
    cin >> a >> b;
    if(a+b==15){
    	cout <<'+';
    }else if(a*b==15){
    	cout <<'*';
    }else{
    	cout << 'x';
    }
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long t = c - a - b;
        long t1 = t * t;
        long t2 = 4 * a * b;
        if(t > 0 && t1 > t2){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23636
#include <stdio.h>

int main() {
  int a[3][3], n;
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  scanf("%d", &n);

  int b[n];
  for(int i = 0; i < n; i++) {
      scanf("%d", &b[i]);
    
    for(int j = 0; j < 3; j++) {
        for(int k = 0; k < 3; k++) {
            if(b[i] == a[j][k]) {
              a[j][k] = 0;
            }
        }
    }

  }

  if( a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0 )   printf("Yes");

  else if( a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0 )  printf("Yes");

  else if( a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0 )  printf("Yes");

  else if( a[0][0] == 0 && a[1][0] == 0 && a[2][0] == 0 )  printf("Yes");

  else if( a[0][1] == 0 && a[1][1] == 0 && a[2][1] == 0 ) printf("Yes");

  else if( a[0][2] == 0 && a[1][2] == 0 && a[2][2] == 0 ) printf("Yes");

  else if( a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0 ) printf("Yes");

  else if( a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0 ) printf("Yes");

  else  printf("No");

  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
    vec A(N+1); REP(i,N+1) cin>>A[i];
    vec B(N); REP(i,N) cin>>B[i];
    int ans = 0;
    REP(i,N){
       if(A[i]>B[i]) ans += B[i];
       else if(A[i+1]<=B[i]-A[i]){
              ans += A[i]+A[i+1];
              A[i+1]=0;
       }
      else{
        ans +=B[i];
        A[i+1] -= B[i]-A[i];
      }
    }
    Out(ans);
}

Measured memory_bytes: 1792
use std::io::*;
use std::cmp;

fn main() {
    let mut nm = String::new();
    stdin().read_line(&mut nm).unwrap();
    let n: i32 = nm.trim().split_whitespace().collect::<Vec<&str>>()[0].parse().unwrap();
    let m: i32 = nm.trim().split_whitespace().collect::<Vec<&str>>()[1].parse().unwrap();

    let mut tl = 0;
    let mut tr = n;

    for i in 1..m + 1 {
        let mut lr = String::new();
        stdin().read_line(&mut lr).unwrap();
        let l: i32 = lr.trim().split_whitespace().collect::<Vec<&str>>()[0].parse().unwrap();
        let r: i32 = lr.trim().split_whitespace().collect::<Vec<&str>>()[1].parse().unwrap();

        tl = cmp::max(tl, l);
        tr = cmp::min(tr, r);

    }
    println!("{}", cmp::max(0, tr - tl + 1));


}


Measured memory_bytes: 4352
use std::f64::consts::PI;

fn main() {
    proconio::input! {
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    }
    let t = 60.0 * h + m; // in minuite
    let angle_m = - 2.0 * PI / 60.0 * t + PI / 2.0;
    let angle_h = - 2.0 * PI / (60.0*12.0) * t + PI / 2.0;
    let (x0, y0) = (b * angle_m.cos(), b * angle_m.sin());
    let (x1, y1) = (a * angle_h.cos(), a * angle_h.sin());
    let dist = ((x0-x1).powi(2) + (y0-y1).powi(2)).sqrt();
    println!("{}", dist);
}

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

int main() {
  int n, k, answer = 0;
  cin >> n >> k;
  for(int i = 1; i <= n; i++) {
    int h;
    cin >> h;
    if(h >= k) 
      answer++;
  }
  cout << answer;
  return 0;
}

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

int main(){
 int n;
  cin >> n;
  char s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  
  for(int i=0;i<n;i++){
    if(s[i]=='Y'){
      cout <<"Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;
typedef unsigned long long ull;

inline int scan() {
    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;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
using namespace std;
struct A
{
    ll x;
    ll v;
};
int cmp(A a, A b)
{
    return a.x < b.x;
}
A a[100005];
ll sum[100005];
ll hou[100005];
ll maxs[100005];
ll maxs1[100005];
int main()
{
    ios::sync_with_stdio(false);
    ll n, c;
    cin >> n >> c;
    for(int i = 1; i <= n; i++)
    cin >> a[i].x >> a[i].v;
    sort(a+1, a+1+n, cmp);
    ll ans = 0;
    for(int i = 1; i <= n; i++)sum[i] = sum[i-1]+a[i].v;
    for(int i = n; i >= 1; i--)hou[i] = hou[i+1]+a[i].v;
    for(int i = n; i >= 1; i--)
    {
        maxs[i] = max(maxs[i+1], hou[i]-2*(c-a[i].x));
//        cout << maxs[i] << endl;
    }
    for(int i = 1; i <= n; i++)
    {
        maxs1[i] = max(maxs1[i-1], sum[i]-2*a[i].x);
    }
    for(int i = 1; i <= n; i++)
    {
//        cout << max(sum[i]-a[i].x+maxs[i+1], hou[i]-(c-a[i].x)) << ' ' << max(sum[i]-a[i].x, hou[i]-(c-a[i].x)+maxs1[i-1]) << endl;
        ans = max(ans, max(sum[i]-a[i].x+maxs[i+1], hou[i]-(c-a[i].x)));
        ans = max(ans, max(sum[i]-a[i].x, hou[i]-(c-a[i].x)+maxs1[i-1]));
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
    int n;
    cin >> n; //入力
    int ans = 0; //入れ替えた回数を定義
    string s;
    cin >> s; //色の並びの入力
    int back = n-1; //後ろからのカウント数
    for (int i=0; i<n; i++) { //前から色を調べていく
        if (s[i] == 'W') { //Wの場合、後ろからRを探して交換する
            for (int j=back; j>i; j--) { //後ろからRがあるかカウントしていく
                if (s[j] == 'R') { //後ろから数えてRがあった場合
                    s[j] = 'W'; //そのRをWに変換する
                    s[i] = 'R'; //前からのカウントしたWをRに変換する。上と合わせて石を入れ替えている
                    back--; //後ろからのカウント数を覚えておく
                    ans++; //入れ替えた数+1
                    break; //ループ抜ける
                }
                else { //後ろから数えてRがなかった場合
                    back--; //後ろからのカウントだけ進めておく
                    if (back == i) break; //後ろからのカウントが数えている一つ右を越えたらループを抜ける
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    long long start = a[0];
    int sz = a.size();
    long long money = 1000, stock = 0;
    for(int i=1;i<sz;i++){
    	long long cur = a[i];
    	if(start<cur) {
    		stock = money / start;
    		money %= start;
    		money += (stock*cur);
    		stock=0;
    		start = cur;
		} else if(start > cur) {
			start = cur;
		}
	}
	cout << money << endl;
    return 0;
} 

Measured memory_bytes: 3652
#include<stdio.h>


int main(void) {
	int r, c;
	int i, j;
	int allsum = 0;
	int sheet[101][101] = { 0 };
	scanf("%d", &r);
	scanf("%d", &c);



	for (i = 0; i < r; i++)
		for (j = 0; j < c; j++) {
			scanf("%d", &sheet[i][j]);
		}

	for (i = 0; i < r; i++) {
		int sum = 0;
		for (j = 0; j < c; j++) {
			sum += sheet[i][j];
		}
		sheet[i][c] = sum;
		allsum += sum;
	}

	for (i = 0; i < c; i++) {
		int sum = 0;
		for (j = 0; j < r; j++) {
			sum += sheet[j][i];
		}
		sheet[r][i] = sum;
	}

	sheet[r][c] = allsum;

	for (i = 0; i < r + 1; i++) {
		for (j = 0; j < c + 1; j++) {
			if (j == 0) printf("%d", sheet[i][j]);
			else printf(" %d", sheet[i][j]);
		}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 2104
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N = I()
A = LI()

ans = 1
for a in A:
    ans *= a

    if ans > 10**18:
        ans = -1
        break

print(ans if not 0 in A else 0)


Measured memory_bytes: 83444
n = int(input())

t_list = [ int(v) for v in input().split() ]
a_list = [ int(v) for v in input().split() ]
a_list_reverse = list(reversed(a_list))

t_confirm_list = [t_list[0]] + [None for i in range(n-1)]
a_confirm_list = [a_list_reverse[0]] + [None for i in range(n-1)]


for i in range(n-1):
    if t_list[i]  < t_list[i+1]:
        t_confirm_list[i+1] = t_list[i+1]
    if a_list_reverse[i]  < a_list_reverse[i+1]:
        a_confirm_list[i+1] = a_list_reverse[i+1]

a_confirm_list.reverse()


mod = 10**9+7
ans = 1
for i in range(n):
    if a_confirm_list[i] != None and t_confirm_list[i] != None:
        if a_confirm_list[i] != t_confirm_list[i]:
            ans = 0
    elif a_confirm_list[i] == None and t_confirm_list[i] == None:
        ans *= min(a_list[i],t_list[i])
        ans %= mod
    elif a_confirm_list[i] is not None and a_confirm_list[i] > t_list[i]:
            ans = 0
    elif t_confirm_list[i] is not None and t_confirm_list[i] > a_list[i]:
            ans = 0

print(ans)    


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

int main(){
  string S;
  cin >> S;
  sort(S.begin(),S.end());
  if(S.at(0)==S.at(1) && S.at(1)!=S.at(2) && S.at(2)==S.at(3)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No"  << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextInt();
		double b = sc.nextInt();
		double x = sc.nextDouble();
		double res = a * a * b - x;
		double lrad = Math.atan(b / a);
		double rad = Math.atan(res * 2.0/ (a * a * a));
		double rad2 = Math.atan(b * b * a / (2.0 * x));
		if(lrad >= rad){
			System.out.println((rad * 180.0 / Math.PI));
		}else{
			System.out.println((rad2 * 180.0 / Math.PI));
		}
	}
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b|b==c|a==c){
    if(a==b&&b==c){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl;
    }

  }else{
    cout << "No" << endl;
  }
    

  

  return 0;
}


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

using namespace std;

#define ALL(x) begin(x), end(x)

const string YES = "YES";
const string NO = "NO";

void solve(int N, vector<int> p) {
  bool pred = [&]() {
    if (is_sorted(ALL(p))) return true;
    for (auto i = 0; i != N; ++i) {
      for (auto j = 0; j != N; ++j) {
        swap(p[i],p[j]);
        if (is_sorted(ALL(p))) return true;
        swap(p[i],p[j]);
      }
    }
    return false;
  }();

  cout << (pred ? YES : NO) << endl;
}

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  solve(N, move(p));
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<cstdlib>
    using namespace std;
    const long long Max = 1e4;
     
    long long l[Max + 5];
    int n;
     
    int main()
    {
    	cin>>n;
    	l[0] = 2,l[1] = 1;
    	if(n == 1) cout<<l[1]<<endl;
    	else
    	{
    		for(int i = 2 ; i <= n; i++)
    		{
    			l[i] = l[i-1] + l[i-2];
    		}
    		cout<<l[n]<<endl;
    	}
    	return 0;
    }

Measured memory_bytes: 256
list = [int(i) for i in input().strip().split()]
for i in range(len(list) - 1):
    for j in range(1, len(list) - i):
        if list[j - 1] > list[j]:
            tmp = list[j]
            list[j] = list[j - 1]
            list[j - 1] = tmp
print(" ".join(map(str, list)))


Measured memory_bytes: 5604
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String s = scanner.nextLine();

		String temp = null;

		int ans1 = 0;
		int ans2 = 0;

		for(int i = 0; i < s.length(); i++) {

			temp = String.valueOf(s.charAt(i));

			if(temp.equals("A") || temp.equals("C")|| temp.equals("G")|| temp.equals("T")) {

				for(int j = i; j < s.length(); j ++) {
					temp = String.valueOf(s.charAt(j));

					if(temp.equals("A") || temp.equals("C")|| temp.equals("G")|| temp.equals("T")) {
					ans1++;
					}else {
						break;
					}

				}

			}

			i += ans1;
			ans2 = Math.max(ans1, ans2);
			ans1 = 0;


		}

		System.out.println(ans2);


	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

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(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};


int main() {

    int A,B,C,D;

    cin >> A >> B >> C>>D;

    int i = 0;

    while(1){
        if(i%2 == 0){
            C = C-B;
            if(C<=0){
                cout << "Yes" << endl;
                return 0;
            }
        }else{
            A = A-D;
            if(A<=0){
                cout << "No" << endl;
                return 0;
            }
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
const int NUM=10000;

int Search(int key,int *A,int n){
  A[n]=key;
  int i=0;
  while(A[i]!=key){
    i++;
  }
  if(i==n){
    return 0;
  }
  else return 1;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int sn;
  int tn;
  int S[NUM];
  int T[NUM];
  int count=0;

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

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

  for(int i=0;i<tn;i++){
    if(Search(T[i],S,sn)==1){
      count++;
    }
  }

  cout<<count<<endl;

  return 0;
}

      

  



Measured memory_bytes: 3272
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#define ll long long

using namespace std;

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

ll comb(ll n, ll r){
    ll child = 1, mother = 1;
    ll mod = 1000000007;
    for(ll i = 1; i <= r; i++){
        child = child * (n-i+1) % mod;
        mother = mother * i % mod;
    }
    mother = modpow(mother, mod-2, mod);
    ll ans = child * mother % mod;
    return ans;
}

int main(void){
    ll x, y;
    cin >> x >> y;
    ll ans;
    if((x+y)%3!=0) ans = 0;
    else if((x+y)%3==0){
        ll t = (x+y)/3;
        ll r = 2*t - min(x, y);
        ans = comb(t, r);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int P = sc.nextInt();
        int totalP = A * 3 + P;
        int PI = totalP / 2;
        
        System.out.println(PI);
    }
}

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

class E
{
	static void Main()
	{
		var M = 1000000007;
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var k = h[1];

		var map = new int[h[0] + 1].Select(_ => new List<int>()).ToArray();
		foreach (var r in new int[h[0] - 1].Select(_ => read()))
		{
			map[r[0]].Add(r[1]);
			map[r[1]].Add(r[0]);
		}

		var u = new bool[h[0] + 1];
		var q = new Queue<int>();
		u[1] = true;
		q.Enqueue(1);

		long c = k;
		while (q.Any())
		{
			var p = q.Dequeue();
			c = c * ModNpr(k - (p == 1 ? 1 : 2), map[p].Count - (p == 1 ? 0 : 1), M) % M;

			foreach (var np in map[p])
			{
				if (u[np]) continue;
				u[np] = true;
				q.Enqueue(np);
			}
		}
		Console.WriteLine(c);
	}

	static long ModNpr(int n, int r, int mod)
	{
		if (n < r) return 0;
		for (long x = 1, i = n - r; ; x = x * ++i % mod) if (i >= n) return x;
	}
}


Measured memory_bytes: 33916
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (n, d) = {
    let v: Vec<usize> = read_vec();
    (v[0], v[1])
  };

  let mut x: Vec<Vec<i64>> = Vec::new();
  for _ in 0..n {
    let v: Vec<i64> = read_vec();
    x.push(v);
  }
  let mut ans = 0;
  for i in 0..n-1 {
    for j in i+1..n {
      let tmp = dist(&x[i], &x[j]);
      if check(tmp) {
        ans += 1;
      }
    }
  }

  println!("{}", ans);
}


fn dist(v: &Vec<i64>, t: &Vec<i64>) -> i64 {
  let n: usize = v.len();
  let mut res = 0;
  for i in 0..n {
    res += (v[i] - t[i]) * (v[i] - t[i]);
  }

  res
}


fn check(val: i64) -> bool {
  for i in 0..20_000 {
    if val == i * i {
      return true;
    }
  }

  return false;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    ll n; cin>>n;
    ll a=26;
    int keta=1;
    while(a<n){
        n-=a;
        keta++;
        a*=26;
    }
    string ans;
    n--;
    rep(i,keta){
        int b=n%26;
        ans.push_back('a'+b);
        n/=26;        
    }
    string  an;
    n=ans.size();
    rep(i,n) an.push_back(ans[n-1-i]);
    cout<<an<<endl;
}

Measured memory_bytes: 3596
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  bool is_three = true;
  for (int i = 0; i < n; i++) {
    char c;
    std::cin >> c;
    if (c == 'Y') {
      is_three = false;
      break;
    }
  }
  if (is_three) {
    std::cout << "Three";
  } else {
    std::cout << "Four";
  }
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr ll MOD = 998244353;

// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

ll pmod(ll x, ll i) {
  if (i == 0) return 1;
  if ((i%2) == 1) return pmod(x, i-1) * x % MOD;
  ll h = pmod(x, i/2);
  return h * h % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,k;
  cin>>n>>m>>k;
  if (m == 1) {
    if (n == 1 || k == n-1) {
      cout<<1<<endl;
    } else {
      cout<<0<<endl;
    }
    return 0;
  }
  ll pmm1 = pmod(m-1, n-1);
  ll invm1 = inv(m-1, MOD);
  ll ans = 0;
  ll comb = 1;
  FOR(i,1,k+1) {
    ans += pmm1 * comb;
    ans %= MOD;
    pmm1 *= invm1;
    pmm1 %= MOD;
    comb *= (n - i);
    comb %= MOD;
    comb *= inv(i, MOD);
    comb %= MOD;
  }
  ans += pmm1 * comb;
  ans %= MOD;
  ans *= m;
  ans %= MOD;
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    string d1 = "dreameraser";
    string d2 = "dreamerase";
    string d3 = "dreamer";
    string d4 = "dream";
    string r1 = "eraser";
    string r2 = "erase";
    bool ans = 1;
    for (int i = 0; i < (int)s.size();)
    {
        if (s[i] == 'd')
        {
            if (s.substr(i, d1.size()) == d1)
                i += d1.size();
            else if (s.substr(i, d2.size()) == d2)
                i += d2.size();
            else if (s.substr(i, d3.size()) == d3)
                i += d3.size();
            else if (s.substr(i, d4.size()) == d4)
                i += d4.size();
            else
            {
                ans = 0;
                break;
            }
        }
        else if (s[i] == 'e')
        {
            if (s.substr(i, r1.size()) == r1)
                i += r1.size();
            else if (s.substr(i, r2.size()) == r2)
                i += r2.size();
            else
            {
                ans = 0;
                break;
            }
        }
        else
        {
            ans = 0;
            break;
        }
    }

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


Measured memory_bytes: 3744
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define ull unsigned long long
using namespace std;
void io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

const int MAXN = 2e3 + 5;
const ll INF = 0x3f3f3f3f3f3f3f;
const ll prim = 1e9 + 7;

int n;
ll t[MAXN];
int a[MAXN];

inline int lowbit(int x) { return x & (-x); }

void init() {
    for (int i = 1; i < MAXN; i++) {
        if (i + lowbit(i) < MAXN) {
            t[i + lowbit(i)] += t[i];
        }
    }
}

ll getsum(int x) {
    ll ans = 0;
    while (x) {
        ans += t[x];
        x -= lowbit(x);
    }
    return ans;
}

ll getsum(int l, int r) { return getsum(r) - getsum(l - 1); }

int main() {
    io();
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        t[a[i]]++;
    }
    init();
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            int l = abs(a[i] - a[j]);
            int r = a[i] + a[j];
            ans += getsum(l + 1, r - 1);
            if (l < a[i]) {
                ans--;
            }
            if (l < a[j]) {
                ans--;
            }
        }
    }
    cout << ans / 3;
}


Measured memory_bytes: 3684
// Created by Krishna Ashok
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> Tree;

#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define For(i,n,a) for(int i=a;i<(n);++i)
#define Forr(i,n) for(int i=n-1;i>=0;i--)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define sz(a) (int)a.size()
#define Fill(a,b) memset(a,b,sizeof(a));
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
const int INF=1e9;

void topsort(int u,vector<bool> &vis,vector<vi> &adj,stack<int> &order){
	vis[u]=true;
	for(int v:adj[u]){
		if(!vis[v])topsort(v,vis,adj,order);
	}
	order.push(u);
}


void solve(){
	int n,m,x,y;
	cin>>n>>m;
	vector<vi> adj(n+1);
	for(int i=0;i<m;i++){
		cin>>x>>y;
		adj[x].push_back(y);
	}
	stack<int> order;
	vector<int> dist(n+1,-INF);
	dist[0]=INF;
	vector<bool> vis(n+1,false);
	for(int i=1;i<=n;i++){
		if(!vis[i])topsort(i,vis,adj,order),dist[i]=0;
	}
	while(!order.empty()){
		int u=order.top();
		order.pop();
		if(dist[u]==-INF)continue;
		for(int v:adj[u]){
			if(dist[v]==-INF)dist[v]=dist[u]-1;
			else dist[v]=min(dist[v],dist[u]-1);
		}
	}

	cout<<*min_element(all(dist))*-1<<endl;

}



int main(){
    fin;
    solve();
    return 0;
}

Measured memory_bytes: 12744
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
int main()
{

    speed;
    ll x,y;
    cin>>x>>y;
    if(x>y)
    swap(x,y);
    if(x==1 && y==2)
    cout<<"3"<<"\n";
    else if(x==2 && y==3)
    cout<<"1"<<"\n";
    else 
    cout<<"2"<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

void solve1();
int score1();
int change(int, int, int);
vector<int> changeT(vector<int>);

int ti;
int D;
int sumC;
int k = 26;
int score;
vector<int> c(k), t;
vector<vector<int>> s;

int main() {
	srand((unsigned)time(NULL));
	cin >> D;
	s.resize(D);

	rep(i, k) {
		cin >> c[i];
		sumC += c[i];
	}
	rep(i, D) {
		s[i].resize(k);
		rep(j, k) {
			cin >> s[i][j];
		}
	}
	t.resize(D);

	rep(i, D) {
		t[i] = rand() % 26;
	}
	score = score1();

	solve1();

	rep(i, D) {
		cout << t[i] + 1 << endl;
	}

}

void solve1() {

	ti = clock();
	int count = 0;

	while (1) {
		count++;
		double time = (double)(clock() - ti) / CLOCKS_PER_SEC;
		if (time > 1.5) {
			break;
		}

		int no = 5;
		int sz = score;
		vector<P> temp;
		rep(i, no) {
			int d = rand() % D;
			int q = rand() % k;
			sz = change(sz, d, q);
			temp.push_back(mp(d, q));
		}
		if (sz > score) {
			score = sz;
			rep(i, temp.size()) {
				t[temp[i].first] = temp[i].second;
			}
		}
		
	}

	//cout << count << endl;
}

vector<int> changeT(vector<int> t) {
	int no = 5;
	rep(i, no) {
		int d = rand() % D;
		int q = rand() % k;
	}
	return t;
}

int score1() {
	//最後にコンテストが行われた日
	vector<int> last(k, -1);
	int ans = 0;

	rep(i, D) {
		ans += s[i][t[i]];
		last[t[i]] = i;
		rep(j, k) {
			ans -= c[j] * (i - last[j]);
		}
		//cout << ans << endl;
	}
	return ans;
}

int change(int score, int d, int q) {
	score += s[d][q] - s[d][t[d]];
	int x = d + 1;
	while (x != D && t[x] != q) {
		x++;
	}
	int y = d - 1;
	while (y >= 0 && t[y] != q) {
		y--;
	}
	score += c[q] * (d - y) * (x - d);

	x = d + 1;
	while (x != D && t[x] != t[d]) {
		x++;
	}
	y = d - 1;
	while (y >= 0 && t[y] != t[d]) {
		y--;
	}
	score -= c[t[d]] * (d - y) * (x - d);

	t[d] = q;
	return score;
}

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

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> snuke(n+1);
    for(int i=0; i<n; i++){
        int d;
        cin >> d;
        for(int j=0; j<d; j++){
            int a; cin >> a;
            snuke[a]++;
        }
    }

    int ans = 0;
    for(int i=1; i<=n; i++){
        if(snuke[i] == 0) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3628