akhauriyash/Code-Regression huggingface dataset:
import bisect
n = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0

for i in range(n-1):
    for j in range(i+1,n):
        index = bisect.bisect_left(L,L[i]+L[j])
        ans += index - (j+1)

print(ans)

Measured memory_bytes: 3188
from itertools import accumulate
n, w = map(int, input().split())
w_0, v_0 = map(int, input().split())
v_list = [[] for _ in range(4)]
v_list[0].append(v_0)
for _ in range(n - 1):
    w_in, v_in = map(int, input().split())
    v_list[w_in - w_0].append(v_in)
v_list = [[0] + list(accumulate(sorted(v, reverse=True))) for v in v_list]
ans = 0
for i in range(len(v_list[0])):
    for j in range(len(v_list[1])):
        for k in range(len(v_list[2])):
            for l in range(len(v_list[3])):
                if ((i) * w_0) + ((j) * (w_0 + 1)) + ((k) * (w_0 + 2)) + (((l) * (w_0 + 3))) <= w:
                    ans = max(ans, v_list[0][i] + v_list[1][j] + v_list[2][k] + v_list[3][l])
                else:
                    break
print(ans)

Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

const int MSQ = sqrt(N) + 5;

std::vector<int> wa;
bool  y[1000005];
void sieve(){
	for(int i=2;i<=1000000;i++){
		if(y[i])continue;
		wa.pb(i);
		for(int j=i;j<=1000000;j+=i){
			y[j]=1;
		}
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();
	
	int n;
	scanf("%d",&n);

	std::vector<int> v;
	for(int i=1;i<=n;i++)v.pb(i);
	std::vector<int> a(n),b(n);

	for(auto &x:a)scanf("%d",&x);
	for(auto &x:b)scanf("%d",&x);
	int aa , bb;
	int cnt = 0;
	do{
		cnt++;
		if(v==a)aa=cnt;
		if(v==b)bb=cnt;
	}while(next_permutation(all(v)));

	printf("%d\n",abs(aa-bb));
}		



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

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);

                long A = scan.nextLong();
                long B = scan.nextLong();
                long N = scan.nextLong();

                long x = B - 1;

                long first;
                long second;
                long f;

                long max = -1000;

                if (B == 1) {
                        System.out.println(0);
                } else {
                        while (x < N ) {
                                first = A*x/B;
                                second = x/B;
                                f = first - A*second;
                                if (max < f) {
                                        max = f;
                                }
                                x += B;
                        }

                        first = A*N/B;
                        second = N/B;
                        f = first - A*second;
                        if (max < f) {
                                max = f;
                        }
                
                        System.out.println(max);

                }
        }

}

Measured memory_bytes: 35772
N = int(input())
S = [input() for _ in range(N)]

ans = 0
ba = 0
xa = 0
bx = 0
for s in S:
  ans += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    ba += 1
  elif s[0] == 'B' and s[-1] != 'A':
    bx += 1
  elif s[0] != 'B' and s[-1] == 'A':
    xa += 1
if xa == 0 and bx == 0:
  ans += max(ba-1,0)
elif (xa == 0 and bx != 0) or (xa != 0 and bx == 0):
  ans += ba
else:
  ans += ba+1 + min(xa-1,bx-1)
print(ans)

Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll m1, m2, d1, d2;
	in(m1);
	in(d1);
	in(m2);
	in(d2);

	if (m1 != m2) {
		outn(1);
	}
	else {
		outn(0);
	}

	return 0;


}


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

int main(){
    int n;
    while(cin>>n){
        if(n==0) break;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int ans=1e9;
        for(int i=1;i<n;i++){
            ans=min(ans,a[i]-a[i-1]);
        }
        cout<<ans<<endl;
        
    }

}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define xx first
#define yy second
 
#define pii pair <int, int >
#define pll pair < ll, ll >
#define xx first
#define yy second
#define vi vector < int >
#define vl vector < ll >
#define vp vector < pii >
 
#define inf  100000000
 
#define f(i, c, n) for(int i = c; i < n; i++)
#define fe(i, c, n) for(int i = c; i <= n; i++)
#define fr(i, n, c) for(int i = n - 1; i >= c; i--)
 
#define be(a) a.begin(), a.end()
#define vsort(a) sort(a.begin(), a.end())
#define mem(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define srti(a, n) sort(a, a + n)
#define srtd(a, n) sort(a, a + n, greater<int>())
#define LB(a, x) (lower_bound(vbe(a), x) - a.begin())
#define UB(a, x) (upper_bound(vbe(a), x) - a.begin())
#define S " "
#define N "\n"

//cout << "Case " << ++cs << ": " <<
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);


void solve() {
	int n;
	cin >> n;
	if(n % 2) {
		cout << n * 2 << N;
	} else cout << n << N;
}

int main() {
    // FILE;
    fast;
    // int t; cin >> t; while(t--)
    solve();
}

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

constexpr double EPS = 1e-10;
typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
typedef Segment Line;
typedef pair<Point, double> Circle;
typedef vector<Point> Polygon;
double dot(Vector a, Vector b){
	return real(a) * real(b) + imag(a) * imag(b);
}
double cross(Vector a, Vector b){
	return real(a) * imag(b) - imag(a) * real(b);
}
Point project(Line l, Point p){
	Vector base = l.second - l.first;
	base /= abs(base);
	double r = dot(p - l.first, base);
	return l.first + r * base;
}
Point reflect(Line l, Point p){
	return p + (project(l, p) - p) * 2.0;
}
int ccw(Point p0, Point p1, Point p2){
	Vector v = p1 - p0, w = p2 - p0;
	if(cross(v, w) > EPS) return 1; // COUNTER_CLOCKWISE
	if(cross(v, w) < -EPS) return -1; // CLOCKWISE
	if(dot(v, w) < -EPS) return 2; // ONLINE p2 - p0 - p1
	if(norm(v) + EPS < norm(w)) return -2; // ONLINE p0 - p1 - p2
	return 0; // ONLINE p0 - p1 - p2
}
bool isOrthogonal(Vector v1, Vector v2){
	double t = abs(dot(v1, v2));
	return t <= EPS;
}
bool isParallel(Vector v1, Vector v2){
	double t = abs(cross(v1, v2));
	return t <= EPS;
}
bool intersect(Segment s1, Segment s2){
	int t = ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second);
	int u = ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second);
	return (t == 0 || t == -1 || t == -4) && (u == 0 || u == -1 || u == -4);
}
Point getCrossPoint(Segment s1, Segment s2){
	assert(intersect(s1, s2));
	assert(!isParallel(s1.second - s1.first, s2.second - s2.first));
	Vector base = s2.second - s2.first;
	double d1 = abs(cross(base, s2.first - s1.first));
	double d2 = abs(cross(base, s2.first - s1.second));
	return s1.first + (s1.second - s1.first) * d1 / (d1 + d2);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	while(q--){
		double x[4], y[4];
		for(int i=0; i<4; ++i) cin >> x[i] >> y[i];
		Point p0(x[0], y[0]), p1(x[1], y[1]), p2(x[2], y[2]), p3(x[3], y[3]);
		Point p = getCrossPoint(Segment(p0, p1), Segment(p2, p3));
		cout << setprecision(14) << real(p) << " " << imag(p) << "\n";
	}
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int ans=0;
  for(int i=A;i<=B;i++){
    vector<int> X(5);
    int N=i;
    for(int j=0;j<5;j++){
      X[j]=N%10;
      N/=10;
    } 
    if(X[0]==X[4] && X[1]==X[3]){
      ans++;
    }
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
R = [i for i in range(N)]
def root(R, i):
  if R[i] == i:
    return i
  else:
    R[i] = root(R, R[i])
    return R[i]
def union(i, j):
  ri = root(R, i)
  rj = root(R, j)
  if ri <= rj:
    R[rj] = ri
  else:
    R[ri] = rj
for m in range(M):
  i, j = map(int, input().split())
  union(i, j)
for i in range(N):
  R[i] = root(R, i)
if N < 2 * (N - M - 1):
  print('Impossible')
elif M == N - 1:
  print(0)
else:
  cnt= 0
  E = N - M - 2
  C = [0] * N
  F = sorted([[a, R[i]] for i, a in enumerate(A)])
  for a, r in F:
    if C[r] == 0:
      C[r] = a
      cnt += a
    elif E > 0:
      cnt += a
      E -= 1
  print(cnt)

Measured memory_bytes: 23108
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;
const int INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(c<a+b){cout<<"No";return 0;}
    else{
        cout<<(4*a*b<(c-a-b)*(c-a-b)?"Yes":"No")<<endl;
    }
}

Measured memory_bytes: 256
import collections

N = int(input())
A = input().split()

c = collections.Counter(A)
cou = list(c.values())

ans = 0
for j in range(len(cou)):
	m = cou[j]
	k = m*(m-1)/2
	ans += int(k)


for i in range(N):
	x = c[A[i]]
	print(ans - x + 1)

Measured memory_bytes: 84684
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

chlist = []
for i in range(Q):
    chlist.append(tuple(map(int, input().split())))

counter = Counter(A)

sums = 0
for key, value in counter.items():
    sums += key * value

for t in chlist:
    if t[0] in counter.keys():
        t0s = counter[t[0]]

        if t[1] in counter.keys():
            counter[t[1]] += counter[t[0]]
        else:
            counter[t[1]] = counter[t[0]]

        counter.pop(t[0])
        sums += (t[1] - t[0]) * t0s

    print(sums)


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int H = 222;
vector<int> e[2 * H];
int indeg[2 * H], outdeg[2 * H];
int sum[2 * H];

void fail() {
    cout << "NO\n";
    exit(0);
}

int par[2 * H];

int get (int u) {
    if (par[u] == u) return u;
    return par[u] = get(par[u]);
}

void unite(int u, int v) {
    u = get(u), v = get(v);
    if (u != v) par[u] = v;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    forn(i, 0, 2 * H) par[i] = i;
    int n, h;
    cin >> n >> h;
    forn(i, 0, n) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int from, to;
        if (c == 0)
            from = a;
        else
            from = c + H;

        if (d == 0)
            to = b + H;
        else
            to = d;

        e[from].eb(to);
        ++indeg[to];
        ++outdeg[from];
        unite(from, to);
        //cerr << from << ' ' << to << '\n';

    };
    /*forn(i, 0, 2 * H) {
        if (indeg[i] || outdeg[i]) {
            cout << i << ' ' << indeg[i] << ' ' << outdeg[i] << '\n';
        }
    }*/
    forn(i, 0, H) {
        int j = get(i);
        sum[j] += outdeg[i] - indeg[i];
        j = get(i + H);
        sum[j] += indeg[i + H] - outdeg[i + H];
    }
    forn(i, 0, H) {
        if (indeg[i] > outdeg[i])
            fail();
        if (indeg[i + H] < outdeg[i + H])
            fail();
    }
    forn(i, 0, 2 * H) {
        if (indeg[i] || outdeg[i]) {
            int j = get(i);
            //cerr << j << ' ' << sum[j] << '\n';
            if (sum[j] <= 0) fail();
        }
    }
    cout << "YES\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int W, H, N;
  cin >> W >> H >> N;
  int xl = 0;
  int xr = W;
  int yl = 0;
  int yr = H;
  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    switch (a) {
      case 1:
        xl = max(xl, x); break;
      case 2:
        xr = min(xr, x); break;
      case 3:
        yl = max(yl, y); break;
      case 4:
        yr = min(yr, y); break;
    }
  }
  cout << max(0,(xr-xl))*max(0,(yr-yl)) << endl;
  return 0;
}


Measured memory_bytes: 3564
N = int(input())
S =  input()

nR = 0
nG = 0
nB = 0

for s in S:
    if s == "R":
        nR += 1
    elif s == "G":
        nG += 1
    elif s == "B":
        nB += 1
        
c1pat = nR*nG*nB

mcount = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        k = j + (j-i)
        if k < N:
#             print(i,j,k)
            if set([S[i],S[j],S[k]]) == set(["R","G","B"]):
                mcount += 1
                
                
print(c1pat - mcount)


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

int main()
{
    int A,B;

    cin >> A>>B;

    int ans;

    if(A>=13){
        ans =B;
    }else if(A <= 5){
        ans = 0;
    }else{
        ans = B/2;
    }
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

queue<pair<int, int>> q;

bool checker(vector<string>& grid, vector<vector<int>>& dis, pair<int, int> posi) {
    int H = grid.size(), W = grid[0].size();
    if (posi.first<0 || posi.first>H - 1 || posi.second<0 || posi.second>W - 1)
        return false;
    if (grid[posi.first][posi.second] == '#')
        return false;
    if (dis[posi.first][posi.second] > 0)
        return false;

    return true;

}
void dis_deci(vector<string> &grid, vector<vector<int>>& dis) {
    
    pair<int, int> p = q.front();
    q.pop();
    vector<int> tate = { -1,0,1,0 }, yoko = { 0,1,0,-1 };
    for (int i = 0; i < 4; i++) {
        pair<int, int> y = make_pair(p.first + tate[i], p.second + yoko[i]);
        if (checker(grid, dis, y)){
            dis[y.first][y.second] = dis[p.first][p.second] + 1;
            q.push(y);
        }
    }
    if (q.empty())return;
    else dis_deci(grid, dis);
}

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> grid(H);
    vector<vector<int>> dis(H, vector<int>(W));
    for(int i=0;i<H;i++)
    cin >> grid[i];
   
    q.push(make_pair(0, 0));
    dis_deci(grid, dis);

    int white = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '.')
                white++;
        }
    }
    if (dis[H - 1][W - 1] == 0)cout << "-1" << endl;
    else cout << white - dis[H - 1][W - 1] - 1 << endl;
}


Measured memory_bytes: 640
from bisect import bisect_left

s = input()
t = input()
ls, lt = len(s), len(t)

exsist = [[] for _ in range(26)]
for i in range(ls) :
    exsist[ord(s[i])-97].append(i)

ret = 0
now = -1
for i in range(lt) :
    ot = ord(t[i])-97
    if len(exsist[ot]) == 0 :
        print('-1')
        break
    
    a = bisect_left(exsist[ot], now + 1)
    if a == len(exsist[ot]) :
        ret += ls
        now = exsist[ot][bisect_left(exsist[ot], -1)]
    else :
        now = exsist[ot][a]
        
else :
    print(ret+now+1)

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

const int INF = 1e+9;
typedef pair<int, string> P;

map<string, vector<string>> magic;
map<string, int> check;

void dfs(string s){
	check[s] = true;
	for(int i = 0; i < magic[s].size(); ++i){
		if(!check[magic[s][i]])
			dfs(magic[s][i]);
	}
}

int main() {
	ios::sync_with_stdio(false);
	
	string s, t;
	int n, x, m, cnt = 0;
	vector<P> goods;
	map<string, bool> ended;
	
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> s >> x;
		goods.push_back(P(x, s));
	}
	sort(goods.begin(), goods.end());
	
	cin >> m;
	for(int i = 0; i < m; ++i){
		cin >> s >> t;
		magic[s].push_back(t);
		magic[t].push_back(s);
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i){
		dfs(goods[i].second);
		for(auto& c : check){
			if(!ended[c.first]){
				ended[c.first] = true;
				ans += goods[i].first;
				cnt++;
			}
		}
		if(cnt >= n)
			break;
		check.clear();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2320
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define in &
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vvl vector<vector<ll> >
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define eb emplace_back
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference
//priority_queue implements max heap by default

int main(){
    fastio;
    int n;
    cin>>n;
    string s;
    cin>>s;
    map<char,ll> m;
    for(auto x:s){
        m[x]++;
    }
    ll ans = 1;
    for(auto x:m){
        ans = (ans*(x.se+1))%MOD;
    }
    cout<<(ans-1+MOD)%MOD;
    return 0;
}

Measured memory_bytes: 512
import math
import fractions

def gcd_list(numbers):
    for i in range(1, len(numbers)):
        ans = fractions.gcd(ans, numbers[i])
    return ans

def lcm_list(numbers):
    ans = numbers[0]
    for i in range(1, len(numbers)):
        ans = ans * numbers[i] // fractions.gcd(ans, numbers[i])
    return ans



N = int(input())
A_line = list(map(int, input().split()))

lcm = lcm_list(A_line)
mother = sum(map(lambda x: lcm//x, A_line))

print(lcm/mother)

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

int main(){
    int n, m;
    cin>> n >> m;
    
    vector<int> h(n);

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

    vector<int> good(n, 0);
    for(int i=0; i<m; i++){
        int a, b;
        cin>> a >> b;
        a--;
        b--;
        good[a] = max(good[a], h[b]);
        good[b] = max(good[b], h[a]);
    }
    int cnt = 0;
    for(int i=0; i<n; i++){
        if(h[i] > good[i]){
            cnt++;
        }
    }
    cout<< cnt <<endl;
    return 0;
}

Measured memory_bytes: 4048
#include <cstdio>
#include <algorithm>

using namespace std;

void print(char str[],int a,int b){
	for(int i = a; i <= b; i++)	printf("%c",str[i]);
	printf("\n");
}

void replace(char str[],char p[],int a,int b){
	int p_length = b-a+1;
	for(int i = 0; i < p_length;i++) str[a+i] = p[i];
}

void reverse(char str[],int a,int b){
	int left = a,right = b;
	while(left < right){
		swap(str[left++],str[right--]);
	}
}

int main(){
	char str[1001],p[1001],order[8];
	int q,a,b;
	scanf("%s",str);
	scanf("%d",&q);
	for(int i = 0; i < q; i++){
		scanf("%s %d %d",order,&a,&b);
		switch(order[2]){
		case 'i':
			print(str,a,b);
			break;
		case 'v':
			reverse(str,a,b);
			break;
		case 'p':
			scanf("%s",p);
			replace(str,p,a,b);
			break;
		}
	}
}



Measured memory_bytes: 2696
#include <iostream>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

#define echo(A) cout << A << endl;

typedef long long llong;

int main() {
	char A;
	cin >> A ;
	if(A == 'A'){echo('T');return 0;}
	if(A == 'T'){echo('A');return 0;}
	if(A == 'C'){echo('G');return 0;}
	if(A == 'G'){echo('C');return 0;}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll R,C,K;
  cin >> R >> C >> K;
  vector<vector<int>> G(R, vector<int>(C, false));
  for(ll r=0; r<R; r++) {
    string S;
    cin >> S;
    for(ll c=0; c<C; c++) {
      G[r][c] = (S[c]=='#');
    }
  }

  ll ans = 0;
  for(ll a=0; a<(1<<R); a++) {
    for(ll b=0; b<(1<<C); b++) {
      ll score = 0;
      for(ll r=0; r<R; r++) {
        for(ll c=0; c<C; c++) {
          bool is_red = (((a>>r)&1) == 1) || (((b>>c)&1)==1);
          if(!is_red && G[r][c]) {
            score++;
          }
        }
      }
      if(score==K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;

    vector<int> v(3 * n);
    for(int i = 0; i < 3 * n; i++)
    {
        cin >> v.at(i);
    }

    sort(v.rbegin(), v.rend());

    unsigned long int ans = 0;

    for(int i = 0; i < 2 * n; i++)
    {
        if(i % 2 == 1) ans += v.at(i);
    }
    cout << ans << endl;
}
 

Measured memory_bytes: 1408
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
R = []
L = []
U_ = defaultdict(list)
U__ = defaultdict(list)
D_ = defaultdict(list)
D__ = defaultdict(list)
Ux = defaultdict(list)
Dx = defaultdict(list)
Ry = defaultdict(list)
Ly = defaultdict(list)
for _ in range(n):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    if u == 'U':
        Ux[x].append(y)
        U_[x+y].append((x, y))
        U__[x-y].append((x, y))
    elif u == 'D':
        Dx[x].append(y)
        D_[x+y].append((x, y))
        D__[x-y].append((x, y))
    elif u == 'R':
        Ry[y].append(x)
        R.append((x, y))
    else:
        Ly[y].append(x)
        L.append((x, y))

for i in Ux.values():
    i.sort()
for i in Ry.values():
    i.sort()

ans = inf
for i, j in Dx.items():
    for k in j:
        r = br(Ux[i], k)
        if r != 0:
            ans = min(ans, int((k - Ux[i][r-1]) / 2 * 10))
for i, j in Ly.items():
    for k in j:
        r = br(Ry[i], k)
        if r != 0:
            ans = min(ans, int((k - Ry[i][r-1]) / 2 * 10))

for i in U_.values():
    i.sort(reverse=True)
for i in U__.values():
    i.sort(reverse=True)
for i in D_.values():
    i.sort(reverse=True)
for i in D__.values():
    i.sort(reverse=True)

for (i, j) in R:
    for (k, l) in D__[i-j]:
        if l - j >= 0:
            ans = min(ans, (l - j) * 10)
        else:
            break

for (i, j) in R:
    for (k, l) in U_[i+j]:
        if j - l >= 0:
            ans = min(ans, (j - l) * 10)
        else:
            break

for (i, j) in L:
    for (k, l) in U__[i-j]:
        if i - k >= 0:
            ans = min(ans, (i - k) * 10)
        else:
            break

for (i, j) in L:
    for (k, l) in D_[i+j]:
        if i - k >= 0:
            ans = min(ans, (i - k) * 10)
        else:
            break


if ans == inf:
    print('SAFE')
else:
    print(ans)    


Measured memory_bytes: 229480
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

ll N,C;
vector<pair<pll,ll>> stc;
vector<int> checked;

bool ok(int c){
    ll pret,prec;
    fill(checked.begin(),checked.end(),0);
    for(int i = 0; i < c;i++){
        pret = -1,prec = -1;
        for(int i = 0; i < N;i++){
            if(checked[i] == 1) continue;
            if(pret < stc[i].first.first){
                checked[i] = 1;
                pret = stc[i].first.second;
                prec = stc[i].second;
                continue;
            }else if(pret == stc[i].first.first){
                if(prec == stc[i].second){
                    checked[i] = 1;
                    pret = stc[i].first.second;
                    prec = stc[i].second;
                    continue;
                }
            }
        }
    }
    for(auto f:checked){
        if(f == 0) return false;
    }
    return true;
}

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> C;
    stc.resize(N);
    for(auto& in:stc) cin >> in.first.first >> in.first.second >> in.second;
    sort(stc.begin(),stc.end());
    checked.resize(N);
    
    for(int i = 1;i <= 30;i++){
        if(ok(i)){
            cout << i << endl;
            break;
        }
    }
    
    return 0;
}



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

int main(){
  lint h, w; cin >> h >> w;
  
  lint ans = 1e11;
  for(lint i=1;i<h;i++){
    lint mx = w * max(i, (h-i+1)/2);
    lint mn = w * min(i, (h-i)/2);
    ans = min(ans, mx-mn);
    
    mx = max(w*i, (h-i)*((w+1)/2));
    mn = min(w*i, (h-i)*(w/2));
    ans = min(ans, mx-mn);
  }
  
  for(lint i=1;i<w;i++){
    lint mx = h * max(i, (w-i+1)/2);
    lint mn = h * min(i, (w-i)/2);
    ans = min(ans, mx-mn);
    
    mx = max(h*i, (w-i)*((h+1)/2));
    mn = min(h*i, (w-i)*(h/2));
    ans = min(ans, mx-mn);
  }
  
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    char a[n+2][m+2]= {};
    memset(a,'#',sizeof(a));
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            cin>>a[i][j];
    for(int i=0; i<=n+1; i++)
    {
        for(int j=0; j<=m+1; j++)
        {
            cout<<a[i][j];
        }
        cout<<'\n';
    }
    return 0;
}




Measured memory_bytes: 3620
n,k =map(int,input().split())
h =[0]*n

for i in range(n):
  h[i]= int(input())

sort_h = sorted(h)
diffmin=10**9

for times in range(n-k+1):

  diff = sort_h[k+times-1]-sort_h[times]
  if diffmin > diff:
    diffmin=diff

print(diffmin)

Measured memory_bytes: 46040
from sys import stdin


def iterate_tokens():
    for line in stdin:
        for word in line.split():
            yield word


def main():
    tokens = iterate_tokens()
    next(tokens)
    Q = int(next(tokens))
    S = next(tokens)
    L = []
    R = []
    for i in range(Q):
        L.append(int(next(tokens)) - 1)
        R.append(int(next(tokens)) - 1)
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(L, R):
        print(AC[r] - AC[l])
    return


main()


Measured memory_bytes: 14292
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL N,X; R(N,X);
    LL an=1;
    LL v=0;
    REP(i,N){
        LL t; R(t);
        v+=t;
        if(v<=X)an++;
    }
    W(an);
    return 0;
}


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

using namespace std;

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

    int n, i;
    i = 1;
    while (cin >> n, n) {
        cout << "Case " << i << ": " << n << endl;
        i++;
    }
    return 0;
}



Measured memory_bytes: 3120
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<set>
#include<queue>
#include<cstdlib>
#include<algorithm>

using namespace std;
#define pb push_back
#define mp make_pair
#define ls(x) (x << 1)
#define rs(x) (x<<1|1)
#define SZ(x) (int)(x).size()

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<LL, LL> pll;
typedef pair<bool, int> pbi;

const double eps = 1e-10;
const double PI = acos(-1.0);
//const double PI = 3.14159265358979323846264338327950288419716939937510
int dcmp(const double &x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; }
const int MOD = 1e9 + 7;
const int INF = 2147483647;
const double INF_d = 1e64;

template<class T>
T qmod(T a, T b){ T ret = 1; while (b){ if (b & 1) ret *= a; b >>= 1; a *= a; } return ret; }
template<class T>
T gcd(T a, T b){ return !b ? a : gcd(b, a % b); }
template<class T>
T ex_gcd(T a, T b, T &x, T &y){
    if (!b){ x = 1, y = 0; return a; }
    T t, ret;
    ret = ex_gcd(b, a % b, x, y);
    t = x, x = y, y = t - a / b * y;
    return ret;
}
template<class T>
T inv(T t, T p){ return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p; }

// head

const int N = 2e5 + 7;
struct node{
    int l, r, val, tag;
};

int n, m, op, x, y, w;
node T[N << 2];

void build(int rt, int l, int r){
    T[rt].l = l, T[rt].r = r, T[rt].val = INF, T[rt].tag = 0;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(ls(rt), l, mid);
    build(rs(rt), mid + 1, r);
}

void push_down(int rt){
    if (T[rt].tag){
        T[ls(rt)].val = T[rs(rt)].val = T[rt].val;
        T[ls(rt)].tag = T[rs(rt)].tag = 1;
        T[rt].tag = 0;
    }
}

void push_up(int rt){
    T[rt].val = min(T[ls(rt)].val, T[rs(rt)].val);
}

void update(int rt, int l, int r, int val){
    if (l > T[rt].r || r < T[rt].l) return;
    if (l <= T[rt].l && T[rt].r <= r){
        T[rt].val = val; T[rt].tag = 1; return;
    }
    push_down(rt);
    int mid = (T[rt].l + T[rt].r) >> 1;
    if (l <= mid) update(ls(rt), l, r, val);
    if (r > mid) update(rs(rt), l, r, val);
    push_up(rt);
}

int query(int rt, int l, int r){
    if (l > T[rt].r || T[rt].l > r) return INF;
    if (l <= T[rt].l && T[rt].r <= r) return T[rt].val;
    push_down(rt);
    int ret = INF, mid = (T[rt].l + T[rt].r) >> 1;
    if (l <= mid) ret = min(ret, query(ls(rt), l, r));
    if (r > mid) ret = min(ret, query(rs(rt), l, r));
    return ret;
}

int main(){
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    build(1, 1, n);
    for (int i = 0; i < m; i++){
        scanf("%d", &op);
        if (!op){
            scanf("%d%d%d", &x, &y, &w); x++, y++;
            update(1, x, y, w);
        }
        else{
            scanf("%d%d", &x, &y); x++, y++;
            printf("%d\n", query(1, x, y));
        }
    }
    return 0;
}



Measured memory_bytes: 7316
a = gets.chomp.split(" ").map(&:to_i)
n=a[0]
m=a[1]
for i in 1..n
  for j in 1..m
  if a[2] == i*j + (a[0]-i) * (a[1]-j)
    puts "Yes"
    exit
  end
  end
end
for i in 1..m
  for j in 1..n
  if a[2] == i*j + (a[1]-i) * (a[0]-j)
    puts "Yes"
    exit
  end
  end
end
if a[2]==0 || a[2]==n*m || a[2] % n == 0 || a[2] % m == 0 
puts "Yes"
exit
end
a[2] = n*m-a[2]
for i in 1..n
  for j in 1..m
  if a[2] == i*j + (a[0]-i) * (a[1]-j)
    puts "Yes"
    exit
  end
  end
end
for i in 1..m
  for j in 1..n
  if a[2] == i*j + (a[1]-i) * (a[0]-j)
    puts "Yes"
    exit
  end
  end
end
if a[2]==0 || a[2]==n*m || a[2] % n == 0 || a[2] % m == 0 
puts "Yes"
exit
end
puts "No"

#if a[0]-1+a[1]-1 <=a[2] && a[2] <= 1+(a[0]*a[1])
#puts "Yes"
#else
#puts "No"
#end


Measured memory_bytes: 1788
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    #[inline(always)]
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    #[inline(always)]
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    let n = get!(usize);
    let mut aa = util::gets::<u64>();

    aa.sort_by_key(|&a| Rev(a));

    let mut sum = 0;
    for i in 0..n {
        sum += unsafe { *aa.get_unchecked(i * 2 + 1) };
    }

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


Measured memory_bytes: 13428
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {

    int N, K;
    cin >> N >> K;
    vector<int64_t> H(N);
    for(int i = 0; i < N; i++) cin >> H.at(i);

    if(N <= K) {
        cout << 0 << endl;
        return 0;
    }

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

    int64_t ans = accumulate(H.begin(), H.end() - K, (int64_t)0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main (){
  long long int n1,n,i,a=10000000000,r=0;
  cin>>n1;
  n=n1;
  for(i=0;i<10;i++){
    a/=10;
      
  if(n/a!=0){
    r+=n/a;
    n-=(n/a)*a;
  }
  }
  if(n1%r==0)
    cout<<"Yes";
  else cout<<"No";
}
    


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
    
    int n;
    scanf("%d", &n);
    
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(i * j == n){
                printf("Yes\n");
                return 0;
            }
        }
    }
    
    printf("No\n");
    return 0;
}

Measured memory_bytes: 1636
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input!{
        n: usize,
        a: [i32; n],
    }
    let mut cols = 0;
    for i in 0..8 {
        if a.iter().any(|&x| 400 * i <= x && x < 400 * ( i + 1 )) { cols += 1; }
    }
    println!("{} {}", max(1, cols), cols + a.iter().filter(|&&x| x >= 3200).count() as i32);
}


Measured memory_bytes: 4352
import java.util.*;
class Main
{
public static void main(String args[])
{
int i=0,j=0,flag=0,s;
char a[]={'h','i'};
Scanner inn=new Scanner(System.in);
String v =inn.next();
s=v.length();
if(s%2!=0)
System.out.println("No");
else
{
for(j=0;j<s;j++)
{
i=i%2;
if(v.charAt(j)!=a[i])
{

flag=1;
break;
}
i++;
}
if(flag==0)
System.out.println("Yes");
else
System.out.println("No");
}
}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int w, d;
    while(scanf("%d%d", &w, &d) && w){
        int a[w], b[d];
        multiset<int> S;
        rep(i, w){
            scanf("%d", &a[i]);
            S.insert(a[i]);
        }
        rep(i, d) scanf("%d", &b[i]);
        int ans = 0;
        rep(i, d){
            ans += b[i];
            if(S.find(b[i]) != S.end()) S.erase(S.find(b[i]));
        }
        for(int i: S) ans += i;
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 3156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private class DisjointSet {
		
		int[] p, rank;
		
		public DisjointSet(int size) {
			p = new int[size];
			rank = new int[size];
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		private void makeSet(int x) {
			p[x] = x;
			rank[x] = 0;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		private int findSet(int x) {
			if (p[x] != x) {
				p[x] = findSet(p[x]);
			}
			return p[x];
		}
		
		public void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		private void link(int x, int y) {
			if (rank[x] < rank[y]) {
				p[y] = x;
			} else {
				p[x] = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x= Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				ds.unite(x, y);
			} else {
				System.out.println(ds.same(x, y)?"1":"0");
			}
		}
		reader.close();
	}
}


Measured memory_bytes: 61156
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int,int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for(int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for(int i = L; i != (int)R; --i)
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    double x;
    cin >> x;
    x /= 3;
    cout << fixed << setprecision(8) << x * x * x << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    cout<<((h2*60+m2)-(h1*60+m1))-k<<"\n";

    return 0;
}


Measured memory_bytes: 3636
import itertools

S = list(input())
Idxs = list(itertools.combinations(range(len(S)), 2)) 

def ACGT(Word):
    for w in Word:
        if w not in ["A", "C", "G", "T"]:
            return 0
    return len(Word)

ans = 0

for s in S:
    if s in ["A", "C", "G", "T"]:
        ans = 1
        break

for idx in Idxs:
    tmp = S[idx[0]:idx[1]+1]
    ans = max(ans, ACGT(tmp))
    
print(ans)

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b; cin >> a >> b;
    if(a > b) swap(a, b);
    rep(i, b) cout << a; cout << endl;
    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  programs
//
//  Created by Arunesh Sarker on 18/11/19.
//  Copyright © 2019 Arunesh Sarker. All rights reserved.
//

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <unordered_set>
using namespace std;

typedef unsigned long long ll;
#define mod 1000000007
    // 60 60 30 40 5 5
     
  // Function to return LCM of two numbers
 ll gcd(ll a, ll b)
 {
     if (a == 0)
         return b;
     return gcd(b % a, a);
 }
   
 // Function to find gcd of array of
 // numbers
 ll findGCD(ll arr[], ll n)
 {
     ll result = arr[0];
     for (ll i = 1; i < n; i++)
     {
         result = gcd(arr[i], result);
   
         if(result == 1)
         {
            return 1;
         }
     }
     return result;
 }
// 1 1 2 3 8 15 48 7*15 8*48
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    if(n%2==1)
        cout<<0<<"\n";
    else{
        ll i=10;ll count=0;
        while(1)
        {
           if(i<=n)
               count+=n/i;
            else
                break;
            
            i*=5;
        }
        cout<<count<<"\n";
              
    }
}


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

    
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String str1 = in.nextLine();
    String str2;
    int num1 = Integer.parseInt(str1);
    int num2, max, min;
    max = 0;
    min = 0;
    long sum = 0;
    
    for (int i=0; i<num1; i++)
        {
        str2 = in.next();
        num2 = Integer.parseInt(str2);
        sum += num2;
        if (i == 0)
        {
        max = num2;
        min = num2;
        }else
        if (num2 > max){max = num2;}else
        if (num2 < min){min = num2;}
        }
    System.out.println(min +" "+ max +" "+ sum);
    
    }
    
}

Measured memory_bytes: 40720