akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(int argc, char* argv[]){
  int a=0,b=0,ans=0;
  char  t[10],s[10],c[10];
  scanf("%s %s",s,t);
  scanf("%d %d",&a,&b);
  scanf("%s",c);
  if (strcmp(s,c)==0) {
    a--;
  }
  if(strcmp(t,c)==0){
    b--;
  }
  printf("%d %d\n",a,b);
  return 0;
}


Measured memory_bytes: 128
/*
 * author :Sadik Hassan
 * 
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;
const ll MX=1e15+5;

int main()
{
    _SAD()
	int n,cnt=1;
	cin>>n;
	//int a;
	//set<int>s;
	vector<int>v(n);
	rep(i,n)
	{
		cin>>v[i];
	}
	ll ans=MX;
	for(int i=1;i<=100;i++)
	{
		ll gu=0;
		for(int j=0;j<n;j++)
		{
			gu+=((v[j]-i)*(v[j]-i));
		}
		ans=min(gu,ans);
	}
	cout<<ans<<nl;
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	ll N, ans=0;
	int A[100005]={};

	cin >> N;
	rep(i,N) cin >> A[i+1];

	rep(i,N){
		if( A[i] > 0 && A[i+1] > 0 ){
			A[i+1]--;
			ans++;
		}
		ans += A[i+1] / 2;
		A[i+1] %= 2;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
char s[100005];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	if(len==2)
	{
		if(s[0]==s[1])	printf("1 2\n");
		else printf("-1 -1\n");
		return 0;
	}
	for(int i=0;i<len-2;i++)
	{
		if(s[i]==s[i+1]||s[i]==s[i+2])
		{
			printf("%d %d\n",i+1,i+3);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec

void Main()
{
	int X;
	cin>>X;
	cout<<!X<<_n;
}


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


Measured memory_bytes: 3636
n = gets.strip.to_i
a = n.times.map{ gets.strip.to_i }

max = 1
nxt = 0

(0..n-1).each do |i|
  nxt = max if a[i] == max
  max = a[i] if a[i] > max
  if a[i] > nxt && a[i] < max
    nxt = a[i]
  end
end

(0..n-1).each do |i|
  if a[i] == max
    puts nxt
  else
    puts max
  end
end

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

using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    ll temp;
    cin >> temp;
    ans += temp;
  }

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



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final String ABC = "ABC";
	private static final String ARC = "ARC";

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.next();
			System.out.println((ABC.equals(s)) ? ARC : ABC);
		}
	}
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll K; cin >> K;
  for (ll i = 0; i < K; i++) {
    cout << "ACL";
  }
  cout << endl;

  return 0;

}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

void solve()
{
    vector<int>arr(3);
    for(int i=0;i<3;i++)
    cin>>arr[i];
    
    sort(arr.begin(),arr.end());
    int ans=(arr[0]*arr[1])/2;
    cout<<ans<<endl;
}
int32_t main()
{
    rapido;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, m;
    cin >> n >> m;

    ll res;
    if (n == 1 && m == 1) res = 1;
    else if (n == 1 || m == 1) res = n * m - 2;
    else if (n == 2 || m == 2) res = 0;
    else {
        res = n * m - (2 * (n + m) - 4);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t;

    for(int i=0 ; i<s.length() ; i++){
      t = s.substring(i,i+1);
      System.out.print("x");
    }
    System.out.println();
  }
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;

int main(){
    int a;
    int b;
    cin >> a >> b ;
    
    if(a >=b){
        for(int i = 0; i< a; i++){
            cout << b;
        }
        cout << endl;
        return 0;
    }else{
        for(int i = 0; i< b; i++){
            cout << a;
        }
        cout << endl;
        return 0;
    }
}

    

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

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

    int n;
    cin >> n;
    int max = 0, result = 0;
    for (int i = 0; i < n; i++) {
        int m1;
        cin >> m1;
        result += m1;
        if (max < m1)
            max = m1;
    }

    result -= max / 2;
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val monsters =  readLine()!!.split(" ").map{it.toLong()}
    val heroes = readLine()!!.split(" ").map{it.toLong()}
    var result = 0L
    var amari = 0L
    for(i in 0..n){
        val hero = if(i!=n)heroes[i] else 0
        var monster = monsters[i]
        if(amari>=monster){
            result += monster
            amari = hero
            continue
        }else{
            monster -= amari
            result += amari
            amari = 0
        }
        if(hero>=monster){
            result += monster
            amari = hero - monster
        }else{
            result += hero
        }
    }
    println(result)
}

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

int main()
{
    int dp[401][401]{}, n, ma, mb;
    scanf("%d%d%d", &n, &ma, &mb);
    std::fill(dp[0], dp[0] + 401 * 401, 100000000);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        for (int j = 400 - a; j >= 0; j--)
        {
            for (int k = 400 - b; k >= 0; k--)
            {
                dp[j + a][k + b] = std::min(dp[j][k] + c, dp[j + a][k + b]);
            }
        }
    }
    int min{100000000};
    for (int i = 1; i < 401; i++)
        for (int j = 1; j < 401; j++)
        {
            if (ma * j != mb * i) continue;
            min = std::min(min, dp[i][j]);
        }
    
    if (min == 100000000)
        printf("-1\n");
    else
        printf("%d\n", min);

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	string S, T;
	int ANS = 0;
	cin >> S >> T;

	for (int i = 0; i < 3; i++)
	{
		if (S[i] == T[i])
		{
			ANS++;
		}
	}
	cout << ANS << endl;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n+5);
  vector<int> b(n+5);
  vector<int> c(n+5);
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=1;i<=n;i++){
    cin>>b[i];
  }
  for(int i=1;i<n;i++){
    cin>>c[i];
  }
  int ans=b[a[1]];
  for(int i=2;i<=n;i++){
    ans+=b[a[i]];
    if(a[i]-a[i-1]==1)ans+=c[a[i-1]];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MOD 998244353
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;


int main()
{
    int n, a, b, c, d, i, flag=0;
    char s[200000];
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",s);
    if(c<d) {
        for(i=a; i<d; i++) {
            if(s[i-1]=='#' && s[i]=='#') {
                flag = 1;
                break;
            }
        }
    } else {
        for(i=a; i<c; i++) {
            if(s[i-1]=='#' && s[i]=='#') {
                flag = 1;
                break;
            }
        }
        int temp = 1;
        int start = MAX(b, 2);
        int end = MIN(d, n-1);
        for(i=start; i<=end; i++) {
            if(s[i-2]=='.' && s[i-1]=='.' && s[i]=='.') {
                temp = 0;
                break;
            }
        }
        if(temp==1) {
            flag = 1;
        }
    }
    printf(flag==0?"Yes":"No");
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,m; cin >> n >> m;
  vector<P<ll,ll>> v(n),w(m);
  for(auto&e:v)cin >> e.first >> e.second;
  for(auto&e:w)cin >> e.first >> e.second;
  
  for(auto e:v){
    int idx = 0;
    ll dist = 1001001001001;
    for(int i = 0; i < m; ++i){
      if(ChangeMin(dist,abs(e.first-w[i].first)+abs(e.second-w[i].second))){
	idx = i;
      }
    }
    cout << idx+1 << endl;
  }
  return 0;
}



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


void solve(string S){
    long long ans1, ans2;
    ans1 = 0;
    ans2 = 0;
    for(long long i = 0; i < S.size(); i++){
        //cout << S[i] << endl;
        if(i % 2 == 0){
            if(S[i] != '0') ans1++;
        }else{
            if(S[i] != '1') ans1++;
        }
    }
    for(long long i = 0; i < S.size(); i++){
        if(i % 2 == 0){
            if(S[i] != '1') ans2++;
        }else{
            if(S[i] != '0') ans2++;
        }
    }
    cout << min(ans1, ans2) << endl;
}

int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
ll fast_pow( ll a , ll b , ll m )
{
 
    ll res=1;
    while(b>0)
    {
        if(b&1) res =  (res*a)%m;
        a=(a*a)%m;
        b=b/2;
    }
    return res;
}
 
template <typename T,typename U>                                                   
std::pair<T,U> operator-(const std::pair<T,U> & l,const std::pair<T,U> & r) {   
    return {l.first-r.first,l.second-r.second};                                    
} 
 
template <typename T,typename U>                                                   
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {   
    return {l.first+r.first,l.second+r.second};                                    
} 
 
const ll maxn = 105;
const int inf = 0x3f3f3f;
const ll MOD = 1e9+7LL;


ll lcm(ll a , ll b)
{
    return (a*b)/__gcd(a ,b);
}



int main()
{
    // freopen( "input.txt" , "w" , stdout );
    
   
 
 
    //------- INPUT GENERATION ------
 
    // cout<<200000<<endl;
 
    //------- /INPUT GENERATION ------

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    char c;
    cin>>c;
    cout<<(char)(c+1)<<endl;
    

   
    // cout<<endl;
    // end = std::chrono::system_clock::now(); 
  
    // std::chrono::duration<double> elapsed_seconds = end - start; 
    // std::time_t end_time = std::chrono::system_clock::to_time_t(end); 
  
    // std::cout << "finished computation at " << std::ctime(&end_time) 
    //           << "elapsed time: " << elapsed_seconds.count() << "s\n"; 
 
 
 
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;

int n;

int h[100001];
int memo[100001];

int dp (int pos) {
	cerr << "pos = " << pos << "\n";
	if (pos < 0 or pos >= n)
		return INF;
	if (memo[pos] != -1)
		return memo[pos];
	int ans = INF;
	if (pos >= 1) {
		ans = min(ans, (abs(h[pos] - h[pos - 1]) + dp(pos - 1)));
		cerr << "ans (pos >= 1) = " << ans << "\n";
	}
	if (pos >= 2) {
		ans = min(ans, (abs(h[pos] - h[pos - 2]) + dp(pos - 2)));
		cerr << "ans (pos >= 2) = " << ans << "\n";
	}
	memo[pos] = ans;
	return ans;
}

int main () {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	for (int i = 0; i < n; i++)
		memo[i] = -1;
	memo[0] = 0;
	cout << dp(n - 1) << "\n";
	for (int i = 0; i < n; i++)
		cerr << memo[i] << " ";
	return 0;
}

Measured memory_bytes: 5760
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints

A.sort!
max = A.last

half = max / 2.to_f

ax = A.map { |a| [(a-half).abs, a] }.sort { |x,y| x[0] <=> y[0] }

puts "#{max} #{ax.first[1]}"




Measured memory_bytes: 24112
#include<stdio.h>
int main(void)
{
	int a,b,n,x[10001],y[10001],i,j;
	int xx,yy,t;
	t=0;
	scanf("%d %d %d",&a,&b,&n);
	for(i=1;i<=n;i++){
		scanf("%d %d",&x[i],&y[i]);		
	}
	for(i=1;i<n;i++) {
		xx=x[i]-x[i+1];
		yy=y[i]-y[i+1];
		if(xx*yy<0) {
			if(xx<0) {
				xx=-xx;
			}
			if(yy<0) {
				yy=-yy;
			}
			t+=xx+yy;
		}
		else {
			if(xx<0) {
				xx=-xx;
			}
			if(yy<0) {
				yy=-yy;
			}
			if(xx>yy){
				t+=xx;
			}
			else{
				t+=yy;
			}
		}
	}
	printf("%d\n",t);
	return 0;
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
class UnionFind{
  vector<int> par;
  vector<int> rank;
  
public:  
  void init(int size){
    for(int i=0;i<size;i++){
      par.push_back(i);
      rank.push_back(0);
    }
  }
  
  int getpar(int x){
    if(x==par[x]) return x;
    return par[x]=getpar(par[x]);
  }
  
  bool samepar(int x,int y){
    return getpar(x) == getpar(y);
  }
  
  void put_together(int x, int y){
    int x_per=getpar(x),y_per=getpar(y);
    if(x_per==y_per) return;
    if(rank[x_per]<rank[y_per]) par[x_per] = y_per;
    else{
      par[y_per] = x_per;
      if (rank[x_per] == rank[y_per]) ++rank[x_per];    
    }
  }
  
};
  
int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> q;
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    auto p = make_pair(a,b);
    q.push_back(p);
  }
  
  int res=0;
  for(int i=0;i<q.size();i++){
    UnionFind f;
    f.init(n+1);
    for(int j=0;j<q.size();j++){
      if(i==j) continue;
      f.put_together(q[j].first,q[j].second);
    }
    if(!f.samepar(q[i].first,q[i].second)) res++;
  }
  cout << res;
  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

struct BinaryIndexedTree{
	int n;
	vector<int>dat;
	BinaryIndexedTree(int n=0):n(n){
		dat.resize(n+1);
	}
	void add(int k,int x){
		for(k++;k<=n;k+=k&-k)dat[k]+=x;
	}
	int sum(int k){
		int ret=0;
		for(k++;k;k-=k&-k)ret+=dat[k];
		return ret;
	}
};

int N,K;
int A[222222];
int S[222222];
signed main(){
    cin>>N>>K;
    vpint v;
    rep(i,N){
        cin>>A[i];
        S[i+1]=S[i]+A[i];
    }

    for(int i=0;i<=N;i++){
        v.pb({S[i]-K*i,i});
    }

    sort(all(v));
    BinaryIndexedTree bit(N+114);
    int ans=0;
    rep(i,v.size()){
        int x=v[i].se;
        ans+=bit.sum(x-1);
        bit.add(x,1);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9584
#include <iostream>
using namespace std;
int check(string str){
  int n=str.length();
  int ans =0;
  for(int i=0;i<n;i++){
    ans+= (str[i]-'0');
  }
  return (ans%9 ==0) ;
}
int main(){
  string str;
  cin>>str;
  check(str)? cout << "Yes" : cout << "No ";
  return 0;  
}


    


Measured memory_bytes: 3488
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール

// 処理内容
int main() {

    ll n, m; cin >> n >> m;
    vector<ll> a(m);
    REP(i, m) cin >> a[i];
    vector<ll> d = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    sort(ALL_OF(a), greater<ll>());
    
    vector<ll> dp(n+1, -INF);
    dp[0] = 0;
    REP(i, n+1) {
        REP(j, m) if (i - d[a[j]] >= 0) {
            chmax(dp[i], dp[i - d[a[j]]] + 1);
        }
    }

    string s = "";
    for (ll i = n; i > 0; ) {
        REP(j, m) if (i - d[a[j]] >= 0) {
            if (dp[i] == dp[i - d[a[j]]] + 1) {
                i -= d[a[j]];
                s.push_back('0' + a[j]);
                break;
            }
        }
    }
    
    cout << s << '\n';
    
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define ll long long
#define pii pair < ll , ll >
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define vvvll vector<vector<vector<ll>>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
#define  ones(x)  __builtin_popcount(x)
using namespace std;
int n;
struct compare { 
    bool operator()(const pair<ll, ll>& value,  
                                const ll& key) 
    { 
        return (value.first < key); 
    } 
    bool operator()(const ll& key,  
                    const pair<ll, ll>& value) 
    { 
        return (key < value.first); 
    } 
};

// bool cmp(pii a, pii b){
//     if(a.second == b.second)return a.first < b.first;
//     return a.second > b.second;
// }

int main(){
    cin >> n;
    vll a(n);
    fo(i,0,n)cin >> a[i];
    ll L[n];vector<pair<ll,ll>> R(n);
    fo(i,0,n){L[i] = i + 1 + a[i]; R[i].first = i  + 1 - a[i];R[i].second = i;}

    // fo(i,1,n+1)cout << L[i]<<" ";
    // cout << endl;
    // fo(i,1,n+1)cout <<"{"<<R[i].first<<", "<<R[i].second <<"}";
    sort(all(R));
    ll ans = 0;
    
    pair<std::vector<pii>::iterator, std::vector<pii>::iterator> p;
    for(int i = 0; i < n; i++){
        p = equal_range(all(R),L[i],compare());
        for(auto it1 = p.first ; it1 != p.second; it1++){
            if(it1->second > i ){
                ans += p.second - it1;
                break;
            }
        }
    }
    cout << ans;
     //fo(i,0,n)cout <<"{"<<R[i].first<<", "<<R[i].second <<"}";


    
    

    

}

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

typedef long long ll;
typedef long double ld;

using namespace std;

const int INF = 1e9;
const int maxn = 210;
const int mod = 1e9+7;

int n;
vector<int> g[maxn];

int bfs(int v)
{
    bool mark[maxn];
    int dis[maxn];
    queue<int> q;
    int mx = 0;

    memset(mark, 0, sizeof mark);

    mark[v] = 1;
    dis[v] = 1;
    q.push(v);

    while(q.size())
    {
        int u = q.front();
        mx = max(mx, dis[u]);
        q.pop();

        for(auto x : g[u]){
            if(!mark[x]){
                mark[x] = 1;
                dis[x] = dis[u] + 1;
                q.push(x);
            }
            if(mark[x] && dis[x] == dis[u]){
                cout<< -1;
                exit(0);
            }
        }
    }

    return mx;
}

int main()
{
    cin>> n;
    for(int i = 1; i <= n; i++){
        string s; cin>> s;
        for(int j = 1; j <= n; j++)
            if(s[j-1] - '0')
                g[i].push_back(j);
    }

    int ans = 0;
    for(int v = 1; v <= n; v++)
        ans = max(ans, bfs(v));
    cout<< ans;
}




Measured memory_bytes: 512
//include
//------------------------------------------
#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;


int main()
{
	int n;
	cin >> n;
	vector<LL> a(n);
	VI c(n);
	REP(i, n) cin >> a[i];
	REP(i, n) c[i] = 0;

	REP(i, n) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			c[i]++;
		}
	}
	int ans = 0;
	REP(i, n)
		ans += c[i];
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    string s;
    cin >> s;
    int count=0;
    for(int i=0;i<s.size();i+=2){
        if(s.at(i)=='0')count++;
    }
    for(int i=1;i<s.size();i+=2){
        if(s.at(i)=='1')count++;
    }
    int a=s.size();
    cout << min(count,(a-count)) << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
 double pi,s,a,b,c,l,deg,rad,h;

 cin >> a >> b >> deg;

 pi = acos(-1);
 rad = deg * pi / 180;

 s = a * b * sin(rad) / 2;

 c = sqrt(a*a + b*b - 2 * a * b * cos(rad));

 l = a+b+c;

 h = s / a * 2;

 printf("%lf\n%lf\n%lf\n", s, l, h);

 return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/
string s;
ll d;

ll dp[10000][100][2];

ll count(ll ind, ll sum , ll fl){
    if(ind == s(s) and sum) return 0;
    if(ind == s(s) and sum==0) return 1;
    if(dp[ind][sum][fl]>=0) return dp[ind][sum][fl];
    dp[ind][sum][fl]=0;
    if(fl){
        int x = s[ind]-'0' , i;
        fo(i,x){
            dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind+1,(sum+i)%d, 0))%mod;
        }
        dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind+1,(sum+x)%d,1))%mod;
    }else{
        int i;
        fo(i,10){
            dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind+1,(sum+i)%d, 0))%mod;
        }
    }
    return dp[ind][sum][fl];
}

int main(){
   
    _cin;
    // cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> s;
    cin >> d;
    fo(i,10000) fo(j,100) fo(k,2) dp[i][j][k]=-1;
    cnt = (count(0,0,1)+mod-1)%mod;
    cout << cnt;
}
 return 0;      
}

Measured memory_bytes: 16896
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int n,A[2010],vis[2010];
std::vector<int>G[2010];
struct cmp{bool operator()(int a,int b){return A[a]<A[b];}};
std::priority_queue<int,std::vector<int>,cmp>que;
void dfs(int x){
	vis[x]=1;
	for(int i=1;i<=n;++i)if(!vis[i]&&std::__gcd(A[x],A[i])>1)dfs(i),G[x].push_back(i);
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=gi();
	for(int i=1;i<=n;++i)A[i]=gi();
	std::sort(A+1,A+n+1);
	for(int i=1;i<=n;++i)if(!vis[i])que.push(i),dfs(i);
	memset(vis,0,sizeof vis);
	while(!que.empty()){
		int x=que.top();vis[x]=1;printf("%d ",A[x]);que.pop();
		for(int i:G[x])que.push(i),vis[i]=1;
	}
	return 0;
}


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<long> a(n);
    vector<long> b(n);
    vector<long> c(m);
    vector<long> d(m);
    
    for (int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    for (int i=0;i<m;i++){
        cin >> c[i] >> d[i];
    }

    for (int i=0;i<n;i++){
        long min=100000000000;
        int ans=0;
        for(int j=0;j<m;j++){
            long count=abs(a[i]-c[j])+abs(b[i]-d[j]);
            //cout << count<<" "<<min <<endl;
            if (min>count){
                min=count;
                ans=j+1;
            }
            //cout << count <<endl;
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int A, B, C, K, sum = 0;

	cin >> A >> B >> C >> K;

	for (int i = 0; i < K; i++) {
		if (A > 0) {
			sum++;
			A--;
		}
		else if (B > 0) {
			B--;
		}
		else if(C>0){
			sum--;
			C--;
		}

	}
	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
char f[6][6],i,j,a,y,x,p;
int main()
{
	for(;i<9;++i){
		scanf("%s",f[5]);
		for(j=0;j<4+i%2;++j){
			a=f[5][j]-48;
			f[i/2][j]|=a<<(1+i%2);
			f[i/2+i%2][j+!(i%2)]|=a<<3-i%2*3;
		}
	}
	do{
		while(!((f[y][x]>>(p=(p+1)%4))&1));
		putchar("URDL"[p]);
		x+=p?2-p:0;
		y+=p==3?0:p-1;
		p=(p+2)%4;
	}while(y||x||f[0][0]==6&&p==3);
	return!puts(""); 
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>

using namespace std;

int main(){
	cout << setprecision(3) << setiosflags(ios::fixed);
	double a, b, c, d, e, f;

	while(cin >> a >> b >> c >> d >> e >> f){
		cout << (c*e-f*b)/(a*e-d*b) + 0.000001<< " " << (c*d-f*a)/(b*d-a*e) + 0.000001 << '\n';
		}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;
typedef long long ll;

int main( void )
{
	ll x;

	cin >> x;

	int a = 0;

	while ( true ) {
		if ( x >= 500 ) {
			a += 1000;
			x -= 500;
		}
		else if ( x >= 5 ) {
			a += 5;
			x -= 5;
		}
		else {
			break;
		}
	}

	cout << a << endl;
}


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

int main() {
  int N, W;
  cin >> N >> W;
  vector<long> DP(N * 1e3 + 1, 2e18);
  DP.at(0) = 0;
  for (int w, v; cin >> w >> v;) {
    vector<long> tmp = DP;
    for (int i = v; i < tmp.size(); i++) {
      tmp.at(i) = min(tmp.at(i), DP.at(i - v) + w);
    }
    DP = tmp;
  }
  long ans = 0;
  for (int i = 0; i < DP.size(); i++) {
    if (DP.at(i) <= W) ans = max(ans, (long) i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1800
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define N 100000
#define Q 50000
int main(){
  int i,n,q,j,S[N],T[Q],AI=0,left,right,mid;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    left=0;
    right=n;
    while(left<right){
      mid=(left+right)/2;
      if(T[i]==S[mid]){
    AI++;
    break;
      }
      if(T[i]>S[mid])
    left=mid+1;
      else if(T[i]<S[mid])
    right=mid;
    }
  }
  printf("%d\n",AI);
   
   
  return 0;
}

Measured memory_bytes: 1184
object Main extends App{
    val n = scala.io.StdIn.readInt
    if(((n/1.08).toInt * 1.08).toInt == n) println((n/1.08).toInt)
    else if(((n/1.08).ceil.toInt * 1.08).toInt == n) println((n/1.08).ceil.toInt)
    else println(":(")
    
}


Measured memory_bytes: 25544
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
	int index = 0, i,j, pos = 0;
	char word[33], longest[33], freq[33], text[32001][33];
	do {
		scanf("%s", &word);
		for(i=0;word[i]!=0;i++) {
			word[i]=tolower(word[i]);
		}
		strcpy(text[index], word);
		index++;
		if(strlen(word) > strlen(longest)) {
			strcpy(longest, word);
		}
	}while(getchar() != '\n');
	int count = 0, highest = 0;
	for(i = 0; i < index; i++) {
		count = 0;
		for(j=i;j<index;j++) {
			if(strcmp(text[i], text[j]) == 0) {
				count++;
			}
		}
		if(count > highest) {
			highest = count;
			pos = i;
		}
	}
	printf("%s %s\n", text[pos], longest);
	return 0;
}


Measured memory_bytes: 2028
import java.util.Scanner;
        public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length = 2*a+2*b;
        System.out.println(area+" "+length);
        sc.close();

    }
        }


Measured memory_bytes: 26172
a = input().split(" ")
n = int(a[0])
l = int(a[1])
m = 0
if l >= 0:
    for i in range(n - 1):
        m += l + i + 1
    print(m)
elif l + n - 1 >= 0:
    for i in range(n):
        m += l + i
    print(m)
else:
    for i in range(n - 1):
        m += l + i
    print(m)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

    
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  int w,s;
  cin >> s>> w;
  if(w>=s)cout << "unsafe"<<endl;
  else cout << "safe" << endl;
  return 0;
  
}


Measured memory_bytes: 15608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>


int main(void){
    int n;
    int *a;

    scanf("%d",&n);

    a=(int *)malloc(sizeof(int)*n);

    for(int i=0;i<n;i++) scanf("%d",&a[i]);

    int *ans;
    ans=(int *)malloc(sizeof(int)*n);

    int m=n-1;
    int k=0;

    if(n%2==0){
        while(m>0){
            ans[k]=a[m];
            k++;
            m-=2;
        }
        m++;
        while(m<n){
            ans[k]=a[m];
            k++;
            m+=2;
        }
    }
    else{
        while(m>=0){
            ans[k]=a[m];
            k++;
            m-=2;
        }
        m+=3;
        while(m<n){

            //printf("::%d,%d\n",a[m],m);

            ans[k]=a[m];
            k++;
            m+=2;
        }
    }

    for(int i=0;i<n;i++) printf("%d ",ans[i]);
    printf("\n");
    return 0;
}


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

double dp[3000][3000];

int main()
{
    int n;
    cin>>n;
    double p[n+5];
    for(int i=0;i<n;i++)cin>>p[i];
    dp[0][0]=1.000;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(!j)dp[i][j]=dp[i-1][j]*(1.0-p[i-1]);
            else
                dp[i][j]=dp[i-1][j-1]*p[i-1]+((1.00-p[i-1])*dp[i-1][j]);
        }
    }
    double ans=0.0;
    for(int i=n/2+1;i<=n;i++)
        ans+=dp[n][i];
    cout<<fixed<<setprecision(9)<<ans<<endl;
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
    int N, M; cin >> N >> M;
    vector<int> L(M), R(M);
    int Lmax = 0, Rmin = inf;
    for (int i = 0; i < M; i++) {
        cin >> L.at(i) >> R.at(i);
        Lmax = max(Lmax, L.at(i));
        Rmin = min(Rmin, R.at(i));
    }
    int ans;
    if (Lmax <= Rmin) {
        ans = Rmin - Lmax + 1;
    }
    else {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, p;
  cin >> N;
  string ans = "APPROVED";
  for (int i=0; i<N; i++) {
    cin >> p;
    if (p%2==0) {
      if (p%3 != 0 && p%5 != 0) {
        ans = "DENIED";
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll l, r;
    cin >> l >> r;

    int ans = 2019;
    for(ll i = l;  i < r; i++){
        for(ll j = i+1; j <= r; j++){
            ll res = i*j%2019;
            if(res == 0){
                cout << 0;
                return 0;
            }
            if(res < ans)ans = res;
        }
    }
    cout << ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr first
#define sc scanf
#define pf printf
#define se second
#define sq(x) x * x
#define ll long long
#define pb push_back
#define mk make_pair
#define ld long double
#define pr pair<int,int>
#define sz(s) int(s.size())
#define piip pair< pair<ll,ll>,ll >
#define fin(s) freopen( s, "r", stdin )
#define fout(s) freopen( s, "w", stdout )
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll INF = 1e9;
const ll N = 2e2+7;
const ll mod = 1e9 + 7;
const long double eps = 1E-7;
ll a, b, n , cnt ,mx,ans,c;
ll used[ N ];
string s;
int main()
{
        TIME;
        cin >> a ;
        if( a==25 )
            cout<<"Christmas";
        else if( a==24 )
            cout<<"Christmas Eve";
        else if( a==23 )
            cout<<"Christmas Eve Eve";
        else
            cout<<"Christmas Eve Eve Eve";
}


/* MADE BY
//________________________________________________________
//________________________________________________________ //
                                                           //
// ██╗   ██╗     ██████╗     ███████╗    ██╗    ███╗   ██╗ //
// ╚██╗ ██╔╝    ██╔═══██╗    ██╔════╝    ██║    ████╗  ██║ //
//  ╚████╔╝     ██║   ██║    ███████╗    ██║    ██╔██╗ ██║ //
//   ╚██╔╝      ██║   ██║    ╚════██║    ██║    ██║╚██╗██║ //
//    ██║       ╚██████╔╝    ███████║    ██║    ██║ ╚████║ //
//    ╚═╝        ╚═════╝     ╚══════╝    ╚═╝    ╚═╝  ╚═══╝ //
//________________________________________________________ //
//________________________________________________________ */


Measured memory_bytes: 256
$offset = Array.new(12, 0)
$offset.length.times{ |i|
	$offset[i] = (1..i).inject(0) { |total, n| total + 4**n }
}

def StrToAddress(s)
	return if s.length < 1

	bas = ""
	s.chars { |c|
		case c
		when 'A'
			bas += "0"
		when 'C'
			bas += "1"
		when 'G'
			bas += "2"
		when 'T'
			bas += "3"
		end
	}

	bas.to_i(4) + $offset[s.length]
end

dic = Array.new(4**12, false)
gets.to_i.times {
	str = gets.chomp.split(" ")
	add = StrToAddress(str[1])

	case str[0]
	when "insert"
		dic[add] = true
	when "find"
		if dic[add]
			puts "yes"
		else
			puts "no"
		end
	end
}

Measured memory_bytes: 139932
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long X, K, D;
    cin >> X >> K >> D;
    long long s = abs(X) / D;
    if(s >= K){
        if(X < 0) cout << abs(X + D * K) << endl;
        else cout << abs(X - D * K) << endl;
        return 0;
    }
    K -= s;
    if(X < 0) X += s * D;
    else X -= s * D;
    if(X < 0){
        if(K % 2 == 0) cout << abs(X) << endl;
        else cout << X + D << endl;
        return 0;
    }
    if(K % 2 == 0) cout << X << endl;
    else cout << abs(X - D) << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 100005
lld fact[N],invfact[N],pos[N],a[N];
lld nCr(lld n,lld r) {
	if(n<r) return 0LL;
	lld ans = (fact[n] * invfact[r])%MOD;
	ans = (ans * invfact[n-r])%MOD;
	return ans;
}
int main()
{
	fact[0]=1,invfact[0]=1;
	rep(i,1,N) fact[i]=(fact[i-1]*i)%MOD,invfact[i]=powm(fact[i],MOD-2);
	lld n,ele1,ele2;
	cin>>n;
	rep(i,1,n+2) {
		cin>>a[i];
		if(pos[a[i]]) ele1 = pos[a[i]]-1, ele2 = n+1-i;
		else pos[a[i]]=i;
	}
	rep(k,1,n+2) {
		lld tmp = nCr(n+1,k);
		tmp = (tmp - nCr(ele1 + ele2,k-1) + MOD)%MOD;
		cout<<tmp<<endl;
	}
	return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;

const ll mod = 1e9+7;

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

  ll n, k;
  cin >> n >> k;

  ll ans = k;
  rep(i, n-1) {
    ans *= --k;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <bitset>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n, m;
	std::vector<bool> members;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(ifs >> n >> m){
#else
	while(std::cin >> n >> m){
#endif
		if(n == 0 && m == 0){ break; }
		members.clear();
		members.resize(n, true);

		int i = 0, mm = m;
		for(;;){
			int rcounter = 0;
			for(int j = 0; j < members.size(); j++){
				if(members[j]){
					rcounter++;
				}
			}
			if(rcounter == 1){
				int winner = 0;
				for(int j = 0; j < members.size(); j++){
					if(members[j]){
						winner = j + 1;
						break;
					}
				}
				std::cout << winner << std::endl;
				break;
			}
			
			mm = m - 1;
			while(mm >= 1){
				if(members[i]){
					mm--;
				}
				i++;
				if(i == members.size()){
					i = 0;
				}
			}
			while(!members[i]){
				i++;
				if(i == members.size()){
					i = 0;
				}
			}
			members[i] = false;
		}
	}


 
#if INPUT_FROM_FILE
	//fclose(fp);
#endif
    return 0;
}


Measured memory_bytes: 3104
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
journey = [1]

for i in range(2*n+1000):
    nxt = a[journey[-1]]
    journey.append(nxt)

if k < n+1:
    print(journey[k])
    exit()

loop_end = n
loop_start = n-1

while(journey[loop_start] != journey[loop_end]):
    loop_start -= 1

period = loop_end-loop_start
k %= period

while k < n:
    k += period

print(journey[k])


Measured memory_bytes: 32152