akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  int a[n];
  rep(i,n) R a[i];
  sort(a,a+n);
  int l=0,ans=0;
  rep(r,n) {
    while(a[r]-a[l]>2) l++;
    ans=max(ans,r-l+1);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <string.h>
#include<bits/stdc++.h>
#include <iostream>
#include<algorithm>
#include<list>
#include <functional>
#include <map>
#include <deque>
using namespace std;

#define pt(...) prllf(__VA_ARGS__)
#define sf(...) scanf(__VA_ARGS__)
#define fui(p,n,d) for(ll i = p;i <= n; i += d)
#define fut(p,n,d) for(ll t = p;t <= n; t += d)
#define fuj(p,n,d) for(ll j = p;j <= n; j += d)
#define fdi(n,p,d) for(ll i = n;i >= p; i -= d)
#define fdt(n,p,d) for(ll t = n;t >= p; t -= d)
#define fdj(n,p,d) for(ll j = n;j >= p; j -= d)
#define Conn(x,y) x##y
#define ToString(x) #x
#define ll long long
#define MOD 1000000007
#define p(a,b) pow((double)a, b)
#define me(a,b) memset(a,b,sizeof(a))
bool compare(ll a, ll b){return a>b;}

const ll MAX = 1e7+5;
double a, b, l = -1, r = MAX;

int main(){
    cin>>a>>b;
    if(a*12.5 == (ll)(a*12.5)){
        if(a*12.5 > l) l = (ll)(a*12.5);
    }else l = (ll)(a*12.5+1);
    if((ll)((a+1)*12.5-1) < r) r = (ll)((a+1)*12.5-1);
    if(b*10 == (ll)(b*10)){
        if(b*10 > l) l = (ll)(b*10);
    }else l = (ll)(b*10+1);
    if((ll)((b+1)*10-1) < r) r = (ll)((b+1)*10-1);
    if(l > r) cout<<-1;
    else if(l == -1 || l == 0){
        cout<<1;
    }else cout<<l;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long aa (long long a, long long b,long long c)
{
	int d[3];
	d[0] = a;
	d[1] = b;
	d[2] = c;
	sort(d,d+3);
	return d[0] * d[1];
}
int main()
{
	long long a,b,c;
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << "0";
		else cout << min(min(a*b,a*c),b*c) << endl;
	return 0;	
 } 

Measured memory_bytes: 256
from operator import itemgetter

N,M=map(int,input().split())
ab=[[int(i) for i in input().split()] for j in range(M)]
ab=sorted(ab, key=itemgetter(1))
ans=0
k=0
for i in ab:
    if i[0]>k:
        k=i[1]-1
        ans+=1
print(ans)

Measured memory_bytes: 23656
//Code from Freecontest
#include <bits/stdc++.h>

using namespace std;

#define debug(a) cout << #a << ": " << a << endl
#define fto(i, l, r) for(int i = l; i <= r; ++i)
#define fdto(i, r, l) for(int i = r; i >= l; --i)

typedef long long ll;

const int MAXN = 5005;
const int MAXM = 205;
const int MAXK = 20;

int n, m, k, a[MAXN], b[MAXN][MAXM];
int st[MAXM][MAXK][MAXN];
ll x[MAXN], maxVal[MAXN];

int query(int j, int l, int r) {
    int level = log2(r-l+1);
    return max(st[j][level][l], st[j][level][r-(1<<level)+1]);
}

void solve(int l, int r, int kmin, int kmax) {
    if (l > r) return;

    int mid = (l+r)/2;
    int best = -1;

    fdto(i, min(kmax, mid), kmin) {
        ll val = 0;
        fto(j, 0, m-1)
            val += query(j, i, mid);
        val -= x[mid] - x[i];
        if (val >= maxVal[mid]) {
            maxVal[mid] = val;
            best = i;
        }
    }

    solve(l, mid-1, kmin, best);
    solve(mid+1, r, best, kmax);
}

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d%d", &n, &m);
    fto(i, 1, n-1) scanf("%d", &a[i]);
    fto(i, 0, n-1)
        fto(j, 0, m-1) scanf("%d", &b[i][j]);

    x[0] = 0;
    fto(i, 1, n-1) x[i] = x[i-1] + a[i];

    k = log2(n);
    fto(j, 0, m-1) {
        fto(i, 0, n-1)
            st[j][0][i] = b[i][j];
        fto(level, 1, k) {
            int sz = 1<<level;
            fto(i, 0, n-sz)
                st[j][level][i] = max(st[j][level-1][i], st[j][level-1][i + sz/2]);
        }
    }

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

    ll ans = 0;
    fto(i, 0, n-1)
        ans = max(ans, maxVal[i]);
    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 55532
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GS(A);
  GS(B);
  if (A.size() < B.size()) {
    print("LESS");
  } else if (A.size() > B.size()) {
    print("GREATER");
  } else {
    for (int i = 0; i < A.size(); ++i) {
      if (A[i] > B[i]) {
        print("GREATER");
        return 0;
      } else if (A[i] < B[i]) {
        print("LESS");
        return 0;
      }
    }
    print("EQUAL");
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  double d,t,s;
  cin >> d >> t >> s;

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

Measured memory_bytes: 3688
S =  input()
arr = [0]
ACGT = ["A", "C", "G", "T"]
max_count = 0
count = 0
for s in S:
  if s in ACGT:
    count += 1
    max_count = max(max_count, count)
  else:    
    count = 0
print(max_count)    
  
  
  


Measured memory_bytes: 2940
#include <cmath>
#include <iostream>
#include <vector>

int main()
{
    unsigned N;
    std::cin >> N;
    unsigned max = 0;
    std::vector<unsigned> t;
    for(unsigned i = 0; i != N; ++i)
    {
        unsigned buf;
        std::cin >> buf;
        if(buf > max)
        {
            max = buf;
        }
        t.push_back(buf);
    }
    unsigned long result = 0;
    unsigned root = sqrt(max);
    std::vector<unsigned long> up_cache(max+1);
    std::vector<unsigned long> down_cache(max+1);
    for(auto val : t)
    {
        unsigned target;
        if(val > root)
        {
            unsigned i = max / val;
            // クソコード注意: i!=0を利用
            if(down_cache[i])
            {
                i = down_cache[i];
            }
            else
            {
                for(; max % i != 0; --i) {}
                for(unsigned j = max / val; max % j != 0; --j)
                {
                    down_cache[j] = i;
                }
            }
            target = max / i;
        }
        else
        {
            unsigned i = val;
            if(up_cache[i])
            {
                i = up_cache[i];
            }
            else
            {
                for(; max % i != 0; ++i) {}
                for(unsigned j = val; max % j != 0; ++j)
                {
                    up_cache[j] = i;
                }
            }
            target = i;
        }
        result += target - val;
    }
    std::cout << result << '\n';
}


Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		boolean ac[] = new boolean[n+1];
		long wa[] = new long[n+1];
		for(int i=0; i<m; i++) {
			int p = sc.nextInt();
			String s = sc.next();
			if(ac[p]) continue;
			if(s.equals("AC")) {
				ac[p]=true;
			} else {
				wa[p]++;
			}
		}
		long sum1=0;
		long sum2=0;
		for(int i=1; i<=n; i++) {
			if(ac[i]) {
				sum1++;
				sum2 += wa[i];
			}
		}
		System.out.println(sum1 + " " + sum2);
		sc.close();
	}
}


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

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;

int n;
vector<string> ans;
void dfs(string s, int num) {
    if (s.size() == n) {
        ans.push_back(s);
        return;
    }
    for (char c = 'a'; c <= 'a' + num; c++) {
        if (c == 'a' + num) {
            dfs(s+c, num+1);
        } else {
            dfs(s+c, num);
        }
    }
    return;
}


int main() {
    cin >> n;
    dfs("a", 1);
    sort(ans.begin(), ans.end());
    rep(i, ans.size()) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 7796
import java.util.*;
import java.io.*;
import java.lang.*;

 class Main{

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder sb = new StringBuilder("");
    static StringTokenizer stk = new StringTokenizer("");
    static int m = 1000000007;

    public static  void main(String args[]){
        try{
            stk = new StringTokenizer(bf.readLine());
             int H = Integer.parseInt(stk.nextToken());
             int W = Integer.parseInt(stk.nextToken());
             boolean arr[][] = new boolean[H][W];

            for(int i=0;i<H;i++){
                String s = bf.readLine();
                for(int j=0;j<W;j++){
                    arr[i][j] =  s.charAt(j) == '.' ? true : false;
                }
            }

            System.out.println(solver(arr, H, W));

        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public static int solver(boolean[][] arr, int H,int W){
        int[][] dp = new int[H][W];
        dp[0][0] = 1;

        for(int i=0;i<H;i++){
            for(int j=0;j<W ;j++){
                if(i-1 >= 0 && j-1 >=0){

                    dp[i][j] = ((arr[i-1][j] == true ? dp[i-1][j]%m : 0) + (arr[i][j-1] == true ? dp[i][j-1]%m : 0 ))%m;
                
                }else if(i-1 >= 0 && j-1 < 0){

                    dp[i][j] = (arr[i-1][j] == true ? dp[i-1][j]%m : 0) ;
                
                }else if(i-1 < 0 && j-1 >=0){
                   
                    dp[i][j] = arr[i][j-1] == true ? dp[i][j-1]%m : 0 ;
                
                }
            }
        }

       return dp[H-1][W-1]%m;
    }

}



Measured memory_bytes: 29808
#include <vector>
#include <cstddef>
#include <cassert>
#include <functional>

template<class T>
struct sparse_table {
	using value_type = T;
	using size_type = std::size_t;
	using binary_op = std::function<T(T, T)>;
private :
	const binary_op op;
	std::vector<std::vector<value_type>> node;
	std::vector<size_type> msb;

public : 
	sparse_table (const binary_op &op) noexcept : op(op) { } 

	template<class Iterator>
	void build (Iterator l, Iterator r) noexcept {
		const size_type n = (r - l), b = 32 - __builtin_clz(n);
		msb.assign(n + 1, 0);
		node.assign(b, std::vector<value_type>(n));
		for (size_type i = 2; i < n + 1; i++) msb[i] = msb[i >> 1] + 1;
		for (size_type i = 0; i < n; i++, l++) node[0][i] = (*l);
		for (size_type i = 1; i < b; i++) {
			for (size_type j = 0; j < n; j++) {
				const size_type k = std::min(j + (1 << (i - 1)), n - 1);
				node[i][j] = op(node[i - 1][j], node[i - 1][k]);
			}
		}
	}

	value_type fold (size_type l, size_type r) noexcept {
		assert(l < r);
		const size_type &b = msb[r - l];
		return op(node[b][l], node[b][r - (1 << b)]);
	}

};

#include <iostream>
#include <vector>
#include <utility>
#include <functional>
#include <queue>
#include <algorithm>

using usize = std::size_t;
using xy = std::pair<usize, usize>;
using range = std::pair<usize, usize>;
template<class T>
using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

int main() {
	usize n;
	std::cin >> n;
	std::vector<usize> a(n + 1, n + 1), s(n, n), t(n, n), index(n);
	for (usize i = 0; i < n; i++) {
		std::cin >> a[i];
		index[a[i] - 1] = i;
		if (i & 1) t[i] = i;
		else s[i] = i;
	}
	
	auto f = [&] (const usize &lhs, const usize &rhs) {
		return (a[lhs] < a[rhs] ? lhs : rhs);
	};
	
	sparse_table<usize> st1(f), st2(f);
	st1.build(s.begin(), s.end());
	st2.build(t.begin(), t.end());
	
	std::vector<usize> ans;
	std::queue<range> que;
	min_heap<std::pair<xy, range>> heap;
	ans.reserve(n);
	que.emplace(0, n);
	
	while (ans.size() < n) {
		while (not que.empty()) {
			auto [l, r] = que.front(); que.pop();
			if (r - l < 2) continue;
			usize i = ((l & 1) ? st2.fold(l, r) : st1.fold(l, r));
			usize j = ((l & 1) ? st1.fold(i, r) : st2.fold(i, r));
			heap.emplace(std::make_pair(a[i], a[j]), range(l, r));
		}
		auto [p1, p2] = heap.top();
		heap.pop();
		auto [ai, aj] = p1;
		auto [l, r] = p2;
		usize i = index[ai - 1], j = index[aj - 1];
		ans.push_back(ai);
		ans.push_back(aj);
		que.emplace(l, i);
		que.emplace(i + 1, j);
		que.emplace(j + 1, r);
	}
	
	for (usize i = 0; i < n; i++) {
		std::cout << ans[i] << " \n"[i + 1 == n];
	}
	
	return 0;
}

Measured memory_bytes: 74300
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int t[n][n+1];
		rep(i,n)rep(j,n+1)cin>>t[i][j];
		int dp[(1<<n)];
		rep(i,1<<n)dp[i]=INF;
		dp[0]=0;
		loop(i,1,1<<n){
			rep(j,n){
				if(i&(1<<j)){
					rep(k,n+1){
						if(j==k-1)continue;
						if(k==0)dp[i]=min(dp[i],dp[i^(1<<j)]+t[j][0]);
						else if(i&(1<<(k-1))){
							dp[i]=min(dp[i],dp[i^(1<<j)]+t[j][k]);
						}
					}
				}
			}
		}
		cout<<dp[(1<<n)-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1416
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

const ll mod = 1000000007;
//const ll mod = 998244353;

template<int MOD> class Fp {
    ll val;
public:
    constexpr Fp(ll v = 0) noexcept : val(v % MOD) {
        if(val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator- () const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+ (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator- (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator* (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/ (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator+= (const Fp& r) noexcept {
        val += r.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator-= (const Fp& r) noexcept {
        val -= r.val;
        if(val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator*= (const Fp& r) noexcept {
        (val *= r.val) %= MOD;
        return *this;
    }
    constexpr Fp& operator/= (const Fp& r) noexcept {
        ll a = r.val, b = MOD, u = 1, v = 0;
        while(b){
            ll t = a/b;
            a -= t*b; swap(a, b);
            u -= t*v; swap(u, v);
        }
        (val *= u) %= MOD;
        if(val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator== (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator!= (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    constexpr bool operator> (const Fp& r) const noexcept {
        return this->val > r.val;
    }
    constexpr bool operator< (const Fp& r) const noexcept {
        return this->val < r.val;
    }
    friend constexpr ostream& operator<< (ostream &os, const Fp<MOD>& x){
        ll tmp = x.val;
        os << tmp;
        return os;
    }
    friend constexpr istream& operator>> (istream &is, const Fp<MOD>& x){
        ll tmp;
        is >> tmp;
        x = Fp<MOD>(tmp);
        return is;
    }
    constexpr Fp<MOD> modpow(ll n) noexcept {
        if(n == 0) return 1;
        auto t = modpow(n>>1);
        t *= t;
        if(n & 1) t *= *this;
        return t;
    }
};
using mint = Fp<mod>;

int main(){
    ll n; cin >> n;
    map<ll, ll> a;
    rep(i, n){
        ll b; cin >> b;
        a[b]++;
    }
    ll ed = n%2;
    mint ans(1);
    for(auto i : a){
        if(i.first%2 == ed) ans = 0;
        if(i.first == 0 && i.second != 1) ans = 0;
        if(i.first != 0 && i.second != 2) ans = 0;
    }
    ans *= mint(2).modpow(n/2);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n,m;
    cin>>n>>m;
    VV vv(n);
    rep(i,n){
        ll k;
        cin>>k;
        rep(j,k){
            ll x;
            cin>>x;
            x--;
            vv[i].pb(x);
        }
    }
    ll ans=0;

    rep(i,m){
        bool like = true;
        rep(j,n){
            if(find(ALL(vv[j]),i)==vv[j].end()){
                like = false;
            }
        }
        if(like)ans++;
    }
    cout<<ans<<endl;
    return  0;
}


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

class Customer {
	int n,c;

	Customer(int n,int c) {
		this.n = n;
		this.c = c;
	}

	boolean NotUsed() {
		if (this.n==-1) return true;
		return false;
	}

	void Set(int n) {
		this.n = n;
	}

	void count() {
		this.c++;
	}
}

class List {
	Customer ct[] = new Customer[1000];

	List() {
		for (int i=0;i<1000;i++) {
			ct[i] = new Customer(-1,0);
		}
	}

	void addNewNumber(int n) {
		for (int i=0;i<1000;i++) {
			if (ct[i].NotUsed()) {
				ct[i].Set(n);
				ct[i].count();
				for (int j=i;j>0;j--) {
					if (ct[j].n<ct[j-1].n) {
						Customer t = ct[j-1];
						ct[j-1] = ct[j];
						ct[j] = t;
					} else break;
				}
				break;
			}
			else if (this.ct[i].n==n) {
				ct[i].count();
				break;
			}
		}
	}

	void Search(List list) {
		for (int i=0;i<1000;i++) {
			if (this.ct[i].NotUsed()) break;
			for (int j=0;j<1000;j++) {
				if (list.ct[j].NotUsed()) break;
				if (this.ct[i].n==list.ct[j].n) System.out.println(this.ct[i].n+" "+(this.ct[i].c+list.ct[j].c));
			}
		}
	}
}

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			List list[] = {new List(),new List()};
			while (!(buf = br.readLine()).equals("")) {
				StringTokenizer st = new StringTokenizer(buf,",");
				list[0].addNewNumber(Integer.parseInt(st.nextToken()));
			}
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf,",");
				list[1].addNewNumber(Integer.parseInt(st.nextToken()));
			}
			list[0].Search(list[1]);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16936
type Table = ([Int],[Int],[Int])
fst3 (x,_,_) = x
primes :: [Int]
primes = concatMap fst3 $ iterate sieve ([],[2],[2..])
sieve :: Table -> Table
sieve (ps,q:qs,ss)
  = let (xs,ys) = span (q*q >) ss
    in (xs,qs++xs,filter ((/= 0) . (`mod` q)) ys)

main = getContents >>= mapM_ print . map (\n -> length $ takeWhile (<=n) primes) . map read . words

Measured memory_bytes: 18700
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
int main(void) {
    int a, b, c, n;
    cin >> a >> b >> c;

    if(a >= b){
        if(a <= c){
        cout << a + b + c - c + c * 10 << endl;
        }else{
        cout << a + b + c - a + a * 10 << endl;
        }
    }else if(b >= a){
        if(b <= c){
           cout << a + b + c - c + c * 10 << endl; 
        }else{
            cout << a + b + c - b + b * 10 << endl;
        }
    }else if(b >= c){
        if(b <= a){
            cout << a + b + c - a + a * 10 << endl; 
        }else{
            cout << a + b + c - b + b * 10 << endl;
        }
    }

    return 0;
}

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

int main(){
	string s;
	cin >> s;
	int n = s.size();
	int cnt = 0;
	for (int i = 0; i < n / 2; i++){
		if (s[i] == s[n - i - 1]) continue;
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;


int b[20];


int main(){
    LL n,m;
    cin>>n>>m;
    LL ans=0;

    P p[100000];
    for(int i=0;i<n;++i){
        int a,b;
        cin>>a>>b;
        p[i].first=a;
        p[i].second=b;
    }
    sort(p,p+n);

    LL now=0;
    while(m>0){
        bool idou=false;
        if(m>p[now].second)idou=true;
        LL minu=min(p[now].second,m);
        m-=minu;
        ans+=minu*p[now].first;
        if(idou)now++;
    }

    cout<<ans<<endl;

}



Measured memory_bytes: 1792
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int K,T;
	cin >> K >> T;
	int MAX = 0;
	int A;
	for(int i=0;i<T;++i){
		cin >> A;
		MAX = max(MAX,A);
	}
	cout << max( MAX-1-(K-MAX), 0 ) << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

const int INF = 1001001001;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> dist(n, vector<int>(n,INF));
  rep(i,n) dist[i][i] = 0;
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    dist[a][b] = dist[b][a] = c;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(dist[i][j], dist[i][k]+dist[k][j]);
  vector<vector<int>> dist2(n, vector<int>(n,INF));
  rep(i,n)rep(j,n) {
    if (dist[i][j] <= l) dist2[i][j] = 1;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
  int q;
  cin >> q;
  rep(qi,q) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    int ans = dist2[s][t]-1;
    if (dist2[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

constexpr long long inv(long long x, long long m) {
  return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x;
}

const int N = 1e5 + 5, M = 1e9 + 7;
int n, k, fac[N], flag;
vector<int> g[N];

int per(int n, int k) {
  if (k > n) return flag = 1, 0;
  return k == 0 ? 1 : fac[n] * inv(fac[n - k], M) % M;
}
int dp(int u, int p) {
  int cnt = g[u].size(), ans;
  if (p == -1) {
    ans = per(k - 1, cnt);
  } else
    ans = per(k - 2, cnt - 1);
  for (auto v : g[u])
    if (v != p) {
      ans = 1LL * ans * dp(v, u) % M;
    }
  return ans;
}

int main() {
  fac[0] = fac[1] = 1;
  for (int i = 2; i < N; i++) fac[i] = 1LL * fac[i - 1] * i % M;
  // DEBUG(per(3, 3));
  cin >> n >> k;
  FI(i, 2, n) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = 1LL * dp(1, -1) * k % M;
  if (flag)
    cout << 0 << endl;
  else
    cout << ans << endl;
}

Measured memory_bytes: 10752
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] A = new int[N];

    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    sc.close();

    double result = 0.0;

    for (int i = 0; i < N; i++) {
      result +=  1 / (double) A[i];
    }

    System.out.println(1 / result);

  }

}

Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    val useMyclass = namayatsuHeap(a)
    for (i in 0 until m) {
        var max = useMyclass.mySortedList[0] / 2
        useMyclass.removeMax()
        useMyclass.addNum(max)
    }
    var total:Long = 0
    for (i in 0 until n){
        total += useMyclass.mySortedList[i]
    }
    println(total)
}



private class namayatsuHeap(mylist: MutableList<Long>) {
    val mySortedList = mylist.sortedDescending().toMutableList()
    val listSize = mySortedList.count()

    fun addNum(addedNumber: Long) {
        mySortedList += addedNumber
        val listSizuInthis = mySortedList.count()
        var uppingIndexNum = listSizuInthis - 1
        for (i in 0 until listSize) {

            val parentIndexNum = (uppingIndexNum - 1 ) / 2
            if (addedNumber > mySortedList[parentIndexNum]) {
                var tmp = mySortedList[parentIndexNum]
                mySortedList[parentIndexNum] = mySortedList[uppingIndexNum]
                mySortedList[uppingIndexNum] = tmp
                uppingIndexNum = parentIndexNum
            } else {
                break
            }
        }
    }

    fun removeMax() {
        mySortedList[0] = mySortedList[listSize - 1]
        mySortedList.removeAt(listSize - 1)
        var dawningIndexNum = 0
        for(i in 0 until listSize){
            var childIndexNumFir = 2 * dawningIndexNum + 1
            var childIndexNumSec = 2 * dawningIndexNum + 2
            var childIndexNum = 0
            if (childIndexNumFir > listSize-2){
                break
            } else if (childIndexNumFir == listSize - 2){
                childIndexNum = childIndexNumFir
            } else if (mySortedList[childIndexNumFir] >= mySortedList[childIndexNumSec]){
                childIndexNum = childIndexNumFir
            } else {
                childIndexNum = childIndexNumSec
            }
            if (mySortedList[dawningIndexNum] < mySortedList[childIndexNum]){
                var Tmp = mySortedList[childIndexNum]
                mySortedList[childIndexNum] = mySortedList[dawningIndexNum]
                mySortedList[dawningIndexNum] = Tmp
                dawningIndexNum = childIndexNum
            } else {
                break
            }
        }
    }
}

Measured memory_bytes: 78632
from random import randrange
from heapq import heapify, heappush, heappop
from time import time
K = 150
rand = lambda: randrange(1 << K)
sTime = time()
N = int(input())
S, IS, C = [], [], []
for _ in range(N):
    s, c = input().split()
    S.append(s)
    IS.append(s[::-1])
    C.append(int(c))

D = {}
r = rand()
D[r] = (0, "", 0)
H = [r]
ans = 1 << K
while H:
    r = heappop(H)
    if time() - sTime > 1.7:
        break
    d, s, c = D[r]
    if d == 0:
        for ss, cc in zip(S, C):
            m = min(len(s), len(ss))
            if s[:m] == ss[:m]:
                if abs(len(s) - len(ss)) <= 1 or len(ss) > len(s) and ss[m:] == ss[m:][::-1]:
                    ans = min(ans, c + cc)
                else:
                    if len(s) < len(ss):
                        r = rand() + (c + cc << K)
                        D[r] = (1, ss[m:], c + cc)
                        heappush(H, r)
                    else:
                        r = rand() + (c + cc << K)
                        D[r] = (0, s[m:], c + cc)
                        heappush(H, r)
    else:
        for ss, cc in zip(IS, C):
            m = min(len(s), len(ss))
            if s[:m] == ss[:m]:
                if abs(len(s) - len(ss)) <= 1 or len(ss) > len(s) and ss[m:] == ss[m:][::-1]:
                    ans = min(ans, c + cc)
                else:
                    if len(s) < len(ss):
                        r = rand() + (c + cc << K)
                        D[r] = (0, ss[m:], c + cc)
                        heappush(H, r)
                    else:
                        r = rand() + (c + cc << K)
                        D[r] = (1, s[m:], c + cc)
                        heappush(H, r)

print(ans if ans < 1 << K - 2 else -1)


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

int64_t getVal(int64_t d){
  int64_t ans = 1;
  for(int i=1;i<d;i++){
    ans *= 10;
  }
  return ans;
}

signed main() {
  int64_t n;
  cin >> n;
  
  cout << n*n << endl;
  return 0;
}




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

struct xy {
    double x;
    double y;
};

int main() {
    int n;
    cin >> n;
    vector<xy> T(n);
    rep(i, n) cin >> T[i].x >> T[i].y;


    vector<int> one_case;
    for (int i = 0; i < n; i++) { // one_case = {0,1,2,3,...n-1} とする
        one_case.emplace_back(i);
    }
    double tot = 0.0;
    do {
        double tmp = 0.0;
        for (int i = 0; i < n-1; i++) {
            tmp += sqrt((T[one_case[i]].x -T[one_case[i+1]].x)*(T[one_case[i]].x -T[one_case[i+1]].x)
                      + (T[one_case[i]].y -T[one_case[i+1]].y)*(T[one_case[i]].y -T[one_case[i+1]].y));
        }
        tot += tmp;
    } while (next_permutation(one_case.begin(), one_case.end()));

    int nn = 1;
    for (int i = 1; i <= n; i++) nn *= i;

    printf("%.10f\n", (double)tot/nn);
    
    return 0;
}

Measured memory_bytes: 3816
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
int main(){
  string x,y;
  const int INF=(1<<29);
  int a,b,i,j,dp[1010][1010];
  cin >> x >> y;
  a=x.size(),b=y.size();
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      dp[i][j]=INF;
    }
  }
  for(i=0;i<=a;i++){
    dp[i][0]=i;
  }
  for(i=0;i<=b;i++){
    dp[0][i]=i;
  }
  for(i=1;i<=a;i++){
    for(j=1;j<=b;j++){
      if(dp[i][j]>dp[i-1][j]+1){
        dp[i][j]=dp[i-1][j]+1;
      }
      if(dp[i][j]>dp[i][j-1]+1){
        dp[i][j]=dp[i][j-1]+1;
      }
      if(x[i-1]==y[j-1]){
        if(dp[i][j]>dp[i-1][j-1]){
          dp[i][j]=dp[i-1][j-1];
        }
      }
      else{
        if(dp[i][j]>dp[i-1][j-1]+1){
          dp[i][j]=dp[i-1][j-1]+1;
        }
      }
    }
  }
  printf("%d\n",dp[a][b]);
  return 0;
}


Measured memory_bytes: 7284
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=2e5+4;
int a[101];
vector<int> moves;
int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("in","r",stdin);
		freopen("out","w",stdout);
	#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];

	for(int i=n;i>=1;i--)
	{
		int o=0;
		for(int j=1;j<=i;j++)
		if(a[j]==j)o=j;

		if(o==0){cout<<-1;return 0;}

		moves.push_back(o);
		for(int j=o;j<i;j++)a[j]=a[j+1];
	}
	reverse(moves.begin(),moves.end());
	for(auto i:moves)cout<<i<<"\n";
	
	
}


Measured memory_bytes: 3636
import sys

readline = sys.stdin.readline
MOD = 998244353
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from copy import copy

    n, s = list(map(int, readline().split()))
    a = list(map(int, readline().split()))

    # iである個数
    dp = [[0] * (s + 1) for _ in range(n)]
    dp[0][0] = 2
    if a[0] <= s:
        dp[0][a[0]] = 1

    for i, x in enumerate(a[1:], 1):
        dp[i] = [y * 2 % MOD for y in dp[i - 1]]
        for j in range(s + 1):
            cur = j + x
            if cur > s:
                break
            dp[i][cur] += dp[i - 1][j]

    print(dp[-1][-1] % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 191240
n = int(input())
l_s = list(map(int,input().split()))
l_s.append(0)
l_s.sort()
ans = 0
#一番長い辺を選ぶ
#print(l_s)
for j in range(2,n):
    for i in range(j+1,n+1):
        if l_s[i] < l_s[j] + l_s[j-1]:
            
            OK = j-1
            NG = 0
            while (OK - NG) > 1:
                mid = (OK+NG)//2
                if l_s[i] < l_s[j] + l_s[mid]:
                    OK = mid
                else:
                    NG = mid
            ans = ans + j - OK 
print(ans)



Measured memory_bytes: 42844
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) // <a> must be sorted in advance

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    string S;
    cin >> A >> B >> S;

    if(S[A] != '-') {
        cout  << "No" << endl;
        return 0;
    }
    REP(i, A+B+1) {
        if(S[i]=='-' && i != A) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define SZ(c) int(c.size())
#define ff first
#define ss second
#define INF 1e9 + 1
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { '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' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
int LCM(int a, int b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
			n /= i;
		}
	}
	if (n > 2)printf("%d ", n);
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int ans = 0;
	int have = 0;
	for (int i = 0; i < n; i++)
	{
		if (have >= a[i])
			have = a[i];
		else {
			ans += a[i] - have;
			have = a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
   
    int N;
    cin>>N;
    bool flag=true;
    if(N%2==0){
    vector<int> S(N/2);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        if(a%2==0||a<=0||a>N){
            flag=false;
        }
        else{
            S.at(a/2)++;
        }
    }
        for(int i=0;i<N/2;i++){
            if(S.at(i)!=2) flag=false;
        }
        if(flag){
            int ans=1;
            for(int i=0;i<N/2;i++){
                ans=(ans*2)%1000000007;
            }
            cout<<ans<<endl;
        }
        else cout<<0<<endl;
        }
    if(N%2==1){
        vector<int> S(N/2+1);
        for(int i=0;i<N;i++){
            int a;cin>>a;
            if(a%2==1||a<0||a>N){
                flag=false;
            }
            else{
                S.at(a/2)++;
            }
        }
        if(S.at(0)!=1) flag=false;
        for(int i=1;i<N/2+1;i++){
            if(S.at(i)!=2) flag=false;
        }
        if(flag){
            int ans=1;
            for(int i=1;i<N/2+1;i++){
                ans=(ans*2)%1000000007;
            }
            cout<<ans<<endl;
        }
        else cout<<0<<endl;
    }
        
    }


Measured memory_bytes: 384
import math
import sys
from functools import lru_cache
sys.setrecursionlimit(10000000)

N = int(input())
A_list = [int(e) for e in input().split()]

#pairwise coprime …… 素因数分解したとき、共通のものが1個もない
#setwise coprime　…… 素因数分解したとき、全てで共通のものがない

#試し割の結果の辞書を求める
def make_trial_division_dict(n):
    #import math
    td_dict = dict()
    for i in range(2,n+1):
        if i not in td_dict:
            td_dict[i] = i
            for j in range(2,1+n//i):
                if j*i not in td_dict:
                    td_dict[j*i] = i
    td_dict[1] = 1
    return td_dict

#試し割結果の辞書を利用して素因数分解する
@lru_cache(maxsize=None)
def high_speed_prime_factorization(n):
    pf_list = list()
    pf_list.append(td_dict[n])
    
    if n//td_dict[n] == 1:
        if n!=1:
            pf_list.append(1)
        return pf_list
    else:
        pf_list.extend(high_speed_prime_factorization(n//td_dict[n]))
        return pf_list

td_dict = make_trial_division_dict(max(A_list))

all_pf = set()    #含まれる素因数がすべて集約される
common_pf = set() #共通する素因数が集約される
all_pf |= set(high_speed_prime_factorization(A_list[0]))
common_pf |= set(high_speed_prime_factorization(A_list[0]))
is_pairwise = True

#print(A_list[0],set(high_speed_prime_factorization(A_list[0])))

for i in range(1,len(A_list)):
    A_pf = set(high_speed_prime_factorization(A_list[i]))
    common_pf &= A_pf 
    
    #print(A_list[i],set(high_speed_prime_factorization(A_list[i])))
    
    if is_pairwise and len(all_pf&A_pf)!=1: #1は共通で含まれる
        is_pairwise = False
    else:
        all_pf |= A_pf

if is_pairwise:
    print("pairwise coprime")
elif len(common_pf) == 1: #1は共通で含まれる
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 320128
fn solve() {
    let s = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().to_owned()
    };

    match s.chars().last().unwrap() {
        's' => println!("{}es", s),
        _ => println!("{}s", s),
    }
}

fn main() {
    solve();
}


Measured memory_bytes: 2116
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

bool chmin(ll &a, ll b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  ll dp[N];
  const ll INF = 1LL << 60;
  for (int i = 0; i < N; i++) {
    dp[i] = INF;
  }
  dp[0] = 0;
  dp[1] = abs(H[0] - H[1]);
  for (int i = 2; i < N; i++) {
    chmin(dp[i], dp[i - 1] + abs(H[i] - H[i - 1]));
    chmin(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]));
  }

  cout << dp[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=100000+10;
int n,a[maxn],u[maxn],v[maxn];
int main(){
    scanf("%d",&n);
    for(int i=0,In;i<n;++i){
        scanf("%d",&In);
        if(i&1)++u[In];
        else ++v[In];
    }
    int mxu=0,mxv=0,secu=-1,secv=-1,idu,idv;
    for(int i=1;i<=100000;++i){
        if(mxu<=u[i]){
            secu=mxu;
            mxu=u[i];
            idu=i;
        }
        if(mxv<=v[i]){
            secv=mxv;
            mxv=v[i];
            idv=i;
        }
    }
    for(int i=1;i<=100000;++i){
        if(secu<u[i]&&i!=idu){
            secu=u[i];
        }
        if(secv<v[i]&&i!=idv){
            secv=v[i];
        }
    }
    if(idu==idv){
        //cout<<"fuck"<<endl;
        int ans=min(n-mxu-secv,n-mxv-secu);
        printf("%d",ans);
    }
    else {
        printf("%d",n-mxu-mxv);
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl \n
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,k;
    bool c = true;
    cin >> k >> a >> b;

    for(int i = a ;  i<= b ; i++)
        if( i % k ==0){
            c = false;
            cout << "OK";
            break;
        }
    
    if(c)
        cout << "NG";
    return 0;
}

Measured memory_bytes: 3640
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    b = LI()
    if sum(a) < sum(b):
        print(-1)
        return
    c = [a[i]-b[i] for i in range(n)]
    mc = [-i for i in c if i < 0]
    pc = [i for i in c if i >= 0]
    pc.sort(reverse = True)
    for i in range(1,len(pc)):
        pc[i] += pc[i-1]
    s = sum(mc)
    if s == 0:
        print(0)
        return
    for i in range(len(pc)):
        if pc[i] >= s:
            break
    print(len(mc)+i+1)
    return

#Solve
if __name__ == "__main__":
    solve()


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int n, m;
  cin >> n >> m;
  int x[n+1], y[m+1];
  cin >> x[0] >> y[0];
  for(int i=0; i<n; i++) cin >> x[i+1];
  for(int i=0; i<m; i++) cin >> y[i+1];
  sort(x, x+n+1);
  sort(y, y+m+1);
  string ans;
  if(x[n]>=y[0]) ans = "War";
  else ans = "No War";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256