akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	ll h,w;
	ll ans=0LL;
	cin >>h>>w;
	ll sub=0LL;
	ans=min(h,w);
	if(not(h%3 and w%3)){
		ans=0LL;
	}else{
		for(ll i=0LL;i<h;i++){
			sub=(h-i)*(w/2);
			chmin(ans, max({sub, (h-i) * w - sub , i * w}) - min({i * w, sub, (h-i) * w - sub}));
		}
		for(ll i=0LL;i<w;i++){
			sub=(w-i)*(h/2);
			chmin(ans, max({h * i, sub, h * (w-i) - sub}) - min({h * i, sub, h * (w-i) - sub }));
		}
	}	
	cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

template<typename T> class LazyRMQ {
    public:
    int n;
    T inf = INT_MAX;
    vector<T> data, lazy;
    
    LazyRMQ(int m, T init_value=INT_MAX){
        // 2のべき乗にする
        n = 1;
        while(n < m) n <<= 1;
        data.assign(2*n-1, init_value);
        lazy.assign(2*n-1, init_value);
        inf = init_value;
    }

    void eval(int k, int kl, int kr){
        if(data[k] == inf) data[k] = inf;
        if(lazy[k] == inf) return;
        data[k] = min(data[k], lazy[k]);
        if(kr - kl > 1){
            lazy[2*k+1] = min(lazy[2*k+1], lazy[k]);
            lazy[2*k+2] = min(lazy[2*k+2], lazy[k]);
        }
        lazy[k] = inf;
    }

    // [s,t)
    void add(int s, int t, T x, int k, int kl, int kr){
        eval(k, kl, kr);
        if(kr <= s || t <= kl) return;
        if(s <= kl && kr <= t){
            lazy[k] = min(lazy[k], x);
            eval(k, kl, kr);
            return;
        }
        int kc = (kl+kr)/2;
        add(s, t, x, 2*k+1, kl, kc);
        add(s, t, x, 2*k+2, kc, kr);
        data[k] = min(data[2*k+1], data[2*k+2]);
    }

    void add(int s, int t, T x) {
        add(s, t, x, 0, 0, n);
    }

    // [s,t)
    T find(int s, int t, int k, int kl, int kr){
        eval(k, kl, kr);
        if(kr <= s || t <= kl) return inf;
        if(s <= kl && kr <= t) return data[k];
        int kc = (kl+kr)/2;
        T vl = find(s, t, 2*k+1, kl, kc);
        T vr = find(s, t, 2*k+2, kc, kr);
        return min(vl, vr);
    }

    T find(int s, int t) {
        return find(s, t, 0, 0, n);
    }
};


int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    vector<ll> s(N), t(N), x(N);
    set<ll> st; // 座標圧縮
    for(int i=0;i<N;++i){
        cin >> s[i] >> t[i] >> x[i];
        s[i] -= x[i];
        t[i] -= x[i];
        st.insert(s[i]);
        st.insert(t[i]);
    }

    vector<ll> d(Q);
    for(int i=0;i<Q;++i){
        cin >> d[i];
        st.insert(d[i]);
        st.insert(d[i]+1);
    }

    map<ll, ll> mp;
    {
        int pos = 0;
        for(ll x: st) {
            mp[x] = pos++;
        }
    }

    LazyRMQ<ll> tree(st.size()+1);
    for(int i=0;i<N;++i) {
        tree.add(mp[s[i]], mp[t[i]], x[i]);
    }

    for(int i=0;i<Q;++i){
        int ans = tree.find(mp[d[i]], mp[d[i]]+1);
        if(ans == INT_MAX) ans = -1;
        cout << ans << endl;
    }
}


Measured memory_bytes: 127744
//-------------------------------------------
//-               Train Fare                -
//-                                         -
//-       autumn_eel niha katemasen!        -
//-------------------------------------------
#include<iostream>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
int n, m, q, a[200001], b[200001], c[200001], d[200001], e[100001], dist[100001], E[200001];
vector<pair<int, int>>x[100001], y[100001], z[100001];
vector<int>D[100001];
void reader(int *x) {
	int k = getchar(); *x = k - '0';
	while (true) {
		k = getchar();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
int main() {
	reader(&n); reader(&m); reader(&q);
	fill(d, d + m + 1, 1 << 30);
	for (int i = 1; i <= m; i++) reader(&a[i]), reader(&b[i]);
	for (int i = 1; i <= q; i++) reader(&c[i]), d[c[i]] = i;
	for (int i = 1; i <= m; i++) {
		x[a[i]].push_back(make_pair(b[i], d[i]));
		x[b[i]].push_back(make_pair(a[i], d[i]));
	}
	fill(dist, dist + n + 1, -1); dist[1] = 0;
	queue<int> Q1; Q1.push(1);
	while (!Q1.empty()) {
		int a1 = Q1.front(); Q1.pop();
		for (pair<int, int> i : x[a1]) {
			if (dist[i.first] == -1) {
				dist[i.first] = dist[a1] + 1;
				Q1.push(i.first);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		D[dist[i]].push_back(i);
		for (pair<int, int> j : x[i]) {
			if (dist[i] < dist[j.first]) y[i].push_back(j);
			if (dist[i] > dist[j.first]) z[i].push_back(j);
		}
	}
	e[1] = (1 << 30);
	for (int i = 1; i < n; i++) {
		for (int j : D[i]) {
			for (pair<int, int>k : z[j]) {
				e[j] = max(e[j], min(e[k.first], k.second));
			}
		}
	}
	for (int i = 2; i <= n; i++) { if (e[i] < 300000)E[e[i]]++; }
	for (int i = 1; i <= q; i++)E[i] += E[i - 1];
	for (int i = 1; i <= q; i++) {
		printf("%d\n", E[i]);
	}
	return 0;
}

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

int main(void)
{
  ll N, K;
  cin >> N >> K;
  N %= K;
  ll diff = abs(N - K);
  if (diff < N) N = diff;
  cout << N << endl;
}

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

using tiii = tuple<int,int,int>;

int main(){
  int W, H ,N;
  cin >> W >> H >> N;
  tiii T;
  vector<tiii>A(110);
  
  for(int i =0; i <N; i++){
    cin >> get<0>(A[i]) >> get<1>(A[i]) >> get<2>(A[i]);
  }
  //tuple<x座標，ｙ座標，a>
  int colored_H = 0;
  int colored_W= 0; //塗り潰されたHとW
  int colored_H2= 0;
  int colored_W2= 0;//塗り潰されたHとW(座標(H,W)側からの距離)
  
  for(int i=0; i <N; i++){
    if(get<2>(A[i]) == 1 && colored_W < get<0>(A[i])){ //a == 1のとき，左側を塗りつぶす.すでに塗り潰されていれば無視
      colored_W = get<0>(A[i]);
    }
    else if(get<2>(A[i]) == 2 && colored_W2 < (W - get<0>(A[i]) ) ){
      colored_W2 = W - get<0>(A[i]);
    }
    else if(get<2>(A[i]) == 3 && colored_H < get<1>(A[i]) ){
      colored_H = get<1>(A[i]);
    }
    //↓問題のコード
    else if(get<2>(A[i]) == 4 && colored_H2 < (H - get<1>(A[i]) ) ){
      colored_H2 = H - get<1>(A[i]);
      //ここで出力しない場合，なぜかここでcoloredH2が変更されない
     
      //↑問題のコード　
    }

  }
  
  H -= colored_H + colored_H2;
  W -= colored_W + colored_W2;
  if(H < 0) H = 0;
  if(W < 0) W = 0;
  cout << H * W << endl;
  
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n,k;
	sd(n);sd(k);
	vi dp,a;
	for(int i=0;i<n;i++){
		int ai;
		sd(ai);
		a.pb(ai);
		if(i==0){
			dp.pb(0);
		}else{
			int mn=INT_MAX;
			for(int j=1;j<k+1&&i-j>=0;j++){
				mn=min(mn, dp[i-j]+abs(a[i]-a[i-j]));
			}
			dp.pb(mn);
		}
	}
	pd(dp[n-1]);
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

bool f(vl& a, ll x) {
  int n = sz(a), m = n+1;
  ll s = 0;
  rep(i,n) {
    ll d = a[i]+x-(n-1);
    s += (d+m-1)/m;
    if (s > x) return false;
  }
  return true;
}

int main() {
  int n;
  scanf("%d",&n);
  vl a(n);
  cin>>a;
  ll ans = LINF;
  rep(i,n) {
    ll l = -1, r = 1e16; r *= 2;
    while (l+1<r) {
      ll c = (l+r)/2;
      if (f(a,c*n)) r = c; else l = c;
    }
    mins(ans,r*n+i);
    sort(rng(a));
    rep(j,n) a[j]++;
    a.back() -= n+1;
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 256
import Foreign;x%'1'=2*x+1;x%c=2*x;f 0=0;f x=1+f(rem x.toInteger$popCount x);main=do n<-readLn;s<-getLine;putStr.unlines$show.f.xor(foldl(%)0s).bit<$>[n-1,n-2..0]

Measured memory_bytes: 13184
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = INF
  for S in [s[b - 1], s[b]]:
    for T in [t[d - 1], t[d]]:
      d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
      res = min(res, d1, d2)
  print(res)


Measured memory_bytes: 78248
#include <iostream>
#include <cstdio>
#include <cmath>
 
#define pai 3.141592653
 
using namespace std;
 
int main(void)
{
    int n, s[1000];
    double sum, avg, a;
    int i;
 
    while(scanf("%d", &n)!=EOF && n!=0){
        sum = 0;
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum += s[i];
        }
        avg = sum / n;
 
        sum = 0;
        for(i=0;i<n;i++)
            sum += pow(s[i] - avg, 2);
        a = sqrt(sum / n);
 
        printf("%.8f\n", a);
    }
 
    return 0;
}

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

using namespace std;

enum eRoll{
	W,
	S,
	N,
	E
};

class Dice {
private:
	int _dice[6];
public:
	void roll(eRoll er) {
		int _diceinfo[6];
		for (int i = 0; i < 6; ++i) {
			_diceinfo[i] = _dice[i];
		}
		switch (er) {
		case W:
			_dice[0] = _diceinfo[2];
			_dice[1] = _diceinfo[1];
			_dice[2] = _diceinfo[5];
			_dice[3] = _diceinfo[0];
			_dice[4] = _diceinfo[4];
			_dice[5] = _diceinfo[3];
			break;
		case S:
			_dice[0] = _diceinfo[4];
			_dice[1] = _diceinfo[0];
			_dice[2] = _diceinfo[2];
			_dice[3] = _diceinfo[3];
			_dice[4] = _diceinfo[5];
			_dice[5] = _diceinfo[1];
			break;
		case N:
			_dice[0] = _diceinfo[1];
			_dice[1] = _diceinfo[5];
			_dice[2] = _diceinfo[2];
			_dice[3] = _diceinfo[3];
			_dice[4] = _diceinfo[0];
			_dice[5] = _diceinfo[4];
			break;
		case E:
			_dice[0] = _diceinfo[3];
			_dice[1] = _diceinfo[1];
			_dice[2] = _diceinfo[0];
			_dice[3] = _diceinfo[5];
			_dice[4] = _diceinfo[4];
			_dice[5] = _diceinfo[2];
			break;
		}
	}

	void setDice(int forward, int top) {
		if (_dice[1] != forward) {
			bool work = true;
			while (work) {
				for (int i = 0; i < 4; ++i) {
					roll(eRoll::S);
					if (_dice[1] == forward) {
						work = false;
						break;
					}
				}
				roll(eRoll::W);
			}
		}

		if (_dice[0] != top) {
			while (true) {
				roll(eRoll::W);
				if (getTopNum() == top) {
					break;
				}
			}
		}
	}

	int getTopNum() {
		return _dice[0];
	}

	int getRSideNum() {
		return _dice[2];
	}

	void setNum() {
		for (int i = 0; i < 6; ++i) {
			cin >> _dice[i];
		}
	}
};

int main() {
	Dice dice;
	dice.setNum();

	int n;
	int a[2];

	cin >> n;

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

		dice.setDice(a[1], a[0]);

		cout << dice.getRSideNum() << endl;

	}


	return 0;
}



Measured memory_bytes: 3060
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  float n;
  scanf("%f", &n);
  printf("%d\n", (int)ceil(n / 2));
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		int xp1 = sc.nextInt();
		int yp1 = sc.nextInt();
		int xp2 = sc.nextInt();
		int yp2 = sc.nextInt();

		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			int xp0 = sc.nextInt();
			int yp0 = sc.nextInt();

			int ax = xp2 - xp1;
			int ay = yp2 - yp1;
			int bx = xp0 - xp1;
			int by = yp0 - yp1;
			double dot = Geom.dot(ax, ay, bx, by);
			int a2 = Geom.sumofsquare(ax, ay);
			double x = dot / a2 * 2 * ax - bx + xp1;
			double y = dot / a2 * 2 * ay - by + yp1;
			
			System.out.printf("%.9f %.9f\n", x, y);
		}

		sc.close();
	}
	
	@SuppressWarnings("unused")
	private static class Geom {
		static int dot(int xa, int ya, int xb, int yb) {
			return xa * xb + ya * yb;
		}

		static int cross(int xa, int ya, int xb, int yb) {
			return xa * yb - xb * ya;
		}
		
		static int sumofsquare(int xa, int ya) {
			return xa * xa + ya * ya;
		}
	}
}

Measured memory_bytes: 32884
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

a.insert(0,0)
a.append(0)


s = 0
for i in range(n+1):
    s += abs(a[i+1] - a[i])


for i in range(1, n+1):
    print(s + abs(a[i+1] - a[i-1]) - (abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]) ))

Measured memory_bytes: 13924
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    ls = [0 for i in range(a[-1])]
    for i in range(n):
        if ls[a[i]-1] == -1:
            continue
        elif ls[a[i]-1]==1:
            ls[a[i]-1] = -1
        else:
            ls[a[i]-1] = 1
            for j in range(2,a[-1]//a[i]+1):
                ls[a[i]*j-1] = -1
    ans = 0
    for i in range(len(ls)):
        if ls[i]==1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 32132
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> dp(100010, -1);
int H[100010];

int q (int i) {
    if (dp[i] != -1) return dp[i];

    if (H[i] >= H[i+1]) dp[i] = 1 + q(i-1);
    else dp[i] = 0;

    return dp[i];
}

int main() {
    int N;
    cin >> N;

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

    int max = 0;
    for (int i = 0; i < N-1; i++)
    {
        if (q(i) > max) max = q(i);
    }
    
    cout << max << endl;

}

Measured memory_bytes: 1024
import sys
f = sys.stdin
n = int(f.readline())
a, b = map(int,f.readline().split())
P = list(map(int, f.readline().split()))
x = [0 for _ in range(3)]
for p in P:
  if p <= a:
    x[0]+=1
  elif p <= b:
    x[1] += 1
  else:
    x[2] += 1
print(min(x))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll          long long
#define all(a)      (a).begin(),(a).end()
#define pb          push_back
#define INF         10000000000000000
using namespace std;
ll i,j,k,n,x,mid,sum1=0,sum2=0,ans,l[300005],r[300005];
vector<ll> v(300005);
int main()
{
    cin>>n;
	for(i=0;i<3*n;i++){
		cin>>v[i];
	}
	priority_queue<int> pq; //max_heap for first half
	priority_queue<int,vector<int>,greater<int> > pq2; //min_heap for second half
	ll csum=0;
	for(i=0;i<3*n;i++){
		pq2.push(v[i]);
		csum+=v[i];
		if(pq2.size()>n){
			csum-=pq2.top();pq2.pop();
		}
		if(pq2.size()==n)l[i]=csum;else l[i]=-INF; //maximum  possible sumof n numbers till ith index so, 
	}											//if i<n or pq2.size<n set it to -inf cause it is not favourable
	csum=0;
	for(int i=3*n-1;i>=0;i--){
		pq.push(v[i]);
		csum+=v[i];
		if(pq.size()>n){
			csum-=pq.top();pq.pop();
		}
		if(pq.size()==n) r[i]=csum;else r[i]=INF;//minimum  possible sumof n numbers till ith index from back so, 
	}											//if i<2*n or pq2.size<n set it to inf cause it is not favourable
	ll ans=-INF;
	for(i=0;i<3*n-1;i++){
		ans=max(ans,l[i]-r[i+1]); //checking at where the partition would be for maximum ans
								// u can also loop from n to 2*n because l[i]is -inf before n and r[i]is inf after 2*n
	}
	cout<<ans<<endl;
 
    return 0;
}

Measured memory_bytes: 8184
n=int(input())+1
e=[input().split()for _  in[0]*~-n]
p=[int(e[0][0])]+list(int(x[1])for x in e)
m=[[0]*n for _ in[0]*n]
for l in range(2,n):
 for i in range(1,n-l+1):
  j=i+l-1;m[i][j]=1e6
  for k in range(i,j):m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
print(m[1][n-1])


Measured memory_bytes: 5728
#include <stdio.h>

int main(void){
   double k1, k2, l1, l2;
   //kは傾き、lはベクトルのx軸の向きと長さを示す
   int i, n, a, b, c, d, x, y;
   scanf("%d %d %d %d", &a, &b, &c, &d);
   scanf("%d", &n);
   l1 = c - a;
   y = d - b;
   if(a != c){
   k1 = y / l1;
   }else{
       if(d > b){
           k1 = 100000;
       }else{
           k1 = -100000;
       }
   }
   if(l1 > 0){
       x = 1;
   }else if(l1 < 0){
       x = 0;
   }else if(k1 > 0){
       x = 2;
   }else{
       x = 3;
   }
   for(i = 0; i < n; i++){
       scanf("%d %d", &c, &d);
       l2 = c - a;
       if(a != c){
           k2 = (d - b) / l2;
           
       }else{
           if(d > b){
               k2 = 100000;
               
           }else{
               k2 = -100000;
               
           } 
           
       }
       switch(x){
           case 0:
           if(a == c && b == d){
               printf("ON_SEGMENT\n");
           }else if((l2 >= 0 && k2 > k1)||(l2 < 0 && k2 < k1) ){
			   printf("CLOCKWISE\n");
		   }else if((l2 >= 0 && k2 < k1)||(l2 < 0 && k2 > k1) ){
			   printf("COUNTER_CLOCKWISE\n");
		   }else if(l1 / l2 < 0){
			   printf("ONLINE_BACK\n");
		   }else if(l1 > l2){
			   printf("ONLINE_FRONT\n");
		   }else{
			   printf("ON_SEGMENT\n");
		   }
		   break;
		   case 1:
           if(a == c && b == d){
               printf("ON_SEGMENT\n");
           }else if((l2 >= 0 && k2 < k1)||(l2 < 0 && k2 > k1) ){
			   printf("CLOCKWISE\n");
		   }else if((l2 >= 0 && k2 > k1)||(l2 < 0 && k2 < k1) ){
			   printf("COUNTER_CLOCKWISE\n");
		   }else if(l1 / l2 < 0){
			   printf("ONLINE_BACK\n");
		   }else if(l1 < l2){
			   printf("ONLINE_FRONT\n");
		   }else{
			   printf("ON_SEGMENT\n");
		   }
		   break;
		   case 2:
           if(a == c && b == d){
               printf("ON_SEGMENT\n");
           }else if(l2 > 0){
			   printf("CLOCKWISE\n");
		   }else if(l2 < 0){
			   printf("COUNTER_CLOCKWISE\n");
		   }else if(k2 < 0){
			   printf("ONLINE_BACK\n");
		   }else if(d - b > y){
			   printf("ONLINE_FRONT\n");
		   }else{
			   printf("ON_SEGMENT\n");
		   }
		   break;
		   case 3:
           if(a == c && b == d){
               printf("ON_SEGMENT\n");
           }else if(l2 < 0){
			   printf("CLOCKWISE\n");
		   }else if(l2 > 0){
			   printf("COUNTER_CLOCKWISE\n");
		   }else if(k2 > 0){
			   printf("ONLINE_BACK\n");
		   }else if(d - b < y){
			   printf("ONLINE_FRONT\n");
		   }else{
			   printf("ON_SEGMENT\n");
		   }
		   break;
       }
   }
   return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
using namespace std;
typedef long long ll;

int main(){
	ll dp[10][1001]={};
	dp[0][0] = 1;
	for(int i=0;i<=100;i++){
		for(int j=8;j>=0;j--){
			for(int k=0;k<1000;k++){
				if(k+i>1000) continue;
				dp[j+1][k+i] += dp[j][k];
			}
		}
	}
	int N,S;
	while(cin>>N>>S,N||S){
		printf("%lld\n",dp[N][S]);
	}
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

void solve() {
    int n;
    scanf("%d", &n);
    int i = 0;
    for(i = 0;; i++) {
        if(i * (i + 1) / 2 > n) break;
    }
    std::vector<int> v(i);
    std::iota(begin(v), end(v), 1);
    int kesu = i * (i + 1) / 2 - n;
    rep(_, i) {
        if(_ != kesu - 1) {
            std::cout << v[_] << std::endl;
        }
    }
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int n,a,b;
        cin >> n >> a >> b;
        int total = 0;
        for (size_t i = 1; i <= n; i++) {
                int sum = 0;
                int tmp = i;
                while(tmp > 0) {
                        sum += tmp % 10;
                        tmp /=10;
                }
                if(a <= sum && sum <= b ) total+=i;
        }
        cout << total << endl;
        return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

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

B = []
C = []
for _ in range(Q):
    B_i, C_i = map(int, input().split())
    
    B.append(B_i)
    C.append(C_i)

max_i = max(max(A), max(C))

A_N = [0 for _ in range(max_i + 1)]
sum_i = 0

for a in A:
    A_N[a] += a
    sum_i += a

for i in range(Q):
    diff_replace = int(A_N[B[i]] / B[i]) * C[i]
    sum_i += diff_replace - A_N[B[i]]
    
    A_N[C[i]] += diff_replace
    A_N[B[i]] = 0
    
    print(sum_i)


Measured memory_bytes: 24140
import math

A, B, H, M = map(int,input().split())
p = math.pi

a  = M / 60 * 2 * p
b = (H * 60 + M )/(60*12) * 2 * p

result = (A**2 + B**2 - 2* A*B*math.cos(a-b) )**0.5

print(result)


Measured memory_bytes: 9476
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void)
{
	int h, w, H, W;

	cin >> H >> W;
	cin >> h >> w;

	cout << H * W - h * W - H * w +h*w<< endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

s = list(input())
fl = True

sf = list(s)
sf.reverse()

if sf != s:
    fl = False
else:
    s1 = s[:len(s)//2]
    s1r = list(s1)
    s1r.reverse()
    if s1 != s1r:
        fl = False
    else:
        s2 = s[(len(s) + 3) // 2 - 1:]
        s2r = list(s2)
        s2r.reverse()
        if s2r != s2:
            fl = False

if fl:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#include<stdio.h>

int main(){
  int a[]={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};

  int k;
  scanf("%d",&k);

  printf("%d\n",a[k-1]);

  return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
using namespace std;
  
int main(){
    int N;
    long long W,tV=0,tW=0,x=0;
    scanf("%d%lld",&N,&W);
    vector<pair<long long,long long> >v;
    for(int i=0;i<N;i++){long long z,w;scanf("%lld%lld",&z,&w);if(w<=W)v.emplace_back(z,w),tV+=z,tW+=w;}
N=v.size();
 
        int n=N/2;
        deque<pair<long long,long long> >se1,se2;
        for(int i=0;i<1<<n;i++){
            long long V=0,w=0;
            for(int j=0;j<n;j++)if(i&(1<<j))V+=v[j].first,w+=v[j].second;
            se1.emplace_back(w,V);
        }
        for(int i=0;i<1<<(N-n);i++){
            long long V=0,w=0;
            for(int j=0;j<(N-n);j++)if(i&(1<<j))V+=v[j+n].first,w+=v[j+n].second;
            se2.emplace_back(w,V);
        }
sort(se1.begin(),se1.end());
sort(se2.begin(),se2.end());
        for(auto it=se1.begin();it!=se1.end();){
            auto it2=it;
            for(++it2;it2!=se1.end()&&it->second>=it2->second;)it2=se1.erase(it2);
            ++it;
        }
        for(auto it=se2.begin();it!=se2.end();){
            auto it2=it;
            for(++it2;it2!=se2.end()&&it->second>=it2->second;)it2=se2.erase(it2);
            ++it;
        }
vector<pair<long long,long long> >_se2(se2.begin(),se2.end());
        long long r=0;
        for(auto &e1:se1){
            auto it=lower_bound(_se2.begin(),_se2.end(),make_pair(W-e1.first+1,0LL));
            if(it!=_se2.begin()){
                --it;
                r=max(r,e1.second+it->second);
            }
        }
        printf("%lld\n",r);
}

Measured memory_bytes: 36536
#include <bits/stdc++.h>
using namespace std;
 int main(){
   string a;
   for(int i=0;i<3;i++){
     cin >> a[i] ;
   }
   int count=0;
   for(int i=0;i<3;i++){
     if(a[i]=='1'){
     count++;
     }
   }
   cout << count << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int oki = h1*60 + m1;
  int ner = h2*60 + m2;
  int ans = ner - oki;
  ans -= k;
  chmax(ans, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
int main(){
  int a[8],b[8],re[8],i,j;
  for(i=0;i<7;i++){
    scanf("%d%d",&a[i],&b[i]);
      re[i]=a[i]-b[i];
  }
  for(j=0;j<7;j++){
  printf("%d\n",re[j]);
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, l;
int a[100000 + 5], t[100000 + 5];
bool check[100000 + 5];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> l;
    rep(i, n) cin >> a[i];
    queue<int> q;
    rep(i, n) {
        if (i == 0 && a[i] > a[i + 1]) {
            check[i] = true;
            q.push(i);
        }
        else if (i == n - 1 && a[i] > a[i - 1]) {
            check[i] = true;
            q.push(i);
        }
        else {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) {
                check[i] = true;
                q.push(i);
            }
        }
    }
    while (!q.empty()) {
        int now = q.front(); q.pop();
        t[now] += l - a[now];
        a[now] = 0;
        int dx[2] = {1LL, -1LL};
        rep(i, 2) {
            int nx = now + dx[i];
            if (nx < 0 || nx >= n || check[nx]) continue;
            if (nx == 0 && a[nx] > a[now]) {
                check[nx] = true;
                t[nx] = max(t[nx], t[now]);
                q.push(nx);
            }
            else if (nx == n - 1 && a[nx] > a[now]) {
                check[nx] = true;
                t[nx] = max(t[nx], t[now]);
                q.push(nx);
            }
            else {
                if (a[nx - 1] < a[nx] && a[nx] > a[nx + 1]) {
                    check[nx] = true;
                    t[nx] = max(t[nx], t[now]);
                    q.push(nx);
                }
                else {
                    t[nx] = max(t[nx], t[now]);
                }
            }
        }
    }
    ll ans = 0;
    rep(i, n) ans = max(ans, t[i]);
    cout << ans << endl;
}

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

int main() {
  
  int n;
  cin >> n;
  
  if (n < 3) cout << 4 << endl;
  else {
    int i = 1;
    while(1) {
      if (n == 4) break;
      if (n % 2 == 0) n /= 2;
      else n = 3 * n + 1;
      i++;
    }
    cout << i+3 << endl;
  }
}

Measured memory_bytes: 3636
import sys
import  math
import fractions
from collections import defaultdict
from functools import reduce
import collections 
stdin = sys.stdin
         
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
     
INF=10**18
mod=10**9+7
N=int(input())
A=nl()
NMAX=10**6
class Sieve:
    def __init__(self,n):
        self.n=n
        self.f=[0]*(n+1)
        self.prime=[]
        self.f[0]=self.f[1]=-1
        for i in range(2,n+1):
            if(self.f[i]):
                continue
            else:
                self.prime.append(i)
                self.f[i]=i
                for j in range(i*i,n+1,i):
                    if(~self.f[j]):
                        self.f[j]=i
    def isProme(self,x):
        return (self.f[x]==x)
    def factorList(self,x):
        res=[]
        while(x!=1):
            res.append(self.f[x])
            x//=self.f[x]
        return res
    def factor(self,x):
        fl=self.factorList(x)
        return collections.Counter(fl)
        


                
                
            
        
        
def get_sieve_of_eratosthenes(n):
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]



sieve=Sieve(10**6)
mp=defaultdict(int)
for i in range(N):
    f=sieve.factor(A[i])
    for key,val in f.items():
        mp[key]=max(val,mp[key])


lcm=1
for key,val in mp.items():
    lcm*=(key**val)


ans=0
for i in range(N):
    ans+=lcm//A[i]

print(ans%mod)

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

using namespace std;

int func(int n, int c[], int r_num){
	int re = 0;
	for(int i = 0; i < r_num; i++){
		if(c[i] != 1) re++;
	}
	return re;
}

int main(void)
{
	int n;
	cin>>n;
	int c[n];
	int r_num = 0;
	char color;
	for(int i = 0; i < n; i++){
		cin>>color;
		if(color == 'R'){
			c[i] = 1;
			r_num++;
		}
		else if(color == 'W') c[i] = 2;
	}
	int ans = func(n,c,r_num);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 4344
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    public class Test
    {
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        public static void Main(string[] args)
        {
            var t = new Test();
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            t.JudgeNum(a);
            t.JudgeNum(b);

            if(t.count1 == 0)
            {
                Console.WriteLine("1");
            }
            else if(t.count2 == 0)
            {
                Console.WriteLine("2");
            }
            else if(t.count3 == 0)
            {
                Console.WriteLine("3");
            }
            
        }

        public void JudgeNum(int a) 
        {
            if(a == 1)
            {
                count1++;
            }

            if(a == 2)
            {
                count2++;
            }

            if(a == 3)
            {
                count3++;
            }
        }
           

        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public int[] ConvertIntArray(string[] x)
        {
            var convertedArray = new int[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public double[] ConvertDoubleArray(string[] x)
        {
            var convertedArray = new double[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }
    }
}


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

struct ss {
  int x, y, w;
};

int main(){
  int h, w; cin >> h >> w;
  queue<ss> p; bool a[h][w]; fill(a[0], a[h], 0);
  int c = 0;
  
  for(int i=0; i<h; i++) {
    string s; cin >> s;
    for(int j=0; j<w; j++) {
      a[i][j] = s[j] == '#';
      if (a[i][j]) {p.push({i,j,1}); c++;}
    }
  }
  
  int an = 0;
  while (c < h * w) {
    ss t = p.front(); p.pop();
    if (t.x != 0) {
      if (!a[t.x-1][t.y]) {
        a[t.x-1][t.y]=1; c++;
        p.push({t.x-1, t.y, t.w+1}); an = t.w;
      }
    }
    if (t.x != h-1) {
      if (!a[t.x+1][t.y]) {
        a[t.x+1][t.y]=1; c++;
        p.push({t.x+1, t.y, t.w+1}); an = t.w;
      }
    }
    if (t.y != 0) {
      if (!a[t.x][t.y-1]) {
        a[t.x][t.y-1]=1; c++;
        p.push({t.x, t.y-1, t.w+1}); an = t.w;
      }
    }
    if (t.y != w-1) {
      if (!a[t.x][t.y+1]) {
        a[t.x][t.y+1]=1; c++;
        p.push({t.x, t.y+1, t.w+1}); an = t.w;
      }
    }
  }
  cout << an << endl;
}

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

int b[8] = {4, 1, 4, 1, 2, 1, 2, 1};

int main(){
    int p[8];
    while(cin >> p[0]){
        vector<int> ans(8, 0);
        for(int i=1; i < 8; i++) cin >> p[i];

        int maxPoint = 0;
        for(int i=0; i < 8; i++){
            int point = 0;
            vector<int> tmp(8, 0);
            for(int j=0; j < 8; j++){
                point += min(p[j], b[(i+j)%8]);
                tmp[j] = b[(i+j)%8];
            }
            if(maxPoint <= point){
                if(maxPoint == point && ans < tmp) continue;
                else {
                    for(int k=0; k < 8; k++){
                        ans[k] = tmp[k];
                    }
                }
                maxPoint = point;
            }
        }
        for(int i=0; i < 8; i++){
            if(i == 0) cout << ans[i];
            else cout << " " << ans[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1192
$luc = []
$luc[0] = 2
$luc[1] = 1
def lucas(n)
	if $luc[n]
		return $luc[n]
	else
		return $luc[n] = lucas(n-2) + lucas(n-1)
	end
end

k = gets.to_i
puts lucas(k)


Measured memory_bytes: 1788
nums = [0, 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(nums[int(input())])

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

import math
import bisect
import numpy as np

n = int(input().split()[0])
a_list = list(map(int, input().split()))


def C(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


a_list = sorted(a_list)
max_comb = -float("inf")
a_list = sorted(a_list, reverse=True)
ai = a_list[0]
w_list = a_list[1:]
w_list = sorted(w_list)

# 真ん中に一番近い値を取得する
if ai % 2 == 0:
    idx = np.abs(np.asarray(w_list) - ai // 2).argmin()
    aj = w_list[idx]
else:
    t_1 = (ai - 1) // 2
    idx_1 = np.abs(np.asarray(w_list) - t_1).argmin()
    aj_1 = w_list[idx_1]

    t_2 = (ai + 1) // 2
    idx_2 = np.abs(np.asarray(w_list) - t_2).argmin()
    aj_2 = w_list[idx_2]

    if abs(t_1 - aj_1) < abs(t_2 - aj_2):
        aj = aj_1
    else:
        aj = aj_2

ans = "{} {}".format(ai, aj)
print(ans)


Measured memory_bytes: 23100
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int n,m,tmpN,tmpM;
        n=scan.nextInt();
        m=scan.nextInt();
        tmpM=0;
        tmpN=0;
        for(int i=1;i<n;i++){
            tmpN +=i;
        }
        for(int i=1;i<m;i++){
            tmpM += i;
        }
        System.out.println(tmpM+tmpN);
    }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64

int main(){
    int n;
    cin >> n;
    int color[9]={};
    int tmp;
    REP(i,n){
        cin >> tmp;
        color[ min(tmp/400,8)]+=1;
    }
    int _min=0;
    REP(i,8){
        if(color[i]>0) _min+=1;
    }
    
    cout << max(1,_min) << " ";
    cout <<  _min + color[8]<< endl;;
}



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

void solve()
{
  int x;
  cin >> x;
  if (x>=30)
    cout << "Yes" << endl;
 else cout << "No" << endl;
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);     
    int t;
    //cin >> t;
    t=1;
    for (int tt=0;tt<t;tt++)
        {
            solve();
        }    
        return 0;
}

Measured memory_bytes: 3636
inp = list(map(int,input().split()))
left_max=0
right_min=inp[0]
upper_min=inp[1]
lower_max=0

for i in range(inp[2]):
    inin = list(map(int,input().split()))
    if inin[2] == 1 and inin[0]>left_max:
        left_max=inin[0]
    if inin[2] == 2 and inin[0]<right_min:
        right_min=inin[0]
    if inin[2] == 4 and inin[1]<upper_min:
        upper_min=inin[1]
    if inin[2] == 3 and inin[1]>lower_max:
        lower_max=inin[1]
left_max=min(left_max,right_min)
upper_min=max(upper_min,lower_max)
print((right_min-left_max)*(upper_min-lower_max))


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x,long long int y) {
	return(x + y-1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int N;
	cin >> N;
	int b[120];
	for (int i = 0; i < N-1; i++) {
		int a;
		cin >> a;
		b[i] = a;
	}
	int sum = 0;
	int a[120];
	a[0] = b[0];

	for (int i = 1; i < N; i++) {
		if (i == N - 1) {
			a[i] = b[i-1];
			break;
		}
		a[i] = min(b[i - 1], b[i]);
	}
	for (int i = 0; i < N; i++) {
		sum = sum + a[i];
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[100];
signed main(){
	int n = 10;
	rep(i,n)scanf("%lld", &a[i]);
	int ans = 0;
	rep(i,n)ans += a[i];
	printf("%lld\n", ans);
	return 0;
}





Measured memory_bytes: 3172
from collections import deque
n = int(input())
d = [[] for i in range(n)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a].append([b,c])
    d[b].append([a,c])
q, k = map(int, input().split())
k -= 1

def bfs():
    d2 = [True] * n
    ans = [0] * n
    que = deque([k])
    d2[k] = False
    while len(que) != 0:
        val = que.popleft()

        for i in range(len(d[val])):
            if d2[d[val][i][0]] == True:
                que.append(d[val][i][0])
                ans[d[val][i][0]] += (ans[val] + d[val][i][1])
                d2[d[val][i][0]] = False
    return ans
ans = bfs()
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(ans[x] + ans[y])


Measured memory_bytes: 94624
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		@SuppressWarnings("unused")
		int N = sc.nextInt();
		int M = sc.nextInt();

		//int[] aを入れるリスト
		List<int[]> list = new ArrayList<>();

		for(int i = 0; i < M; i++) {
			int[] a = new int[2];
			a[0] = sc.nextInt();
			a[1] = sc.nextInt();
			list.add(a);
		}

		list.sort((a1,a2)->a1[1]-a2[1]);
		int count = 0,  latest = 0;
		for(int[]a:list) {
			//System.out.println(a[0]+":"+a[1]);
			if(a[0]<=latest && latest<a[1]) {
				//条件に一致したら次の繰り返し処理に飛ばす
				continue;
			}
			latest = a[1]-1;
			//System.out.println(latest);
			count++;
		}
		System.out.println(count);
		sc.close();
	}

}

Measured memory_bytes: 90768
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    int n = s.size();
    function<bool(int)> check = [&](int x){
        DEBUG{
            printf("%d\n",x);
        }
        int cnt = 0;
        int n_rev=0;
        vector<int> chk(n,0);
        rep(i,n){
            n_rev -= chk[i];
            if((s[i]-'0'+n_rev)%2!=0){
                if(i+x-1<n){
                    n_rev++;
                    if(i+x<n)chk[i+x]=1;
                }else{
                    break;
                }
            }
            cnt++;
        }
        return cnt>=x;
    };
    int from = 1,to=n;
    while(to-from>1){
        int mid = (to+from)/2;
        if(check(mid)){
            from = mid;
        }else{
            to = mid;
        }
    }
    cout << (check(to) ? to : from) << endl;
    return 0;
}


Measured memory_bytes: 848
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int N, M; cin >> N >> M;
    cout << N*(N-1)/2 + M*(M-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

L = []
R = []
k = 0
for i in range(N):
    k = gcd(k, A[i])
    L.append(k)
k = 0
for j in range(N)[::-1]:
    k = gcd(k, A[j])
    R.append(k)
R[:] = R[::-1]

ans = 0
for i in range(N):
    if i == 0:
        ans = R[1]
    elif i == N-1:
        ans = max(ans, L[N-2])
    else:
        ans = max(ans, gcd(L[i-1], R[i+1]))
print(ans)


Measured memory_bytes: 16124