akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using i2 = std::array<int64_t, 2>;

std::string S;

i2 calcFormula(int& s_i);

int main()
{
	std::cin >> S;
	int s_i{};
	printf("%lld\n", calcFormula(s_i)[1]);

	return 0;
}

i2 calcFormula(int& s_i)
{
	std::vector<int> num;
	std::vector<bool> isBegin(1), isEnd(1);
	while (S[s_i] == '(')
	{
		s_i++;
		isBegin.back() = true;
	}
	num.push_back(S[s_i] - '0');
	s_i++;
	while (S[s_i] == ')')
	{
		s_i++;
		isEnd.back() = true;
	}
	std::vector<char> operators;
	while (s_i < (int)S.size())
	{
		operators.push_back(S[s_i]);
		s_i++;
		isBegin.push_back(false);
		while (S[s_i] == '(')
		{
			isBegin.back() = true;
			s_i++;
		}
		num.push_back(S[s_i] - '0');
		s_i++;
		isEnd.push_back(false);
		while (s_i < (int)S.size() && S[s_i] == ')')
		{
			isEnd.back() = true;
			s_i++;
		}
	}
	using vi = std::vector<int64_t>;
	using vvi = std::vector<vi>;
	int size{(int)num.size()};
	vvi minTable(size + 1, vi(size + 1, 1ll << 60)), maxTable(size + 1, vi(size + 1, -(1ll << 60)));
	for (int i{}; i < size; i++)
		minTable[i][i + 1] = maxTable[i][i + 1] = num[i];
	for (int width{2}; width <= size; width++)
		for (int left{}; left + width <= size; left++)
		{
			int right{left + width};
			if (isEnd[left] || isBegin[right - 1]) continue;
			for (int mid{left + 1}; mid < right; mid++)
			{
				if (operators[mid - 1] == '+')
				{
					minTable[left][right] = std::min(minTable[left][right], minTable[left][mid] + minTable[mid][right]);
					maxTable[left][right] = std::max(maxTable[left][right], maxTable[left][mid] + maxTable[mid][right]);
				}
				else
				{
					minTable[left][right] = std::min(minTable[left][right], minTable[left][mid] - maxTable[mid][right]);
					maxTable[left][right] = std::max(maxTable[left][right], maxTable[left][mid] - minTable[mid][right]);
				}
			}
		}
	return {minTable[0][size], maxTable[0][size]};
}


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

int main(int argc, char const *argv[]) {
    
    while (1) {
        char num[1000];
        scanf("%s", num);
        int sum = 0;
        int len = strlen(num);

        if (num[0] == '0') {
            break;
        } else {
            for (int i = 0; i < len; i++){
                sum += num[i] - '0';
            }
            printf("%d\n", sum);
        }
    }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s[n];
    int p[n];
    int c[n];
    
    for(int i=0;i<n;i++){
        cin >> s[i] >> p[i];
        c[i]=i+1;
    }
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]>s[j]){
                swap(s[i],s[j]);
                swap(p[i],p[j]);
                swap(c[i],c[j]);
            }
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j]){
                if(p[i]<p[j]){
                    swap(s[i],s[j]);
                    swap(p[i],p[j]);
                    swap(c[i],c[j]);
                }
            }
        }
    }
    
    for(int i=0;i<n;i++){
        cout << c[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int a[N] , n;
ll sum[N];

int main(){
  scanf("%d",&n);
  rep(i,0,n) scanf("%d",a+i);
  sort(a,a+n);
  rep(i,0,n) sum[i]=a[i]+(i?sum[i-1]:0);
  int ans=0;
  per(i,0,n)
    if(sum[i]*2>=a[i+1])
      ans++;
    else break;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1408
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B& lang=jp

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

#define INF 999999999;
#define MOD 1000000007

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int N, W;
int DP[105][100005];
vector<pair<int, int>> VWs;


int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
    cin >> N >> W;

	VWs.push_back(pair<int, int>(0, 0));
	for(int i = 0; i < N; i++){
		pair<int, int> inn;
		cin >> inn.first >> inn.second;
		VWs.push_back(inn);
	}

	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= W; j++){
			if(VWs[i].second > j) DP[i][j] = DP[i-1][j];
			else{
				DP[i][j] = max(DP[i-1][j-VWs[i].second]+VWs[i].first, DP[i-1][j]);
			}
			//cout << DP[i][j] << " ";
		}
		if(i == N){
			int ans;
			for(int j = 1; j <= W; j++){
				ans = max(ans, DP[N][j]);
			}
			cout << ans << "\n";
		}
		//cout << "\n";
	}


	return 0;
}



Measured memory_bytes: 7436
n, m = map(int, input().split())
abl = []
for _ in range(n):
  abl.append(tuple(map(int, input().split())))

c = 0
bought = 0
for a, b in sorted(abl, key=lambda x: x[0]):
  if bought + b < m:
    c += a * b
    bought += b
  else:
    c += a * (m - bought)
    break
print(c)

Measured memory_bytes: 18904
#include <cassert>
#include <cstdint>
#include <utility>
#include <vector>

class UnionFind {

public:
	using size_type = std::uint_fast32_t;

private:
	std::vector<std::pair<bool, size_type>> tree;

public:
	UnionFind(const size_type size) : tree(size, std::make_pair(1, 1)) {}
	size_type find(const size_type x) {
		assert(x < size());
		if (tree[x].first)
			return x;
		return tree[x].second = find(tree[x].second);
	}
	bool unite(size_type x, size_type y) {
		assert(x < size());
		assert(y < size());
		x = find(x);
		y = find(y);
		if (x == y)
			return false;
		if (tree[x].second < tree[y].second)
			std::swap(x, y);
		tree[x].second += tree[y].second;
		tree[y] = std::make_pair(0, x);
		return true;
	}
	bool same(const size_type x, const size_type y) {
		assert(x < size());
		assert(y < size());
		return find(x) == find(y);
	}
	size_type size(const size_type x) {
		assert(x < size());
		return tree[find(x)].second;
	}
	size_type size() const noexcept { return tree.size(); }
	bool empty() const noexcept { return tree.empty(); }
};

#include <cstddef>
#include <functional>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

template <class GraphContainer, class UnionFindDataStructure>
std::vector<typename GraphContainer::size_type> TarjansOfflineLCA(
	const GraphContainer &graph, const typename GraphContainer::size_type root,
	const std::vector<std::pair<typename GraphContainer::size_type,
	typename GraphContainer::size_type>> &queries) {
	using size_type = typename GraphContainer::size_type;
	const size_type size_ = graph.size();
	UnionFindDataStructure uft(size_);
	std::vector<size_type> ret(queries.size(), size_), anc(size_);
	std::vector<std::vector<std::size_t>> qset(size_);
	std::stack<std::pair<size_type, size_type>> st;

	for (std::size_t i = 0; i < queries.size(); ++i) {
		qset[queries[i].first].emplace_back(i);
		qset[queries[i].second].emplace_back(i);
	}

	st.emplace(root, 0);

	std::function<void(const size_type, const size_type)> dfs =
		[&](const size_type v, const size_type prev) {
		anc[v] = v;
		for (const auto e : graph[v]) {
			if (e.to != prev) {
				dfs(e.to,v);
				uft.unite(v, e.to);
				anc[uft.find(v)] = v;
			}
		}
		for (const auto e : qset[v])
			if (ret[e] == size_)
				ret[e] = v;
			else
				ret[e] = anc[uft.find(ret[e])];
	};
	dfs(root, size_);
	return ret;
}

struct edge {
	int to;
	edge(int x):to(x){}
};
#include<iostream>
int main() {
	int n;
	std::cin >> n;
	using Graph = std::vector<std::vector<edge>>;
	Graph g(n);
	for (int i = 0;i < n;++i) {
		int k, c;
		std::cin >> k;
		while (k--) {
			std::cin >> c;
			g[i].emplace_back( c );
		}
	}
	int q;
	std::cin >> q;
	using S = typename Graph::size_type;
	std::vector<std::pair<S, S>> Q;
	while (q--) {
		S u, v;
		std::cin >> u >> v;
		Q.emplace_back(u, v);
	}
	const auto ans=TarjansOfflineLCA<Graph, UnionFind>(g, 0, Q);
	for (const auto e : ans)
		std::cout << e << std::endl;
	return 0;
}


Measured memory_bytes: 36536
#include <bits/stdc++.h>
char s[10];
int cnt=0;
int main()
{
	scanf("%s",s);
    for (int i=0;i<3;i++)
      if (s[i]=='A') cnt++;
    if (cnt!=3&&cnt!=0) puts("Yes");
    else puts("No");
	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 n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        StringBuilder sb = new StringBuilder();
        int openCount = 0;
        int level = 0;
        for (char c : arr) {
            if (c == '(') {
                level++;
                sb.append(c);
            } else {
                if (level <= 0) {
                    openCount++;
                } else {
                    level--;
                }
                sb.append(c);
            }
        }
        for (int i = 0; i < openCount; i++) {
            sb.insert(0, '(');
        }
        for (int i = 0; i < level; i++) {
            sb.append(')');
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 21844
Value = list(map(int,input().split()))
#Value[0] = Q,Value[1] = H,Value[2] = S…
N = int(input())
N = N*100
res = 0
l = [25,50,100,200]

for i in range(3):
    if Value[i]*2 < Value[i+1]:
        Value[i+1] = Value[i]*2

for i in range(4)[::-1]:
    n = N//l[i]
    N = N%l[i]
    res += Value[i]*n

print(res)


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int n, k;
    cin >> n >> k;
    int count = 0;
    ll tmp = 1;
    while(n > tmp) {
        tmp *= k;
    }
    while(n > 0) {
        count++;
        n /= k;
        tmp /= k;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import os
import sys
from itertools import permutations, product, combinations_with_replacement

def main():
	n,m,q = map(int, input().split())
	target = [list(map(int,input().split())) for _ in range(q)]
	max_value = 0	
	
	for v in combinations_with_replacement(range(1,m+1),n):
		result = 0
		for i in target:
			if v[i[1]-1] - v[i[0]-1] == i[2]:
				result += i[3]
			else:
				pass
		max_value =  max(result,max_value)

	print(max_value)

if __name__ == "__main__":
        main()



Measured memory_bytes: 8788
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005
#define SIZE 31

int R_OK,R_FALSE,K;
double cost[SIZE];
double dp[SIZE][NUM];
double memo[NUM];


double recursive(int length){

	if(memo[length] != DBL_MAX){
		return memo[length];
	}

	for(int x = 1; x <= min(K,length); x++){

		if(x == 1){

			for(int start = 1; start <= length-1; start++){

				dp[x][length] = min(dp[x][length],(double)start/(double)length*(recursive(start)+cost[1])+
						(double)(length-start)/(double)length*(recursive(length-start)+cost[0]));
			}

		}else{

			for(int start = 1; start <= length-x; start++){

				dp[x][length] = min(dp[x][length],(double)start/(double)length*(recursive(start)+cost[x])+
						(double)(length-start)/(double)length*dp[x-1][length-start]);
			}
		}
		memo[length] = min(memo[length],dp[x][length]);
	}

	return memo[length];
}

int main(){

	scanf("%d %d %d",&R_OK,&R_FALSE,&K);

	int max_index = R_FALSE-R_OK;

	for(int i = 0; i <= K; i++){
		scanf("%lf",&cost[i]);
	}

	for(int i = 0; i <= min(K,max_index); i++){
		for(int k = 0; k <= max_index; k++){
 			dp[i][k] = DBL_MAX;
		}
	}

	for(int i = 0; i <= max_index; i++)memo[i] = DBL_MAX;

	memo[0] = 0;
	memo[1] = 0;
	memo[2] = (cost[0]+cost[1])/2.0;
	dp[1][2] = memo[2];

	printf("%.10lf\n",recursive(max_index));

	return 0;
}



Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

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

int main()
{
    cin >> s;
    REP(i,s.size()){
        if(s[i]=='1'){
            cnt++;
        }
    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 764
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSevne = false;
            bool isFive1 = false;
            bool isFive2 = false;

            string[] input = Console.ReadLine().Split(' ');
            if (input.Length < 3) {
                Console.WriteLine("NO");
                return;
            }

            for(int i = 0; i <= input.Length - 1; i++)
            {
                if(input[i] == "7") { isSevne = true; }
                if(input[i] == "5")
                {
                    if (isFive1)
                    {
                        isFive2 = true;
                    }
                    else
                    {
                        isFive1 = true;
                    }
                }
            }

            if(isSevne && isFive1 && isFive2)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11092
// Aizu Vol-1 0173: Haunted House
// 2017.8.2

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

void getStr(char *w)
{
	while (isspace(*p)) p++;
	while (isalnum(*p)) *w++ = *p++;
	*w = 0;
}

int main()
{
	int i, am, pm;
	char w[30];

	for (i = 0; i < 9; i++) {
		gets(p = buf);
		getStr(w), am = getInt(), pm = getInt();
		printf("%s %d %d\n", w, am + pm, am * 200 + pm * 300);
	}
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()

#define MAX_A 17
#define MAX_B 17

int a, b; // 1 <= a, b <= 16
int n;    // 1 <= n <= 40
bool ok[MAX_A+1][MAX_B+1];
// evaluate score with starting point (x, y)
int eval(int x, int y) {
  // cout << "("<<x<<", " << y << ")"<<endl;
  // goal
  if (x == (a-1) && y == (b-1)) return 1;
  if (x >= a || y >= b) return 0;

  bool up    = ok[y+1][x];
  bool right = ok[y][x+1];
  if (up && right) return eval(x+1, y) + eval(x, y+1);
  if (!up && !right) return 0; // stop
  if (up)    return eval(x, y+1);
  if (right) return eval(x+1, y);

  return INT_MIN;
}
int main() {
  while (true) {
    // input
    cin >> a >> b;
    if (a == 0 && b == 0) break;
    cin >> n;
    rep(y, b) {
      rep(x, a) {
        ok[y][x] = true;
      }
    }
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      ok[y-1][x-1] = false;
    }
    /*
    for (int y=b-1; y>=0; y--) {
      rep(x, a) {
        cout << (ok[y][x]?"o":"x");
      }
      cout << endl;
    }
    */
    //
    cout << eval(0, 0) << endl;
  }
  return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

lli n, k;

int main()
{
	scanf("%lld %lld",&n,&k);

	lli ans = min( n%k , k - n%k );

	printf("%lld\n",ans);
}

Measured memory_bytes: 256
// Name: Transit Tree Path
// Level: 2
// Category: Graph, 最短経路問題
// Note: 深さ優先探索

#include <iostream>
#include <vector>
#define MAX_V 100001

using namespace std;

struct edge { int to; long long cost; };

vector<edge> tree[MAX_V];
long long depth[MAX_V];

// v: 今いる頂点, p: v の親
void dfs(int v, int p, long long d) {
    depth[v] = d;
    for (int i = 0; i < tree[v].size(); i++) {
        edge e = tree[v][i];
        // 戻らないようにする処理
        if (e.to == p) { continue; }
        dfs(e.to, v, d + e.cost);
    }
}

int main() {
    int N, a, b, c;
    int Q, K, x, y;

    cin >> N;

    for (int i = 0; i < N-1; i++) {
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back(edge{b, c});
        tree[b].push_back(edge{a, c});
    }

    cin >> Q >> K;
    dfs(K-1, -1, 0);

    for (int i = 0; i < Q; i++) {
        cin >> x >> y;
        x--; y--;
        cout << depth[x] + depth[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define ll long long
#define M 1000000007
#define H 200010
#define N 3010
using namespace std;

struct pt{int x,y;};

ll h,w,k,x,y,dx,dy,dp[N],fac[H],inv[H];
pt ps[N];

bool cmp(pt a,pt b)
{
    if(a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}

ll bpow(ll a, ll b)
{
    ll ret=1;
    while(b)
    {
        if(b&1) ret=(ret*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    return ret;
}

ll ncr(ll n,ll r)
{
    return ((fac[n]*inv[n-r])%M*inv[r])%M;
}

int main()
{
    fac[0]=1;
    FOR(i,1,H) fac[i]=(fac[i-1]*i)%M;
    FOR(i,0,H) inv[i]=bpow(fac[i],M-2);
    cin>>h>>w>>k;
    FOR(i,0,k) cin>>ps[i].x>>ps[i].y;
    ps[k].x=1; ps[k].y=1;
    ps[k+1].x=h; ps[k+1].y=w;
    sort(ps,ps+k+2,cmp);
    dp[0]=1;
    FOR(i,1,k+2)
    {
        dp[i]=ncr(ps[i].x+ps[i].y-2,ps[i].x-1);
        FOR(j,1,i)
        {
            dx=ps[i].x-ps[j].x; dy=ps[i].y-ps[j].y;
            if(dx<0 || dy<0) continue;
            dp[i]=(dp[i]-(dp[j]*ncr(dx+dy,dx))%M+M)%M;
        }
    }
    cout<<dp[k+1]<<'\n';

    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <bitset>

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

using namespace std;

typedef long long ll;

int binary(ll A[],int N,ll k){
    ll left=-1;
    ll right=N;
    while(left+1<right){
        ll num=(left+right)/2;
        if(k<A[num]){
            right=num;
        }else{
            left=num;
        }
       // cout<<"left:"<<left<<" right:"<<right<<endl;
    }
    return right;
}



int main(){

    int N,M;
    cin>>N>>M;
    ll K;
    cin>>K;
    ll A[N+1],B[M+1]; 
    ll a,b;

    int ans=0;

    A[0]=0;
    B[0]=0;
    
    for(int i=1;i!=N+1;++i){
        cin>>a;
        A[i]=a+A[i-1];
    };
    for(int i=1;i!=M+1;++i){
            cin>>b;
            B[i]=b+B[i-1];
    }

    ll* x;
    ll total;

    for(int i=0;i<=N;++i){
       ll y=binary(B,M+1,K-A[i]);

       //cout<<A[i]<<":"<<K-A[i]<<":"<<(*x)<<":"<<x-B-1<<":"<<i<<endl;
       ans=ans>=(i+y-1)?ans:(i+y-1);
       if(A[i]>K){
          break;
       }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 6760
n = int(input())
room = [[[0]*10 for i in range(3)]for j in range(4)]
for i in range(n):
    a,b,c,d=map(int,input().split())
    room[a-1][b-1][c-1]+=d

for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" "+str(room[i][j][k]),end="")
        print()
    if i != 3:
        for x in range(20):
            print("#",end="")
        print()
    


Measured memory_bytes: 5632
#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>;
 
const int INF = 1001001001;
 
int a[12][12];
 
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }
 
  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
data class Point(val x: Double, val y: Double) {
    fun distanceFrom(that: Point): Double = (this - that).let{Math.sqrt(it.x * it.x + it.y * it.y)}
    operator fun minus(that: Point): Point = Point(x - that.x, y - that.y)
}
class Line(from: Point, to: Point) {
    val a: Double = to.y - from.y
    val b: Double = from.x - to.x
    val c: Double = from.y * to.x - from.x * to.y
    fun distanceFrom(point: Point): Double {
        return Math.abs(a * point.x + b * point.y + c) / Math.sqrt(a * a + b * b)
    }
}

class Edge(val from: Point, val to: Point) {
    fun distanceFrom(point: Point): Double {
        return if ((from to to) dot (from to point) >= 0 && (to to from) dot (to to point) >= 0){
            Line(from, to).distanceFrom(point)
        }else {
            Math.min(from.distanceFrom(point), to.distanceFrom(point))
        }
    }
}
data class Vector(val x: Double, val y: Double) {
    infix fun dot(that: Vector): Double = x * that.x + y * that.y
}
infix fun Point.to(that: Point): Vector = (that - this).let{Vector(it.x, it.y)}

class Circle(val center: Point, val radius: Double) {
    fun canMoveTo(point: Point, barrier: Circle): Boolean {
        return Edge(center, point).distanceFrom(barrier.center) >= radius + barrier.radius
    }
}

fun solve(coins: List<Pair<Circle, Circle>>): Int {
    val memo = IntArray(1 shl coins.size){-1}
    memo[memo.lastIndex] = 0
    fun sub(state: Int): Int {
        if (memo[state] == -1) {
            val currentPosition = coins.withIndex().map{(i, pair) -> if (state and (1 shl i) == 0) pair.first else pair.second}
            val suspects = coins.indices.filter{state and (1 shl it) == 0 && (1 until coins.size).map{i -> currentPosition[(i + it) % coins.size]}.all{c -> coins[it].first.canMoveTo(coins[it].second.center, c)}}
            memo[state] = suspects.map{sub(state or (1 shl it)) + 1}.max() ?: 0
        }
        return memo[state]
    }
    return sub(0)
}
fun main(args: Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val coins = List(n){
        val (r, sx, sy, tx, ty) = readLine()!!.trim().split(' ').map(String::toDouble)
        Pair(Circle(Point(sx, sy), r), Circle(Point(tx, ty), r))
    }
    println(solve(coins))
}


Measured memory_bytes: 77844
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<iostream>
#define ll long long
using namespace std;
const int N = 81;
const int  av=12800;
int h,w,ans,a[N][N],b[N][N],x[N][N];
bool can[N][N][N*N*4+160];
int main(){
	scanf("%d%d",&h,&w);
	ans=0x7fffffff;
	for(int i=1;i<=h;i++) 
		for(int j=1;j<=w;j++) 	
			scanf("%d",&a[i][j]);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++) 	
			scanf("%d",&b[i][j]);
	can[0][1][av]=1;can[1][0][av]=1;
	for(int i=1;i<=h;i++) 
		for(int j=1;j<=w;j++){
			x[i][j]=max(a[i][j],b[i][j])+max(x[i-1][j],x[i][j-1]);
			int k1=a[i][j]-b[i][j];
			int k2=-k1;
			for(int k=x[i][j]+av;k>=av-x[i][j];k--) 
				if(can[i-1][j][k-k1]||can[i-1][j][k-k2]||can[i][j-1][k-k1]||can[i][j-1][k-k2])
					can[i][j][k]=1;
		}
	for(int k=av-x[h][w];k<=av+x[h][w];k++)
		if(can[h][w][k]) 
			ans=min(ans,abs(k-av)); 
	printf("%d\n",ans);
	return 0;
}


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

int main(void) {
	int id;
	int hoge;
	char line[128];
	int i, j;
	int id_a[1024][2], a = 0;
	int id_b[1024][2], b = 0;

	memset(id_a, 0, sizeof(id_a));
	memset(id_b, 0, sizeof(id_b));

	fgets(line, 128, stdin);
	while(line[0] != '\n') {
		sscanf(line, "%d,%d", &id, &hoge);
		fgets(line, 128, stdin);

		for(i = 0; i < a; i++) {
			if(id_a[i][0] == id) {
				id_a[i][1]++;
				break;
			}
		}

		if(i == a) {
			id_a[i][0] = id;
			id_a[i][1]++;
			a++;
		}
	}

	while(fgets(line, 128, stdin) != NULL) {
		sscanf(line, "%d,%d", &id, &hoge);

		for(i = 0; i < b; i++) {
			if(id_b[i][0] == id) {
				id_b[i][1]++;
				break;
			}
		}

		if(i == b) {
			id_b[i][0] = id;
			id_b[i][1]++;
			b++;
		}
	}

	for(i = 0; i < a; i++) {
		for(j = 0; j < b; j++) {
			if(id_a[i][0] == id_b[j][0])
				printf("%d %d\n", id_a[i][0], id_a[i][1] + id_b[j][1]);
		}
	}

	return 0;
}

Measured memory_bytes: 620
#!/usr/bin/env python3
N = int(input())
a = [chr(i) for i in range(97, 97+26)]
ret = []
def backtrack(N,s,i):
    #print(N,s,i)
    if N == 1:
        ret.extend([s+c for c in a[:i+1]])
        return
    for j in range(i+1):#max i+1
        #print("a:",j)
        if j == i:
            backtrack(N-1,s+a[j],i+1)
        else:
            backtrack(N-1,s+a[j],i)
backtrack(N,"",0)
for s in ret:
  print(s)

Measured memory_bytes: 12656
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));


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

    int n;
    cin >> n;
    double ans;
    if(n % 2 == 0){
        ans = n / 2.0;
        ans = ans / n;
    }else {
        ans = (n+1) / 2.0;
        ans = ans / n;
    }
    cout << ans << endl;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
lis = list(map(int,input().split()))
x = 0
for i in lis:
    if i % 2 == 0:
        if i % 3 != 0 and i % 5 != 0:
            x += 1
if x == 0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 2940
#include <stdio.h>

int main(void){
	int r=0,g=0,b=0;
	int n=0;
    scanf("%d %d %d",&r,&g,&b);
	if( r<1|g<1|b<1|9<r|9<g|9<b){
		printf("入力エラー\n"); 
        return 1;
   }
   int num = 0;
   num = (r*100+g*10+b)%4;
   if( num == 0 ){
	  printf("YES\n");
	}else{
	  printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.print( a / b + " " + a % b + " ");
        System.out.printf("%.8f\n", (double)a / b);
    }
}


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

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

    sort(A.begin(), A.end());
    int pre = 0, cnt = 0, res = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == pre) {
            cnt++;
        } else {
            if (cnt % 2 != 0)
                res++;
            cnt = 1;
        }
        pre = A[i];
    }
    if (cnt % 2 != 0) res++;
    cout << res << endl;
    return 0;
}

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

int main() {
  int n;
  int a1[100] = {0};
  int a2[100] = {0};
  int ans1 = 0, ans2 = 0, max = 0;

  cin >> n;

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

  for (int i = 0; i < n; i++) {
    ans1 += a1[i];
    ans2 = ans1;
    for (int j = i; j < n; j++) {
      ans2 += a2[j];
    }
    if (ans2 > max) {
      max = ans2;
    }
  }

  cout << max << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vel vector<long long>
#define veb vector<bool>
#define vvel vector<vel>
#define int long long
#define pin pair<int,int>
#define ppin pair<int,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define maxel(vec, j) *max_element(vec.begin(), vec.begin()+j)

using namespace std;
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
signed main() {
    int pr = 1000;
    pr *= pr * pr; pr += 7;
    int N;
    string S;
    cin >> N;
    cin >> S;
    int left_dis = 0, right_dis = 0;
    rep(i, N){
        if(S[i] == '.') right_dis++;
    }
    int min_value = left_dis + right_dis;
    rep(i, N){
        if(S[i] == '#'){
            left_dis++;
        }else{
            right_dis--;
        }
        int dis = left_dis + right_dis;
        if(min_value > dis) min_value = dis;
    }
    cout<<min_value;
    return 0;
}


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

using namespace std;

const int MAXN = 3e5 + 5;
const int INF = 1e9;

set <int> g[MAXN];
set <int> gt[MAXN];


main(){

	int n, m; cin >> n >> m;


	int u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;

		u--; v--;

		g[u].insert(v + n);
		g[u + n].insert(v + 2 * n);
		g[u + 2 * n].insert(v);
	}


	int s, t; cin >> s >> t;

	s--; t--;


	vector <int> d(n * 3, INF);

	queue <int> q;

	q.push(s);
	d[s] = 0;

	while(!q.empty()){
		int v = q.front(); q.pop();

		for(int to : g[v]){
			if(d[to] > d[v] + 1){
				d[to] = d[v] + 1;
				q.push(to);
			}
		}
	}

	cout << (d[t] == INF ? -1 : d[t] / 3) << endl;


	return 0;
}

Measured memory_bytes: 43648
from itertools import product
import math
D,G = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(D)]
cmin = 10**4
for x in product((0,1),repeat=D):
    scr = 0
    cnt = 0
    j = -1
    for i in range(D):
        if x[i]==1:
            scr += 100*(i+1)*A[i][0]+A[i][1]
            cnt += A[i][0]
        else:
            j = i
    if scr>=G:
        cmin = min(cmin,cnt)
    else:
        k = math.ceil((G-scr)/(100*(j+1)))
        if k<A[j][0]:
            cmin = min(cmin,cnt+k)
print(cmin)

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

using namespace std;

int dp[3005][3005];
int par[3005][3005];
string s, t;
stack<char> stk;

int main(){
    cin >> s >> t;
    int N = s.size(), M = t.size();
    for(int i = 1; i<=N; i++){
        for(int j =1; j<=M; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else if(dp[i-1][j] > dp[i][j-1]){
                dp[i][j] = dp[i-1][j];
                par[i][j] = 1;
            }
            else{
                dp[i][j] = dp[i][j-1];
                par[i][j] = -1;
            }
        }
    }
    int i = N, j = M;
    while(i*j){
        if(par[i][j] == 1){
            i--;
        }
        else if(par[i][j] == -1){
            j--;
        }
        else{
            stk.push(s[i-1]);
            i--;
            j--;
        }
    }
    while(stk.size()){
        cout << stk.top();
        stk.pop();
    }
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;

int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll cost=0;
    ll i=0;
    ll mini=10000000000000000;
    while(1)
    {
        ll temp=0;
        ll p1 = x-i/2;

        ll p2 = y-i/2;
        temp=temp+i*c;
        if(p1<0 && p2<0) break;
        if(p1>0)
        {
            temp+=p1*a;
        }
        if(p2>0)
        {
            temp+=p2*b;
        }
        if(mini>temp && temp!=0) mini=temp;
        i+=2;

    }
    cout<<mini<<endl;
}



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


typedef pair<ll, ll> Pair;

int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N, K; cin >> N >> K;
  vector<ll> H(N+1);
  for (int i = 0; i < N; i++) cin >> H.at(i);

  vector<vector<Pair>> st(K+1);
  st.at(0).emplace_back(0, 0);

  for (int i = 0; i < N; i++) {
    vector<vector<Pair>> newst(K+1);
    for (int k = 0; k < K; k++) {
      for (Pair p : st.at(k)) {
	if (p.first != H.at(i)) newst.at(k+1).push_back(p);
      }
    }
    for (int k = 0; k <= K; k++) {
      if (st.at(k).size() == 0) continue;
      ll cmin = LLONG_MAX;
      for (Pair p : st.at(k)) {
	ll ht = p.first;
	ll cost = p.second;
	cmin = min(cmin, cost + max(H.at(i) - ht, 0LL));
      }
      newst.at(k).emplace_back(H.at(i), cmin);
    }
    st = move(newst);
  }
  ll ans = LLONG_MAX;
  for (int k = 0; k <= K; k++) {
    for (Pair p : st.at(k)) {
      ans = min(ans, p.second);
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 2432
#include<iostream>
using namespace std;
int main(){
  int a,b,c,ans;
  cin>>a>>b>>c;
  if(a>=b && a>=c){
    ans=a*10+b+c;
  }else if(b>=a && b>=c){
    ans=b*10+a+c;
  }else{
    ans=c*10+a+b;
  }
  cout<<ans<<"\n";
  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(int n){
    int d;
    vector<string> name(n);
    cin >> d;
    rep(i,0,n) cin >> name[i];
    sort(name.begin(),name.end());

    function<set<string>(const string&)> enumerate_neighborhood=[&](const string &s){
        set<string> st;
        //replace
        {
            string t=s;
            rep(i,0,s.size()){
                rep(j,0,26){
                    t[i]='a'+j;
                    st.insert(t);
                }
                t[i]=s[i];
            }
        }
        //insert
        {
            string x;
            rep(i,0,s.size()+1){
                string y=s.substr(i);
                rep(j,0,26){
                    x.push_back('a'+j);
                    auto t=x+y;
                    st.insert(t);
                    x.pop_back();
                }
                x+=s[i];
            }
        }
        //delete
        {
            string x;
            rep(i,0,s.size()){
                string t=x+s.substr(i+1);
                st.insert(t);
                x+=s[i];
            }
        }
        //swap adjacent
        {
            string t=s;
            rep(i,0,s.size()-1){
                swap(t[i],t[i+1]);
                st.insert(t);
                swap(t[i],t[i+1]);
            }
        }
        return st;
    };

    vector<set<string>> us(n);
    rep(i,0,n) us[i]=enumerate_neighborhood(name[i]);

    int count=0;
    rep(i,0,n){
        rep(j,i+1,n){
            if(d==1){
                if(us[i].find(name[j])==us[i].end()) continue;
            }else{
                vector<string> v;
                set_intersection(us[i].begin(),us[i].end(),us[j].begin(),us[j].end(),back_inserter(v));
                if(v.empty()) continue;
            }
            cout << name[i] << "," << name[j] << endl;
            ++count;
        }
    }
    cout << count << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    for(;;){
        int n;
        cin >> n;
        if(!n) break;
        solve(n);
    }
    return 0;
}

Measured memory_bytes: 17624
def next_koch(n):
    turn60 = 0.5 + 3 ** 0.5 * 0.5j
    n_next = [n[0]]
    for i in range(1, len(n)):
        s = (n[i - 1] * 2 + n[i]) / 3
        t = (n[i - 1] + n[i] * 2) / 3
        u = (t - s) * turn60 + s
        n_next +=[s, u, t, n[i]]
    return n_next
 
p1 = 0 + 0j
p2 = 100 + 0j
koch = [p1, p2]
 
n = int(input())
for i in range(n):
    koch = next_koch(koch)
 
for z in koch:
    print("{:.8f} {:.8f}".format(z.real, z.imag))


Measured memory_bytes: 5736
#include <bits/stdc++.h>
#define _boost ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fi first
#define se second
#define clz __builtin_clz
#define clzll __builtin_clzll
#define bp __builtin_popcount
#define _unique(x) sort((x).begin(),(x).end()),(x).erase(unique((x).begin(), (x).end()),(x.end()))
#define all(x) (x).begin(),(x).end()
#define _rand(i,j) uniform_int_distribution<int>(i, j)(rng___)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;
template < typename _T, typename _T2> string to_string(pair<_T,_T2> x) {return "<"+to_string(x.fi)+", "+to_string(x.se)+">";}
template < typename _T> string to_string(vector<_T> vec) {string s="[ "; for(auto el:vec)s+=to_string(el)+", "; s[s.size()-1]=']';s[s.size()-2]=' '; return s;}
template < typename _T> string to_string(set<_T> vec) {string s="{ "; for(auto el:vec)s+=to_string(el)+", "; s[s.size()-1]='}';s[s.size()-2]=' '; return s;}
template < typename _T, typename _T2> string to_string(map<_T,_T2> vec) {string s="{ "; for(auto el:vec)s+="mp["+to_string(el.fi)+"]= "+to_string(el.se)+", "; s[s.size()-1]='}';s[s.size()-2]=' '; return s;}
template < typename _T > inline void _DBG(const char *s, _T x){cerr << s << " = " << to_string(x) << "\n";}
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a){while(*s != ',') cerr << *s++;cerr << " = " << to_string(x) << "\n";_DBG(s + 1, a...);}
#ifdef LOCAL
#define _print(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define _print(...) ;//cout<<2;//(__VA_ARGS__)
#endif
mt19937 rng___(chrono::steady_clock::now().time_since_epoch().count());


const LL MOD = 1e9+7;//998244353;
const LL LLINF = 1e18+7;
const int N=1e5+8;


int main()
{
    _boost;
    int n,k;
    cin>>n>>k;
    vector<int> in(n);
    for(int i=0;i<n;i++)cin>>in[i];
    vector<int> dp(k+1,0);
    for(int i=0;i<=k;i++)
    {
        if(dp[i]==0)
        {
            dp[i]=-1;
        }
        if(dp[i]==-1)
        {
            for(int j=0;j<n;j++)
            {
                if(i+in[j]<=k)dp[i+in[j]]=1;
            }
        }
    }
    //_print(dp);
    cout<<(dp[k]==1?"First":"Second");
}




Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int N,i;
  long long int T,A,TRatio,ARatio,j,k;

  scanf("%d",&N);
  scanf("%lld %lld",&T,&A);
  for(i=1;i<N;++i){
    scanf("%lld %lld",&TRatio,&ARatio);
    j=T/TRatio;
    if(T%TRatio) ++j;
    k=A/ARatio;
    if(A%ARatio) ++k;
    if(j>k){
      T=TRatio*j;A=ARatio*j;
    }
    else{
      T=TRatio*k;A=ARatio*k;
    }
  }
  printf("%lld\n",T+A);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  string s;
  cin >> s;
  int cnt = 0;
  int mxcnt = 0;
  int status = 0; //0: find a, 1: find z;
  REP(i,s.size()){
    if(status == 0){
      if(s[i] == 'A'){
        status = 1;
        cnt++;
      }
    }
    else{
      cnt++;
      if(s[i] == 'Z'){
        mxcnt = max(cnt, mxcnt);
      }
    }
  }

  cout << mxcnt << endl;
  return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  cin >> n >> k;
  vector<long int> a(n);
  for(long int i = 0; i < n; i++) cin >> a[i];
  for(long int i = 0; i < n-k; i++){
    if(a[i] < a[i+k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 4844
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	
	rep(i, n) {
		cin >> a[i];
	}
	
	vector<int> ans;
	
	for(int i = -100; i <= 100; ++i) {
		int tmp = 0;
		for (int j = 0; j < n; j++) {
			tmp += pow((a[j] - i), 2);
		}
		ans.push_back(tmp);
	}
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
	return 0;
}


Measured memory_bytes: 256
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<long long int>>;
using wgraph = vector<vector<pair<long long int, long long int>>>;
long long int INF = 1001001001001001LL;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(long long int i = 0; i < (n); i++)
#define rrep(i,n) for(long long int i = 1; i <= (n); i++)
#define drep(i,n) for(long long int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(long long int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
    
  map<string, string> m;
  m["Sunny"] = "Cloudy";
  m["Cloudy"] = "Rainy";
  m["Rainy"] = "Sunny";
  string s; cin >> s;
  cout << m[s] << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int n;
    cin >> n;
    int h[n];
    rep(i,n) cin >> h[i];
    int ans = 1;
    for(int i=1;i<n;i++){
        int k = 0;
        for(int j=0;j<i;j++){
            if(h[j] <= h[i]){
                k++;
            }
        }
        if(k == i && h[i-1] <= h[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int N,K;
VV<ll> vs;

struct S{
	int w;
	ll v;
	int c;
	S(int w,ll v,int c):w(w),v(v),c(c){}
	bool operator<(const S& r) const {
		return v*2/w > r.v*2/r.w;
	}
};

int main(){
	cin>>N>>K;
	vs.resize(K);
	rep(i,N){
		int c,v;
		cin>>c>>v;
		c--;
		vs[c].pb(v);
	}
	V<S> g;
	rep(c,K){
		sort(all(vs[c]),greater<ll>());
		int n = vs[c].size();
		g.push_back(S(2,vs[c][0]+vs[c][1],c));
		rep(i,n-2){
			g.push_back(S(1,vs[c][i+2],c));
		}
	}
	sort(all(g));
	V<ll> ans(N+1,-1);
	int sz = 0;
	ll V = 0;

	ll inf = 1e18;
	ll bestoL = inf;
	ll bestL2 = inf;

	multiset<ll> oR;

	multiset<ll> R3;
	rep(c,K){
		int n = vs[c].size();
		if(n>=3){
			R3.insert(vs[c][0]+vs[c][1]+vs[c][2]);
		}
	}

	for(S x: g){
		int w = x.w;
		ll v = x.v;
		int c = x.c;
		
		if(w==2){
			//sz+1 ?
			if(bestoL != inf){
				chmax(ans[sz+1],V+v-bestoL);
			}
			if(!oR.empty()){
				chmax(ans[sz+1],V + *oR.rbegin());
			}
			if(bestL2 != inf && !R3.empty()){
				chmax(ans[sz+1], V - bestL2 + *R3.rbegin() );
			}
		}

		sz += w;
		V += v;
		ans[sz] = V;

		if(w==1){
			chmin(bestoL,v);
		}

		if(w==2){
			int n = vs[c].size();
			rep(i,n-2) oR.insert(vs[c][i+2]);
		}else{
			auto it = oR.lower_bound(v);
			assert(*it == v);
			oR.erase(it);
		}

		if(w==2){
			int n = vs[c].size();
			if(n>=3){
				auto it = R3.lower_bound(vs[c][0]+vs[c][1]+vs[c][2]);
				R3.erase(it);
			}
			chmin(bestL2,v);
		}
	}
	rep1(i,N) cout<<ans[i]<<endl;
}

Measured memory_bytes: 21612
#include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    #include<cctype>
    #include<climits>
    #include<iostream>
    #include<string>
    #include<vector>
    #include<map>
    #include<list>
    #include<queue>
    #include<deque>
    #include<algorithm>
    #include<numeric>
    #include<utility>
    #include<complex>
    #include<memory>
    #include<functional>
    #include<set>
     
    using namespace std;
     
    #define ALL(g) (g).begin(),(g).end()
    #define REP(i, x, n) for(int i = x; i < n; i++)
    #define rep(i,n) REP(i,0,n)
    #define F(i,j,k) fill(i[0],i[0]+j*j,k)
    #define P(p) cout<<(p)<<endl;
    #define INF 1<<25
     
    typedef long long ll;
     
    int dy[8]={1,1,1,0,0,-1,-1,-1};
    int dx[8]={-1,0,1,-1,1,-1,0,1};
    struct S{
    	int a,b,c;
    };
    bool asc(const S& left,const S& right){
    	return left.c > right.c;
    }
     
    vector<int>A,B,C;
    int main(){
    	int N;
    	cin>>N;
    	int tmp;
    	rep(i,N){
    		cin>>tmp;
    		A.push_back(tmp);
    	}
    	rep(i,N){
    		cin>>tmp;
    		B.push_back(tmp);
    	}
    	rep(i,N){
    		cin>>tmp;
    		C.push_back(tmp);
    	}
    	sort(ALL(A));
    	sort(ALL(B));
    	sort(ALL(C));
    	ll ans=0;
    	rep(i,N){
    		ll u=lower_bound(ALL(A),B[i])-A.begin();
    		ll o=C.end()-upper_bound(ALL(C),B[i]);
    		ans+=u*o;
    	}
    	cout<<ans<<endl;
    	return 0;
    }
     

Measured memory_bytes: 1784