akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)

//変数
ll Q;
vector<ll> l, r;

bool isPrime(ll num) {

	if (num <= 1) return false;

	bool flag = true;
	for (int i = 2; i <= sqrt(num); i++) {
		if (num%i == 0) {
			flag = false;
			break;
		}
	}

	return flag;
}

//解法
void solve() {

	//全部先にやっておけばいいのでは？
	ll mini = *min_element(l.begin(), l.end());
	ll maxi = *max_element(r.begin(), r.end());

	vector<ll> vec;

	//最初から最後まで、2017に似た数を先に調べておく
	for (ll i = mini; i <= maxi; i += 2) {
		if (isPrime(i) && isPrime((i + 1) / 2)) vec.emplace_back(i);
	}

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


	rep(i, Q) {

		ll ans = 0;
		rep(j, vec.size()) {
			if (vec[j] >= l[i] && vec[j] <= r[i]) ans++;
		}

		cout << ans << endl;
	}

	return;
}

int main() {
	//入力
	cin >> Q;
	l.resize(Q);
	r.resize(Q);
	rep(i, Q) cin >> l[i] >> r[i];
	solve();
	//cout << endl;
	return 0;
}


Measured memory_bytes: 2176
// Problem : M - Candies
// Contest : AtCoder - Educational DP Contest
// U
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define Ma7moud_7amdy                 \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define Open_Sesame Open()
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define watch(x) cout << #x << " = " << x << endl;
#define RT(x) return cout << (x), 0;
#define Accepted 0
#define INF 0x3f3f3f3f3f3f3f3fLL
typedef long long ll;
typedef vector<int> vi;
const int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
void Open()
{
#ifndef ONLINE_JUDGE 
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
const int mod = ll(1e9 + 7), N = 2000 + 5;
//“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
int n, k, a[101], mem[101][100005],dp[101][100005];
map<int, int>mp;
int solve(int i = 0, int rem = k) {
	if (!rem)return 1;
	if (i == n)
	{
		return rem == 0;
	}
	int& ret = mem[i][rem];
	if (~ret)return ret;
	ret = 0;
	for (int ch = 0; ch <= min(rem, a[i]); ch++) {
		ret += solve(i + 1, rem - ch) % mod;
		ret %= mod;
	}
	return ret;
}
int main()
{
	Ma7moud_7amdy;
//	Open_Sesame;
	//clr(mem, -1);
	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
//	cout << solve() << endl;

	//baseCase
	for (int i = 0; i <= n; i++) {
		dp[i][0] = 1;
	}

	//itteration
	for (int i = n - 1; i >= 0;i--) {
		//perfixSum
		for (int rem = 1; rem <= k; rem++) {
			dp[i+1][rem] +=dp[i+1][rem-1]%mod;
			dp[i+1][rem]%=mod;
		}
		for (int rem = 0; rem <=k; rem++) {
			int& ret = dp[i][rem];
			ret = 0;
			/*for (int ch = 0; ch <= min(rem, a[i]); ch++) {
				ret += dp[i + 1][rem - ch];
				ret %= mod;
			}*/
			ret += ((dp[i + 1][rem] - dp[i + 1][rem - min(rem, a[i])-1])%mod+mod)%mod;
			ret%=mod;
		}
	}
	cout << dp[0][k] << endl;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> L(55);
    for (int i = 0; i < n; i++) {
        cin >> L[i];
    }

    int sum = 0;
    sort(L.begin(), L.end(), greater<int>());
    for (int i = 0; i < k; i++) {
        sum += L[i];
    }

    cout << sum << endl;


    return 0;
}


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

using namespace std;

#define MY_BIG_INT long long

class MYCP {
public:

	
	//数値を必要な個数だけ読み取る
	static vector<long long> ReadInts(long long number) {
		vector<long long> a(number);
		for (int i = 0; i < number; i++) {
			std::cin >> a[i];
		}

		return a;
	}


	//最初に呼び出す
	static void SetUp() {
		cin.tie(0);
		ios::sync_with_stdio(false);
	}
};

MY_BIG_INT NizyouGosa(vector<MY_BIG_INT> a, MY_BIG_INT x) {
	MY_BIG_INT i, foo, sum = 0;

	for (i = 0; i < a.size(); i++) {
		foo = x - a[i];
		foo = foo * foo;
		sum += foo;
	}

	return sum;
}

MY_BIG_INT avef(vector<MY_BIG_INT> a,int n) {
	MY_BIG_INT i, sum, ave;
	sum = 0;

	for (i = 0; i < n; i++) {
		sum += a[i];
	}

	ave = sum / n;

	return ave;
}

MY_BIG_INT mymin(MY_BIG_INT a, MY_BIG_INT b, MY_BIG_INT c) {
	if (a < b&a < c)return a;
	else
	{
		if (b < c)return b;
	}

	return c;
}

int main(void) {
	MYCP::SetUp();

	MY_BIG_INT i, j, k, n, x, y, z, ave;
	cin >> n;
	auto a = MYCP::ReadInts(n);

	ave = avef(a,n);

	x = NizyouGosa(a, ave);
	y = NizyouGosa(a, ave - 1);
	z = NizyouGosa(a, ave + 1);


	cout << mymin(x, y, z) << endl;
}


Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ld n,d;
    cin>>n>>d;
    ll res=0;
    rep(i,n){
        ld x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d){
            res++;
        }
    }
    cout<<res<<endl;
}


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

template <int& MOD_> struct modnum {
	static constexpr int& MOD = MOD_;
	//static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int N, K; cin >> N >> K;
	static int MOD_; cin >> MOD_; // static to give it linkae
	using num = modnum<MOD_>;

	auto solve_connected = [&](int N, int K) -> num {
		K = min(K, N-2);
		if (N-1 > 2 * K) return 0;
		num ans = 0;
		vector<num> dp(K+2);
		for (int st = N-1-K; st <= K; st++) {
			fill(dp.begin(), dp.end(), 0);
			dp[st]++;
			for (int i = 1; i <= N-st; i++) {
				// shift right
				dp[K+2-i] = 0;
				// shift down
				for (int j = K+1-i; j > 0 && i+j-1 >= N-1-K; j--) {
					dp[j-1] += dp[j];
				}
			}
			ans += dp[0];
		}
		return ans;
	};
	num ans = 0;
	if (K >= N-1) ans++;
	for (int c = 0; c <= N-3; c++) {
		ans += solve_connected(N-c, K-c) / num(N-c);
	}
	for (int i = 1; i <= N; i++) ans *= i;


	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3652
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        int n = scanInt(), d = scanInt();
        int count = 0;
        for (int i = 0; i < n; i++) {
            long x = scanLong();
            long y = scanLong();
            x = x * x;
            y = y * y;
            x += y;
            if (Math.sqrt(x) <= d) {
                count++;
            }
        }
        out.print(count);
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 54580
// https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

void recursive_comb(int *indexes, int s, int rest, function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

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

  ll ans = 1e16;
  foreach_comb(n, k, [&](int *indexes) {
    // indexes[0] より左に高い建物がないことを確認する
    // 高い建物があるなら、その建物を選んだときの方がコストは低い
    for(int i=indexes[0]-1;i>=0;i--) {
      if(a[indexes[0]] < a[i]) {
        return;
      }
    }

    int cur = 0;
    ll val = 0;
    ll h = a[indexes[cur]];
    while(cur < k - 1) {
      // indexes[cur]とindexes[cur+1]の間にhよりも高いビルがあったら
      // hをその高さに合わせる
      for(int i=indexes[cur]+1;i<indexes[cur+1];i++) {
        if(h < a[i]) {
          h = a[i];
        }
      }
      ll h_n = a[indexes[cur+1]];
      if(h < h_n) {
        h = h_n;
        cur++;
        continue;
      }
      h = h+1;
      val += h - h_n;
      cur++;
    }
    // printf("%d %d %d → %d\n", indexes[0], indexes[1], indexes[2], val);
    ans = min(ans, val);
  });

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
# define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;



int main(){
    string s;
    cin >> s;
    int l = s.size();
    int cutnum = 2;
    int prev_wall = 1;
    int prev_prev_wall = 0;
    if(l==1){
        cout << 1;
    }else{
    reps(i,1,l-1){
        if(s[i]==s[i-1] && prev_wall == i && prev_prev_wall == i-1){
        }else{
            cutnum ++;
            prev_prev_wall = prev_wall;
            prev_wall = i+1;
        }
    }
    if(prev_wall == l-1 && prev_prev_wall == l-2 && s[l-1]==s[l-2]){
        cutnum --;
    }
    cout << cutnum;
    }
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))

if(a[0]==1):
    if(n==0):
        print(1)
    else:
        print(-1)
    exit()

max_e = sum(a)
if(max_e > 2**n):
    print(-1)
    exit()

not_leaf = [0] * (n+1)
not_leaf[0] = 1

for i,leaf in enumerate(a):
    if(i==0):
        continue

    not_leaf[i] = min(not_leaf[i-1]*2, max_e) - leaf
    if(not_leaf[i] < 0):
        print(-1)
        exit()
    max_e -= leaf

ans = sum(a) + sum(not_leaf)
print(ans)

Measured memory_bytes: 83424
import math


def comb(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

b = 0
for n in d.values():
    b += comb(n, 2)

for k in range(N):
    a = A[k]
    print(b - d[a] + 1)


Measured memory_bytes: 26140
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
B = [int(input()) for i in range(n)]
C = [[0] * 3 for i in range(3)]
for i in range(3):
    for j in range(3):
        for k in range(n):
            if A[i][j] == B[k] :
                C[i][j] += 1
y=0
for i in range(3):
    if sum(C[i]) == 3:
        y = 1
    if C[0][i] + C[1][i] + C[2][i] == 3:
        y = 1
if C[0][0] + C[1][1] + C[2][2] == 3:
    y = 1
if C[0][2] + C[1][1] + C[2][0] == 3:
    y = 1
if y == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
void init() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(all(a));
  int ans = abs(x - a[0]);
  for (int i = 1; i < n; i++) {
    ans = __gcd(ans, abs(x - a[i]));
  }
  cout << ans << endl;
}

int32_t main() {
  IOS;
  init();
  return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m; cin >> n >> m;
	Graph g(n);
	REP(i, m)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		add_edge(g, a, b, 0);
	}
	vector<bool> vis(n);
	int ans = 0;
	REP(i, n)
	{
		if (vis[i]) continue;
		vis[i] = true;
		int cntv = 1, cnte = 0;
		queue<int> que; que.push(i);
		while (!que.empty())
		{
			int t = que.front();
			que.pop();
			for (auto e : g[t])
			{
				cnte++;
				if (!vis[e.to])
				{
					vis[e.to] = true;
					cntv++;
					que.push(e.to);
				}
			}
		}
		ans += cnte - cntv + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3264
import java.util.*;

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

    int n = sc.nextInt();
    long ans = 0;

    for(int i = 1; i < n + 1; i++){
      if(i % 3 != 0 && i % 5 != 0){
        ans += i;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 35748
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  int a,b,c;cin>>a>>b>>c;
  if(a<1200){
    cout << "ABC";
    return 0;
  }else{
    cout << "ARC";
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	ll n;
	scanf("%lld",&n);
	printf("%lld",n*(n-1)/2);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;



signed main(){
    int n,k; cin>>n>>k;
    
    int ans=k;
    for(int i=1;i<n;i++){
        ans *= (k-1);
    }
    
    cout<<ans<<endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> V(N, 0);
  // vector<ll> s(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  // s[0] = V[0];
  // for (int i = 1; i < N; i++) {
  //   s[i] = s[i-1] + V[i];
  // }
  ll maxpt = 0;
  int maxtake = min(K, N);
  for (int i = 0; i <= maxtake; i++) {
    for (int j = 0; j <= i; j++) {
      ll pt = 0;
      priority_queue<ll, vector<ll>, greater<ll> > que;
      for (int k = 0; k < j; k++) {
        pt += V[k];
        que.push(V[k]);
      }
      for (int k = N - 1; k >= N - (i-j); k--) {
        pt += V[k];
        que.push(V[k]);
      }
      int cntremain = K - i;
      // if (!que.empty()) cout << "!" << que.top() << endl;;
      while (cntremain > 0 && !que.empty() && que.top() < 0) {
        pt -= que.top();
        que.pop();
        cntremain--;
      }
      // cout << i << " " << j << " " << pt << " " << cntremain << endl;
      maxpt = max(maxpt, pt);
    }
  }
  cout << maxpt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
int qpow(int a,int n)
{
    int r=1%P;
    for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;
    return r;
}
const int maxn=2e5+50;

int a[maxn];
  int n,k;
int check(int x)
{  int kk=0;
   for(int i=1;i<=n;i++)
   {
    kk+=(a[i]-1)/x;
   }
   if(kk>k)
    return 0;
   else
    return 1;
}
int main()
{
  cin>>n>>k;
  for(int i=1;i<=n;i++)
  {
      cin>>a[i];
  }
  int l=1,r=1e9;
  int ans=0;
  while(l<=r)
  {
      int mid=(l+r)/2;
      if(check(mid))
      {
          r=mid-1;
          ans=mid;
      }
      else
      {
          l=mid+1;
      }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4320
#include<stdio.h>

#define N 2000

int a[N], n, sum;

int check(int i,int m){
  if(sum < m)return 0;
  if(m == 0)return 1;
  if(i >= n)return 0;
  return check(i+1,m) || check(i+1,m-a[i]);
}

int main(){
  int q,m,i;

  sum = 0;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&m);
    if (check(0,m)){
      printf("yes\n");
    }else{
      printf("no\n");
    }

  }
  return 0;
}

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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n;
	cin >> n;
	if(n%1000==0)
		cout << 0 << endl;
	else
	 cout << 1000*(n/1000 + 1) - n << endl;
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] x = new long[n];
    long[] y = new long[n];
    long[] h = new long[n];
    int p = 0;
    for(int i = 0; i < n; i++) {
      x[i] = sc.nextLong();
      y[i] = sc.nextLong();
      h[i] = sc.nextLong();
      if(h[i] > 0) p = i;
    }
    long ansx = 0;
    long ansy = 0;
    long ansh = 0;
    for(long cx = 0; cx <= 100; cx++) {
      int t1 = 0;
      for(long cy = 0; cy <= 100; cy++) {
        long ch = h[p] + Math.abs(x[p] - cx) + Math.abs(y[p] - cy);
        int t2 = 0;
        for(int i = 0; i < n; i++) {
          if(Math.max((ch - Math.abs(x[i] - cx) - Math.abs(y[i] - cy)), 0) != h[i]) {
            t2 = 1;
            break;
          } 
        }
        if(t2 == 0) {
          t1 = 1;
          ansx = cx;
          ansy = cy;
          ansh = ch;
          break;
        } 
      }
      if(t1 > 0) break;
    }
    System.out.println(ansx + " " + ansy + " " + ansh);
  }
}

Measured memory_bytes: 23764
// https://atcoder.jp/contests/arc059/tasks/arc059_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    s += " ";
    REP(i, len - 1) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << "\n";
            return 0;
        } else if (s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << "\n";
            return 0;
        }
    }
    cout << "-1 -1\n";
    return 0;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    if (n >= 1 && n == (n&-n)) {
        cout << "No"; return;
    }
    cout << "Yes\n";
    auto p = [](int x, int y){
        cout << x << ' ' << y << "\n";
    };
    p(n+1,n+2); p(n+2, 3); p(3, 1); p(1, 2); p(2, n+3);
    for (int x = 4; x+1 <= n; x+=2) {
        p(x, 1); p(1, x+1);
        p(x, n+x+1); p(x+1, n+x);
    }
    if (n%2 == 0) {
        int x = 1 << (31-__builtin_clz(n));
        int y = n^x;
        y^=1;
        p(x, n); p(y,n+n);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2304
package main

import (
    "fmt"
)

func main() {
	var n, k int
	var s []byte 
    fmt.Scan(&n, &k, &s)
	if s[k-1] == 'A'{
		s[k-1] = 'a'
	} else if s[k-1] == 'B' {
		s[k-1] = 'b'
	} else if s[k-1] == 'C' {
		s[k-1] = 'c'
	}
	fmt.Println(string(s))
}

Measured memory_bytes: 512
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //long start = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        sc.close();

        int min = t.length();

        for (int i = 0;i<s.length() - t.length() + 1;++i)
        {
            int count = t.length();
            String tmp = s.substring(i,i+t.length());
            System.err.println(tmp);
            for (int j = 0;j<t.length();++j)
            {
                String ss = tmp.substring(j,j+1);
                String tt = t.substring(j,j+1);
                if (ss.equals(tt)) --count;
            }

            if (min > count) min = count;
        }
        System.out.println(min);

//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }
}

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

using namespace std;

long long n,m,ans;

int main()
{
    cin >> n >> m;
    if (n==1&&m==1) cout << 1;
    else if (n==1) cout << m-2;
    else if (m==1) cout << n-2;
    else if (n==2||m==2) cout << 0;
    else cout << n*m-2*n-2*m+4;
}

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


#define ll long long

using namespace std;

map<string, int> wordsMap;


int main()
{
    wordsMap.clear();
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n;
    cin >> n;

    string w;

    while (n--)
    {
        cin >> w;
        wordsMap[w]++;
    }

    int maxCount = 0;
    for(auto w : wordsMap)
    {
        if(w.second > maxCount) maxCount = w.second;
    }
    for(auto it = wordsMap.begin(); it != wordsMap.end(); ++it)
    {
        if(it->second == maxCount)
        {
            cout << it->first << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 25472
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;

	vector<int> h(n);
	for(auto &x : h) {
		cin >> x;
	}

	int result = count_if(h.begin(), h.end(), [k](int i){ return i >= k;} );
	cout << result << endl;
	
	return 0;
}


Measured memory_bytes: 640
import sys

input = sys.stdin.readline

# 使用量が確定するのは次の人が押したとき！
# どういうケースがあるのかをいかに早く気がつくかが肝心だった


def main():
    # 1 <= N <= 200,00, 1 <= T <= pow(10,9)
    N, T = [int(ele) for ele in input().split()]
    t = [int(ele) for ele in input().split()]
    usage = [None] * N
    for idx in range(N-1):
        usage[idx] = min(T, t[idx+1] - t[idx])

    usage[-1] = T
    print(sum(usage))


if __name__ == "__main__":
    main()


Measured memory_bytes: 81488
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 1005
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n;
int headd[maxn],nextt[maxn],to[maxn],cntt;
inline void add(int u,int v)
{nextt[++cntt]=headd[u];headd[u]=cntt;to[cntt]=v;}
int dp[maxn*5],f[maxn*5],val[maxn];
inline void dfs(int u)
{
    reg int j,tmp;f[u]=998244353;
    for(reg int i=headd[u];i;i=nextt[i])dfs(to[i]);
    for(j=0;j<=val[u];++j)dp[j]=998244353;dp[0]=0;
    for(reg int i=headd[u];i;i=nextt[i])
    {
        for(j=val[u];j>=0;--j)
        {
            tmp=998244353;
            if(j>=val[to[i]])tmp=min(tmp,dp[j-val[to[i]]]+f[to[i]]);
            if(j>=f[to[i]])tmp=min(tmp,dp[j-f[to[i]]]+val[to[i]]);
            dp[j]=tmp;
        }
    }
    for(j=0;j<=val[u];++j)f[u]=min(f[u],dp[j]);
    if(f[u]==998244353){puts("IMPOSSIBLE");exit(0);}
}
int main()
{
    n=read();
    for(reg int i=2;i<=n;++i)add(read(),i);
    for(reg int i=1;i<=n;++i)val[i]=read();
    dfs(1);puts("POSSIBLE");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		int w,a,b,distance;
		Scanner sc = new Scanner(System.in);

		w = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
		
		if(a+w < b){
			distance = b - (a+w);
		}else if(a > b+w){
			distance = a - (b+w);
		}else{
			distance = 0;
		}
		System.out.println(distance);
	}
}



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

using namespace std;

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

	int n;
	cin >> n;

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

	long long ans = 0;
	sort(a.begin(), a.end());

	ans += a.back();
	int cur = n - 2;
	int f = 0;
	for(int i = n - 3; i >= 0; --i) {
		ans += a[cur];
		if(f == 1) {
			cur -= 1;
		}
		f ^= 1;
	}

	cout << ans << '\n';

	return 0;
}

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

 int main() {
   string S, T, U;
   cin >> S >> T;
   int A, B;
   cin >> A >>B;
   cin >> U;
  if (S == U) {
    A--;
  } else if (T == U) {
    B--;
  }
   cout << A << ' ' << B << '\n';
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
    long long int N; 
    cin >> N; 
    long long int a[114514];
    for(int i = 0; i < N; ++i){
    cin >> a[i];
    }
    sort(a, a + N, greater<int>());
    long long int M = a[0]; 
    long long int b[114514]; 
    for(int i = 0; i < N; ++i){
    b[i] = abs(M - a[i] * 2);  
    }
    long long int m = M; 
    for(int i = 1; i < N; ++i){
    m = min(m, b[i]);
    }
    string ans = "No"; 
    for(int i = 1; i < N; ++i){
    if(2 * a[i] == M - m){
    ans = "Yes"; 
    break;}
    }
    if(ans == "Yes") 
      cout << M << " " << (M-m)/2 << endl; 
    else if(ans == "No") 
      cout << M << " " << (M+m)/2 << endl; 
}


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

int main() {
  string s;
  cin >> s;
  string hitachi = "";

  for(int i = 1; i <= 5; i++) {
    hitachi += "hi";
    if(hitachi == s) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

}

Measured memory_bytes: 3628
{-# OPTIONS_GHC -Wall #-}

readInt :: String -> Int
readInt = read

divisors :: Int -> [Int]
divisors n = filter (\d -> n `mod` d == 0) [1..n]

solve :: Int -> Int
solve n = (length . filter isOk) [1..n]
    where
        isOk m = odd m && (length . divisors) m == 8

main :: IO ()
main = do
    n <- fmap readInt getLine

    let ans = solve n

    print ans


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
 
void fail(){
    cout << "No" << endl;
    exit(0);
}
 
int main(){
    int N;
    cin >> N;
    
    // 各パーツの特徴を (min, sum) の形で保持する。
    // sum >= 0であるものをAposに、sum < 0 であるものをAnegに入れる。
    vector<pair<int, int>> Apos, Aneg;
    
    for(int i=0; i<N; i++){
        string S;
        cin >> S;
        int s = 0, mn = 0;
        for(char c : S){
            s += (c == '(' ? 1 : -1);
            mn = min(mn, s);
        }
        if(s >= 0){
            Apos.emplace_back(mn, s);
        }else{
            Aneg.emplace_back(mn, s);
        }
    }

    // 全体の累積和
    int T = 0;

    // まずAposから使う。minが大きい方から使えば良い。使えない場合fail
    sort(Apos.rbegin(), Apos.rend());

    for(auto& p : Apos){
        if(T + p.first < 0) fail();
        T += p.second;
    }

    // Anegを、sum-minが大きい方から使う。使えない場合fail
    sort(Aneg.begin(), Aneg.end(), [](auto a , auto b){ return a.second - a.first > b.second - b.first; });
    for(auto& p : Aneg){
        if(T + p.first < 0) fail();
        T += p.second;
    }

    // 合計がぴったり0でなければfail
    if(T != 0) fail();

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

Measured memory_bytes: 11580
import math
import sys

def pi(n):
    m = int(math.sqrt(n))
    keys = [n / i for i in range(1, m + 1)]
    keys += range(keys[-1] - 1, 0, -1)
    h = {i : i - 1 for i in keys}
    for i in range(2, m + 1):
        if h[i] > h[i - 1]:
            hp = h[i - 1]
            i2 = i * i
            for j in keys:
                if j < i2: break
                h[j] -= h[j / i] - hp

    return h[n]

for line in sys.stdin:
    i = int(line)
    print pi(i)

Measured memory_bytes: 6708
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int x=-1;
  cin >> n;
  for(int i=1;i<500;i++){
    if(i*(i+1)/2==n){
      x=i;
      break;
    }
  }
  if(x>0){
    cout << "Yes" << endl;
    cout << x+1;
    int co=1;
    vector<vector<int>> ans(x+1,vector<int>(x));
    for(int i=0;i<x;i++){
      for(int j=0;j<i+1;j++){
        ans[i+1][j]=co;
        ans[j][i]=co;
        co++;
      }
    }
    for(int i=0;i<x+1;i++){
      cout << endl << x;
      for(int j=0;j<x;j++){
        cout << ' ' << ans[i][j];
      }
    }
    cout << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 2176
import java.net.Inet4Address;
import java.util.*;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int[][] AB = new int[N][2];
        for (int i = 0; i < N; i++) {
            AB[i][0] = sc.nextInt();
            AB[i][1] = sc.nextInt();
        }

        Arrays.sort(AB, new Comparator<int[]>(){
            @Override
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[0], o2[0]);
            }
        });

        long moneySum = 0; // answer
        int count = 0;

        for (int i = 0; i < N; i++) {
            int money = AB[i][0];
            int maxCount = AB[i][1];

            for (int j = 0; j < maxCount; j++) {
                moneySum += money;
                count++;
                if (count == M) {
                    System.out.print(moneySum);
                    return;
                }
            }
        }
    }

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

}


Measured memory_bytes: 94232
#include<bits/stdc++.h> 
#define AndIamIronMan ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); 
#define M 1000000007 

#define int128 __int128
using namespace std;
 
typedef  long long int lli; 

bool prime(lli n){
	bool x=true;
	int i;
	for(i=2;i<=sqrt(n);i++){
		if(n%i==0){
			x=false;
		}	
	}
	return x;
}
string BaseConv(lli b,lli n){
//	lli sum=0;
	string s="";
	while(n){
		lli r=n%b;
//		sum+=r;
		s+=to_string(r);
		n/=b;
	}
	return s;
} 

bool SubStrCheck(string sub,string mai){
	lli i,j,n,m;
	n=sub.length();
	m=mai.length();
	string s="";
	for(i=0;i<m-n+1;i++){
		s="";
		for(j=i;j<i+n;j++){
			s+=mai[j];	
		}
		if(sub==s){
			return true;
		}
	}
	return false;
}  

int main(){
		
    AndIamIronMan;
	lli co=0,i,n,y,m,d,j,k,t,x=0,a,b,c;
//	cin>>t;
//	while(t--){
	cin>>n;
	map<string,lli> mp;
	for(i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<'\n';
	cout<<"WA x "<<mp["WA"]<<'\n';
	cout<<"TLE x "<<mp["TLE"]<<'\n';
	cout<<"RE x "<<mp["RE"];
//	}
	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
using namespace std;

int main() {
	int h, w, ans = 0;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; ++i) cin >> s[i];
	vector<vector<int>> l(h + 2, vector<int>(w + 2)), r(h + 2, vector<int>(w + 2)),
		u(h + 2, vector<int>(w + 2)), d(h + 2, vector<int>(w + 2));
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			l[i][j] = (s[i - 1][j - 1] == '#' ? 0 : l[i][j - 1] + 1);
			u[i][j] = (s[i - 1][j - 1] == '#' ? 0 : u[i - 1][j] + 1);
		}
	}
	for (int i = h; i >= 1; --i) {
		for (int j = w; j >= 1; --j) {
			r[i][j] = (s[i - 1][j - 1] == '#' ? 0 : r[i][j + 1] + 1);
			d[i][j] = (s[i - 1][j - 1] == '#' ? 0 : d[i + 1][j] + 1);
			ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 67200
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define MOD 1000000007

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>

using namespace std;

// clang-format on

/*
for k in 1 .. M
  i[k] = (x / (n - 1)) + 1
  j[k] = (x % (n - 1)) + 1
  if (i[k] > j[k])
    swap(i[k], j[k])
  else
    j[k] = j[k] + 1
  end
  x = (x + d) % (n * (n - 1))
end
*/

map<pair<int, int>, int> p;

main {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int s = sum(a);
  if (s % n == 0) {
    int avg = s / n;
    int c = 0;
    rep(i, n) c += (avg - a[i]) * (avg - a[i]);
    cout << c << endl;
  } else {
    int ava = s / n, avb = (s + n - 1) / n;
    int c = 0, d = 0;
    rep(i, n) {
      c += (ava - a[i]) * (ava - a[i]);
      d += (avb - a[i]) * (avb - a[i]);
    }
    cout << min(c, d) << endl;
  }
  bye;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
const int inf = 1e9;
typedef pair<int, int> pii;

int main(){
	vector<bool> prime(1000000, true);
	prime[0] = prime[1] = false;
	for(int i=2; i*i <1000000; i++){
		if(prime[i]){
			for(int j=i*2; j<1000000; j+=i){
				prime[j] = false;
			}
		}
	}

	int n,m,s,t;
	cin >> n >> m >> s >> t;
	s--; t--;
	vector<vector<int>> adj(n);
	for(int i=0; i<m; i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	queue<pii> wait;
	wait.push(pii(s, 0));
	vector<vector<int>> mincost(n, vector<int>(2, inf));
	mincost[s][0] = 0;
	while(!wait.empty()){
		pii curr = wait.front();
		wait.pop();
		for(int next: adj[curr.first]){
			if(mincost[next][1-curr.second] == inf){
				mincost[next][1-curr.second] = mincost[curr.first][curr.second]+1;
				wait.push(pii(next, 1-curr.second));
			}
		}
	}

	if(mincost[t][0] == 2){
		cout << 2 << endl;
		return 0;
	}
	if(mincost[t][1] == inf){
		cout << -1 << endl;
		return 0;
	}
	for(int i=mincost[t][1]; ; i+=2){
		if(prime[i]){
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 13796
import sys

allCards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

for line in sys.stdin:
  try:
    a, b, c = [int(i) for i in line.split()]
    safe = 20 - (a + b)
    safeCards = [i for i in allCards if i <= safe and i != a and i != b and i != c]
    print("YES" if len(safeCards) / 7 >= 0.5 else "NO")
  except:
    break



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

int abs(int n) {
  if (n<0) {return -n;}
  else {return n;}
}

int main() {
  int N; cin >> N;
  vector<int> w;
  int odd = 0;
  for (int i = 0; i < N; i++) {
    int x; cin >> x; odd+=x; w.push_back(x);
  }
  int ans = odd;
  for (int i = 0; i < N; i++) {
    ans = min(ans, abs(odd - 2*w[i]));
    odd -= (2*w[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000
#define NIL -1
int n;
long long A[MAX];

bool check1(){
  for ( int i = 0; i < n; i++){
    if ( A[i] != 0) return 0;
  }
  return 1;
}

bool check2(){
  long long x = NIL;
  int cnt_0 = 0, cnt_x = 0;
  for ( int i = 0; i < n; i++){
    if ( A[i] != 0 && x == NIL){
      x = A[i];
    }
    if ( A[i] != 0 && A[i] != x) return 0;
    if ( A[i] == 0) cnt_0 ++;
    if ( A[i] == x) cnt_x ++;
  }

  return 3 * cnt_0 == n && 3 * cnt_x == 2 * n ;
}

bool check3(){
  long long x = A[0], y = NIL, z = NIL;
  int cnt_x = 0, cnt_y = 0, cnt_z = 0;
  for ( int i = 0; i < n; i++){
    if ( A[i] != x && y == NIL) y = A[i];
    else if ( A[i] != x && A[i] != y && y != NIL && z == NIL){
      z = A[i];
      if ( (x xor y xor z) != 0){
        return 0;
      }
    } else if ( A[i] != x && A[i] != y && A[i] != z){
        return 0;
    }

    if ( A[i] == x)cnt_x++;
    if ( A[i] == y)cnt_y++;
    if ( A[i] == z)cnt_z++;
  }

  return 3 * cnt_x == n &&  3 * cnt_y == n && 3 * cnt_z == n  && x != y  && x != z && y != z && x != NIL && y != NIL && z != NIL;
}

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

  if ( check1() || check2() || check3() ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define int ll
using ll=long long;
using namespace std;

int A[200*1000+100];
int L[200*1000+100];
int R[200*1000+100];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    rep(i, 1, N) cin >> A[i];
    rep(i, 2, N) L[i] = max(L[i-1], A[i-1]);
    for(int i=N-1; i>=1;i--) R[i] = max(R[i+1], A[i+1]);
    rep(i, 1, N) cout << max(L[i], R[i]) << endl;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 H, W, K;
	cin >> H >> W >> K;
	vector<string> s(H);
	REP(i, H) cin >> s[i];
	vector<vector<int64>> res(H, vector<int64>(W, 0));
	int64 last_row = -1;
	int64 cnt = 1;
	REP(i, H) {
	  vector<int64> x;
	  REP(j, W) {
	    if (s[i][j] == '#') x.push_back(j);
	  }
	  if (x.size() == 0) continue;
    x.push_back(W);
    for (int64 j = 0; j < x.size()-1; j++) {
      for(int64 c = (j == 0 ? 0 : x[j]); c < x[j+1]; c++) {
        FOR(r, last_row+1, i+1) {
          res[r][c] = cnt;
        }
      }
      cnt++;
    }
    last_row = i;
	}
	REP(i, H) {
	  REP(j, W) {
	    if (res[i][j] == 0) {
	      res[i][j] = res[i-1][j];
	    }
	  }
	}
	REP(i, H) {
	  REP(j, W) {
	    cout << res[i][j] << " ";
	  }
	  cout << endl;
	}
}


Measured memory_bytes: 1664
import  math
N=int(input())
Towns=[]
distance=0
for i in range(N):
    tmp=input().split()
    Towns.append([int(tmp[0]),int(tmp[1])])

for i in range(N):
    for j in range(i,N):
        distance+=math.sqrt((Towns[i][0]-Towns[j][0])**2 + (Towns[i][1]-Towns[j][1])**2)

print(2*distance/N)

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

using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    int cont=0;
    if(n>=2)
    {
        cont=n*(n-1)/2;
    }
    if(m>=2)
    {
        cont+=m*(m-1)/2;
    }
    cout<<cont;
    return 0;

}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int n; cin >> n;
	VI x(n),y(n);
	REP(i,n){
		cin >> x[i] >> y[i];
	}

	vector<vector<double>> d(n);
	REP(i,n){
		d[i].resize(n);
	}
	REP(i,n){
		REP(j,n){
			d[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
			d[j][i] = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
		}
	}
	
    vector<int> v(n);
	REP(i,n){
		v[i] = i;
	}

	double result = 0;
    do {
		double dd = 0;
		//REP(i,n){
		//	cerr << v[i] << " ";
		//}
		//cerr << endl;

		REP(i,n-1){
			dd += d[v[i]][v[i+1]];
		}
		result += dd;
		//dump(dd)
		//dump(result)
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

	int kai = 1;
	REP(i,n){
		kai *= i+1;
	}
	//dump(kai)

	cout << result / kai << endl;
    
	






	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

static const int N = 100;
int p[N+1];
int m[N+1][N+1];

int main(){
    int h;
    cin >> h;
    for(int i = 0; i < h; i++){
        cin >> p[i] >> p[i+1];
    }

    for(int i = 1; i <= h; i++) m[i][i] = 0;

    // lはこれから計算する行列積を成す行列の数2->h(DP)
    for(int l = 2; l <= h; l++){
        // iはこれから計算する行列積の先頭の行列
        for(int i = 1; i <= h-l+1; i++){
            // jはこれから計算する行列積の末尾の行列(これを含む)
            int j = i + l -1;
            m[i][j] = 1<<30;
            for(int k = i; k < j; k++){
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }        
    }

    cout << m[1][h] << endl;
    return 0;
}


Measured memory_bytes: 3120