akhauriyash/Code-Regression huggingface dataset:
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

//DEBUG_OUT("----\n");

int waitTimeAtStation(int arriveTime, int s, int f)
{
    while (arriveTime > s) {
        s += f;
    }
    int waitTime = s - arriveTime;
    return waitTime;
}

void func(void)
{
    int N;
    cin >> N;
    vector<int> C(N - 1);
    vector<int> S(N - 1);
    vector<int> F(N - 1);
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }

    DEBUG_OUT("----\n");

    // 各駅からのスタートのループ
    for (int i = 0; i < N-1; i++) {
        // 終点までのループ
        int time = 0;
        for (int j = i; j < N - 1; j++) {
            // 現在駅での次の発車までの待ち時間
            time += waitTimeAtStation(time, S[j], F[j]);
            // 次の駅までの所要時間
            time += C[j];
        }
        cout << time << endl;
    }
    cout << 0 << endl;
}



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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

const long long INF = 1e10;
const int MAXV = 2550;

struct Edge {
    long long from, to, cost;
};

long long shortest(vector<Edge> &edges, int n, int s, int t) {
    long long d[MAXV];
    for (int i=0; i<MAXV; ++i) d[i] = INF;
    d[s] = 0;
    long long pret = d[t];
    for (int i=0; i<2*n; ++i) {
        for (Edge e: edges) {
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
            }
        }
        if (i >= n  && pret != d[t]) return INF+1;
        pret = d[t];
    }
    return d[t];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N, M, P;
    cin >> N >> M >> P;

    vector<Edge> edges;
    for (int i=0; i<M; ++i) {
        int A, B, C;
        cin >> A >> B >> C;
        edges.push_back((Edge){ A, B, -(C-P) });
    }

    long long score = shortest(edges, N, 1, N);
    if (score > INF) {
        cout << -1 << endl;
    } else {
        cout << max(0LL, -score) << endl;
    }

    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){

  ll n,m,l;
  cin>>n>>m>>l;
  vector<vector<ll>> dist1 (n,vector<ll>(n,INF));
  vector<vector<ll>> dist2 (n,vector<ll>(n,INF));
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    chmin(dist1[a][b],c);
    chmin(dist1[b][a],c);
  }
  ll q;
  cin>>q;
  vector<pair<ll,ll>> query;
  rep(i,q){
    ll s,t;
    cin>>s>>t;
    s--;t--;
    query.emplace_back(s,t);
  }

  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist1[i][j],dist1[i][k]+dist1[k][j]);
  }

  rep(i,n)rep(j,n){
    if(dist1[i][j]<=l)dist2[i][j]=1;
  }

  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
  }

  rep(i,q){
    ll s,t;tie(s,t)=query[i];
    if(dist2[s][t]==INF)puts("-1");
    else cout<<to_string(dist2[s][t]-1)<<endl;
  }

}


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

using ll = long long;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    int N, K; cin >> N >> K;
    vector<int> A(N); cin >> A;

    vector<ll> sum;
    ll all_or = 0;
    rep(i, N) {
        ll s = 0;
        for (int j = i; j < N; j++) {
            s += A[j];
            sum.push_back(s);
            all_or |= s;
        }
    }
    // set<int> idx;
    unordered_set<int> idx;
    for (int i = 0; i < sum.size(); i++) {
        idx.insert(i);
    }

    ll ans = 0;
    for (ll b = (1LL << 41); b > 0; b >>= 1) {
        if (!(all_or & b)) continue;
        // set<int> on;
        unordered_set<int> on;
        for (int i : idx) {
            if (sum[i] & b) {
                on.insert(i);
            }
        }
        if (on.size() >= K) {
            ans |= b;
            idx = on;
        }
    }
    cout << ans << endl;
}


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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x, y, a, b, c;
  long long int sum = 0;
  cin >> x >> y >> a >> b >> c;
  vector <long long int> p(a);
  vector <long long int> q(b);
  vector <long long int> r(c);
  for (int i = 0; i < a; ++i){
	  cin >> p[i];
  }
  for (int i = 0; i < b; ++i){
	  cin >> q[i];
  }
  for (int i = 0; i < c; ++i){
	  cin >> r[i];
  }
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  sort(r.begin(),r.end());
  reverse(p.begin(),p.end());
  reverse(q.begin(),q.end());
  reverse(r.begin(),r.end());
  vector <long long int> fs;
  for (int i = 0; i < x; ++i){
	fs.push_back(p[i]);
  }
  for (int i = 0; i < y; ++i){
	fs.push_back(q[i]);
  }
  sort(fs.begin(),fs.end());
  for (int i = 0; i < x + y; ++i){
	  if (!r.empty()){
		if (fs.back() >= r[0]){
			sum += fs.back();
			fs.erase(fs.end()-1);
		}else{
			sum += r[0];
			r.erase(r.begin());
		}
	  }else{
		sum += fs.back();
		fs.erase(fs.end()-1);
	  } 
  }
 cout << sum << "\n"; 
return 0;
}


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

using namespace std;
#define ALL(v) (v).begin(), (v).end()

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

  int s = 0;
  for (int i = 1; i <= N+1; ++i) {
    s += abs(A[i-1]-A[i]);
  }

  for (int i = 1; i <= N; ++i) {
    cout << s + abs(A[i-1]-A[i+1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1])) << endl;
  }
}

Measured memory_bytes: 1664
/* ***********************************************
Author        :yang12138
Created Time  :2017年12月11日 星期一 13时23分50秒
File Name     :D.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=100;
int a[N],b[N];
int mx,pos;

void solve(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i),b[i]=abs(a[i]);

	mx=-1;
	for(int i=1;i<=n;i++){
		if(b[i]>mx) mx=b[i],pos=i;
	}

	printf("%d\n",2*n-1);
	for(int i=1;i<=n;i++){
		printf("%d %d\n",pos,i);
	}
	if(a[pos]>=0){
		for(int i=1;i<n;i++) printf("%d %d\n",i,i+1);
	}
	else{
		for(int i=n-1;i>=1;i--) printf("%d %d\n",i+1,i);
	}
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	solve();
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

const int N_MAX = 100005;

vector<int> ROOT[N_MAX];

int sign[N_MAX];

int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        ROOT[a].push_back(b);
        ROOT[b].push_back(a);
    }

    queue<int> POINT;
    for(int i = 0; i <= n; i++)sign[i] = -1;
    sign[1] = 0;
    POINT.push(1);
    while(!POINT.empty()){
        int now = POINT.front();
        POINT.pop();
        for(int i = 0; i < ROOT[now].size(); i++){
            int next = ROOT[now][i];
            if (sign[next] < 0){
                sign[next] = now;
                POINT.push(next);
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 2; i <= n; i++){
        cout << sign[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 9960
#include<bits/stdc++.h>
#define pb push_back
#define pair pair<int,int>
#define ll long long
#define f first
#define se second
using namespace std;
double pi=acos(-1.0);
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m2>m1)
    cout<<1;
    else
    cout<<0;
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <list>

using namespace std;


int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	list<char> v;
	for (char c : s) {
		v.push_back(c);
	}
	list<char>::iterator curr = v.begin();
	++curr;
	bool ans = false;
	while (true) {
		list<char>::iterator prev = curr;
		--prev;
		list<char>::iterator next = curr;
		++next;
		if (next == v.end()) {
			break;
		}
		if (*prev != *next) {
			ans = !ans;
			v.erase(curr);
			curr = next;
			if (prev != v.begin()) {
				curr = prev;
			}
		} else {
			curr = next;
		}
	}
	cout << (ans ? "First" : "Second") << endl;
	return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        String s;
        int[] n_w_s_e ={0,0,0,0};
        s=scan.next();
        for(int i=0;i<s.length();i++){
            switch (s.charAt(i)){
                case 'N':
                    n_w_s_e[0]+=1;
                    break;
                case 'W':
                    n_w_s_e[1]+=1;
                    break;
                case 'S':
                    n_w_s_e[2]+=1;
                    break;
                case 'E':
                    n_w_s_e[3]+=1;
                    break;
            }
        }
        if((n_w_s_e[0]!=0&&n_w_s_e[2]!=0)||(n_w_s_e[0]==0&&n_w_s_e[2]==0)){
            if((n_w_s_e[1]!=0&&n_w_s_e[3]!=0)||(n_w_s_e[1]==0&&n_w_s_e[3]==0)){
                System.out.println("Yes");
            }
            else System.out.println("No");
        }
        else System.out.println("No");
    }
}

Measured memory_bytes: 23252
while 1:
    n=int(input())
    if n==0:break
    a=0
    s=input().split()
    for i in range(0,len(s),2):
        if i+1==len(s):break
        s[i]+=s[i+1]
        if(('lu' in s[i] and 'ru' in s[i])or('ld' in s[i] and 'rd' in s[i])):a+=1
    print(a)

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n%10==3){
        cout<<"bon";
    }else{
        if(n%10==0||n%10==1||n%10==6||n%10==8){
            cout<<"pon";
        }else{
            cout<<"hon";
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
using lint = long long;
int main() {
	int res = 0;
	lint X, Y; cin >> X >> Y;
	for (int i = 1; X <= Y; i++) {
		X *= 2;
		res = i;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int a[N];
    int m=0;
    rep(i,N){
        cin>>a[i];
        m=max(m,a[i]);
    }
    int b[2]{};
    rep(i,N){
        if(m==a[i])b[0]++;
        else if(a[i]==m-1)b[1]++;
        else{
            cout << "No"<<endl;
            return 0;
        }
    }
    if(b[1]==0&&N>=m*2) cout << "Yes"<<endl;
    else if(m>b[1]&&b[0]>=2*(m-b[1])) cout << "Yes" << endl;
    else if(N-1==m&&b[1]==0) cout << "Yes"<<endl;
    else cout << "No" << endl;
    

    



}

Measured memory_bytes: 1024
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @s = gets.chomp
  end

  def solve
    s.count("x") < 8
  end

  def show(ans)
    puts ans ? "YES" : "NO" 
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14268
#include<stdio.h>
int main(void)
{
	int a,b,min;
	scanf("%d %d", &a, &b);
	min=a+b;
	if(a-b>min)
	min=a-b;
	if(a*b>min)
	min=a*b;
	printf("%d\n", min);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    vvi x(10, vi(10));
    REP(i, 10) REP(j, 10) cin >> x[i][j];

    int ans = 0;
    REP(a, 10) REP(b, 10) REP(c, 10) REP(d, 10) {
        int e = x[x[x[x[0][a]][b]][c]][d];
        assert(x[x[x[x[x[0][a]][b]][c]][d]][e] == 0);
        bool canDetect = true;
        REP(i, 10) if (i != a) {
            if (x[x[x[x[x[0][i]][b]][c]][d]][e] == 0) canDetect = false;
        }
        REP(i, 10) if (i != b) {
            if (x[x[x[x[x[0][a]][i]][c]][d]][e] == 0) canDetect = false;
        }
        REP(i, 10) if (i != c) {
            if (x[x[x[x[x[0][a]][b]][i]][d]][e] == 0) canDetect = false;
        }
        REP(i, 10) if (i != d) {
            if (x[x[x[x[x[0][a]][b]][c]][i]][e] == 0) canDetect = false;
        }
        REP(i, 10) if (i != e) {
            if (x[x[x[x[x[0][a]][b]][c]][d]][i] == 0) canDetect = false;
        }
        if (b != a and x[x[x[x[x[0][b]][a]][c]][d]][e] == 0) canDetect = false;
        if (c != b and x[x[x[x[x[0][a]][c]][b]][d]][e] == 0) canDetect = false;
        if (d != c and x[x[x[x[x[0][a]][b]][d]][c]][e] == 0) canDetect = false;
        if (e != d and x[x[x[x[x[0][a]][b]][c]][e]][d] == 0) canDetect = false;
        if (!canDetect) ++ans;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3224
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		long a = scan.nextInt();
		long b = scan.nextInt();
		
		System.out.println(lcm(a,b));
		
	}

	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  p=1e9+7; 



 int main() {
        ff;
        ll k;
        cin>>k;
        string s;
        cin>>s;
        if(s.length()<=k){
            cout<<s<<endl;
        }else{
            for(ll i=0;i<k;i++){
                cout<<s[i];
            }
            cout<<"..."<<endl;
        }
        
            
            
            
        
           
       
    return 0;
}


Measured memory_bytes: 3668
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,a[2000];
int main()
{
while (1)
{
    scanf("%d%d",&n,&m);
    if (n==0&&m==0) break;
    for (int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    int max1=-1;
    for (int i=1;i<=n;i++)
    for (int j=1;j<=n;j++)
        if (i!=j)
    {
        if (a[i]+a[j]<=m&&a[i]+a[j]>max1)
            max1=a[i]+a[j];
    }
    if (max1==-1) printf("NONE\n"); else printf("%d\n",max1);

}

    return(0);
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int r, D, x;
	cin >> r >> D >> x;

	rep(i, 10) {
		x = x * r - D;
		co(x);
	}
	
	Would you please return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
cmd = []
ans = 0
for i in range(N):
    if i < K or T[i] != cmd[i-K]:
        cmd.append(T[i])
        if T[i] == "r":
            ans += P
        if T[i] == "s":
            ans += R
        if T[i] == "p":
            ans += S
    else:
        cmd.append("")

print(ans)


Measured memory_bytes: 4212
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
 
int main()
{
  double a, b, c;
  double angle, rad;
  double S,L,h;

  cin >> a >> b >> angle;

  rad = angle*M_PI/180;

  h = b * sin(rad);
  S = a * h / 2;
  c = sqrt( pow( h, 2.0) + pow(a-b*cos(rad), 2.0) );
  L = a + b + c;
                         
  
  cout << fixed
    << setprecision(5)
      << S
        << endl
          << L
            << endl
              << h
                << endl;

  return(0);
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int now = 0;
while(now < s.size()) {

if(now + 5 <= s.size() && s[now] == 'd' && s[now + 1] == 'r' && s[now + 2] == 'e' && s[now + 3] == 'a' && s[now + 4] == 'm') {
now += 5;
if(now + 2 <= s.size() && s[now] == 'e' && s[now + 1] == 'r') {
if(!(now + 3 <= s.size() && s[now + 2] == 'a')) {
now += 2;
}
}
}
else if(now + 5 <= s.size() && s[now] == 'e' && s[now + 1] == 'r' && s[now + 2] == 'a' && s[now + 3] == 's' && s[now + 4] == 'e') {
now += 5;
if(now + 1 <= s.size() && s[now] == 'r') {
now++;
}
}
else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



int main() {

	ll n;
	cin >> n;
	vector<ll> a(n);
	ll hoge = 1LL;

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

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

	double ans = (double)a[0];

	for (int i = 1; i < n; i++)
	{
		ans = (ans + a[i]) / 2;
	}
	printf("%.9f\n", ans);




	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
p = list(range(n+1))
x = [0]*(n+1)
def find(i):
    if p[i] == i:
        return i
    p[i],x[i]=find(p[i]),x[i]+x[p[i]] #root->i dist
    return p[i]

for _ in range(m):
    l,r,d=map(int, input().split())
    pl=find(l)
    pr=find(r)
    #pl!=pr means ununited
    if pl==pr and x[r]-x[l]!=d:
        print('No')
        break
    else:
        p[pr]=pl #unite
        x[pr]=x[l]+d-x[r] #calculate dist
else:
    print('Yes')


Measured memory_bytes: 9844
//2019.7.26 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define lb long db
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
#define Pi 2.0*acos(-1.0)
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG __int128 x){
//    if(x>10)write(x/10);
//    putchar(x%10+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=5e2+10;
namespace MAIN{
    int n,kcz;
    inline void add(res &x,const res &y){
        x+=y,x>=kcz?x-=kcz:1;
    }
    inline int Add(const res &x,const res &y){
        return x+y>=kcz?x+y-kcz:x+y;
    }
    inline int mul(const res &x,const res &y){
        return int(1LL*x*y%kcz);
    }
    Pair a[N];
    int buc[N],top,ans;
    inline int F(const res &x,const res &y){
        res i=0;
        while(i<(n<<1)&&i*i+y*y<x*x)i++;
        return i;
    }
    inline int G(const res &x,const res &y){
        res i=0;
        while(i<(n<<1)&&i*i+y*y<=x*x)i++;
        return i;
    }
    int dp[N];
    inline void MAIN(){
        n=read(),kcz=read();
        for(res i=0;i<n;i++)a[++top]=mp(F(n,i),-i);
        for(res i=n;i<n<<1;i++)a[++top]=mp(G(n<<1,i),1);
        for(res i=0;i<n;i++)buc[i]=G(n<<1,i);
        sort(a+1,a+top+1);
        for(res k=0;k<=n;k++){
            for(res i=0;i<=k;i++)dp[i]=0;
            dp[0]=1;
            res s1=0,s2=0;
            for(res i=1;i<=top;i++)
                if(a[i].se==1){
                    for(res j=0;j<=min(k,s2);j++)dp[j]=mul(dp[j],Add(a[i].fi,kcz-s1-j));
                    s1++;
                }
                else {
                    for(res j=min(k,s2);~j;j--)add(dp[j+1],mul(dp[j],Add(a[i].fi,kcz-s1-j))),dp[j]=mul(dp[j],Add(buc[-a[i].se],kcz-n-k-s2+j));
                    s2++;
                }
            add(ans,(k&1)?kcz-dp[k]:dp[k]);
        }
        printf("%d\n",ans);
    }
}
int main(){
//    freopen("compound1.in","r",stdin);
//    freopen("compound.out","w",stdout);
    MAIN::MAIN();
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std;
const int maxn=1000000+5;
int n,hd[maxn],to[maxn*2],nxt[maxn*2],w[maxn*2],cnt,dis[maxn];
inline void add(int s,int x,int y){
	w[cnt]=s;to[cnt]=y;nxt[cnt]=hd[x];hd[x]=cnt++;
}
inline void dfs(int root,int fa){
	for(int i=hd[root];i!=-1;i=nxt[i])
		if(to[i]!=fa)
			dis[to[i]]=dis[root]+w[i],dfs(to[i],root);
}
signed main(void){
	scanf("%d",&n);cnt=0;
	memset(hd,-1,sizeof(hd));
	for(int i=1,x,y,s;i<n;i++)
		scanf("%d%d%d",&x,&y,&s),add(s,x,y),add(s,y,x);
	dis[0]=0;dfs(0,-1);int id=0;
	for(int i=1;i<=n;i++)
		id=dis[id]>dis[i]?id:i;
	dis[id]=0;dfs(id,-1);
	for(int i=0;i<=n;i++)
		id=dis[id]>dis[i]?id:i;
	cout<<dis[id]<<endl;
	return 0;
}

Measured memory_bytes: 12056
N = int(input())
A = list(map(int,input().split()))
A.sort()
alice_score = []
bob_score = []
for i in range(N):
    if i % 2 == 0:
        alice_score.append(A.pop())
    else:
        bob_score.append(A.pop())
print(sum(alice_score) - sum(bob_score))

Measured memory_bytes: 3060
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H, W, K = map(int, readline().split())
S = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W] == b'#'

MOD = 10 ** 9 + 7

if K in [0,1]:
    print(1)
    exit()

B = int(S.sum())

if H == 1 or W == 1:
    if B == H * W:
        answer = 1
    else:
        answer = pow(int(B), K-1, MOD)
    print(answer)
    exit()

concat_h = S[:,0] & S[:,-1]
concat_w = S[0] & S[-1]

bl_h = np.any(concat_h)
bl_w = np.any(concat_w)
if bl_h and bl_w:
    print(1)
    exit()
if (not bl_h) and (not bl_w):
    answer = pow(B, K-1, MOD)
    print(answer)
    exit()
if bl_w:
    H, W = W, H
    S = S.T
    concat_h, concat_w = concat_w, concat_h

def power_mat(A,n,MOD):
    k = A.shape[0]
    if n == 0:
        return np.eye(k,dtype=np.int64)
    B = power_mat(A,n//2,MOD)
    B = np.dot(B,B) % MOD
    return np.dot(A,B) % MOD if n & 1 else B

h_edge = (S[:,:-1] & S[:,1:]).sum()
A = np.array([[B, -h_edge], [0, np.count_nonzero(concat_h)]], np.int64)

answer = power_mat(A, K-1, MOD)[0].sum() % MOD
print(answer)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 998244353LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

class numberTheory{

public:
    numberTheory(){}

    pii extendedEuclid(i64 a, i64 b) { // returns x, y | ax + by = gcd(a,b)

        if(b == 0) return pii(1LL, 0LL);
        else {
            pii d = extendedEuclid(b, a % b);
            return pii(d.yy, d.xx - d.yy * (a / b));
        }

    }

    i64 modularInverse(i64 a, i64 n) {
        pair<i64,i64> ret = extendedEuclid(a, n);
        return ((ret.xx % n) + n) % n;
    }


    i64 bigMod(i64 a, i64 n , i64 m)
    {
        if(n==0) return 1 ;
        i64 ret = bigMod(a,n/2,m) ;
        ret = (ret*ret)%m ;
        if(n%2) ret = (ret*a)%m ;
        return ret ;
    }
};

const i64 N = 400000 ;

i64 fact[N+5] , invFact[N+5] ;

i64 C(i64 n, i64 r)
{
    if( n<0 || r<0 || r>n ) return 0 ;
    i64 ret = (fact[n]*invFact[r])%mod ;
    return (ret*invFact[n-r])%mod ;
}

void preprocess()
{
    numberTheory nt ;

    fact[0] = 1 ;
    for(i64 x=1 ; x<=N ; x++) fact[x] = (fact[x-1]*x)%mod ;

    invFact[N] = nt.modularInverse(fact[N],mod) ;

    for(i64 x=N-1 ; x>=0 ; x--) invFact[x] = (invFact[x+1]*(x+1) )%mod ;
}

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

i64 Floor( i64 a, i64 b )
{
    if(b<0)
    {
        a *= -1 ; b*= -1 ;
    }
    i64 res = a/b ;
    if( a%b !=0 && a<0 ) res-- ;
    return res ;
}
i64 Ceil(i64 a, i64 b)
{
    if(b<0)
    {
        a *= -1 ; b*= -1 ;
    }
    i64 res = a/b ;
    if( a%b !=0 && a>0 ) res++ ;
    return res ;
}

int main()
{
    preprocess() ;

    i64 i , j , k , l , m , n , a , b , c ;

    scanf("%lld %lld %lld %lld",&n,&a,&b,&c) ;

    numberTheory nt ;

    if( c%gcd(a,b) !=0 )
    {
        printf("0\n") ;
        return 0 ;
    }

    i64 g = gcd(a,b) ;

    a /= g ; b/=g ; c/= g ;

    pii sol = nt.extendedEuclid(a,b) ;

    sol.xx *= c ; sol.yy *= c ;

 //   printf("%lld*%lld + %lld*%lld = %lld\n",a,sol.xx,b,sol.yy,c) ;

    i64 st = max( Ceil(-sol.xx,b) , Ceil(sol.yy-n,a) ) , en = min( Floor( sol.yy,a ) , Floor( n-sol.xx,b ) ) ;

    i64 ans = 0LL ;

  //  printf("%lld %lld\n",st,en) ;

    for(i=st ; i<=en ; i++)
    {
        i64 x = sol.xx + b*i  , y = sol.yy - a*i ;

    //    printf("%lld %lld\n",x,y) ;

        ans = ( ans + C(n,x)*C(n,y) )%mod ;
    }

    cout<<(ans%mod + mod)%mod <<endl ;

    return 0;
}


Measured memory_bytes: 6528
using System;
using System.Linq;
using System.Collections.Generic;

namespace AIPC2020
{
    class C
    {
        static void Main(string[] args)
        {
            //var CA = Enumerable.Repeat(0, (long)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var LRd = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = long.Parse(Console.ReadLine());
            //var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var n = new int[N + 10];
            for (long x = 1; x <= 100; x++)
            {
                for (long y = 1; y <= 100; y++)
                {
                    for (long z = 1; z <= 100; z++)
                    {
                        var sum = Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2) + (x * y) + (y * z) + (z * x);
                        if (sum <= N) n[(long)sum]++;
                    }
                }
            }
            for (int i = 1; i <= N; i++)
            {
                Console.WriteLine(n[i]);
            }
        }
    }
}


Measured memory_bytes: 27424
import java.util.Scanner;

public class Main {
	
	static Scanner scan;
	
	public static int[] InsertionSort(int[] input, int length) {
		for(int i = 1; i <= length - 1; i++) {
			printArray(input, length);
			
			int key = input[i];
			int j = i - 1;
			
			while(j >= 0 && input[j] > key) {
				input[j + 1] = input[j];
				j--;
			}
			input[j + 1] = key;
		}
		return input;
	}
	
	public static void printArray(int[] array, int length) {
		for(int i = 0; i < length - 1; i++) {
			System.out.print(array[i] + " ");
		}
		System.out.println(array[length - 1]);
	}
	
	public static void main(String[] args) {
		scan = new Scanner(System.in);
		
		// Get a value of input array's length.
		final int Length = scan.nextInt();
		
		// Get a input array.
		int Array[] = new int[Length];
		for(int i = 0; i < Length; i++) {
			Array[i] = scan.nextInt();
		}
		
		// Carry out the insertion sort program.
		Array = InsertionSort(Array, Length);
		
		// Output to standard output the sorted array.
		printArray(Array, Length);
	}
}



Measured memory_bytes: 32108
N,T=list(map(int,input().split()))
c=[]
t=[]
for i in range(N):
    a,b=list(map(int,input().split()))
    c.append(a)
    t.append(b)
tmp=1001
for i in range(N):
    if(t[i]<=T):
        if(tmp>c[i]):
            tmp=c[i]
if(tmp==1001):    print("TLE")
else:    print(tmp)

Measured memory_bytes: 3064
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
 
 
const int N=2e6+6;
const ll MOD=998244353;

int a[N];
ll n,m,vv,p;

bool check(ll v){
	v+=m;
	ll ans=0;
	FOR(i,n){
		if (i+p>n){
			ans+=m;
		}
		else{
			//if (v==2 && a[i]>v)cout<<i<<endl; 
			if (v<a[i])return false;
			ans+=min(v-a[i],m);
			//if (v==2) cout<<i<<" "<<ans<<endl;
		}
	}
	//if (v==2)cout<<ans<<endl;
	if (ans>=vv*m)return true;
	return false;
}


int main(){
	fastio;
	cin>>n>>m>>vv>>p;
	FOR(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	int l=0,r=n;
	while(l<r){
		int md=(l+r)/2;
		if (check(a[md])){
			r=md;
		}
		else{
			l=md+1;
		}
	}
	//cout<<l<<endl;
	cout<<n-l<<endl;
	return 0;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
typedef pair<int,int> P;


void Main()
{
  	int N, K, S;
	cin >> N >> K >> S;
  	
  	if(S!=1){
  		rep(i,K) cout << S << " ";
  		rep(i,N-K) cout << S-1 << " ";
  	}
  	else if(S==1){
    	rep(i,K) cout << 1 << " ";
      	rep(i,N-K) cout << 2 << " ";
    }
  	cout << endl;
  	return;
}

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


Measured memory_bytes: 1280
fun main(args:Array<String>){
    val (a, b, k) = readLine()!!.split(" ").map { it.toInt() }
    var l= mutableListOf<Int>()
    for (i in 1..Math.max(a,b)) {
        if (a % i == 0 && b % i == 0) l.add(i)
    }
    println(l[l.size-k])
}

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

int main()
{
    int a,b,c,s,t;
    cin>>a>>b>>c;
    s=b-a;
    t=c-b;
    if(s==t)
    {
        cout<<"YES"<<endl;
    }
    else
    {
    cout<<"NO"<<endl;
    }
}

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

void ADD(std::vector<float>& t_v)
{
	if (t_v.size() == 1)
	{
		return;
	}

	float tempA = t_v.at(0);
	float tempB = t_v.at(1);
	t_v.at(0) = (tempA + tempB) / 2.0f;
	t_v.erase(t_v.begin() + 1);
	ADD(t_v);
}

int main()
{
	int N = 0;
	std::cin >> N;

	std::vector<float> v(N);
	for (int i = 0; i < N; ++i)
	{
		std::cin >> v.at(i);
	}

	std::sort(v.begin(), v.end());

	ADD(v);

	for (auto n : v)
	{
		std::cout << n << "\n";
	}

	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

//愚直な式展開をプログラム化した（くそ）

int main() {

    ll N;
    cin >> N;

    ll sum = 0;
    ll fugou = 1;
    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        sum = sum + fugou * 2 * t;
        //cout << ":" << sum << endl;
        vec.push_back(sum);
        //符号の変化を忘れずに
        fugou *= -1;
    }
    //fugou *= -1;

    ll idx = N-1;
    vector<ll > ans(N, 0);
    //一箇所固定して求めていく
    for(ll i = N-1; i >= 0; i--){
        if(i == N - 1) ans[0] = vec[i] / 2;
        else ans[idx] = fugou * (ans[0] - vec[i]), idx--;
        //符号の変化を忘れずに
        fugou *= -1;
        //cout << vec[i] << endl;
    }

    for(ll i = 0; i < N; i++) cout << ans[i] << " ";
    cout << endl;

}

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	if readInt()+readInt()+readInt() >= 22 {
		fmt.Println("bust")
	} else {
		fmt.Println("win")
	}
}

/////////////////////////////////////////
var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
	//scanner.Split(bufio.ScanLines)
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	return t
}

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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }


int main(void) {

	int N;
	cin >> N;

	vector<double> P(N);
	for (auto& p : P) {
		cin >> p;
	}

	vector<vector<double>> dp(N + 1, vector<double>(N + 1));
	dp[0][0] = 1;

	REP(i, N) {
		REP(j, i+1) {
			dp[i + 1][j + 1] += dp[i][j] * P[i];
			dp[i + 1][j] += dp[i][j] * (1 - P[i]);
		}
	}

	int th = ceil((N + 1) / 2);
	double ans = 0;
	FOR(i, th, N + 1) {
		ans += dp[N][i];
	}

	cout << setprecision(10) << ans << endl;


	return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


using pll = pair<long long, long long>;
bool cmp(pll a, pll b) {
    return a.second < b.second;
}


int N;
vector<pll> v;

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

    while (cin >> N) {
        v.resize(N);
        for (int i = 0; i < N; ++i) cin >> v[i].first >> v[i].second;
        sort(v.begin(), v.end(), cmp);

        bool ok = true;
        long long sum = 0;
        for (int i = 0; i < N; ++i) {
            sum += v[i].first;
            if (sum > v[i].second) ok = false;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


















Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std ;
#define int long long
int32_t main() {
    int m ;
    cin >> m ;
    vector<int> v(m) ;
    for(auto &X : v) cin >> X ;
    int maxx = v[0];
    int ans = 0 ;
    for (int i = 1 ; i < m ; i++ ) {
        if (maxx > v[i]) {
            ans += ( maxx - v[i] ) ;
        }
        else {
            maxx = v[i] ;
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 4732
#include<iostream>
#include<deque>
#include<vector>
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

#define SIZEOF(x) (sizeof x) / (sizeof x[0])



int main(){
    int n , a ,b;
    cin >> n>>a>>b;
    if(n*a>b)cout <<b;
    else{cout<<a*n;}
    
    return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int t = sc.nextInt();
		if (t>N) {
			System.out.println(0);
		} else {
			System.out.println(N-t);
		}

	}
}

Measured memory_bytes: 22868
#include<iostream>
using namespace std;
int dice[6];
void exswap(int a,int b,int c,int d){
    int work;
    work=dice[a];
    dice[a]=dice[b];
    dice[b]=dice[c];
    dice[c]=dice[d];
    dice[d]=work;
}
int main(){
    int n;
    while(cin>>n,n){
        for(int i=0;i<6;i++)dice[i]=i+1;
        int sum=0;
        while(n--){
            string str;
            cin>>str;
            if(str=="North")exswap(0,1,5,4);
            else if(str=="East")exswap(0,3,5,2);
            else if(str=="West")exswap(0,2,5,3);
            else if(str=="South")exswap(0,4,5,1);
            else if(str=="Right")exswap(1,2,4,3);
            else exswap(1,3,4,2);
            sum+=dice[0];
        }
        cout<<sum+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1216
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque

def main():
    K = int(input())
    cnt = 0
    dq = deque(['1','2','3','4','5','6','7','8','9'])
    while cnt < K:
        cnt += 1
        d = dq.popleft()
        a = int(d[-1])
        if a == 0:
            dq.append(d+str(0))
            dq.append(d+str(1))
        elif a == 9:
            dq.append(d+str(8))
            dq.append(d+str(9))
        else:
            for i in range(a-1, a+2):
                dq.append(d+str(i))
    print(d)



if __name__ == '__main__':
    main()


Measured memory_bytes: 17004
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	long long n;
	cin >> n;

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

	long long p_sum = 0;
	long long abs_min = abs(2 * a[0] - sum);
	for(int i = 0; i < n - 1; i++){
		p_sum += a[i];
		if(abs(2 * p_sum - sum) < abs_min){
			abs_min = abs(2 * p_sum - sum);
		}
	}

	cout << abs_min << endl;

	return 0;
}

Measured memory_bytes: 1792
import numpy as np

N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp = np.zeros(N,dtype=int)
  
for i in range(N):
  if i < K:
    dp[i] = abs(h[0]-h[i])
  else:
    dp[i] =  min(dp[i-K:i]+abs(h[i]-h[i-K:i]))
    
print(dp[N-1])

Measured memory_bytes: 22836
#include<cmath>
#include<cstdio>
#include<vector>
#include<complex>
#include<algorithm>

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

using namespace std;

typedef complex<double> Point;

const double EPS=1e-9;

class Line:public vector<Point>{
public:
	Line(){}
	Line(const Point &a,const Point &b){ pb(a),pb(b); }
};

class Circle{
public:
	Point c;
	double r;
	Circle(){}
	Circle(const Point &C,double R):c(C),r(R){}
};

double dot(const Point &a,const Point &b){
	return real(a)*real(b)+imag(a)*imag(b);
}

double cross(const Point &a,const Point &b){
	return real(a)*imag(b)-imag(a)*real(b);
}

inline void calc_abc(const Line &l,double &a,double &b,double &c){
	a=imag(l[0])-imag(l[1]);
	b=real(l[1])-real(l[0]);
	c=cross(l[0],l[1]);
}

Point PerpFoot(const Point &p,const Line &l){
	double a,b,c;
	calc_abc(l,a,b,c);
	Point v(a,b);
	return p-(dot(p,v)+c)*v/norm(v);
}

int intersect(const Circle &c,const Line &l){
	Point m=PerpFoot(c.c,l);
	double d2=norm(c.c-m);
	if(c.r*c.r+EPS<d2)      return 0;
	if(abs(c.r*c.r-d2)<EPS) return 1;
	return 2;
}

void addCommonTangent(vector<Line> &lns,const Circle &c1,const Circle &c2){
	double d2=norm(c1.c-c2.c);
	double rsum2=(c1.r+c2.r)*(c1.r+c2.r);
	double rdif2=(c1.r-c2.r)*(c1.r-c2.r);
	Point u=(c2.c-c1.c)/abs(c2.c-c1.c);

	Point v;
	double theta;
	if(d2>rsum2+EPS){
		theta=asin(sqrt(1-rdif2/d2));
		v=u*exp(Point(0,theta));	lns.pb(Line(c1.c+c1.r*v,c2.c+c2.r*v));
		v=u*exp(Point(0,-theta));	lns.pb(Line(c1.c+c1.r*v,c2.c+c2.r*v));

		theta=acos(sqrt(rsum2/d2));
		v=u*exp(Point(0,theta));	lns.pb(Line(c1.c+c1.r*v,c2.c-c2.r*v));
		v=u*exp(Point(0,-theta));	lns.pb(Line(c1.c+c1.r*v,c2.c-c2.r*v));
	}
	else if(d2>rsum2-EPS){
		theta=asin(sqrt(1-rdif2/d2));
		v=u*exp(Point(0,theta));	lns.pb(Line(c1.c+c1.r*v,c2.c+c2.r*v));
		v=u*exp(Point(0,-theta));	lns.pb(Line(c1.c+c1.r*v,c2.c+c2.r*v));

		v=u*Point(0,1);	lns.pb(Line(c1.r*u,c1.r*u+v));
	}
	else if(d2>rdif2+EPS){
		theta=asin(sqrt(1-rdif2/d2));
		v=u*exp(Point(0,theta));	lns.pb(Line(c1.c+c1.r*v,c2.c+c2.r*v));
		v=u*exp(Point(0,-theta));	lns.pb(Line(c1.c+c1.r*v,c2.c+c2.r*v));
	}
	else if(d2>rdif2-EPS){
		v=u*Point(0,1);	lns.pb(Line(c1.r*u,c1.r*u+v));
	}
}

int main(){
	for(int n;scanf("%d",&n),n;){
		Circle jwl[50],mag[50];
		rep(i,n){
			int x,y,m; scanf("%d%d%lf%d",&x,&y,&jwl[i].r,&m);
			jwl[i].c=mag[i].c=Point(x,y);
			mag[i].r=jwl[i].r+m;
		}

		vector<Line> lns;
		rep(i,n)for(int j=i+1;j<n;j++){
			addCommonTangent(lns,jwl[i],jwl[j]);
			addCommonTangent(lns,jwl[i],mag[j]);
			addCommonTangent(lns,mag[i],jwl[j]);
			addCommonTangent(lns,mag[i],mag[j]);
		}

		int cmax=1;
		rep(i,lns.size()){
			int cnt=0;
			rep(j,n){
				if(intersect(jwl[j],lns[i])<=1 && intersect(mag[j],lns[i])>=1) cnt++;
			}
			cmax=max(cmax,cnt);
		}
		printf("%d\n",cmax);
	}

	return 0;
}

Measured memory_bytes: 2584