akhauriyash/Code-Regression huggingface dataset:
using System;

class ABC_123_C
{
    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());
        long A = long.Parse(Console.ReadLine());
        long B = long.Parse(Console.ReadLine());
        long C = long.Parse(Console.ReadLine());
        long D = long.Parse(Console.ReadLine());
        long E = long.Parse(Console.ReadLine());


        if(A>=N && B>=N && C>=N && D>=N && E>=N)
        {
            Console.WriteLine(5);
            return;
        }

        long[] ar = new long[]{ A, B, C, D, E };

        long min = long.MaxValue;
        for(int i=0; i< ar.Length; i++)
        {
            if (min > ar[i]) min = ar[i];
        }

        long time = 0;
        if (min == 1)
        {
            time = 4 + N;
        }
        else
        {
            time = 4 + (N + min) / min;
        }

        Console.WriteLine(time);
    }
}


Measured memory_bytes: 13140
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vi l(n);
    cin >> l;
    int ans = 0;
    rep(i, n) rep2(j, i + 1, n) rep2(k, j + 1, n) {
                vi v;
                v.pb(l[i]);
                v.pb(l[j]);
                v.pb(l[k]);
                sort(all(v));
                if (v[0] == v[1] or v[1] == v[2]) continue;
                if (v[0] + v[1] > v[2]) ans++;
            }
    cout << ans << endl;
}


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

bool is_prime(const unsigned n){
    switch(n){
        case 0: return false;
        case 1: return false;
        case 2: return true;
    }

    if(n%2 == 0) return false;

    for(unsigned i=3; i*i<=n; i+=2){
        if(n%i == 0) return false;
    }

    return true;
}

int main(){
  int cnt=0;
  int n;
  cin >> n;

  int s[n];
  for(int i=0; i<n; i++){
    cin >> s[i];
    if(is_prime(s[i]))cnt++;
  }

  cout << cnt << "\n";

  return 0;
}



Measured memory_bytes: 3088
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define REP(index, begin, end) for (int (index) = (begin); (index) < (end); (index)++)
#define RE(index, end) REP(index, 0, end)
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define DINT(x) printf(#x " = %d\n", x);
#define GETINT(x) scanf("%d", &x)
#define GETLL(x) scanf("%lld", &x)
#define GETSTR(x) scanf("%s", x)

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int town_n, day_lim;
vi dist, day_bad;

vector<vector<int>> dp;

int solve(int pos, int day)
{
	int res;
	if (dp[pos][day] != -1)
	{
		return dp[pos][day];
	}
	if (pos == town_n)
	{
		dp[pos][day] = 0;
		return 0;
	}
	if (day_lim - day == town_n - pos)
	{
		res = solve(pos + 1, day + 1) + day_bad[day] * dist[pos];
	}
	else
	{
		res = min(
			solve(pos, day + 1),
			solve(pos + 1, day + 1) + day_bad[day] * dist[pos]);
	}
	dp[pos][day] = res;
	return res;
}

int main()
{
	GETINT(town_n);
	dist.reserve(town_n);
	GETINT(day_lim);
	day_bad.reserve(day_lim);
	RE(i, town_n + 1)
	{
		vi line;
		line.resize(day_lim + 1, -1);
		dp.push_back(line);
	}
	RE(i, town_n)
	{
		int temp;
		GETINT(temp);
		dist.push_back(temp);
	}
	RE(i, day_lim)
	{
		int temp;
		GETINT(temp);
		day_bad.push_back(temp);
	}
	int res = solve(0, 0);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 5952
using System;

namespace agc001A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = new int[2 * N];
            string[] str = Console.ReadLine().Split();
            for (int i = 0; i < 2 * N; i++)
            {
                a[i] = int.Parse(str[i]);
            }
            Array.Sort(a);
            int Ans = 0;
            for(int i = 0; i < N; i++)
            {
                Ans = Ans + a[2 * i];
            }
            Console.WriteLine(Ans);
        }
    }
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  vector<i64> vec;
  bool getEven = false;
  rep(i, 3) {
    i64 x;
    cin >> x;
    if (x % 2 == 0) getEven = true;
    vec.push_back(x);
  }

  if (getEven) {
    cout << 0 << "\n";
    return 0;
  }

  cout << min({vec[1]*vec[2], vec[0]*vec[2], vec[0]*vec[1]}) << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll inf = (1 << 29);
template<typename T>
T GCD(T a, T b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a = a % b;
		else b = b % a;
	}
	return min(a, b);
}
template<typename T>
T LCM(T a, T b) {
	return a / GCD(a, b)*b;
}
bool prime(ll a) {
	for (int i = 2; i <= sqrt(a); i++) {
		if (!(a%i))return false;
	}
	return true;
}
ll n, m, r, f[10];
ll wsfd[210][210];
int main() {
	cin >> n >> m >> r;
	for (int i = 1; i <= r; i++)cin >> f[i];
	sort(f + 1, f + r + 1);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)wsfd[i][j] = inf;
	}
	for (int i = 1; i <= n; i++)wsfd[i][i] = 0;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		wsfd[a][b] = wsfd[b][a] = c;
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				wsfd[i][j] = min(wsfd[i][j], wsfd[i][k] + wsfd[k][j]);
			}
		}
	}
	ll ans = inf;
	do {
		ll cnt = 0;
		for (int i = 1; i < r; i++)cnt += wsfd[f[i]][f[i + 1]];
		if (ans > cnt)ans = cnt;
	} while (next_permutation(f + 1, f + r + 1));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int d, t, s;

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

	cin >> d >> t >> s;

	if (s * t >= d) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}


Measured memory_bytes: 3644
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

class LazySegTree
  attr_accessor:node,:lazy,:n
  def initialize(n)
    @n=1
    @n*=2 while @n<n
    @node=array(2*@n-1,1,0)
    @lazy=array(2*@n-1,1,0)
  end


  def lazy_eval(i,l,r)
    if @lazy[i]!=0
      @node[i]+=@lazy[i]
      if r-l>1
        @lazy[i*2+1]+=@lazy[i]/2
        @lazy[i*2+2]+=@lazy[i]/2
      end
      @lazy[i]=0
    end
  end


  def add(s,t,x,i,l,r)
    lazy_eval(i,l,r)
    return if r<=s or t<=l
    if s<=l and r<=t
      @lazy[i]+=x*(r-l)
      lazy_eval(i,l,r)
    else
      mid=(r+l)/2
      add(s,t,x,i*2+1,l,mid)
      add(s,t,x,i*2+2,mid,r)
      @node[i]=@node[i*2+1]+@node[i*2+2]
    end 
  end

  def getSum(s,t,i,l,r)
    return 0 if r<=s or t<=l
    lazy_eval(i,l,r)
    return @node[i] if s<=l and r<=t
    mid=(r+l)/2
    leaf_l=getSum(s,t,i*2+1,l,mid)
    leaf_r=getSum(s,t,i*2+2,mid,r)
    return leaf_l+leaf_r
  end
end
n,q=get_i

lst=LazySegTree.new(n)
q.times do
  query=get_i
  if query[0].zero?
    lst.add(query[1]-1,query[2],query[3],0,0,lst.n)
  else
    puts lst.getSum(query[1]-1,query[2],0,0,lst.n)

  end
end


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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if ((x - r) < 0) {
        cout << "No" << endl;
        return 0;
    }
    if (W < (x + r)) {
        cout << "No" << endl;
        return 0;
    }
    if ((y - r) < 0) {
        cout << "No" << endl;
        return 0;
    }
    if (H < (y + r)) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int a,b,k; cin >> a >> b >> k;
	if(a+k - 1 >= b - k + 1) {
		for (int i = a; i <= b ; ++i)
		{
			cout << i << endl;
		}
	}else{
		for (int i = a; i <= a + k - 1; ++i)
		{
			cout << i << endl;
		}
		for (int i = b - k + 1; i <= b; ++i)
		{
			cout << i << endl;
		}
	}
}



Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int a, b, c;
  while (cin >> a >> b >> c) {
    int e = 0, s = 0;
    loop(d, 1, 11) {
      loop(i, 1, 11) {
        if (i == a || i == b || i == c || i == d) continue;
        loop(j, 1, 11) {
          if (j == a || j == b || j == c || j == d || j == i) continue;
          s++;
          e += a + b + i <= 20;
        }
      }
    }
    cout << (e * 2 > s ? "YES" : "NO") << endl;
  }
}

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

using LL = long long;
const LL MOD = 1e9+7;

LL modpow(LL a, LL n) {
    LL ret = 1, tmp = a;
    while (n) {
        if (n & 1) (ret *= tmp) %= MOD;
        (tmp *= tmp) %= MOD;
        n >>= 1;
    }
    return ret;
}


int main()
{
    // O(KlogN + KloglogK)

    int N, K; cin >> N >> K;

    vector<LL> f(K+1);
    for (int d = 1; d <= K; ++d) {
        f[d] = modpow(K / d, N);
    }

    vector<bool> isprime(K+1, true);
    for (int p = 2; p <= K; ++p) {
        if (!isprime[p]) continue;
        for (int i = 1; i * p <= K; ++i) {
            isprime[i * p] = false;
            (f[i] -= f[i * p]) %= MOD;
            if (f[i] < 0) f[i] += MOD;
        }
    }

    LL ans = 0;
    for (int d = 1; d <= K; ++d) {
        (ans += f[d] * d) %= MOD;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main(void)
{
	int a,b=0;
  	
  cin >> a >> b;
  
	if(a + b > a - b)
    {
    	if(a + b > a * b)
          cout << a + b;
      else
        cout << a * b;
    }
  else
    	if(a - b > a * b)
          cout << a - b;
      else
        cout << a * b;
    
  
  
}

Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())
    ans = 0
    if n == 0 & x == 0:
        break
    for a in range(1, n+1):
        for b in range(1, n+1):
            if b <= a:
                continue
            c = x - (a + b)
            if c > b and c <= n:
#                 print(a, b, c)
                ans +=1                
    print(ans)       


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main(){
    long a,b,c;
    cin >> a >> b >> c;
    if(0<c-a-b){
        if((c-a-b)*(c-a-b)-4*a*b>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

ll prime_factor(ll n){
  set<ll> S;
  for(ll i=2; i*i<=n; i++){
    while(n%i==0){
      S.insert(i);
      n/= i;
    }
  }
  if(n!=1) return S.size()+2;
  else return S.size()+1;
}

int main(){
  ll a,b; cin>>a>>b;
  ll x=GCD(a,b);
  cout<<prime_factor(x)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef struct dice{
	int	f[6];
}Dice;
int main(void)
{
	int i, j;
	char roll[101] = {0};
	Dice D0 = {0};
	Dice Dw = {0};
	for(i=0; i<6; i++){
		scanf("%d", D0.f+i);
	}
	scanf("%s", roll);
	j=0;
	while(*(roll+j) != '\0'){
		for(i=0; i<6; i++){
			*(Dw.f+i) = *(D0.f+i);
		}
		switch(*(roll+j)){
			case 'E':
				*(D0.f+0) = *(Dw.f+3);
				*(D0.f+2) = *(Dw.f+0);
				*(D0.f+3) = *(Dw.f+5);
				*(D0.f+5) = *(Dw.f+2);
				break;
			case 'N':
				*(D0.f+0) = *(Dw.f+1);
				*(D0.f+1) = *(Dw.f+5);
				*(D0.f+4) = *(Dw.f+0);
				*(D0.f+5) = *(Dw.f+4);
				break;
			case 'S':
				*(D0.f+0) = *(Dw.f+4);
				*(D0.f+1) = *(Dw.f+0);
				*(D0.f+4) = *(Dw.f+5);
				*(D0.f+5) = *(Dw.f+1);
				break;
			case 'W':
				*(D0.f+0) = *(Dw.f+2);
				*(D0.f+2) = *(Dw.f+5);
				*(D0.f+3) = *(Dw.f+0);
				*(D0.f+5) = *(Dw.f+3);
				break;
			default:
				break;
		}
		j++;
	}
	printf("%d\n", *(D0.f));
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = 998244353;

int main() {
    int n;
    cin >> n;
    ll dd[n];
    rep(i,n){
        dd[i]=0;
    }
    int mx=0;
    rep(i,n){
        int d;
        cin >> d;
        chmax(mx,d);
        if(i==0){
            if(d!=0){
                cout << 0;
                return 0;
            }
        }
        else{
            dd[d]++;
        }
    }
    ll sum=1;
    rep(i,mx+1){
        if(i==0){
            if(dd[0]!=0){
                cout << 0;
                return 0;
            }
            dd[0]++;
        }
        else{
            rep(j,dd[i]){
                sum*=dd[i-1];
                sum%=mod;
            }
        }
    }
    cout << sum;
    


}

/*



 */



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    if(n < 1200)
        cout<<"ABC"<<endl;
    else if(n >= 1200 && n < 2800)
        cout << "ARC"<<endl;
    else if(n >= 2800)
        cout << "AGC"<<endl;
    return 0;
}


Measured memory_bytes: 256
//専用ライブラリ
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int cmp(P a,P b){
        if(a.fi!=b.fi)
        return a.fi>b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;
    cin>>n;
    ll res=0;
    ll rmin=INF,lmax=-INF;
    vector<pair<ll,ll>> a;
    for(int i=0;i<n;i++){
        ll l,r;
        cin>>l>>r;
        chmin(rmin,r);
        chmax(lmax,l);
        a.push_back(make_pair(l,r));
    }
    sort(all(a));
    for(ll i=0;i<n;i++){
        chmax(res,mmax(0,rmin-lmax+1)+a[i].se-a[i].fi+1);
    }
    ll Y=INF;
    for(ll i=n-1;i>=0;i--){
        ll X=a[i].fi;
        if(i<n-1)
            chmax(res,mmax(0,rmin-X+1)+mmax(0,Y-lmax+1));
        chmin(Y,a[i].se);
    }
    cout<<res<<endl;
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll h, w;
	cin >> h >> w;
	vector<string> grid(h);
	for (ll i = 0; i < h; i++) cin >> grid[i];

	vector<vector<vll>> cnt(h, vector<vll>(w, vll(2, 0))); // {縦, 横}
	ll ans = 0;
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			if (grid[i][j] == '#') continue;
			if (i > 0 && grid[i - 1][j] == '.') {
				cnt[i][j][0] = cnt[i - 1][j][0];
			}
			else {
				ll x = i;
				while (x < h && grid[x][j] == '.') {
					cnt[i][j][0]++;
					x++;
				}
			}
			if (j > 0 && grid[i][j - 1] == '.') {
				cnt[i][j][1] = cnt[i][j - 1][1];
			}
			else {
				ll x = j;
				while (x < w && grid[i][x] == '.') {
					cnt[i][j][1]++;
					x++;
				}
			}
			ans = max(ans, cnt[i][j][0] + cnt[i][j][1] - 1);
		}
	}
	cout << ans << endl;
}


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

int main() {
  int H;
  int W;
  cin >> H;
  cin >> W;
  vector<string> a(H);
  for (int i = 0; i < H; i++) {
    cin >> a.at(i);
  }

  // 表示しない行と列をtrueとする
  vector<int> row(H, false);
  vector<int> col(W, false);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a.at(i).at(j) == '#') {
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
	if (row.at(i)) {
      for (int j = 0; j < W; j++) {
        if (col.at(j)) {
          cout << a.at(i).at(j);
        }
      }
      cout << endl;
    }
  }  
}


Measured memory_bytes: 3644
# he doesn't get anything for coins under 5 yen.
# for amounts over 5 yen, he should use the 500-yen
# coin as much as possible, then use the 5-yen coin.

x = int(input())
num500, leftover_from500 = divmod(x, 500)
num5, _ = divmod(leftover_from500, 5)
happiness = 1000*num500 + 5*num5
print(happiness)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int t=n;
    long long sum=0;
    while(n!=0)
    {
        sum=sum+n%10;
        n/=10;
    }
    if(t%sum==0)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**

 *
 * @author Abhijeetkns
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BATCoder solver = new BATCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class BATCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int curr = 0;
            int max = 0;
            for (int i = 0; i < s.length(); i++) {
                String ele = s.substring(i, i + 1);
                if (ele.compareTo("A") == 0 || ele.compareTo("C") == 0 || ele.compareTo("G") == 0 || ele.compareTo("T") == 0) {
                    curr++;
                    if (max < curr)
                        max = curr;
                } else
                    curr = 0;
            }
            out.println(max);
        }

    }
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
const ll MOD = 1e9 + 7;

// 素因数分解
map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i*i <= n; i++){
		while(n % i == 0){
			res[i]++;
			n /= i;
		}
	}
	if(n > 1) res[n]++;
	return res;
}

// 逆元 a^{-1} mod m
// aがmの倍数でないことが前提。O(log m)
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

void mainsolve(){
	ll n;
	cin >> n;

	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	map<ll,ll> lcmmp;
	rep(i,n){
		map<ll,ll> mp = prime_factor(a[i]);
		for(auto itr = mp.begin(); itr != mp.end(); itr++){
			P now = *itr;
			if(lcmmp[now.first] < now.second) lcmmp[now.first] = now.second;
		}
	}

	ll lcm = 1;
	for(auto itr = lcmmp.begin(); itr != lcmmp.end(); itr++){
		P now = *itr;
		rep(i,now.second){
			lcm = (lcm * now.first) % MOD;
		}
	}

	ll res = 0;
	rep(i,n) res = (res + ((lcm * modinv(a[i], MOD)) % MOD) ) % MOD;
	cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 896
def solve(h,w,n):
    temp = max(h,w)
    if n % temp == 0:
        return n // temp
    else:
        return n // temp + 1

def main():
    h = int(input())
    w = int(input())
    n = int(input())
    print(solve(h,w,n))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>

int main()
{
	long int n, a[200010], b[200010];
	std::cin >> n;
	
	for (int i = 0; i < n; ++i)
		std::cin >> a[i];
	
	if (n % 2 == 0)
	{
		int j = 0;
		for (int i = n - 1; i >= 0; i -= 2)
		{
			b[j] = a[i];
			++j;
		}
		for (int i = 0; i < n; i += 2)
		{
			b[j] = a[i];
			++j;
		}
	}
	else
	{
		int j = 0;
		for (int i = n - 1; i >= 0; i -= 2)
		{
			b[j] = a[i];
			++j;
		}
		for (int i = 1; i < n; i += 2)
		{
			b[j] = a[i];
			++j;
		}
	}
	
	for (int i = 0; i < n; ++i)
		std::cout << b[i] << " ";
}

Measured memory_bytes: 5248
// c++include
#include <iostream>
#include <algorithm>
// cinclude
#include <stdio.h>
#include<string.h>
#include<math.h>
//c++標準ライブラリ
#include<vector>
#include<string>
//std使用<-namespace
using namespace std;

// define, typedef
#define rpt(i, n) for(ll i = 0; i < (n); i++)
typedef long long ll;

// 最大公約数
ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		gcd(b, a % b);
	}
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

// main関数
int main(void) {
	int n;
	cin >> n;
	vector<ll> t;
	t.reserve(n);
	rpt(i, n) {
		ll tmp;
		cin >> tmp;
		t.push_back(tmp);
	}
	rpt(i, n - 1) {
		t[i + 1] = lcm(t[i], t[i + 1]);
	}
	cout << t[n - 1];

	return 0;
}

Measured memory_bytes: 256
T=input()
while True:
  if T==str():
    print("YES")
    exit()
  if len(T)<5:
    print("NO")
    exit()
  if T[-5:]=="dream":
    T=str(T[:-5])
  elif T[-7:]=="dreamer":
    T=str(T[:-7])
  elif T[-5:]=="erase":
    T=str(T[:-5])
  elif T[-6:]=="eraser" :
    T=str(T[:-6])
  else:
    print("NO")
    exit()

Measured memory_bytes: 9268
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define mex 1000005
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
bool palin(string s){
	int n=s.size();
	int q=0;
	for(int i=0;i<n/2;i++){
		if(s[i]!=s[n-i-1])
		 q=1;
	}
	if(q==0)
	 return true;
	return false;
}
 	
signed main(){
	fast
	string s;
	cin>>s;
	string s1=s;
	int n=s.size();
	//reverse(s1.begin(),s1.end());
	if(palin(s)){
		s1=s.substr(0,(n-1)/2);
		if(palin(s1)){
			s1=s.substr((n+3)/2-1,n-((n+3)/2)+1);
			if(palin(s1))
			 cout<<"Yes";
			else
			 cout<<"No";
		 }
		 else
		  cout<<"No";
	  }
	  else
	   cout<<"No";
}



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

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner stdId = new Scanner(System.in);
        int s = stdId.nextInt();
        int hh = (int)s/3600;
        int mm = (int)s%3600/60;
        int ss = (int)s%3600%60;
        System.out.println(hh+":"+mm+":"+ss);
    }
}

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

int main()
{
	int a, b, c, s;
	cin >> a >> b >> c;
	int maxj = INT_MIN;
	int minj = INT_MAX;
	if (a > maxj) maxj = a;
	if (b > maxj) maxj = b;
	if (c > maxj) maxj = c;
	if (a < minj) minj = a;
	if (b < minj) minj = b;
	if (c < minj) minj = c;
	int midj = a + b + c - maxj - minj;
	s = maxj * 10 + minj + midj;
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    private static final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) {
        String[] str = readLineStandardInput().split(" ");
        int N = Integer.parseInt(str[0]);
        int X = Integer.parseInt(str[1]);
        int[] m = new int[N];
        int sum_m = 0;
        int mim_m = Integer.MAX_VALUE;
        for(int i = 0; i < m.length; i++){
            String mem = readLineStandardInput();
            m[i] = Integer.parseInt(mem);
            sum_m += m[i];
            if(m[i] < mim_m){
                mim_m = m[i];
            }
        }
        int ret = X - sum_m;
        int num = N + ret / mim_m;
        System.out.println(num);
    }

    private static String readLineStandardInput() {
        String str;
        try {
            str = input.readLine();
        } catch(IOException e){
            str = null;
        }
        return str;
    }
}


Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,count=0;
  string S;
  map<string,int> mp;
  cin>>N;
  for(int i=0;i<N;i++){cin>>S;if(mp.count(S)==1)mp[S]++;else mp[S]=0;count=max(mp[S],count);}
  for(auto p:mp){auto key=p.first;auto value=p.second;if(value==count)cout<<key<<endl;}
}

Measured memory_bytes: 26880
def zb_xyz(x, y, z)
    [x, y, z].sort[1] == y
end

def zb
    n = gets.chomp.to_i
    arr = gets.chomp.split(/\s/).map{|x| x.to_i}

    cnt = 0
    (n-2).times do |i|
        cnt += 1 if zb_xyz(arr[i], arr[i+1], arr[i+2])
    end

    puts cnt
end

#za
zb


Measured memory_bytes: 1916
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	S := sc.Next()

	dp := make([][]int, len(S)+1)

	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, 13)
	}

	mod := int(1e9 + 7)
	for i := 1; i < len(dp); i++ {
		if i == 1 {
			if S[i-1] != '?' {
				dp[i][int(S[i-1]-'0')] = 1
			} else {
				for h := 0; h < 10; h++ {
					dp[i][h] = 1
				}
			}
		} else {
			for n := 0; n < 13; n++ {
				if S[i-1] != '?' {
					A := n*10 + int(S[i-1]-'0')
					dp[i][A%13] += dp[i-1][n]
					dp[i][A%13] %= mod

				} else {
					for h := 0; h < 10; h++ {
						A := n*10 + h
						dp[i][A%13] += dp[i-1][n]
						dp[i][A%13] %= mod
					}
				}
			}
		}
	}

	fmt.Println(dp[len(dp)-1][5])

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 14720
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Remoting.Contexts;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;

namespace Contest
{
    class Program
    {
        private Scanner sc;
        public void Solve()
        {
            sc = new Scanner();
            long L = sc.NextInt();
            long R = sc.NextInt();
            long rr = R / 2019 * 2019;
            if (L <= rr)
            {
                Console.WriteLine(0);
                return;
            }

            long ans = long.MaxValue;
            for (long i = L; i <= R - 1; i++)
            {
                for (long j = i + 1; j <= R; j++)
                {
                    ans = Math.Min(ans, (i * j) % 2019);
                }
            }
            Console.WriteLine(ans);
        }

        static void Main() => new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private readonly char _separator;
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

Measured memory_bytes: 11092
n=int(input())
t=[]
x=0
for i in range(60):
    y=((n-x)%(1<<(i+1)))*(-1)**i
    if y==(-2)**i:
        t+=['1']
        x+=(-2)**i
    else:
        t+=['0']
    if x==n:
        break
print(''.join(t)[::-1])

Measured memory_bytes: 38384
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);ios::sync_with_stdio(false);
	llint n,i,ans=0,sai=mod;cin>>n;
	vector<pair<llint,int>>w(n);
	for(i=0;i<n;i++){cin>>w[i].fir;w[i].sec=i;mineq(sai,w[i].fir);}
	SO(w);
	vector<bool>nao(n);
	for(i=0;i<n;i++){
		if(nao[i]){continue;}
		llint sma=mod,wa=0,x=i,m=0;
		do{
			m++;
			mineq(sma,w[x].fir);
			wa+=w[x].fir;
			nao[x]=1;
			x=w[x].sec;
		}while(x!=i);
		ans+=min((m-2)*sma+wa,wa+sma+(m+1)*sai);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){

    string S;
    cin >> S;

    map<char, int> dict;
    for (int i=0; i<S.size(); i++){
        dict[S.at(i)]++;

        if (dict[S.at(i)] > 1){
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


def solve():
    N = int(input())
    A = inpl()

    max_a = max(A)
    min_a = min(A)
    num_cnt = Counter(A)
    min_cnt = num_cnt[min_a]
    max_cnt = num_cnt[max_a]
    # print(num_cnt)

    if max_a - min_a >= 2:
        return 'No'
    elif len(num_cnt) == 1:
        if min_a == N - 1:
            return 'Yes'
        elif min_a * 2 <= N:
            return 'Yes'
        else:
            return 'No'
    elif A.count(1) >= 2:
        return 'No'
    elif min_cnt == 2 and max_cnt >= max_a:
        return 'Yes'
    elif min_cnt == min_a:
        return 'Yes'
    else:
        return 'No'


print(solve())


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

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int N,K; 
int g = 0, mx = 0;
vi x;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N >> K; x.resize(N);
	F0R(i,N) cin >> x[i];
	F0R(i,N) {
	    g = __gcd(g,x[i]);
	    mx = max(mx,x[i]);
	}
	if (K % g != 0) {
	    cout << "IMPOSSIBLE";
	    return 0;
	}
	if (K > mx) {
	    cout << "IMPOSSIBLE";
	    return 0;
	}
	cout << "POSSIBLE";
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[303030];
set<pair<ll,int>> L,M,R;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,3*N) cin>>A[i];
	ll X=0,Y=0;
	FOR(i,N) {
		L.insert({A[i],i});
		X+=A[i];
	}
	for(i=N;i<3*N;i++) {
		R.insert({A[i],i});
	}
	FOR(i,N) {
		Y+=R.begin()->first;
		M.insert(*R.begin());
		R.erase(R.begin());
	}
	ll ret=X-Y;
	for(i=N;i<2*N;i++) {
		L.insert({A[i],i});
		X+=A[i];
		X-=L.begin()->first;
		L.erase(L.begin());
		
		if(M.count({A[i],i})) {
			Y-=A[i];
			M.erase({A[i],i});
			M.insert(*R.begin());
			Y+=R.begin()->first;
			R.erase(R.begin());
		}
		else {
			R.erase({A[i],i});
		}
		ret=max(ret,X-Y);
		
	}
	
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 21376
'use strict';
const fs = require('fs');
const mod = BigInt(1e9+7);


class ABC041 {
  static A(input) {
    var s, i
    input = input.trim().split('\n');
    [s, i] = input;
    i = parseInt(i, 10);
    console.log(s[i-1]);
  }
  static B(input) {
    var a, b, c;
    input = input.trim().split(' ').map(BigInt);
    [a, b, c] = input;
    var ans = a * b % mod * c % mod;
    ans = Number(ans);
    console.log(ans);
  }
  static C(input) {
    var [n, height] = input.trim().split('\n');
    height = height.split(' ').map(n => parseInt(n, 10));
    n = parseInt(n, 10);
    var height = Object.keys(height).map(key => [parseInt(key, 10)+1, height[key]]);
    height.sort(function(first, second) {
      return (second[1] - first[1]);
    });
    for (var [i, _] of height) {console.log(i);}
  }
  static D(input) {
    var lines = input.trim().split('\n');
    var [n, m] = lines[0].split(' ').map(x => +x);
    var edges = new Array(n).fill(0);
    for (var i = 0; i < m; i++) {
      var [x, y] = lines[1+i].split(' ').map(x => +x);
      edges[x-1] |= 1<<(y-1);
    }
    var comb = new Array(1<<n).fill(null); comb[0] = 1;
    function count(edges, bit) {
      if (comb[bit] != null) {return comb[bit];}
      comb[bit] = 0;
      for (var i = 0; i < n; i++) {
        if (bit>>i&1 && !edges[i]) {
          var nxt_bit = bit & ~(1<<i);
          var nxt_edges = edges.slice();
          for (var j = 0; j < n; j++) {
            nxt_edges[j] &= ~(1<<i);
          }
          comb[bit] += count(nxt_edges, nxt_bit);
        }
      }
      return comb[bit];
    }
    console.log(count(edges, (1<<n)-1));
  }
}

class ABC173 {
  static A(input) {
    var n = +input.trim();
    console.log(Math.floor((n+999)/1000)*1000 - n);
  }
  static B(input) {
  }
  static C(input) {
  }
  static D(input) {
  }
  static E(input) {
  }
  static F(input) {
  }
}


var input = fs.readFileSync('/dev/stdin', 'utf8');
ABC173.A(input);

Measured memory_bytes: 29420
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll

int h, w, n, k, ans;

int pot[50*50];

int query(int y1, int y2, int x1, int x2)
{
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	int ans;
	cin >> ans;
	return ans;
}

void solve(int y1, int y2, int x1, int x2, int cnt, int split)
{
	if(cnt==0)
		return;

	if(cnt==(y2-y1+1)*(x2-x1+1))
	{
		for(int i = y1; i <= y2; ++i)
		{
			for(int j = x1; j <= x2; ++j)
			{
				ans += pot[i*w+j];
				ans %= k;
			}
		}

		return;
	}

	if(split)
	{
		int m = (y1+y2)/2;
		int h = query(y1, m, x1, x2);
		solve(y1, m, x1, x2, h, split^1);
		solve(m+1, y2, x1, x2, cnt-h, split^1);
	}
	else
	{
		int m = (x1+x2)/2;
		int h = query(y1, y2, x1, m);
		solve(y1, y2, x1, m, h, split^1);
		solve(y1, y2, m+1, x2, cnt-h, split^1);
	}
}

int32_t main()
{
	cin >> h >> w >> n >> k;

	pot[0] = 1;

	for(int i = 1; i < 50*50; ++i)
	{
		pot[i] = pot[i-1]*2%k;
	}

	solve(0, h-1, 0, w-1, n, 1);

	cout << "! " << ans << endl;
}

Measured memory_bytes: 724
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    System.out.println(Math.min(a,b)+Math.min(c,d));
  }
  

  
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int n, k;
vector<int> v(N);
int dp[N];
int dfs(int pos){
    if(pos >= n){
        return INF;
    }
    if(pos == n - 1){
        return 0;
    }
    int &res = dp[pos];
    if(res != -1){
        return res;
    }
    res = INF;
    for(int i = 1; i <= k; i++){
        res = min(res, dfs(pos + i) + abs(v[pos] - v[pos + i]));
    }
    return res;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        cin >> n >> k;
        for(int i = 0; i < n; i++){
            cin >> v[i];
        }
        memset(dp, -1, sizeof(dp));
        cout << dfs(0) << '\n';
    }
}

Measured memory_bytes: 51840
n=int(input())
w=list(map(int,input().split()))
s=sum(w)
x=0
fin=1000
for i in range(n-1):
  x+=w[i]
  z=s-x
  con=abs(z-x)
  
  if con<fin:
    fin=con
    
print(fin)

Measured memory_bytes: 3060