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

using namespace std;

using ll = long long;
int main() {
   ios_base::sync_with_stdio(false);
   int N, M;
   cin >> N >> M;
   vector<int> A(N), B(N);
   vector<int> par(N);
   vector<ll> sum(N);
   vector<ll> ans(N);
   for (int i = 0; i < N; ++i) {
      cin >> A[i] >> B[i];
      par[i] = i, sum[i] = B[i], ans[i] = max(A[i], B[i]);
   }
   vector<vector<int>> adj(N);
   for (int i = 0; i < M; ++i) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      adj[x].emplace_back(y);
      adj[y].emplace_back(x);
   }
   vector<int> ord(N);
   iota(ord.begin(), ord.end(), 0);
   sort(ord.begin(), ord.end(), [&](int x, int y) {
      return A[x] - B[x] < A[y] - B[y];
   });
   function<int(int)> getPar = [&](int v) {
      if (v != par[v]) {
         par[v] = getPar(par[v]);
      }
      return par[v];
   };
   vector<bool> visited(N);
   for (int v : ord) {
      vector<int> nxts;
      for (int u : adj[v]) {
         if (visited[u]) nxts.emplace_back(getPar(u));
      }
      sort(nxts.begin(), nxts.end());
      nxts.resize(unique(nxts.begin(), nxts.end()) - nxts.begin());
      for (int u : nxts) {
         par[u] = v;
         sum[v] += sum[u];
      }
      if (nxts.size()) {
         ans[v] = 1e18;
         for (int u : nxts) {
            ans[v] = min(ans[v], max(ll(A[v] - B[v]), ans[u]) + sum[v] - sum[u]);
         }
      }
      visited[v] = true;
   }
   cout << ans[ord.back()] << "\n";
   return 0;
}


Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
pair<int, int> d[4];
vector<vector<char> > c;
vector<vector<int> > dist;
queue<pair<int, int> > que;
int H,W;

int main(){
  cin >>H >>W;
  c.assign(H, vector<char>(W, ' '));
  dist.assign(H, vector<int>(W, 1e9));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char a; cin >>a;
      c[i][j] = a;
      if(a=='#'){
        que.push(make_pair(i,j));
        dist[i][j]=0;
      }
    }
  }

  d[0] = make_pair(-1,0);
  d[1] = make_pair(1,0);
  d[2] = make_pair(0,-1);
  d[3] = make_pair(0,1);

  int ans=0;
  while(!que.empty()){ // BFS開始
    int x, y;
    x = que.front().first; y = que.front().second;
    que.pop();

    for(int k=0; k<4; k++){
      int next_x = x+d[k].first;
      int next_y = y+d[k].second;
      if(next_x<0 || next_x>=H || next_y<0 || next_y>=W) continue;
      if(dist[next_x][next_y]>dist[x][y]+1 && c[next_x][next_y]!='#') {
        dist[next_x][next_y] = dist[x][y] + 1;
        que.push(make_pair(next_x,next_y));
      }
    }
    ans = max(ans, dist[x][y]);
  }

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


Measured memory_bytes: 13328
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long A, long long B){
    vector <bool> ans(4);
    ans[A] = true;
    ans[B] = true;
    if(!ans[1])cout<<1<<endl;
    else if(!ans[2])cout<<2<<endl;
    else cout<<3<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

// グローバル変数


// 関数：


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N;
	int M = 0;
	cin >> N;
	vector<int> A(N), B(N);
	for (int i=0; i<N; i++) {
		cin >> A.at(i);
		B.at(i) = A.at(i);
		M = max(M, A.at(i));
	}
	
	sort(B.begin(), B.end());
	
	for (int i=0; i<N; i++) {
		if ( A[i] != M ) {
			cout << B[N-1] << endl;
		}
		else {
			cout << B[N-2] << endl;
		}
			
	}
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int n;
	double ans=0;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a.at(i);
	rep(i,n)ans+=1.0/a.at(i);
	printf("%.6f\n",1.0/ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  string s; cin >> s;
  string ans = "CODEFESTIVAL2016";
  int num = 0;
  for(int i=0; i<ans.length(); i++){
    if(s[i] != ans[i]){num++;}
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import math

def solve():
    input = sys.stdin.readline
    a, b, x = map(int, input().split())
    total = b * a
    if b * a * a == x: print(0)
    elif x >= 0.5 * b * a * a: #傾きが浅い
        x /= a
        ans = 2 * (total - x) / a
        print(math.degrees(math.atan(ans / a)))
    else: #傾きが大きい
        x /= a
        ans = 2 * x / b
        print(math.degrees(math.atan(b / ans)))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
int I,J,x,y,mas[110][110]={{0}};
int dy_k[6]={-1,-1, 0, 0, 1, 1};
int dx_k[6]={ 0, 1,-1, 1, 0, 1};
int dy_g[6]={-1,-1, 0, 0, 1, 1};
int dx_g[6]={-1, 0,-1, 1,-1, 0};
int d[110][110];
int wall=0;
long long int wall_len=0;
typedef pair<int,int>P;
int bfs();
int wall_reck(int,int);
int main(){
  cin >> x >> y;
  for(int i=0;i<y+2;i++){
    for(int j=0;j<x+2;j++){
      mas[i][j]=0;
    }
  }
 
  for(int i=1;i<y+1;i++){
    for(int j=1;j<x+1;j++){
      cin >> mas[i][j];
    }
  }
 
  for(int i=0;i<y+2;i++){
    for(int j=0;j<x+2;j++){
      if(mas[i][j]==0){
    if(i==0 || j==0 || i==y+1 || j==x+1){
      wall_reck(i,j);
    }
    else{
      I=i;
      J=j;
      bfs();
      //帰ってきた値が1（つまり、抜けられた）、または範囲外（必ず１）なら、周り(六方)の壁の数を計算。
      if(wall == 1){
        wall=0;
        wall_reck(i,j);
      }
    }
       
  
 
      }
    }
  }
  cout << wall_len << endl;
}
 
int bfs(){
  queue<P>que;
  memset(d,-1,sizeof(d));
  que.push(P(I,J));
  d[I][J] = 0;
  while(!que.empty()){
    P p = que.front();
    que.pop();
    //外につながったか。
    if(p.first==0 || p.second==0 || p.first==y+1 || p.second==x+1){
      wall=1;
      break;
    }
    for(int i=0;i<6;i++){
      int ny,nx;
      if(!(p.first&1)){
    ny=p.first+dy_g[i];
    nx=p.second+dx_g[i];
      }
      else{
    ny=p.first+dy_k[i];
    nx=p.second+dx_k[i];
      }
      if(mas[ny][nx]==0 && d[ny][nx]==-1){
    que.push(P(ny,nx));
    d[ny][nx]=d[p.first][p.second]+1;
      }
    }
 
  }
}
 
int wall_reck(int i,int j){
  for(int k=0;k<6;k++){
    if(!(i&1)){
      if(mas[i+dy_g[k]][j+dx_g[k]]==1){
    wall_len++;
      }
    }
    else{
      if(mas[i+dy_k[k]][j+dx_k[k]]==1){
    wall_len++;
      }
    }
 
  }
}

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int N;
    cin >> N;
    int tmp = 0;
    int a;
    rep(i, N) {
        cin >> a;
        if (a % 2 == 1) tmp++;
    }
    if (tmp % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;


    return 0;
}


Measured memory_bytes: 256
// #include "candies.h"

#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>

namespace {

constexpr int modulo{1'000'000'007};

} // namespace

void mod_add(int& add_to, int amount)
{
    add_to += amount;
    if (add_to >= modulo)
        add_to -= modulo;
}

void mod_sub(int& sub_from, int amount)
{
    sub_from -= amount;
    if (sub_from < 0)
        sub_from += modulo;
}

int num_ways(const std::vector<int>& children, int num_candies)
{
    // dp[i] - the number of ways we have used i candies so far
    std::vector<int> dp(num_candies + 1);
    dp.front() = 1;

    for (int child = 0; child < children.size(); ++child) {
        std::vector<int> fake(num_candies + 1);
        for (int used = num_candies; used >= 0; --used) {
            const int tmp{dp[used]};
            const int L{used + 1};
            const int R{used + std::min(static_cast<int>(children[child]),
                                        num_candies - used)};
            if (L <= R) {
                mod_add(fake[L], tmp);
                if (R + 1 <= num_candies) {
                    mod_sub(fake[R + 1], tmp);
                }
            }
        }
        int prefix_sum{0};
        for (int i = 0; i <= num_candies; ++i) {
            mod_add(prefix_sum, fake[i]);
            mod_add(dp[i], prefix_sum);
        }
    }

    return dp.back();
}

// int num_ways(const std::vector<int>& children, int num_candies)
// {
//     Memo memo(children.size() + 1, std::vector<int>(num_candies + 1,
//     -1)); const auto ans = helper(children, 0, num_candies, memo); for (const
//     auto& row : memo) {
//         std::copy(row.cbegin(),
//                   row.cend(),
//                   std::ostream_iterator<
//                       std::iterator_traits<decltype(row.cbegin())>::value_type>(
//                       std::cout, ", "));
//         std::cout << '\n';
//     }
//     return ans;
// }

int main(int argc, char* argv[])
{
    size_t num_children;
    int num_candies;
    std::cin >> num_children >> num_candies;
    std::vector<int> children(num_children);
    for (size_t i = 0; i < num_children; ++i) {
        int candy_capacity;
        std::cin >> candy_capacity;
        children[i] = candy_capacity;
    }
    std::cout << num_ways(children, num_candies) << std::endl;
    return 0;
}


Measured memory_bytes: 3676
import java.util.Scanner;



public class Main {



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		long dp1 = 0;
		long dp2 = 0;
		long dp3 = 0;
		long dp4 = 0;
		long dp5 = 0;
		long dp6 = 0;
		long dp7 = 0;
		long dp8 = 0;
		long dp9 = 0;
		long dp10 = 0;
		
		for (int i=0;i<l;i++) {
			int a = sc.nextInt();
			dp6 = dp1+a;
			dp7 = Math.min(dp1, dp2)+(a==0? 2: a%2);
			dp8 = Math.min(dp1, Math.min(dp2, dp3))+(a+1)%2;
			dp9 = Math.min(Math.min(dp1, dp2), Math.min(dp3, dp4))+(a==0? 2: a%2);
			dp10 = Math.min(Math.min(dp1, Math.min(dp2, dp3)), Math.min(dp4, dp5))+a;
			
			dp1 = dp6;
			dp2 = dp7;
			dp3 = dp8;
			dp4 = dp9;
			dp5 = dp10;
		}
		System.out.println(Math.min(Math.min(dp1, Math.min(dp2, dp3)), Math.min(dp4, dp5)));
	}


}





Measured memory_bytes: 64612
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

#define int ll

//get vector of prime numbers which is lower than or equal n
vector<int> get_primes(int n)
{
    vector<bool> is_prime(n + 1, true);
    vector<int> res;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++)
    {
        if (is_prime[i])
        {
            res.push_back(i);
            for (int j = 2 * i; j < is_prime.size(); j = j + i)
            {
                is_prime[j] = false;
            }
        }
    }
    return res;
}

vector<pair<int, int>> factorize(int n)
{
    vector<pair<int, int>> res;
    for (int i = 2; i * i <= n; i++)
    {
        int tmp = 0;
        while (n % i == 0)
        {
            tmp++;
            n /= i;
        }
        res.push_back(make_pair(i, tmp));
    }
    if (n != 1)
    {
        res.push_back(make_pair(n, 1));
    }
    return res;
}

int mpow(int x, int n)
{
    int res = 1;
    while (n != 0)
    {
        if (n & 1)
            res = res * x % INF;
        x = x * x % INF;
        n = n >> 1;
    }
    return res;
}

//mod frac
vector<int> mfrac;
void set_mfrac(int n)
{
    if (mfrac.size() == 0)
    {
        mfrac.push_back(1);
    }
    for (int i = mfrac.size(); i <= n; i++)
    {
        mfrac.push_back((i * mfrac[i - 1]) % INF);
    }
}

//get nCm mod INF
int mcomb(int n, int m)
{
    if (mfrac.size() <= n)
    {
        set_mfrac(n);
    }
    int res = mfrac[n];
    res = res * mpow(mfrac[m], INF - 2) % INF;
    res = res * mpow(mfrac[n - m], INF - 2) % INF;
    return res;
}

signed main()
{
    int N, T;
    vector<pair<int, int>> data;
    cin >> N >> T;
    for (int i = 0; i < N; i++)
    {
        int x, y;
        cin >> x >> y;

        if (y <= T)
        {
            data.push_back(make_pair(x, y));
        }
    }
    if (data.size() == 0)
    {
        cout << "TLE" << endl;
        return 0;
    }
    sort(data.begin(), data.end());
    cout << data[0].first << endl;
}

Measured memory_bytes: 256
N = gets.to_i
PS = (0...N).map{ gets.split.map &:to_f }
NF = (1..N).reduce(1){ |a,b| a * b } 
A = (1..N-2).reduce(1){ |a,b| a * b } * (N-1) * 2
ss = []
(0...N).each{ |i|
  x1,y1 = PS[i]
  (i+1...N).each{ |j|
	x2,y2 = PS[j]
    ss << Math.sqrt((x1-x2) ** 2 + (y1 - y2) ** 2)
  }
}
p ss.sort.reduce(:+) * A / NF

Measured memory_bytes: 1788
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX_N 233333
#define MOD 1000000007
#define int long long

using namespace std;

int n,ans=0;
int f[MAX_N][4];
char s[MAX_N];

int quick_pow(int x,int k)
{
	if(k<0) return 0;
	int ans=1;
	while(k>0)
	{
		if(k&1) ans=ans*x%MOD;
		x=x*x%MOD,k>>=1;
	}
	return ans;
}

signed main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int ca=0,cq=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='A') ca++;
		if(s[i]=='B') f[i][0]=ca,f[i][2]=cq;
		if(s[i]=='?') f[i][1]=ca,f[i][3]=cq++;
	}
	for(int i=1;i<=n;i++) for(int j=0;j<4;j++) f[i][j]=(f[i][j]+f[i-1][j])%MOD;
	int q0=quick_pow(3,cq);
	int q1=quick_pow(3,cq-1);
	int q2=quick_pow(3,cq-2);
	int q3=quick_pow(3,cq-3);
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='C') ans=(ans+f[i-1][0]*q0%MOD+(f[i-1][1]+f[i-1][2])*q1%MOD+f[i-1][3]*q2%MOD)%MOD;
		if(s[i]=='?') ans=(ans+f[i-1][0]*q1%MOD+(f[i-1][1]+f[i-1][2])*q2%MOD+f[i-1][3]*q3%MOD)%MOD;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
ld distance(ll x,ll y){
  return (double)(sqrt(x*x+y*y));
}
int main(void){
  ll n;
  cin>>n;
  vl x(n);vl y(n);
  rep(i,n)cin>>x[i]>>y[i];
  vi nums(n);
  rep(i,n)nums[i]=i;
  ld ans=0;
  ld n2=0;
  do {
    n2++;
    rep(i,n-1){
      //cout<<nums[i]<<" ";
      ans+=distance(x[nums[i]]-x[nums[i+1]],y[nums[i]]-y[nums[i+1]]);
    }
      //cout<<nums[n-1]<<" ";
   //cout<<endl;
  } while (std::next_permutation(nums.begin(), nums.end()));
  cout<<std::setprecision(15)<<ans/n2;
  return 0;
}

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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin >> n;
    for(int i=0;i<=n;i++) {
        for(int j=0;j<=n;j++) {
            if(i * 4 + j * 7 == n) {
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }
    cout << "No" << '\n';
    return 0;
}



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

#define MOD 1000000007
#define SIZE_1 2000005
#define SIZE_2 1000000
#define INT_BITS 32
typedef long long int ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;

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

    int n, x;
    cin >> n >> x;
    int arr[n + 1];
    arr[0] = 0;
    for (int i = 1; i < n + 1; i++)
        cin >> arr[i];
    

    int ans = 1;
    int j = 1;
    int bounces = 0;
    while (bounces <= x && j <= n)
    {
        ans++;
        bounces += arr[j];
        //cout << bounces << '\n';
        j++;
    }

    if (bounces > x)
        ans--;

    cout << ans;
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define loop1(x,s,e) for(int x=s;x!=e;x+=1-2*(s>e))
#define input_matrix(a,m,n) for(int i=0;i<m;i++)for(int j=0;j<n;j++)cin>>a[i][j];
#define input_array(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define all(x) x.begin(),x.end()
#define newl "\n"
#define tests(t) int t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//########################################################################




int main()
 {
	int n; cin>>n;
	vector<pair<int,int>> a;
	for(int i=0;i<n;i++)
	{
	    int x; cin>>x;
	    a.pb(mp(x,i+1));
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++)cout<<a[i].second<<" ";
	return 0;
}

Measured memory_bytes: 1780
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n = int(sys.stdin.readline())
    a = map(int, sys.stdin.readline().split())

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

    cnt = 0
    for k, v in d.items():
        if k < v:
            cnt += v - k
        elif k > v:
            cnt += v

    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 23328
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static final void main(String[] args) {
		new Main();
	}

	int n;
	int m;
	int[] c;
	int[] x;
	
	public Main() {
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			m = sc.nextInt();
		
			if(n==0 && m==0)
				break;
			
			c = new int[m];
			x = new int[n];
			for(int i=0;i<m;i++)
				c[i] = sc.nextInt();
			for(int i=0;i<n;i++)
				x[i] = sc.nextInt();
			
			solve();
		}
		
	}

	private void solve() {
		int[][] dp = new int[n+1][255+1];
		for(int i=0;i<dp.length;i++)
			Arrays.fill(dp[i], Integer.MAX_VALUE);
		
		dp[0][128] = 0;
		int ny = 0;
		for(int i=0;i<dp.length-1;i++){
			for(int j=0;j<dp[i].length;j++){
				if(dp[i][j]==Integer.MAX_VALUE)
					continue;
				for(int k=0;k<c.length;k++){
					ny = Math.max(0, j + c[k]);
					ny = Math.min(ny, 255);
					dp[i+1][ny] = Math.min(dp[i+1][ny], dp[i][j] + (x[i]-ny)*(x[i]-ny));
				}
			}
		}
		int res = Integer.MAX_VALUE;
		for(int i=0;i<dp[n].length;i++)
			res = Math.min(res, dp[n][i]);
		System.out.println(res);
	}
}

Measured memory_bytes: 123332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------

//------------------------------------------------
int main(){
  int n,count;
  string s;
  count=0;
  cin>>n>>s;
  rep(i,1,n){
    if(s.at(i)==s.at(i-1)) count+=1;
}
 cout<<n-count<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int main() {
	ll Q, H, S, D, N;
	scanf("%lld %lld %lld %lld %lld", &Q, &H, &S, &D, &N);
	H = min(H, 2 * Q);
	S = min(S, 2 * H);
	D = min(D, 2 * S);
	N *= 4;

	ll ans = 0;
	ans += (N / 8) * D;
	N %= 8;
	ans += (N / 4) * S;
	N %= 4;
	ans += (N / 2)*H;
	N %= 2;
	ans += N * Q;
	return !printf("%lld\n", ans);
}

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

int main(){
    char a;
    cin>>a;
    if(isupper(a))cout<<'A'<<endl;
    else cout<<'a'<<endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(void){
 
  int a,b,c,d,e,k;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  scanf("%d", &d);
  scanf("%d", &e);
  scanf("%d", &k);
 
  if (e-a > k) {
    printf(":(\n");
  } else {
    printf("Yay!\n");
  }
 
  return 0;
}

Measured memory_bytes: 128
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = InputNumList();

            if (a[0] == 1) a[0] += 13;
            if (a[1] == 1) a[1] += 13;

            WriteLine(a[0] == a[1] ? "Draw" : (a[0] > a[1] ? "Alice" : "Bob"));
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
int N,M;
const int MAX_V = 10000;
//inf??§?????????
vector<vector<ll>> cost;
ll mincost[MAX_V];
bool used[MAX_V];
ll V;

ll Prim(){
  for(ll i = 0; i < V; ++i){
    mincost[i] = inf;
    used[i] = false;
  }
  mincost[0] = 0;
  ll res =0;

  while(1){
    int v = -1;
    for(ll u = 0; u < V; ++u){
      if( !used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
    }

    if( v == -1){
      break;
    }
    used[v] = true;
    res += mincost[v];
    for(ll u = 0; u < V; ++u){
      mincost[u] = min(mincost[u],cost[v][u]);
    }
  }
  return res;
}

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

struct NODE{
  int pos;
  long long cost;
};
bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
vector<Edge> g[100000],rg[100000];
ll prim(){
  ll res = 0;
  for(ll i = 0; i < V; ++i){
    mincost[i] = inf;
    used[i] = false;
  }
  priority_queue<NODE> q;
  q.push({0,0});
  while(q.size()){
    auto v = q.top();q.pop();
    if(mincost[v.pos] == inf){
      mincost[v.pos] = v.cost;
      res += v.cost;
      for(auto n : g[v.pos]){
        q.push({n.to,n.cost});
      }
    }
  }
  return res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(cin >> N >> M && N && M){
    int a,b,c;
    V = N;
    cost = vector<vector<ll>>(V,vector<ll>(V,inf));
    rep(i,100){
      g[i].clear();
    }
    rep(i,M){
      cin >> a >> b >> c;
      g[a].push_back({b,c});
      g[b].push_back({a,c});
//       cost[a][b] = c;
//       cost[b][a] = c;
    }
    cout << prim() << endl;
  }
  return 0;
}

Measured memory_bytes: 7892
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
int main(){
    int A, B, C, X;
    int cnt = 0;
    cin >> A >> B >> C >> X;
    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                int sum = 500 * i + 100 * j + 50 * k;
                if(X == sum)
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np


def get_rotation_matrix(rad):
    """
    指定したradの回転行列を返す
    """
    rot = np.array([[np.cos(rad), -np.sin(rad)],
                    [np.sin(rad), np.cos(rad)]])
    return rot


def main():
    a, b, h, m = map(int, input().split())

    radis_h = np.deg2rad((360 / 12) * h + 30*(m/60))
    radis_m = np.deg2rad((360 / 60) * m)

    a_point = np.array([0, 1])
    b_point = np.array([0, 1])

    rot_a = get_rotation_matrix(radis_h)
    rot_b = get_rotation_matrix(radis_m)

    a_fin = np.dot(rot_a, a_point) * a
    b_fin = np.dot(rot_b, b_point) * b
    return np.linalg.norm(a_fin - b_fin)


print(main())


Measured memory_bytes: 27340
#include <iostream>
#include <string>

using namespace std;

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

Measured memory_bytes: 256
/* amitdwivedi */
#include <bits/stdc++.h>
using namespace std;
using ll = long long int; 
#define fr(i,b) for (ll i = 0; i < b; ++i)
#define tr(x,cont) for(auto x:cont)
#define c(x) cout << x << endl;
const ll mxn = 2e5+1;
 
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin>>n;
    int a[n];
    fr(i,n) cin>>a[i];
    int i = 0,done = 1,ans = 0;
    while(i!=n){
    	if(a[i]==done) done++;
    	else ans++;
    	i++;
    }
  	if(ans==n) cout << -1 << endl;
  else
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char , char> pcc;
#define pb push_back
#define mp make_pair
#define ft first
#define se second
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)


int main()
{
	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	string s;
  	string t;
  	cin >> s >> t;
  	ll l1=s.length();
  	ll l2=t.length();
  	ll dp[l1+5][l2+5];
  	//pair<ll,ll> prev[l1+5][l2+5];
	for(ll i=0;i<=l1;i++)
	{
		dp[i][0]=0;
	//	prev[i][0]=mp(-1,-1);
	}
	for(ll i=0;i<=l2;i++)
	{
		dp[0][i]=0;
//		prev[0][i]=mp(-1,-1);
	}
	for(ll i=1;i<=l1;i++)
	{
		for(ll j=1;j<=l2;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];
				}
				else 
				{
					dp[i][j]=dp[i][j-1];	
				}
			}
		}
	}
	char lcs[dp[s.length()][t.length()]+5];
	ll index=dp[s.length()][t.length()];
	ll i=l1;
	ll j=l2;
	while(dp[i][j])
	{
		if(s[i-1]==t[j-1])
		{
			lcs[index-1]=s[i-1];
			i--;
			j--;
			index--;
		}
		else if(dp[i-1][j]>=dp[i][j-1])
		{
			i--;
		}
		else
		{
			j--;
		}
	}
	for(i=0;i<dp[s.length()][t.length()];i++)
	{
		cout<<lcs[i];
	}
	return 0;
}

Measured memory_bytes: 70784
N, X = map(int, input().split())
List = list(map(int, input().split()))

s = 0
pS = []
for i in range(N):
    s += List[i]
    pS.append(s)
    
pS = [0]+pS

if pS[-1]<=X:
    print(len(pS))
    
else:
    for j in range(N):
        if (pS[j]<=X)&(X<pS[j+1]):
            print(j+1)

Measured memory_bytes: 3064
n,k=map(int,input().split())
w=[int(input()) for i in range(n)]
def ok(p):
  t=[0]*k
  curr=0
  for i in w:
    if i>p:
      return False
    if t[curr]+i>p:
      curr+=1
      if curr>=k:
        return False
    t[curr]+=i
  return True
l=0
h=10**9+1
while True:
  if l>=h:
    print(l)
    break
  if h==l+1:
    print(l if ok(l) else h)
    break
  mid=(l+h)//2
  if ok(mid):
    h=mid
  else:
    l=mid



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

using namespace std;

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

	string s;

	cin >> s;

	int res = 0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='2')
		{
			res++;
		}
	}

	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  unordered_map<int, int> arr;
  rep(i,n) {
    int a; cin >> a;
    ++arr[a];
  }

  int ans = 0;
  for (auto p : arr) {
    int num, count;
    tie(num,count) = p;
    if (num > count) ans += count;
    else if (num < count) ans += count - num;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4260
import math

def f(theta):
    theta = math.radians(theta)
    if x > a * b / 2:
        return a * b - a * a * math.tan(theta) / 2
    else:
        return b * b / (2 * math.tan(theta))
        
a, b, x = map(int, input().split())
x /= a

left = 0
right = 90
for i in range(40):
    theta = (left + right) / 2
    
    if f(theta) > x:
        left = theta
    else:
        right = theta
print(theta)

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
/////////////////// 
//

#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  int x,y;cin>>x>>y;
  if(x%y==0)cout<<"-1"<<endl;
  else cout<<x<<endl;
  return 0;
}







Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i++)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 100000000

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;


int main()
{
	int x, a, b;
	cin >> x >> a >> b;

	if (abs(x - a) < abs(x - b)) cout << "A" << endl;
	else cout << "B" << endl;


	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(0<=(x-r) && W>=(x+r)){
            if(0<=(y-r) && H>=(y+r)) printf("Yes\n");
            else printf("No\n");
    }
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 584
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r)
  in doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (f x; doit l; doit r)
  in doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (doit l; f x; doit r)
  in doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        doit s1 (String.sub s (i + 1) (String.length s - String.length s1 - 1) :: acc)
  in doit str []

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then begin
      match split (read_line ()) ' ' with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | _ -> (print t; read (i + 1) t)
    end in
  read 0 (create ())

Measured memory_bytes: 31800
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize1,
        hh: [u64;n]
    }
    let mut hh = hh;
    hh.sort();
    let mut v = Vec::new();
    for i in k..hh.len() {
        v.push(hh[i] - hh[i-k]);
    }
    println!("{}", v.iter().min().unwrap());
}


Measured memory_bytes: 6396
n, m = map(int, input().split())
edges = []
for _ in range(m):
    a, b, c = map(int, input().split())
    edges.append((a-1, b-1, -c))

def shortest_path(v, s, edges, inf):
    d = [inf] * v
    d[s] = 0
    for i in range(2 * n):
        update = False
        for frm, to, cost in edges:
            if d[frm] != inf and d[to] > d[frm] + cost:
                d[to] = d[frm] + cost
                update = True
        if i == n:
            memo = d[-1]
    if memo != d[-1]:
        print('inf')
        exit()
    
    return d[-1]

inf = 1e30
print(-shortest_path(n, 0, edges, inf))

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

int main() {
    long long n, y; cin >> n >> y;
    for (long long i=0; i<=n; ++i) {
        for (long long j=0; i+j<=n; ++j) {
            long long sum = 10000*i + 5000*j;
            if (sum > y) break;
            if (sum + (n-i-j)*1000 == y) {
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}

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

using namespace std;

typedef long long ll;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<double> p(n);
  cin >> p;
  vector<vector<double>> dp(n+1, vector<double>(n+1));
  dp[0][0] = 1.;
  for (int i=0; i<n; i++) {
    for (int j=0; j<=i; j++) {
      dp[i+1][j+1] += dp[i][j] * p[i];
      dp[i+1][j] += dp[i][j] * (1. - p[i]);
    }
  }
  double res = 0.;
  for (int i=(n+1)/2; i<=n; i++) {
    res += dp[n][i];
  }
  cout << fixed << setprecision(10) << res << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int ans = 1000-n%1000;
  if(ans == 1000) ans = 0;
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define intt long long
using namespace std;
int i , j ;
int main ()
{
    int n;
    cin >> n;
    int cnt = 0;
    for ( i =1 ;  i <= n ; i+=2 )
    {
        int res = 0;
        for ( j =1  ; j <= i ; j++ )
        {
            if ( i % j == 0 )
            {
                res++;
            }
        }
        if (res == 8)
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m, k, l;
    cin >> n >> m >> k >> l;
    if (n % k == 0 && m % l == 0) {
        cout << "No\n";
        return 0;
    }
    vector<vector<int>> a(n, vector<int>(m, 0));
    vector<vector<int64_t>> sum(n + 1, vector<int64_t>(m + 1, 0));
    int mvalue = 500000000;
    for (int i = 0; i + k <= n; i += k) {
        for (int j = 0; j + l <= m; j += l) {
            a[i][j] = mvalue - 1;
            a[i + k - 1][j + l - 1] = -mvalue;
        }
    }
    if (n % k != 0) {
        for (int j = m - 1; j >= 0; j -= l) {
            a[n - 1][j] = mvalue - 1;
        }
    }
    if (m % l != 0) {
        for (int i = n - 1; i >= 0; i -= k) {
            a[i][m - 1] = mvalue - 1;
        }
    }
    for (int i = n - 1; i >= 0; --i) {
        for (int j = m - 1; j >= 0; --j) {
            sum[i][j] = sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1] + a[i][j];
        }
    }
    // for (int i = 0; i + k <= n; ++i) {
    //     for (int j = 0; j + l <= m; ++j) {
    //         if (!(sum[i][j] - sum[i + k][j] - sum[i][j + l] + sum[i + k][j + l] < 0)) {
    //             cerr << i << ' ' << j << endl;
    //             //throw;
    //         }
    //     }
    // }
    cout << "Yes\n";
    for (const vector<int>& p: a) {
        for (int x: p) {
            cout << x << ' ';
        }
        cout << '\n';
    }

}


Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	int cnt=0;
	for(int i=1;i<=a;i+=2){
		int k=0;
		for(int j=1;j<=i;j+=2){
			if(i%j==0) k++;
		}
		if(k>=8) cnt++;
	}
	cout<<cnt;
		
	
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  
  ll count=0; ll minA=INF; ll ans=0;
  rep(i,N){
    if(A[i]<0) {A[i]*=-1; count++;}
    chmin(minA,A[i]);
    ans+=A[i];
  }
  
  if(count%2!=0) ans-=minA*2;
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 3976
H,W,A,B = map(int, input().split())

L = [[0 for j in range(W)] for i in range(H)]
for i in range(B):
    for j in range(A):
        L[i][j] = 1
        
for i in range(B,H):
    for j in range(A,W):
        L[i][j] = 1
        
for i in range(H):
    ans = ""
    for j in range(W):
        ans += str(L[i][j])
    print(ans)

Measured memory_bytes: 14708
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int> ps(1<<n);
	for(auto &x:ps) cin>>x, --x;
	out(ps,1);
	rep(i,n){
		vector<int> nxt(1<<n);
		rep(j,1<<n){
			int a=ps[j],b=ps[(j+(1<<i))&((1<<n)-1)];
			if(a>b) swap(a,b);
			nxt[j]=(s[b-a-1]=='1'?b:a);
		}
		out(nxt,1);
		ps=nxt;
	}
	out(ps,1);
	for(auto x:ps) cout<<x+1 NL;
  return 0;
}



Measured memory_bytes: 5524
#include<iostream>
using namespace std;
int main(){
  int f = 0;
  for(int i = 0; i < 3; i++){
    char a;
    cin >> a;
    if(a == '7'){
      f = 1;
    }
  }
  
  if(f == 1){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int r,c,n,x,y,ans[200][200];
int main()
{
    cin>>r>>c>>n;
    x=1,y=1;
    for(int i=1;i<=n;i++)
    {
        int cnt;
        cin>>cnt;
        while(cnt--)
        {
            ans[x][y]=i;
            if(y==c&&x%2==1)
            {
                y=c;
                x++;
            }
            else if(y==1&&x%2==0)
            {
                y=1;
                x++;
            }
            else if(x&1)
                y++;
            else
                y--;
        }
    }
    for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++)
        {
            cout<<ans[i][j];
            if(j==c)
                cout<<endl;
            else
                cout<<' ';
        }
    return 0;
}


Measured memory_bytes: 384