akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int M, N;
int d[260];
bool done[260], visited[260];
vector<int> g[260];

int dfs(int p) {
	if (visited[p]) return 0;
	if (p == N + 1) return 1;
	
	visited[p] = true;
	
	REP(i, g[p].size()) if (dfs(g[p][i])) return 1;
	return 0;
}

int main() {
	while (cin >> M, M) {
		cin >> N;
		
		memset(d, 0, sizeof(d));
		REP(i, N) scanf("%d", d + i + 1);
		
		REP(i, 260) g[i].clear();
		
		REP(i, N + 1) {
			memset(done, 0, sizeof(done));
			FOR(j, 1, M + 1) {
				int p = min(i + j, N + 1);
				p = max(0, min(p + d[p], N + 1));
				done[p] = true;
			}
			
			REP(j, N + 2) if (done[j]) g[i].push_back(j);
		}
		
		bool ans = true;
		
		memset(done, 0, sizeof(done));
		
		queue<int> que;
		que.push(0);
		done[0] = true;
		
		while (!que.empty()) {
			int p = que.front(); que.pop();
			
			memset(visited, 0, sizeof(visited));
			if (!dfs(p)) ans = false;
			
			REP(i, g[p].size()) if (!done[g[p][i]]) {
				done[g[p][i]] = true;
				que.push(g[p][i]);
			}
		}
		
		puts(ans ? "OK" : "NG");
	}
	return 0;
}

Measured memory_bytes: 3172
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.nextLine());
    int B = Integer.parseInt(sc.nextLine());
    int h = Integer.parseInt(sc.nextLine());
    
    System.out.println(((A + B) * h) / 2);
  }
}

Measured memory_bytes: 20692
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int x;
	cin >> x;
	if(x >= 1800 && x <= 1999){
		cout << 1 << endl;
	}
	else if(x >= 1600 && x <= 1799){
		cout << 2 << endl;
	}
	else if(x >= 1400 && x <= 1599){
		cout << 3 << endl;
	}
	else if(x >= 1200 && x <= 1399){
		cout << 4 << endl;
	}
	else if(x >= 1000 && x <= 1199){
		cout << 5 << endl;
	}
	else if(x >= 800 && x <= 999){
		cout << 6 << endl;
	}
	else if(x >= 600 && x <= 799){
		cout << 7 << endl;
	}
	else if(x >= 400 && x <= 599){
		cout << 8 << endl;
	}
	return 0;
}

Measured memory_bytes: 3644
import math

def main():
    N, D = map(int, input().split())
    res = 0

    for i in range(N):
        x, y = map(int, input().split())

        if math.sqrt(x**2 + y**2) <= D:
            res += 1

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 69980
#include<stdio.h>
#include<set>
std::multiset<int> S;
int main() {
	int n, m, t;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &t);
		S.insert(t);
	}
	scanf("%d", &m);
	for (int i = 1; i <= m; i++) {
		scanf("%d", &t);
		auto it = S.find(t);
		if (it == S.end()) {
			printf("NO\n");
			return 0;
		}
		S.erase(it);
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 9600
using System;
public class Hello{
    public static void Main(){
        string s = Console.ReadLine();
        string a = "aiueo";
        for(int i = 0;i < a.Length;i++){
            if(s == a[i].ToString()){
                Console.WriteLine("vowel");
                return;
            }
        }
        Console.WriteLine("consonant");
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

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

void bfs(int y,int x, vector< vector<int> > &g){
  queue<pii> q;
  q.push(pii(y,x));
  g[y][x] = 1;

  while(q.size()){
    y = q.front().first; x = q.front().second;
    q.pop();

    for(int i=0;i<4;i++){
      int ny = y+dy[i], nx = x+dx[i];
      if(ny<0 || nx<0 || ny>=(int)g.size() || nx>=(int)g[0].size())continue;
      if(g[ny][nx] == 1)continue;
      g[ny][nx] = 1;
      q.push(pii(ny,nx));
    }
  }
}

int main(){
  int w,h,n;
  while(cin >> w >> h){
    if(w==0 && h==0)break;
    cin >> n;
    vector<int> cordx, cordy;
    vector<int> x1(n),y1(n),x2(n),y2(n);

    cordx.push_back(0); cordx.push_back(w-1);
    cordy.push_back(0); cordy.push_back(h-1);

    for(int i=0;i<n;i++){
      cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      for(int d=-1;d<=1;d++){
	if(0<=x1[i]+d && x1[i]+d<w)cordx.push_back(x1[i]+d);
	if(0<=x2[i]+d && x2[i]+d<w)cordx.push_back(x2[i]+d);
	if(0<=y1[i]+d && y1[i]+d<h)cordy.push_back(y1[i]+d);
	if(0<=y2[i]+d && y2[i]+d<h)cordy.push_back(y2[i]+d);
      }
    }

    sort(cordx.begin(), cordx.end());
    cordx.erase(unique(cordx.begin(), cordx.end()), cordx.end());
    sort(cordy.begin(), cordy.end());
    cordy.erase(unique(cordy.begin(), cordy.end()), cordy.end());

    for(int i=0;i<n;i++){
      int val = lower_bound(cordx.begin(), cordx.end(), x1[i]) - cordx.begin();
      x1[i] = val;
      val = lower_bound(cordx.begin(), cordx.end(), x2[i]) - cordx.begin();
      x2[i] = val;
      val = lower_bound(cordy.begin(), cordy.end(), y1[i]) - cordy.begin();
      y1[i] = val;
      val = lower_bound(cordy.begin(), cordy.end(), y2[i]) - cordy.begin();
      y2[i] = val;
    }

    h = cordy.size(); w = cordx.size();
    vector< vector<int> > grid(h, vector<int>(w,0));
    for(int i=0;i<n;i++){
      for(int y=y1[i];y<y2[i];y++){
	for(int x=x1[i];x<x2[i];x++)grid[y][x] = 1;
      }
    }

    int res = 0;
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	if(grid[y][x]==0){
	  bfs(y,x,grid);
	  res++;
	}
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 8204
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int a[N][N],s[N][N],t[N][N],b1[N][N],b2[N][N];
int main()
{
    int n,m,q,x1,y1,x2,y2,sum1,sum2;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++)
    {
        getchar();
        for(int j=1;j<=m;j++)
        {
            a[i][j]=getchar()-'0';
            s[i][j]=s[i-1][j]+s[i][j-1]+a[i][j]-s[i-1][j-1];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j])
            {
                if(a[i-1][j])
                    t[i][j]++;
                if(a[i][j-1])
                    t[i][j]++;
            }
            t[i][j]=t[i-1][j]+t[i][j-1]+t[i][j]-t[i-1][j-1];
        }
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]&&a[i-1][j])
                b1[i][j]=1;
            b1[i][j]+=b1[i][j-1];
        }
    }
    for(int i=2;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[j][i]&&a[j][i-1])
                b2[j][i]=1;
            b2[j][i]+=b2[j-1][i];
        }
    }
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        sum1=s[x2][y2]+s[x1-1][y1-1]-s[x1-1][y2]-s[x2][y1-1];
        sum2=t[x2][y2]+t[x1-1][y1-1]-t[x1-1][y2]-t[x2][y1-1];
        sum2-=b1[x1][y2]-b1[x1][y1-1];
        sum2-=b2[x2][y1]-b2[x1-1][y1];
        printf("%d\n",sum1-sum2);
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    
    vector<pair<int, int> > S(N);
    
    for (int i = 0; i < N; i++){
        int n;
        cin >> n;
        S[i] = make_pair(n, i);
    }

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

    for (int i = 0; i < N; i++){
        if (i == N -1){
            cout << S[i].second + 1 << endl;
        }
        else{
            cout << S[i].second + 1 << " ";
        }
    }
}


Measured memory_bytes: 1664
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> m >> x;
  rep(i, m) {
    cin >> a;
    if (a < x) ans++;
  }
  ans = min(ans, m - ans);
  Cout(ans);
  return 0;
}

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

const int MOD = (int)1e9 + 7;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i, n) cin >> a.at(i);
    VVL dp(n + 1, VL(k + 2, 0));
    FOR(j, 0, k)dp[0][j + 1] = 1;
    FOR(i, 1, n)FOR(j, 0, k) {
        ll sum = dp[i - 1][j + 1] - dp[i - 1][max(j - a[i - 1], 0)];
        sum %= MOD;
        dp[i][j + 1] = dp[i][j] + sum;
        dp[i][j + 1] %= MOD;
    }

    cout << (dp[n][k + 1] - dp[n][k] + MOD) % MOD << ln;
    return 0;
}


Measured memory_bytes: 80256
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[])
{
    char s[100], t[100];
    char a;
    int len;
    int i, j;
    scanf("%s", s);
    scanf("%s", t);
    len = strlen(s);

    for (i = 0; i < len; i++)
    {
        if (strcmp(s, t) == 0)
        {
            printf("Yes\n");
            return 0;
        }
        a = s[0];
        for (j = 0; j < len - 1; j++)
        {
            s[j] = s[j + 1];
        }
        s[len - 1] = a;
    }

    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
inf = 0x10101010
def solve(A,strt):
	cost = [inf]*m
	visited = [False]*m
	cost[strt] = 0
	while 1:
		min = inf
		next = -1
		visited[strt] = True
		for i in range(m):
			if visited[i]: continue
			if A[strt][i]:
				d = cost[strt] + A[strt][i]
				if d < cost[i]:
					cost[i] = d
			if min > cost[i]:
				min = cost[i]
				next = i
		strt = next
		if next == -1: break
	return cost
    
while 1:
	n,m = map(int,raw_input().split())
	if n == 0: break
	T = [[0]*m for i in range(m)]
	C = [[0]*m for i in range(m)]
	for i in range(n):
		a,b,c,t = map(int,raw_input().split())
		T[a-1][b-1] = T[b-1][a-1] = t
		C[a-1][b-1] = C[b-1][a-1] = c
	TS = [solve(T,i) for i in range(m)]
	CS = [solve(C,i) for i in range(m)]
	for i in range(input()):
		a,b,q = map(int,raw_input().split())
		if q == 0:
			print CS[a-1][b-1]
		else:
			print TS[a-1][b-1]

Measured memory_bytes: 4816
main = do
    n:a:b:c:_ <- (map read).words <$> getLine
    ls <- (map read).words <$> getContents
    print $ z a b c $ cmb ls

cmb [] = [((0, -10), (0, -10), (0, -10))]
cmb (l:ls) = concat [[(j l a, b, c), (a, j l b, c), (a, b, j l c), (a, b, c)] | (a, b, c) <- cmb ls]
j l (x, s) = (x+l, s+10)

z a b c xs = minimum [abs (a-u) + abs (b-v) + abs (c-w)  + h+i+j| ((u, h), (v, i), (w, j)) <- xs, u/=0, v/=0, w/=0]

Measured memory_bytes: 1020
#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MSIZE = 100100;

struct SegmentTree {
    vector<long long> t;
    SegmentTree(int sz) {
        t.assign(sz * 4, 0);
    }
    
    void Update(int v, int tl, int tr, int i, long long val) {
        if (tl + 1 == tr) {
            t[v] = val;
        } else {
            int tm = (tl + tr) / 2;
            if (i < tm) {
                Update(v * 2 + 1, tl, tm, i, val);
            } else {
                Update(v * 2 + 2, tm, tr, i, val);
            }
            t[v] = max(t[v], val);
        }
    }
    
    long long Get(int v, int tl, int tr, int l, int r) {
        if (tl >= r || tr <= l) return 0;
        if (tl >= l && tr <= r) return t[v];
        int tm = (tl + tr) / 2;
        return max(Get(v * 2 + 1, tl, tm, l, r), Get(v * 2 + 2, tm, tr, l, r));
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int * h = new int [n];
    int * a = new int [n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        h[i]--;
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SegmentTree tree(n);
    for (int i = 0; i < n; i++) {
        tree.Update(0, 0, n, h[i], tree.Get(0, 0, n, 0, h[i]) + a[i]);
    }
    cout << tree.Get(0, 0, n, 0, n) << endl; 
}

Measured memory_bytes: 8064
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,x,y,p[nmax],ch[nmax],viz[nmax],i,j,ans;
vector<int>v,a[nmax];
void dfs(int x)
{
	viz[x]=1,v.pb(x),ch[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i]);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>m;
    for(i=1;i<=n;i++)cin>>p[i];
    while(m--)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	 if(!viz[i])
	 {
	 	dfs(i);
	 	for(j=0;j<v.size();j++)ans+=ch[p[v[j]]];
	 	for(j=0;j<v.size();j++)ch[v[j]]=0;
	 	v.clear();
	 }
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8444
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

//?????????: n??\???????´???°
vector<int> getPrimes(int n) {
	vector<char> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i*i <= n; i++)
		if (is_prime[i]) {
			int j = i + i;
			while (j <= n) {
				is_prime[j] = false;
				j = j + i;
			}
		}
	vector<int> primes;
	rep(i, 0, n + 1)
		if (is_prime[i])
			primes.emplace_back(i);
	return primes;
}

//?´??????°????§£
vector<int> primeFactorization(int x) {
	vector<int> primes = getPrimes(sqrt(x));
	vector<int> factors;
	for (auto &p : primes) {
		while (x%p == 0) {
			x /= p;
			factors.emplace_back(p);
		}
	}
	if (x != 1)factors.emplace_back(x);
	return factors;
}

signed main() {
	int n; cin >> n;
	cout << n << ":";
	vector<int> factors = primeFactorization(n);
	rep(i, 0, factors.size()) { cout << " " << factors[i]; } cout << endl;
	return 0;
}

Measured memory_bytes: 3156
import numpy as np

N, M = map(int, input().split())

if N == 1 and M == 1:
    print(1)
    exit(0)

if N == 1:
    print(M - 2)
    exit(0)
if M == 1:
    print(N - 2)
    exit(0)

print((M - 2) * (N - 2))


Measured memory_bytes: 12420
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
#include<map>
#include<queue>
using namespace std;

vector< vector<int> > bfs(int h, int w, int y, int x, vector< vector<int> > t, int g){
  vector< vector<bool> > b(h, vector<bool> (w, false));
  b[y][x] = true;
  queue< pair<int, int> > q;
  q.push( make_pair(x, y) );
  int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
  int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  while(true){
    if( q.empty() ) break;

    pair<int, int> p = q.front();
    q.pop();
    int px = p.first;
    int py = p.second;

    for(int dir=0; dir<8; dir++){
      int tx = px + dx[dir];
      int ty = py + dy[dir];

      if( tx < 0 || tx >= w || ty < 0 || ty >= h ) continue;
      if( b[ty][tx] ) continue;
      if( t[ty][tx] == 0 ) continue;

      b[ty][tx] = true;
      t[ty][tx] = g;
      q.push( make_pair(tx, ty) );
    }
  }

  return t;
}

int main(){

  int w, h;
  while(cin >> w >> h){
    if( w == 0 && h == 0 ) break;
    vector< vector<int> > t(h, vector<int> (w));
    int g = 2;
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        cin >> t[i][j];
      }
    }

    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        if( t[i][j] == 1 ){
          t = bfs(h, w, i, j, t, g);
          g++;
        }
      }
    }
    cout << g-2 << endl;
  }

  return 0;
}

Measured memory_bytes: 3160
# coding: utf-8
# Your code here!

kind,num = map(int, input().split())
num_list = list(map(int, input().split()))

sum_v = sum(num_list)

thresh = sum_v/(4*num)
cnt = 0
for n in num_list:
    if n >= thresh:
        cnt = cnt+1
#print(cnt)
if cnt >= num:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
a=gets.chomp.split.map(&:to_i)
b=gets.chomp.split.map(&:to_i)
b=b.sort.reverse

b.slice!(0,a[1])
c=0
d=0
if b.length>0
  (b.length).times do 
   d+=b[c]
    c+=1
  end
  puts d
else puts 0
end


Measured memory_bytes: 22500
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    vector<int> v(n,0);
    rep(i,n) cin>>v[i];
    int ans = inf;
    sort(v.begin(),v.end());
    for(int i = v[0];i<=v[n-1];i++){
        //cout<<i<<" ";
        int now = 0;
        rep(j,n) now+=(i-v[j])*(i-v[j]);
        //cout<<now<<endl;
        ans = min(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define int long long

main()
{
  int n;
  int a;
  int sum = 0;
  bool kind[10] = {};
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a;
    if(a >= 3200) {
      sum++;
    } else {
      kind[a / 400] |= 1;
    }
 
  }
  
  int val = 0;
  for(int i = 0; i < 10; i++) {
    if(kind[i]) val++;
  }
  
  cout << max(1LL, val) << " " << val + sum << endl;

  return (0);
}
  


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

int main() {
    int N;
    cin >> N;
    int a[N];
    int cnt=0;
    for (int i=0;i<N;++i) cin >> a[i];
    for (int i=1;i<=N;++i) {
        if (i % 2 == 1 && a[i-1] % 2 == 1) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

bool check(string s,int x,int y){
    for(int i=x; i<y; i++){
        if(s[i] == '#' && s[i+1] == '#')return true;
    }
    return false;
}

int main()
{
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    A--;
    B--;
    C--;
    D--;
    string S;
    cin >> S;
    if(check(S,A,C) || check(S,B,D)){
        cout << "No" << endl;
        return 0;
    }
    bool flag = false;
    if(C > D){
        for(int i=B; i<=D; i++){
            if(S[i-1] == '.' && S[i] == '.' && S[i+1] == '.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3868
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

int N;
vector<int> A;
map<int, int> mp;
int K;

// 戻り値は、最後に変更したindex
int increment(int index){
    if(mp.find(index)==mp.end()){
        mp[index] = 2;
    }else{
        mp[index]++;
    }
    
    // 繰り上がり
    while(mp[index]>K){
        mp[index] = 1;
        index--;
        if(index==-1){
            return index;
        }
        // 繰り上がった先にキーがないとき、そこにはaがある
        if(mp.find(index)==mp.end()){
            mp[index] = 2;
        }else{
            mp[index]++;
        }
    }
    return index;
}

// k種類の文字で解けるかどうか
bool solve(){
    mp.clear();
    mp[A[0]-1] = 1; // 終端のみ

    FOR(i, 1, N){
        // 長くなっているときは簡単(繰り上がりも起こらない)
        if(A[i] > A[i-1]){
            mp[A[i]-1] = 1;
        }
        else if(A[i] == A[i-1]){
            int index = increment(A[i]-1);
            if(index == -1) return false;
        }
        // 短くなった場合
        else{
            mp.erase(mp.lower_bound(A[i]), mp.end());
            int inc_index = A[i] - 1;
            int index = increment(inc_index);
            if(index == -1) return false;
        }
    }
    return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    cin >> N;
    A.reserve(N);

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

    // 文字が1種で解けるか？
    bool canSolveByOne = true;
    int a = A[0];
    FOR(i, 1, N){
        if(A[i] > a){
            a = A[i];
        }else{
            canSolveByOne = false;
            break;
        }
    }
    if(canSolveByOne){
        p(1);
        return 0;
    }

    // ここ以降、文字2種以上を仮定できる

    int left = 2;
    int right = 200000;

    while(left != right){
        ll center = (left + right) / 2;
        K = center;
        if(solve()){
            right = center;
        }
        else{
            left = center + 1;
        }
    }

    p(left);
    
    return 0;
}

Measured memory_bytes: 3840
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

N, x = li()

if x == 1 or x == 2*N-1:
    print('No')
    
elif N == x == 2:
    print('Yes')
    print(1)
    print(2)
    print(3)
    
else:
    ans = [0]*(2*N-1)
    ans[N-1] = x
    
    if x == 2:
        ans[N-2] = x+2
        ans[N] = x-1
        ans[N+1] = x+1
        used = [x-1,x,x+1,x+2]
        
    else:
        ans[N-2] = x-1
        ans[N] = x+1
        ans[N+1] = x-2
        used = [x-2,x-1,x,x+1]
    
    rem = []
    for i in range(1,2*N):
        if i in used:
            continue
        else:
            rem.append(i)
            
    rem = rem[::-1]
    
    for i in range(2*N-1):
        if N-2 <= i <= N+1:
            continue
        
        else:
            ans[i] = rem.pop()
            
    print('Yes')
    for ai in ans:
        print(ai)

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

int main(){
    int k,x; cin >> k >> x;
    if(k*500>=x) cout << "Yes" << endl;
    else cout << "No" << endl;

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N; cin >> N;
    vector<vector<pair<int,int>>> v(N);
    int a;
    REP(i,N){
        cin >> a;
        int x,y;
        REP(j,a){
            cin >> x >> y; x--;
            v[i].push_back(make_pair(x,y));
        }
    }
    int ans = 0;
    REP(i,1<<N){
        bool flag = true;
        REP(j,N){
            REP(k,v[j].size()){
                pair<int,int> p=v[j][k];
                if (((i>>j)&1) && ((i>>(p.first))&1) && p.second==0) flag = false;
                if (((i>>j)&1) && !((i>>(p.first))&1) && p.second==1) flag = false;
            }
        }
        if (flag){
            int cnt = 0;
            REP(j,N){
                if((i>>j)&1) cnt ++;
            }
            ans = max(ans,cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	int a = 0, b = 0, ba = 0, res = 0;
	while (n--)
	{
		string s; cin >> s;
		int l = s.size();
		rep(i, l - 1)
		{
			if (s.substr(i, 2) == "AB")++res;
		}
		if (s[0] == 'B'&&s[l - 1] == 'A')++ba;
		else if (s[0] == 'B')++b;
		else if (s[l - 1] == 'A')++a;
	}
	if (ba > 0)
	{
		res += (ba - 1);
		res += min(a, b);
		if (a != 0 || b != 0)++res;
	}
	else res += min(a, b);
	cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())
if n < 3:
    print(0)
    exit()
l = list(map(int , input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            p =[l[i],l[j],l[k]]
            if p[0] == p[1]:
                continue
            if p[0] == p[2]:
                continue
            if p[1] == p[2]:
                continue
            #p.sort()
            if p[0] + p[1] > p[2]:
                ans += 1

print(ans)


Measured memory_bytes: 68284
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n+1):
        k = n - i - j
        if k >= 0 and k*1000 == y - 10000*i - 5000*j:
            print(i, j, k)
            exit()
print(-1, -1, -1)

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m, 0);
	rep(i, n) {
		int k;
		cin >> k;
		rep(j, k) {
			int A;
			cin >> A;
			A--;
			a[A]++;
		}
	}
	int ans = 0;
	rep(i, m) if (a[i] == n) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 384
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int n;
string s;
stack<char>st;
int main()
{
    cin>>n;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(st.empty())
            st.push(s[i]);
        else
        {
            if(st.top()!=s[i])
                st.push(s[i]);
        }
    }
    cout<<st.size()<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
vector<int> t;
map<string,int> mp;
string A[12]={"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw","ts"};
int cnt[50][50];

string change(int x){
  string res="a";
  if(x<26){
    res[0]+=x;
    return res;
  }else return A[x-26];
}

int main(){
  for(int i=0;i<12;i++)mp[A[i]]=26+i;
  cin>>n;

  while(cin>>s){
    n=s.size();
    vector<int> v;
    for(int i=0;i<n;i++){
      string tmp="";
      if(i+1<n)tmp=s.substr(i,2);
      if(mp[tmp]!=0){
        v.push_back(mp[tmp]);
        i++;
      }else{
        v.push_back(s[i]-'a');
      }
    }
    for(int i=0;i+1<(int)v.size();i++){
      
      cnt[v[i]][v[i+1]]++;
    }
    
  }
  
  for(int i=0;i<38;i++){
    int maxid=0;
    for(int j=0;j<38;j++){
      if(cnt[i][j]>cnt[i][maxid])maxid=j;
    }
    cout<<change(i)<<' '<<change(maxid)<<' '<<cnt[i][maxid]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1288
fun main() {
    val mod = 1000000007L

    fun modPow(x: Long, n: Int, m: Long): Long {
        if (n == 0) return 1 % m
        var u = modPow(x, n / 2, m)
        u = (u * u) % m
        if (n % 2 == 1) u = (u * x) % m
        return u
    }

    fun modInverse(x: Long, m: Long): Long {
        return modPow(x, m.toInt() - 2, m)
    }

    val (n, m) = readInts().map { it.toLong() }

    val mPnArray = LongArray(n.toInt())
    for (j in (m - n + 1)..m) {
        val index = (j - (m - n + 1)).toInt()
        mPnArray[index] = j
        if (index > 0) mPnArray[index] = (mPnArray[index] * mPnArray[index - 1]) % mod
    }

    val factorials = LongArray(n.toInt() + 1)
    val factorialModInverses = LongArray(n.toInt() + 1)
    for (i in 0..n) {
        val index = i.toInt()
        if (index == 0) factorials[index] = 1
        else factorials[index] = (i * factorials[index - 1]) % mod
        factorialModInverses[index] = modInverse(factorials[index], mod)
    }

    val nChooseR = factorials.mapIndexed { index, _ ->
        val nr = factorialModInverses[n.toInt() - index]
        val r = factorialModInverses[index]
        (((factorials[n.toInt()] * nr) % mod) * r) % mod
    }

    fun derangements(): Long {
        val mPn = mPnArray.last()
        val minusTerm = (1..n).map { r ->
            val sign = if (r % 2 == 1L) 1 else -1
            val p = if (n - r - 1 < 0) 1 else mPnArray[(n - r - 1).toInt()]
            val choice = nChooseR[r.toInt()]
            (mod + sign * ((p * choice) % mod)) % mod
        }.reduce { acc, minus -> (acc + minus) % mod }
        return ((mod + mPn) - minusTerm) % mod
    }

    val mPn = mPnArray.last()
    println((mPn * derangements()) % mod)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInts() = readStrings().map { it.toInt() }


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int t;
  cin >> t;
  
  while (t--) {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    
    map<ll, ll> mp; // number, minimum cost from N
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq; // cost, number
    mp[n] = 0;
    mp[0] = 1e18;
    pq.push(make_pair(0, n));
    
    while (!pq.empty()) {
      auto [cost, num] = pq.top();
      pq.pop();
      if (mp[num] < cost || num == 0) continue;
      if (cost >= mp[0]) break;
      
      if (d <= 1e18 / num && mp[0] > cost + d * num) mp[0] = cost + d * num;
      
      for (auto i : {-1, 0, 1}) {
        if ((num + i) % 2 != 0) continue;
        ll num2 = num + i, cost2 = cost + d * abs(i);
        if (mp.find(num2 / 2) == mp.end()) {
          mp[num2 / 2] = cost2 + a;
          pq.push(make_pair(cost2 + a, num2 / 2));
        }
        else if (mp[num2 / 2] > cost2 + a) {
          mp[num2 / 2] = cost2 + a;
          pq.push(make_pair(cost2 + a, num2 / 2));
        }
      }
      
      for (auto i : {-2, -1, 0, 1, 2}) {
        if ((num + i) % 3 != 0) continue;
        ll num2 = num + i, cost2 = cost + d * abs(i);
        if (mp.find(num2 / 3) == mp.end()) {
          mp[num2 / 3] = cost2 + b;
          pq.push(make_pair(cost2 + b, num2 / 3));
        }
        else if (mp[num2 / 3] > cost2 + b) {
          mp[num2 / 3] = cost2 + b;
          pq.push(make_pair(cost2 + b, num2 / 3));
        }
      }
      
      for (auto i : {-4, -3, -2, -1, 0, 1, 2, 3, 4}) {
        if ((num + i) % 5 != 0) continue;
        ll num2 = num + i, cost2 = cost + d * abs(i);
        if (mp.find(num2 / 5) == mp.end()) {
          mp[num2 / 5] = cost2 + c;
          pq.push(make_pair(cost2 + c, num2 / 5));
        }
        else if (mp[num2 / 5] > cost2 + c) {
          mp[num2 / 5] = cost2 + c;
          pq.push(make_pair(cost2 + c, num2 / 5));
        }
      }
    }
    
    cout << mp[0] << '\n';
  }
}

Measured memory_bytes: 4444
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#include <atcoder/all>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N, K;
	cin >> N >> K;
	vector<vl> A(N);
	rep(i, N) {
		A[i].resize(N);
		rep(j, N)
			cin >> A[i][j];
	}
	int s = 2 * N, t = 2 * N + 1;
	mcf_graph<int, ll> g(2 * N + 2);
	g.add_edge(s, t, N* K, InfL);
	rep(i, N) {
		g.add_edge(s, i, K, 0);
		g.add_edge(N + i, t, K, 0);
	}
	rep(i, N) {
		rep(j, N)
			g.add_edge(i, N + j, 1, InfL - A[i][j]);
	}
	g.flow(s, t, N* K);
	auto edges = g.edges();
	ll ans = 0;
	vector<string> S(N);
	rep(i, N) {
		rep(j, N)
			S[i].push_back('.');
	}
	for (auto e : edges) {
		int i = e.from;
		int j = e.to;
		int X = e.flow;
		if (i == s || j == t || X == 0)
			continue;
		S[i][j-N] = 'X';
		ans += (InfL - e.cost);
	}
	cout << ans << endl;
	rep(i, N)
		cout << S[i] << endl;

	return 0;
}

Measured memory_bytes: 3980
#include<stdio.h>
#include<string.h>
int n,m,t;
	char a[105][105];
	char b[105]={"0"};
	char c[10005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	scanf("%s",a[i]);
	for(int i=0;i<n-1;i++)
	for(int j=0;j<n-1-i;j++)
	{
		t=strcmp(a[j],a[j+1]);
		if(t>0)
		{
		strcpy(b,a[j]);
		strcpy(a[j],a[j+1]);
		strcpy(a[j+1],b);
	     }
	}
	strcpy(c,a[0]);
	for(int i=1;i<n;i++)
	strcat(c,a[i]);
	printf("%s",c);
	return 0;
}//

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,ll> pii;
const int max_N=1e5+10;
int n;
const int inf=1e9+5;
vector <pii> G[max_N],rg[max_N];
vector<int>p(105,0);
int a[100005];
int b[100005];
int c[100005];
int main()
{
  cin >> n;
  for(int i=0;i<n;i++)
    {
      cin >> a[i] >> b[i] >> c[i];
    }
  vector<vector<int> >dp(n+5,vector<int>(4,0));
  dp[0][0]=0;
  int ans=0;
  for(int i=0;i<n;i++)
    {
      for(int j=1;j<=3;j++)
	{
	  if(i==0) 
	    {
	      dp[i][1]=max(dp[i][j],dp[0][0]+a[i]);
	      dp[i][2]=max(dp[i][j],dp[0][0]+b[i]);
	      dp[i][3]=max(dp[i][j],dp[0][0]+c[i]);
	    }
	  else
	    {
	      if(j==1) 
		{
		  dp[i][j]=max(dp[i][j],dp[i-1][2]+a[i]);
		  dp[i][j]=max(dp[i][j],dp[i-1][3]+a[i]);
		}
	      if(j==2)
		{
		  dp[i][j]=max(dp[i][j],dp[i-1][1]+b[i]);
		  dp[i][j]=max(dp[i][j],dp[i-1][3]+b[i]);
		}
	      if(j==3)
		{
		  dp[i][j]=max(dp[i][j],dp[i-1][1]+c[i]);
		  dp[i][j]=max(dp[i][j],dp[i-1][2]+c[i]);
		}
	    }
	}
    }
  for(int i=1;i<=3;i++)
    {
      ans=max(ans,dp[n-1][i]);
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11520
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,MOD=1e9+7;

void solve()
{
 int a,b;
 cin>>a>>b;

 if(a<=5)
 cout<<0;
 else if(a>=6 && a<=12)
 cout<<b/2;
 else
 cout<<b;

}

int32_t main()
{
 fast();

 int t=1;
 //cin>>t;
 while(t--)
 {
  solve();
 }

 return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            Integer sum = Integer.parseInt(sc.nextLine());
            if (sum == 0) {
                break;
            }
            int max = 0;
            int x = 0;
            for (int i = 1; i < sum; i++) {
                Integer sumi = i * (i + 1) / 2;
                if (sumi > sum) {
                    break;
                }
                if ((sum - sumi) % i == 0) {
                    max = i;
                    x = (sum - sumi) / i;
                }
            }
            String output = String.format("%d %d", x + 1, max);
            System.out.println(output);
        }
    }
}


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

int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   for (int i=0;i<n;i++) {
      cin >> a.at(i);
   }
   int max=a.at(0);
   int min=a.at(0);
   for (int i=0;i<n;i++) {
      if (max<a.at(i))max=a.at(i);
      if (min>a.at(i))min=a.at(i);
   }
   cout << max-min << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

using PII = pair<ll, int>;
const int N = 200 * 1000 + 5;
vector <pair<int, int>> v[N];
void dijkstra(int s, vector <ll> &dist) {
	priority_queue<PII, vector<PII>, greater<PII>> pq;
	pq.push({0, s});
	dist[s] = 0;
	while(!pq.empty()) {
		int x = pq.top().ss;
		pq.pop();
		for (auto g : v[x]) {
			if(dist[g.ff] > dist[x] + g.ss) {
				dist[g.ff] = dist[x] + g.ss;
				pq.push({dist[g.ff], g.ff});
			}
		}
	}
}
void count_paths(int s, vector <ll> &cnt, vector<ll> &d2, ll mn) {
	vector <int> vis(N, false);
	vector <ll> dist(N, INF);
	priority_queue<PII, vector<PII>, greater<PII>> pq;
	pq.push({0, s});
	dist[s] = 0;
	cnt[s] = 1;
	while(!pq.empty()) {
		int x = pq.top().ss;
		pq.pop();
		if(vis[x])
			continue;
		vis[x] = true;
		for (auto g : v[x]) {
			if(dist[x] + g.ss + d2[g.ff] == mn) {
				cnt[g.ff] += cnt[x];
				cnt[g.ff] %= MOD;
			}
			if(dist[g.ff] > dist[x] + g.ss) {
				dist[g.ff] = dist[x] + g.ss;
				pq.push({dist[g.ff], g.ff});
			}
		}
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	int S, T;
	cin >> S >> T;
	vector <tuple<int, int, int>> ed;
	for (int i = 0; i < m; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		v[x].push_back({y, w});
		v[y].push_back({x, w});
		ed.push_back(make_tuple(x, y, w));
		ed.push_back(make_tuple(y, x, w));
	}
	vector <ll> ds(n + 1, INF);
	dijkstra(S, ds);
	vector <ll> dt(n + 1, INF);
	dijkstra(T, dt);
	ll mn = ds[T];
	vector <ll> cs(n + 1, 0);
	count_paths(S, cs, dt, mn);
	vector <ll> ct(n + 1, 0);
	count_paths(T, ct, ds, mn);
	ll total = (cs[T] * cs[T]) % MOD;
	for (int i = 1; i <= n; i++) {
		if(2 * ds[i] == mn && 2 * dt[i] == mn) {
			ll go = (cs[i] * ct[i]) % MOD;
			total -= (go * go) % MOD;
			total = (total + MOD) % MOD;
		} 
	}
	for (int i = 0; i < 2 * m; i++) {
		int x, y, w;
		tie(x, y, w) = ed[i];
		if(ds[x] + w + dt[y] == mn) {
			if(2 * ds[x] < mn && 2 * dt[y] < mn) {
				ll go = (cs[x] * ct[y]) % MOD;
				total -= (go * go) % MOD;
				total = (total + MOD) % MOD;
			}
		}
	}
	cout << total;
}


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

int main(){
    int A,B;
    cin >> A >> B;
    for(int i = 1;i < 1300;i++){
      	int AA = i * 0.08;
      	int BB = i * 0.1;
    	if(AA == A && BB == B){
        	cout << i << endl;
      		return 0;
        }
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include <math.h>
#include<algorithm>
#include<map>
#include<string>

using namespace std;

int main(int argc,char** argv)
{

	int n,cnt=0,Max=0;
	string s;
	cin >> n >> s;

	for(int i = 0; i < n; i++){
		int a[27] ={0}, b[27] ={0};
		for(int j = 0; j < i; j++){
			a[s[j]-'a']++;
		}
		for(int k = i; k < n; k++){
			b[s[k]-'a']++;
		}
		for(int l = 0; l < 27; l++){
			if(a[l]*b[l]!=0){
				cnt++;
			}
		}
		Max = max(cnt,Max);
		cnt=0;
	}

	cout << Max <<endl;

	return 0;

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int A = sc.nextInt();
   int B = sc.nextInt();
   int ans = -1;
   for(int i = 1 ; i<=1009 ; i++)
   {
     if((i*8)/100==A && i/10 == B)
     {
       ans = i;
       break;
     }
   }
   System.out.print(ans);
 }
}

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

using namespace std;
using ll = long long;


int main()
{
    int n, k;
    cin >> n >> k;
    vector<long double> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] = (1 + a[i]) / 2.0;
    }

    long double ans = 0;
    for(int i = 0; i < k; i++)ans += a[i];
    long double cur = ans;
    for(int i = k; i < n; i++){
        cur += a[i];
        cur -= a[i - k];
        ans = max(ans, cur);
    }
    cout << fixed <<setprecision(12) << ans << endl; 
}

Measured memory_bytes: 3328
[n,y] = [int(i) for i in input().split()]
checker = 0
if y < n * 1000 or y > n * 10000:
  print(-1,-1,-1)
else:
  a = y // 10000
  for i in range(a+1):
    y1 = y - 10000*i
    b = y1 // 5000
    for j in range(b+1):
      y2 = y1 - 5000*j
      c = y2/1000
      #print(i,j,n-i-j)
      if c == n - i - j and checker != 1:
        checker = 1
        print(i,j,n-i-j)
        break
  if checker == 0:
    print(-1,-1,-1)

    

Measured memory_bytes: 40540
x,n=map(int, input().split())
p=list(map(int, input().split()))

l=[i for i in range(-3, 102)]

new_l=list(set(l)-set(p))
new_l.sort()

ans=-3
sa=100
for l_i in new_l:
    # print(abs(l_i-x), sa)
    if abs(l_i-x)<sa:
        ans=l_i
        sa=abs(l_i-x)

print(ans)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define endl '\n'
#define N 1000001
#define mod 1e9+7
using namespace std;
typedef long long ll;
ll a[100001][3];
ll fun(ll n){
    for(ll i=n-1;i>0;i--){
        for(ll j=1;j<=3;j++){
           if(j==1){
              a[i][j]+=max(a[i+1][j+1],a[i+1][j+2]); 
           } 
           if(j==2){
               a[i][j]+=max(a[i+1][j-1],a[i+1][j+1]);
           }
           if(j==3){
               a[i][j]+=max(a[i+1][j-2],a[i+1][j-1]);
           }
        }
    }
    ll ans=0;
    for(ll i=1;i<4;i++){
        ans=max(a[1][i],ans);
    }
    return ans;  
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
	    for(ll j=1;j<=3;j++){
	        cin>>a[i][j];
	    }
	}
	cout<<fun(n);
	return 0;
}


Measured memory_bytes: 5968
def read_input():
    a, b, c, d = map(int, input().split())

    return a, b, c, d

def submit():
    a, b, c, d = read_input()

    if b < c or d < a:
        print(0)
        return

    if a < c:
        if d <= b:
            print(d - c)
        else:
            print(b - c)
    else:
        if b <= d:
            print(b - a)
        else:
            print(d - a)
    return

if __name__ == '__main__':
    submit()

Measured memory_bytes: 38256
n, l = map(int, input().split())
apples = [l + i for i in range(n)]
try:
    min_index = apples.index(min([abs(aps) for aps in apples]))
except ValueError:
    min_index = apples.index(-1*min([abs(aps) for aps in apples]))
print(sum(apples)-apples[min_index])



Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

int main()

{
    int a,b,c;
    cin>>a>>b>>c;
    if(c>=a&&c<=b)
    {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int a, b, c, d; cin >> a >> b >> c >> d;
    
    if(abs(a - c) > d)
    {
        if(abs(a - b) > d || abs(c - b) > d)
        {
            cout << "No"; return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
n,W=map(int,input().split())
vw=[]
for i in range(n):
    v,w=map(int,input().split())
    vw.append([v,w])
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(W+1):
        v,w=vw[i-1]
        if j>=w:
            dp[i][j]=max(dp[i-1][j],dp[i][j-w]+v)
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][W])


Measured memory_bytes: 15696
N = int(raw_input())
S = [int(raw_input()) for _ in range(N)]

ans = 0
v = 1000
for s in S:
    if s % 10 != 0:
        v = min(v, s)
    ans += s

if ans % 10 != 0:
    print ans
elif v == 1000:
    print 0
else:
    print ans - v


Measured memory_bytes: 2568
A, B, K = [int(x) for x in input().split()]
if K >= (B - A + 1) / 2:
  l = [i for i in range(A, B + 1)]
else:
  l = [i for i in range(A, A + K)]
  l += [i for i in range(B - K + 1, B + 1)]

for i in l:
  print(i)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  sort(a.begin(), a.end());
  vector<int> v(*max_element(a.begin(),a.end()) + 1, 0);
  v[0] = 2;

  for (int x : a) {
    if (v[x] != 0) {
      v[x] = 2;
      continue;
    }
    for (int i = x; i <= v.size(); i += x) v[i]++;
  }
  int ans = 0;
  for (int x : a) {
    if(v[x] == 1) ans++;
  }
  cout << ans << endl;

}

Measured memory_bytes: 7968