akhauriyash/Code-Regression huggingface dataset:
import java.util.*;


public class Main {

    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] sum = new long[N+1];
        for (int i = 1; i <= N; i++) {
            sum[i] = sum[i-1]+i;
            sum[i] %= MOD;
        }
        long ans = 0;
        for (int i = K; i <= N; i++) {
            long max = sum[N]-sum[N-i];
            if (max < 0) max += MOD;
            long min = sum[i-1];
            long tmp = max-min;
            if (tmp < 0) tmp += MOD;
            tmp += 1;
            tmp %= MOD;

            ans += tmp;
            ans %= MOD;
        }

        ans++;
        ans %= MOD;

        System.out.println(ans);
    }
}


Measured memory_bytes: 28808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (1ll<<31)-1;

ll gcd(ll a,ll b){
    if(a*b==0) return a+b;
    if(b<a) swap(a,b);
    ll r = a%b;
    while(r){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

struct LazySegment {
    int n;
    vector<ll> node,lazy;

    LazySegment(int N){
        n = 1;
        while(n < N) n *= 2;

        // ノード数は ceil(log2(N))^2 * 2 (末端ノード数が2べきとなるよう調整)
        node.assign(2*n-1,0);
        lazy.assign(2*n-1,0);
    }

    void eval(int k,int l,int r){ // k番ノードについて遅延評価
        if(lazy[k]){
            node[k] = lazy[k];

            // 末端ノードでなければ子ノードに伝播
            if(r-l>1){
                lazy[2*k+1] = lazy[k];
                lazy[2*k+2] = lazy[k];
            }
            lazy[k] = 0;
        }
    }

    void update(int a,int b,ll x,int k=0,int l=0,int r=-1){ // [a,b)の各要素をxに更新
        if(r<0) r = n;

        eval(k,l,r);

        // 含まない
        if(b<=l || r<=a) return;
        // 完全に含む
        if(a<=l && r<=b){
            lazy[k] = x;
            eval(k,l,r);
        }else{
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            node[k] = min(node[2*k+1],node[2*k+2]);
        }
    }

    ll range_gcd(int a,int b,int k=0,int l=0,int r=-1){ // [a,b)の要素の総和を返す
        if(r<0) r = n;

        eval(k,l,r);

        // 含まない
        if(b<=l || r<= a) return 0;
        // 完全に含む
        if(a<=l && r<=b) return node[k];

        ll vl = range_gcd(a,b,2*k+1,l,(l+r)/2);
        ll vr = range_gcd(a,b,2*k+2,(l+r)/2,r);
        return gcd(vl,vr);
    }
};

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a[i];
    }
    LazySegment tree(n);
    
    for(int i = 0;i < n;i ++) tree.node[i+tree.n-1] = a[i];
    for(int i = tree.n-2;i >= 0;i --) tree.node[i] = gcd(tree.node[2*i+1],tree.node[2*i+2]); 

    for(int i = 0;i < n;i ++){
        int gl,gr,g;
        gl = i?tree.range_gcd(0,i):0;
        gr = i<n-1?tree.range_gcd(i+1,n):0;

        g = gcd(gl,gr);

        ans = max(ans,g);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>
#include <stdlib.h>

int isEven(int *, int);
void devTwo(int *, int);

int
main(){
  int i, n, a[200], count;
  scanf("%d", &n);
  if(n < 0 || 200 < n)
    return 1;
  
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
    if(a[i] < 1 || 1000000000 < a[i])
      return 1;
  }
  count = 0;
  while(!isEven(a, n)){
    devTwo(a, n);
    count += 1;
  }

  printf("%d\n",count);

  return 0;
}

/*
 * even 0
 * odd 1
 */
int isEven(int *array, int argc){
  int i;
  for (i = 0; i < argc; i++){
    if ( (array[i])%2 || !(array[i]))
      return 1;
  }
  return 0;
}


void devTwo(int *array, int argc){
  int i;
  for (i = 0; i < argc; i++){
    array[i] = array[i] / 2;
  }
}

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

int main() {
    long long int n, k, high = 1e12+10, low = -1;
    cin >> n >> k;
    int a[n], f[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < n; ++i) cin >> f[i];
    sort(a, a+n);   // コスト:低-高
    sort(f, f+n);   // 食べにくさ:低-高
    /* コスト高*食べにくさ低　が修行制限回数で時間t以内に出来るか二部探索 */
    while(1) {
        long long int limit_t = (high + low)/2, limit_k = k;
        for(int i = 0; i < n; ++i) {
            if(limit_k >= 0) {
                /* [コスト*食べにくさ]を時間内にするための修行数 */
                long long int num_syugyo = max(a[n-i-1] - limit_t/f[i], (long long int)0);
                if(limit_k < num_syugyo) {
                    low = limit_t;
                    break;
                } else {
                    limit_k -= num_syugyo;
                }
            }
        }
        /* lowが更新されてなかったらhighを更新 */
        if(low != limit_t) {
            high = limit_t;
        }
        if(abs(high - low) < 2) break;
    }
    cout << high << '\n';
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define D(i, a, b) for (int i = (a); i >= (b); i--)
#define R(i, a, b) for (int i = (a); i < (b); i++)
#define N 500000
int main()
{
#ifdef DOC
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, l; cin >> n >> l;
  vector<string> res(n);
  R(i,0,n){
    string t; cin >> t;
    res.push_back(t);    
  }
  sort(res.begin(), res.end());
  for(string k : res) cout << k;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    char c;
    int a, b;

    cin >> a >> c >> b;

    cout << (c == '+' ? a+b : a-b);

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

map<ll,int> mp;

int n,m;
ll s,ans;

int main()
{
    scanf("%d%d",&n,&m);
    mp[0]=1;
    for(int i=1,x;i<=n;i++)
    {
        scanf("%d",&x);
        s+=x;s%=m;
        ans+=mp[s];
        mp[s]++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
    lli a, b, n;
    cin>>a>>b>>n;
    vll A(a), B(b);
    loop(i, 0, a)
        cin>>A[i];
    loop(i, 0, b)
        cin>>B[i];
    lli ans = *min_element(A.begin(), A.end()) + *min_element(B.begin(), B.end());
    loop(i, 0, n){
        lli x, y, c;
        cin>>x>>y>>c;
        lli temp = A[x-1] + B[y-1] - c;
        ans = min(temp, ans);
    }
    cout<<ans<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}

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

int isPrime(int);

int main(){
  int n, c = 0,i = 0;
  scanf("%d",&n);
  int array[n];
  
  for(i = 0; i < n; i++) scanf("%d", &array[i]);

  for(i = 0; i < n; i++){
    if(isPrime(array[i]) == 1) c++;
  }
  printf("%d\n",c);

  return 0;
}

int isPrime(int x){
  int i;
  if(x == 2) return 1;
  else if(x < 2 || x % 2 == 0) return 0;
  else{
    i = 3;
    while(i <= sqrt(x)){
      if(x % i == 0) return 0;
      i = i + 2;
    }
    return 1;
  }
  
}
	  



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

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline

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

if sum(a) > n:
    print('-1')
else:
    print(n - sum(a))


Measured memory_bytes: 68836
#include <stack>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
    
    int n;
    while(cin >> n && n != 0)
    {
        int a[11][11];
        for(int i = 0;i < n;i++)
        {
            for(int j = 0; j<n;j++)
            {
                cin >> a[i][j];
            }
        }
        for(int i = 0; i<n;i++)
        {
            a[i][n] = 0;
            a[n][i] = 0;
            for(int j = 0;j < n;j++)
            {
                a[i][n] += a[i][j];
                a[n][i] += a[j][i];
            }
        }
        a[n][n] = 0;
        for(int i = 0;i<n;i++)
        {
            a[n][n] += a[i][n];
        }
        for(int i = 0; i< n+1;i++)
        {
            for(int j = 0; j<n+1;j++)
            {
                cout << setw(5) << right << a[i][j];
            }
            cout <<endl;
        }
    }
    return 0;
}

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

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

  if( x-r >= 0 && x+r <= W && y-r>=0 && y+r<=H)  cout << "Yes" << endl;
  else cout << "No" <<endl;
}



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

int main()
{
    int i,j;
    char a[3][3];
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    cout << a[0][0] << a[1][1] << a[2][2] << endl;

    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#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 all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main() {
	string s;
	cin >> s;
	cout << (s[0]!=s[1]||s[1]!=s[2]?"Yes":"No") << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>



int main()
{
	int n ,m ;
	int cnt1 ,cnt_other ;


	while( 1 )
	{
		scanf( "%d" ,&n ) ;

		if( n == 0 )
		{
			return 0 ;
		}


		cnt1 = cnt_other = 0 ;



		int i ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%d" ,&m ) ;


			if( m == 1 )
			{
				++cnt1 ;
			}

			else if( m > 0 )
			{
				++cnt_other ;
			}
		}


		if( cnt_other == 0 )
		{
			puts( "NA" ) ;
		}

		else
		{
			printf( "%d\n" ,cnt1 + cnt_other + 1 ) ;
		}
	}
}

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

#define ll long long

int main(void){
    ll n;
    cin >> n;
    vector<ll>a(n+1),b(n);
    for(int i=0;i<n+1;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    ll ans = 0;
    for(int i=n-1;0<=i;i--){
        if(a[i+1] <= b[i]){
            b[i] -= a[i+1];
            ans += a[i+1];
            a[i+1] = 0;
            if(a[i] <= b[i]){
                ans += a[i];
                a[i] = 0;
            }else{
                a[i] -= b[i];
                ans += b[i];
            }
        }else{
            a[i+1] -= b[i];
            ans += b[i];
        }
        
    //     for(int j=0;j<n+1;j++){
    //         cout << a[j] << ' ';
    //     }
    //     cout << endl << endl;
    //     for(int j=0;j<n;j++){
    //         cout << b[j] << ' ';
    //     }
    //     cout << endl;
    }
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}

// 本体

struct edge {
	ll to, cost, time;
	bool operator<(const edge &e) {
		return (*this).time < e.time;
	}
};

constexpr ll MAXC = 50 * 52;
ll d[50][MAXC + 1];
typedef pair<ll, P> node;

int main() {
	IOS();
	ll n, m, s;
	cin >> n >> m >> s;
	vector<vector<edge>> e(n);
	for (int i = 0; i < m; i++) {
		ll a, b, c, t;
		cin >> a >> b >> c >> t;
		a--;
		b--;
		e[a].push_back((edge){b, c, t});
		e[b].push_back((edge){a, c, t});
	}
	vector<P> c(n);
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		c[i] = P(a, b);
	}
	s = min(s, MAXC);
	Fill(d, INF);
	d[0][s] = 0;
	priority_queue<node, vector<node>, greater<node>> que;
	que.push(make_pair(0, P(0, s)));
	while (!que.empty()) {
		auto t = que.top();
		que.pop();
		ll dif = t.first; // 合計時間
		ll pos = t.second.first;
		ll sum = t.second.second; //所持銀
		for (ll i = 0; i < e[pos].size(); i++) {
			edge ne = e[pos][i];
			if (sum >= ne.cost && dif + ne.time < d[ne.to][sum - ne.cost]) {
				d[ne.to][sum - ne.cost] = dif + ne.time;
				que.push(make_pair(d[ne.to][sum - ne.cost], P(ne.to, sum - ne.cost)));
			}
		}
		ll newsum = min(MAXC, c[pos].first + sum);
		ll newdif = dif + c[pos].second;
		if (sum != newsum && newdif < d[pos][newsum]) {
			d[pos][newsum] = newdif;
			que.push(make_pair(d[pos][newsum], P(pos, newsum)));
		}
	}
	for (int i = 1; i < n; i++) {
		ll ans = INF;
		for (int j = 0; j <= MAXC; j++) {
			ans = min(ans, d[i][j]);
		}
		dump(ans);
	}
}


Measured memory_bytes: 7332
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
using namespace std;

int n, a, x[51];
long long dp[51][51][2501];

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> a;
	for(int i = 1; i <= n; i++) cin >> x[i];
	for(int i = 0; i <= n; i++) dp[0][i][0]++;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			for(int k = 0; k <= n * a; k++){
				dp[i][j][k] = dp[i][j - 1][k];
				if(k - x[j] > -1) dp[i][j][k] += dp[i - 1][j - 1][k - x[j]];
			}
	long long sum = 0;
	for(int i = 1; i <= n; i++) sum += dp[i][n][a * i];
	cout << sum << "\n";
	return 0;
}

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

int main()
{
	int m, n;
	cin >> n >> m;
	int sum = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= (sum / (4.0 * m))) {
			cnt++;
		}
	}
	cout << ((cnt >= m) ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int n,d;
	cin>>n>>d;
	int x;
	vector<vector<int>> X;
	rep(i,n){
		X.push_back(vector<int>());
		rep(j,d){
			cin>>x;
			X[i].push_back(x);
		}
	}
	int ans = 0;
	rep(i,n)rep(j,n){
		if(i>=j) continue;
		int memo = 0;
		rep(k, d){
			memo += pow(X[i][k] - X[j][k], 2);
		}
		if((int)sqrt(memo)*(int)sqrt(memo) == memo){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import queue
n,m =  map(int,input().split())
A = [[]for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)

S = [-1 for _ in range(n)]
q = queue.Queue()
for v in A[0]:
    q.put((0,v))
while not q.empty():
    u,v = q.get()
    if S[v] == -1:
        S[v]=u #visit
        for nex in A[v]:
            if S[nex] == -1: #unvisited
                q.put((v,nex))
S[0]= -2
if not -1 in S:
    print('Yes')
    for i in range(1,n):
        print(S[i]+1)
else:
    print('No')  

Measured memory_bytes: 45288
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int N; cin >> N;
	int* W = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}
	int a = 0, b = 0;
	for (int i = 0; i < N; i++) {
		b += W[i];
	}

	int m = b;
	for (int i = 0; i < N; i++) {
		a += W[i];
		b -= W[i];
		m = min(m, abs(b - a));
	}

	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())

R_list = [0]*N
G_list = [0]*N
B_list = [0]*N

for key,val in enumerate(S):
    if val=='R':
        R_list[key] = R_list[key-1]+1
        G_list[key] = G_list[key-1]
        B_list[key] = B_list[key-1]
    elif val=='G':
        R_list[key] = R_list[key-1]
        G_list[key] = G_list[key-1]+1
        B_list[key] = B_list[key-1]
    elif val=='B':
        R_list[key] = R_list[key-1]
        G_list[key] = G_list[key-1]
        B_list[key] = B_list[key-1]+1

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]==S[j]:
            continue
        a=2*(j+1)-(i+1)-1
        check = [S[i],S[j]]
        if 'R' not in check:
            ans += R_list[-1]-R_list[j]
            if a<N and S[a]=='R':
                ans -= 1
        elif 'G' not in check:
            ans += G_list[-1]-G_list[j]
            if a<N and S[a]=='G':
                ans -= 1
        elif 'B' not in check:
            ans += B_list[-1]-B_list[j]
            if a<N and S[a]=='B':
                ans -= 1
print(ans)


Measured memory_bytes: 80600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define double ld
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ifstream in("input.txt");ofstream out("output.txt");
const int inf=1e18;
int n,m;
vector<vector<int> > g;
vector<int> dp;///length of the longest path going down from v


void dfs(int v)
{
    int maxi=-1;
    for(int i=0;i<g[v].size();i++)
    {
        int to=g[v][i];
        if(dp[to]==-1)
            dfs(to);
        maxi=max(dp[to],maxi);
    }
    dp[v]=maxi+1;
}

void init()
{
    cin>>n>>m;
    g.resize(n);
    dp.resize(n,-1);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
    }
    for(int i=0;i<n;i++)
    {
        if(dp[i]==-1)
            dfs(i);
    }
}

void solve()
{
    int best=0;
    for(int i=0;i<n;i++)
    {
        best=max(best,dp[i]);
    }
    cout<<best;
}
signed main()
{
    init();
    solve();
    return 0;
}


















Measured memory_bytes: 9216
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 3e18;
const ll linf = 3e18;
const double eps = 1e-9;

int N, M, K;
int A[20005];
int memo[20005];

int rec(int now)
{
    if (~memo[now]) return memo[now];

    int res = inf;
    int mi = inf, ma = -inf;
    
    for (int i = 0; i < min(N - now, M); ++i) {
        mi = min(mi, A[now + i]);
        ma = max(ma, A[now + i]);

        res = min(res, K + (ma - mi) * (i + 1) + rec(now + i + 1));
    }

    if (res == inf) res = 0;

    return memo[now] = res;
}

signed main()
{ // #define int long long ?????????????????§scanf???????????¨???????????????????????\?????????????????????
    cin >> N >> M >> K;

    rep(i, N) {
        cin >> A[i];
    }

    memset(memo, -1, sizeof (memo));

    cout << rec(0) << endl;
}

Measured memory_bytes: 2724
#include<bits/stdc++.h>
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>

using namespace std;

#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;
const ll inf = 1000000000000000000;
using namespace std;
#define int long long
//BEGIN CUT HERE
struct RUP{
  int n;
  vector<int> dat,laz;
  const int def=INT_MAX;
  RUP(){}
  RUP(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,def);
    laz.clear();
    laz.resize(2*n-1,-1);
  }
  inline void eval(int len,int k){
    if(laz[k]<0) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=laz[k];
      laz[k*2+2]=laz[k];
    }
    dat[k]=laz[k];
    laz[k]=-1;
  }
  int update(int a,int b,int x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b) return laz[k]=x;
    eval(r-l,k);
    dat[k]=min(update(a,b,x,k*2+1,l,(l+r)/2),
	       update(a,b,x,k*2+2,(l+r)/2,r));
    return dat[k];
  }
  int query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
  void update(int a,int b,int x){
    update(a,b,x,0,0,n);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};

signed main(){
    
    int n,q;
    cin>>n>>q;
    RUP h(n);
    RUP w(n);
    int hm = n;
    int wm = n;

    ll ans = 0;
    h.update(0,n,n-2);
    w.update(0,n,n-2);

    rep(loop , 0 , q){

        int t , x;
        cin >> t >> x;

        if (t == 1){
            int now = h.query(x,x+1);
            ans += now;
            if (hm > x){
                hm = x;
                w.update(0,now+2,x-2);
            }
        }else{
            int now = w.query(x,x+1);
            ans += now;
            if (wm > x){
                wm = x;
                h.update(0,now+2,x-2);
            }
        }
    }

    ll pl = (n-2);
    pl *= (n-2);
    cout << pl-ans << endl;

}

Measured memory_bytes: 19612
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N, M, Q;
int table[505][505], sum[505][505];

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    cin >> N >> M >> Q;
    vector<int> p(Q), q(Q);
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        table[l][r]++;
    }
    REP(i, Q) cin >> p.at(i) >> q.at(i);
    FOR(i, 1, N + 1) {
        FOR(j, 1, N + 1) { sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + table[i][j]; }
    }

    REP(i, Q) { cout << sum[q[i]][q[i]] - sum[q[i]][p[i] - 1] - sum[p[i] - 1][q[i]] + sum[p[i] - 1][p[i] - 1] << endl; }

    return 0;
}


Measured memory_bytes: 3712
using System;

class project{
static void Main(){
  
  string [] a = Console.ReadLine().Split(' ');
  int n2 = int.Parse(a[0]);
  int n1 = int.Parse(a[1]);
 
  string result = "";
  for(int i=n1-(n2-1);i<n1+n2;i++){
  result += i.ToString() + " ";
  }
  
  Console.WriteLine(result.Trim());
}

}

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

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; i++ ){
      cout << i << endl;
    }
    for ( int i = b - k + 1; i <= b; i++ ){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
def move_rec(x,y,dp1,dp2,h,w)
	if x+1 != h &&dp1[x+1][y] == "#"
		dp2[x+1][y] = "#"
		move_rec(x+1,y,dp1,dp2,h,w)
	elsif y+1 != w && dp1[x][y+1] == "#"
		dp2[x][y+1] = "#"
		move_rec(x,y+1,dp1,dp2,h,w)
	end
end

h,w = gets.split.map(&:to_i)

dp1 = Array.new(h){Array.new(w)}
dp2 = Array.new(h){Array.new(w){'.'}}

for i in 0 .. h-1
	dp1[i] = gets.chomp.split("")
end 

dp2[0][0] = "#"
move_rec(0,0,dp1,dp2,h,w)

if dp1 == dp2
	puts "Possible"
else
	puts "Impossible"
end

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define all(x) (x).begin(), (x).end()
#define fap(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const int inf = 0x3f3f3f3f;
const ll INF = 2e18;

int main() {
	FastIO;

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

	vector<int> b = a;
	sort(all(b));
	for(int &x : a) x = lower_bound(all(b), x) - b.begin();
	
	int res = 0;
	for(int i=0; i<n; ++i) res += (a[i] % 2 != i % 2);
	res /= 2;

	cout << res << "\n";

	return 0;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int sum = 0;
		for(int i = 1; i <= N; i++) {
			sum += i;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21332
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

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

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };




long long int func(long long int n, long long int x,long long int size[],long long int pa[]) {
	if (x <= 0) {
		return 0;
	}
	if (n == 0) {
		return 1;
	}
	if (x <= size[n-1]+1) {
		return func(n - 1, x - 1, size,pa);
	}
	else if (x <=2*size[n-1]+2 ) {
		return func(n - 1, x - 1, size, pa) + 1 + func(n - 1, x - 2 - size[n - 1], size, pa);
	}
	else {
		return pa[n];
	}
}


int main(void) {
	long long int n, x;
	long long int size[51];
	long long int pa[51];

	cin >> n >> x;

	size[0] = 1;
	pa[0] = 1;
	FOR(i, 1, n) {
		size[i] = 2 * size[i - 1] + 3;
		pa[i] = 2 * pa[i - 1] + 1;
	}

	printf("%lld\n", func(n, x, size, pa));

	//cout << func(n,x,size,pa) << endl;

	

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<math.h> 
#include<algorithm> 
#include<stdio.h> 
#include<sstream>
#include<fstream>  
using namespace std; 
typedef long long ll; 
typedef long double ld; 

int ceil(int a, int m){
    // division of a and m
    if(a % m == 0){
        return a/m; 
    }
    else{
        return a/m + 1; 
    }
}

vector<int> sort(vector<int> arr){
    sort(arr.begin(), arr.end()); 
    return arr; 
}

int minInVector(vector<int> arr){
    int mins = 1e9; 
    for(int i = 0; i<arr.size(); i++){
        mins = min(mins, arr[i]); 
    }
    return mins; 
}

int maxInVector(vector<int> arr){
    int maxs = -1; 
    for(int i = 0; i<arr.size(); i++){
        maxs = max(maxs, arr[i]); 
    }
    return maxs; 
}

bool checkElement(vector<int> arr, int k){
    for(int i = 0; i<arr.size(); i++){
        if(arr[i] == k){
            return true; 
        }
    }
    return false; 
}



const int MOD = 1e9 + 7; 

int main(){

ios_base::sync_with_stdio(false);
cin.tie(NULL); 

char nl = '\n'; 
char bl = ' ';
/*
For array arr use the following preamble to sort
int diff = sizeof(arr)/sizeof(arr[0]); 
sort(arr, arr + diff); 

*/


int n; 
cin >> n; 
vector<int> ins; 
for(int i = 0; i<n; i++){
    int a; 
    cin >> a; 
    ins.push_back(a); 
}
int cnt = 0; 

for(int i = 0; i<ins.size(); i++){
    for(int j = i+1; j<ins.size(); j++){
        for(int z = j+1; z<ins.size(); z++){
            if(i != j && j!=z){
                if((ins[i] + ins[j] > ins[z]) && (ins[i] + ins[z] > ins[j]) && (ins[j] + ins[z] > ins[i]) && (ins[i] != ins[j]) && (ins[j] != ins[z]) && (ins[i] != ins[z])){
                    cnt++; 
                    //cout << i << bl << j << bl << z << nl; 
                    //cout << ins[i] << bl << ins[j] << bl << ins[z] << nl; 
                }
            }
        }
    }
}
cout << cnt; 
}



Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
    double weight;
    while(scanf("%lf",&weight)!=EOF){
     if(weight<=48)
     printf("light fly\n");
     else if(weight>48 && weight<=51)
     printf("fly\n");
     if(weight>51 && weight<=54)
     printf("bantam\n");
     if(weight>54 && weight<=57)
     printf("feather\n");
     if(weight>57 && weight<=60)
     printf("light\n");
     if(weight>60 && weight<=64)
     printf("light welter\n");
     if(weight>64 && weight<=69)
     printf("welter\n");
     if(weight>69 && weight<=75)
     printf("light middle\n");
     if(weight>75 && weight<=81)
     printf("middle\n");
     if(weight>81 && weight<=91)
     printf("light heavy\n");
     if(weight>91)
     printf("heavy\n");
    }
        return 0;
    
}



Measured memory_bytes: 2024
#include<bits/stdc++.h>
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

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

    int A, B;
    cin >> A >> B;
    if (A - B*2 >= 0){
        cout << A - B*2 <<  endl;
    } else {
        cout << 0 <<  endl;
    }

}

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

int main() {
  int N;
  int K;
  int A = 1;
  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    if(A>K){
      A += K;
    }
    else{
      A *= 2;
    }
  }
  cout << A << endl;
}

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)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int h, w;
char s[55][55];
int ans;
int d[55][55];

bool bfs(int x, int y){
    queue<P> q;
    q.push(make_pair(x, y));
    ans = 1;
    while(!q.empty()){
        int tx = q.front().first, ty = q.front().second;
        q.pop();
        rep(i, 4){
            int nx = tx + dx[i], ny = ty + dy[i];
            if (nx<0 || h<=nx || ny<0 || w<=ny) continue;
            if (s[nx][ny]=='#' or d[nx][ny]!=inf) continue;
            d[nx][ny] = d[tx][ty] + 1;
            q.push(P(nx, ny));
        }
    }
}

int main() {
    cin >> h >> w;
    int x_cnts = 0;
    rep(i, h)rep(j, w) {
        cin >> s[i][j];
        if (s[i][j] == '#') x_cnts++;
        d[i][j] = inf;
    }
    d[0][0] = 1;
    bfs(0, 0);
    if (d[h-1][w-1]==inf) cout << -1 << endl;
    else cout << h*w - d[h-1][w-1] - x_cnts << endl;
    return 0;
}

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// hidden common codes{{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(lint ngtkana_is_a_genius=0; ngtkana_is_a_genius<(lint)k; ngtkana_is_a_genius++)
using lint=long long;
using ld=long double;
template<class T> using numr=std::numeric_limits<T>;
struct input_t {
    template<class T> operator T() {
        T t;
        std::cin>>t;
        return t;
    }
} input;
#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    lint n=input,m=input;
    if(n%2){
        for(lint i=0;i<m;i++){
            std::cout<<(i+1)<<' '<<2*m-i<<'\n';
        }
    }else{
        bool ckd=false;
        for(lint i=0,d=1;i<m;i++,d+=2){
            if (n<=2*d && !std::exchange(ckd,true)) {
                d++;
            }
            lint l=m-i;
            lint r=l+d;
            assert(1<=l&&l<=r);
            std::cout<<l<<' '<<r<<'\n';
        }
    }
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;


void solve() {
	int n, k;
	cin >> n >> k; 
	ll cnt = 0;
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		if(x >=k) cnt++;
		}
		cout << cnt << endl;
}


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}
 
 
 



Measured memory_bytes: 3580
#include <stdio.h>

#define MAX 100000

int main(void)
{
  int N;
  char S[MAX];
  int count=1;
  char tmp;
  int i;

  scanf("%d",&N);
  scanf("%s",S);

  tmp = S[0];
  for(i=1;i<N;i++){
    if(tmp!=S[i]){
      tmp = S[i];
      count++;
    }
  }
  printf("%d\n",count);


  return 0;
}



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

int main(){
    char a[3000],b[3000];
    cin>>a;
    cin>>b;
    int i,j,n,m;
    n = strlen(a);
    m = strlen(b);
    int dp[n+1][m+1];
    for(i=0;i<=n;i++){
        for(j=0;j<=m;j++){
            if(i==0||j==0){
                dp[i][j]=0;
            }
            else{
                if(a[i-1]==b[j-1]){
                    dp[i][j] = dp[i-1][j-1]+1;
                }
                else{
                    dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
    }
    i=n;
    j=m;
    char c[3000];
    int k=0;
    while(i>0 && j>0){
        if(a[i-1]==b[j-1]){
            // cout<<a[i-1];
            c[k]=a[i-1];
            k+=1;
            i-=1;
            j-=1;
        }
        else{
            if(dp[i][j]==dp[i-1][j]){
                i-=1;
            }
            else{
                j-=1;
            }
        }
    }
    for(i=k-1;i>=0;i--){
        cout<<c[i];
    }
    cout<<"";
    // cout<<dp[n][m];
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
#define INF 1e8


int main(){
	while(true){
		int pl;
		cin >> pl;			if(!pl) return 0;
		int sump,maxp,minp;
		sump=0;maxp=0;minp=INF;
		REP(pi,pl){
			int p;
			cin>>p;
			sump+=p;
			maxp=max(maxp,p);
			minp=min(minp,p);
		}
		cout<<INT((sump-minp-maxp)/(pl-2))<<endl;

	}
}

Measured memory_bytes: 1160
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a, ll b) {
    ll g = gcd(a,b);
    return a*b/g;
}

int main(void) {
    ll A, B, C, D, cnt = 0;
    cin >> A >> B >> C >> D;

    // C
    cnt += B/C - (A-1)/C;
    // D
    cnt += B/D - (A-1)/D;
    // lcm
    ll m = lcm(C,D);
    cnt -= B/m - (A-1)/m;

    cnt = B-A+1 - cnt;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
tf = [False for _ in range(n)]
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in a:
        tf[j-1] = True
cnt = 0
for k in tf:
    if not k:
        cnt += 1
print(cnt)

Measured memory_bytes: 9192
#include <iostream>
#include <string>
using namespace std;
int main(void) {
	int max, sum, count=0;
	cin >> max >> sum;
	for (int i = 0; i <= max; i++) {
		for (int j = 0; j <= max; j++)
		{
			if (sum - i - j <= max && 0 <= sum - i - j)
				count++;
		}
	}

	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,l,e=0,c=0;
    char s[5];
    scanf("%s",&s);
    for(i=0;i<3;i++){
        if(e==0&&s[i]=='R'){
           e=1;
           c=1;
        }
        else if(e==1&&s[i]=='R'){
           c++;
        }
        else if(e==1&&s[i]=='S'){
           break;
        }
    }
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    int x, n;
    cin >> x >> n;
    set<int> st;
    rep (i, n) {
        int y;
        cin >> y;
        st.insert(y);
    }

    int diff = inf;
    int ans = inf;
    for (int i = -2000; i <= 2000; i++) {
        if (st.count(i)) continue;
        int di = abs(x - i);
        if (di < diff) {
            diff = di;
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
/*
AizuOnline A1202
Title
*/
#include <stdio.h>
// Select Below
#include <stdlib.h>
//#include <string.h>
#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int n;
double cx[100],cy[100],s[100];

double x[200],y[200];
//
int d_comp(const void *x , const void *y)
{
  return(*(double *)x > *(double *)y);
}
int inrects(double x,double y)
{
  int i;

  for(i=0;i<n;i++)
    if(x >= cx[i]-s[i] && x<= cx[i]+s[i] && y >= cy[i]-s[i] && y<= cy[i]+s[i])
      return(-1);
	
  return(0);
}
printx()
{ int i;
  for(i=0;i<6;i++)
    printf("%.2lf:",x[i]);
  printf("\n");
}
main()
{
  int i,j,cnt,tim;
  double ssum;

  tim=0;
  while(scanf("%d",&n) && n)
    {
      cnt = 0;
      for(i=0;i<n;i++)
	{
	  scanf("%lf %lf %lf",&(cx[i]),&(cy[i]),&(s[i]));
	  x[cnt]=cx[i]+s[i];
	  x[cnt+1]=cx[i]-s[i];
	  y[cnt]=cy[i]+s[i];
	  y[cnt+1]=cy[i]-s[i];
	  cnt+=2;
	}
      
      
      qsort(x,cnt,sizeof(double),d_comp);
      qsort(y,cnt,sizeof(double),d_comp);
      

      ssum=0.0;
      for(i=0;i<cnt-1;i++)
	for(j=0;j<cnt-1;j++)
	  {

	    if(inrects((x[i]+x[i+1])/2,(y[j]+y[j+1])/2))
	      {

	      ssum += ((x[i+1]-x[i])*(y[j+1]-y[j]));
	      }
	  }
      tim++;
      printf("%d %.2lf\n",tim,ssum);
    }
return(0);
}

Measured memory_bytes: 708
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

char fi[22][22];
int H, W;
int ans = 0;

int check(int sh, int sw){
    int memo[22][22];
    REP(i,22) REP(j,22) memo[i][j] = INF;
    priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> q;
    q.emplace(0, sh, sw);
    memo[sh][sw] = 0;
    while(!q.empty()){
        ll c;
        int h, w;
        tie(c, h, w) = q.top(); q.pop();
        REP(i,4){
            int nh = h + dy[i];
            int nw = w + dx[i];
            if(!(0 <= nh && nh < H && 0 <= nw && nw < W)) continue;
            if(fi[nh][nw] == '#') continue;
            if(memo[nh][nw] > c + 1){
                memo[nh][nw] = c + 1;
                q.emplace(c + 1, nh, nw);
            }
        }
    }
    int res = 0;
    REP(i,H) REP(j,W){
        if(memo[i][j] != INF) chmax(res, memo[i][j]);
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    REP(i,H) REP(j,W) cin >> fi[i][j];
    REP(i,H) REP(j,W){
        if(fi[i][j] == '#') continue;
        int tmp = check(i,j);
        chmax(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def MaximumProfit(l, N):
    maxv = -1000000000
    minv = l[0]
    for i in range(1,N):
        maxv = max(maxv, l[i] - minv)
        minv = min(minv, l[i])
    print(maxv)

def main():
    # input
    N = int(input())
    l = [int(input()) for i in range(N)]
    # solver
    MaximumProfit(l, N)

if __name__ == '__main__': main()



Measured memory_bytes: 13600