akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, c; cin >> n >> c;
    vector<vector<int>>D(c, vector<int>(c, 0));
    rep(i,c)rep(j,c) cin >> D[i][j];
    vector<vector<int>>C(n, vector<int>(n, 0));
    rep(i,n)rep(j,n) cin >> C[i][j], --C[i][j];
    vector<vector<int>> cost(3, vector<int>(c, 0));
    for(int k = 0; k < c; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                cost[(i+j)%3][k] += D[C[i][j]][k];
            }
        }
    }
    int ans = 1 << 30;
    for(int i = 0; i < c; ++i){
        for(int j = 0; j < c; ++j){
            if(i == j) continue;
            for(int k = 0; k < c; ++k){
                if(i == k || j == k) continue;
                int tmp = cost[0][i] + cost[1][j] + cost[2][k];
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
N,K = map(int,input().split())
if K==0:
    print(N*N)
    exit()

ans = 0
for b in range(K+1,N+1):
    d,m = divmod(N+1,b)
    ans += (b-K)*d
    ans += max(0, (m-1)-K+1)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

ll N, K;
vll A;

bool ok(ld mid)
{
        ll sm = 0;
        rep(i, 0, N) {
                sm += (ll)(A[i] / mid);
        }
        if (sm <= K) {
                return true;
        }
        else return false;
}

int main()
{
        cin >> N >> K;
        A.resize(N);
        rep(i, 0, N) cin >> A[i];



        ld right = 10000000000;
        ld left = 0.001;
        
        rep(i, 0, 100) {
                ld mid = (left + right) / 2.0;
                if (ok(mid)) right = mid;
                else left = mid;
        }

        ll ans = floor(right + 0.9999);
        cout << ans << endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

int n;

void dfs(string s,char tmp){
	if(s.size()==n){
		cout<<s<<endl;
		return;
	}else{
		for(char c='a';c<=tmp+1;c++){
			string t=s;
			t+=c;
			dfs(t,max(c,tmp));
		}
	}
}

int main() {
	cin>>n;
	dfs("",'a'-1);
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<=(int)(n); i++)
#define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll inf=1LL << 60;
const ll MOD=1000000007;

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

  int n, m;
  cin >> n >> m;
  dsu d(n);
  int a, b;
  rep(i, m){
  	cin >> a >> b;
  	d.merge(a-1, b-1);
  }

  set<int> s;
  rep(i, n){
  	int t=d.leader(i);
  	s.insert(t);
  }

  cout << s.size()-1 << endl;

  return 0;
}

Measured memory_bytes: 7668
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        for(int i=1;i<10;i++){
            if(N%i==0 && N/i<10){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

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

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

using namespace std;

typedef long long ll;


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

	int n;
	cin >> n;

	for(int i = 0; 4 * i <= n; i++){
		if((n - 4 * i) % 7 == 0){
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
main(){
  int i,j,n,sum;
  while(1){
    scanf("%d",&sum);
    if(sum==0) break;
    for(i=0;i<9;i++){
      scanf("%d",&n);
      sum-=n;
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vllint a(n);
	int cnt = 0;
	llint ans = 0;
	llint mn = 1000000000;
	rep(i, n) {
		cin >> a[i];
		if (a[i] < 0)cnt++;
		ans += abs(a[i]);
		mn = min(abs(a[i]), mn);
	}
	if (cnt % 2 == 0) {
		cout << ans << endl;
	}
	else {
		cout << ans - mn * 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            k = bisect.bisect_left(l, l[i]+l[j])
            res += max(k-(j+1), 0)
    print(res)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 10684
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int d[maxn],p[maxn],f[maxn];
int main() {
	int n,D,k,a;
	scanf("%d%d",&n,&D);
	for(int i=1;i<=n;i++)
		scanf("%d",d+i);
	p[0]=D;
	for(int i=1;i<=n;i++)
		p[i]=min(p[i-1],abs(p[i-1]-d[i]));
	f[n+1]=1;
	for(int i=n;i>=1;i--) {
		f[i]=f[i+1]+d[i];
		if(d[i]>=2*f[i+1])f[i]=f[i+1];
	}
	scanf("%d",&k);
	while(k--) {
		scanf("%d",&a);
		if(p[a-1]>=f[a+1])puts("YES");
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 9508
L, R = map(int, input().split())
mod = 2019

for i in range(L, R) :
	for j in range(i + 1, R + 1) :
		if((i * j) % 2019 < mod) :
			mod = (i * j) % 2019
			x = ((i * j) // 2019) * 2019 + 2019
			if(x > i * R) :
				break
			else :
				pass
		elif(mod == 0) :
			break
		else :
			pass
	if(mod == 0) :
		break
	else :
		pass
	
print(mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  string s;
  cin >> s;
  int a = s.size();
  int b = 0;
  for(int i=0;i<a;i++){
    b += ctoi(s.at(i));
  }
  if(b % 9 == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3728
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int len=n/2;
		int p[]=new int[n];
		int cnt=0;
		for(int i=0;i<n;i++) {p[i]=sc.nextInt();}	
		Arrays.sort(p);	
		if(p[len]>p[len-1])System.out.println(p[len]-p[len-1]);
		else System.out.println(0);
	}
}

Measured memory_bytes: 50844
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(){
  int unused __attribute__((unused));
  int i, start, Slen, Tlen, ans, dif;
  char S[1001], T[1001];
  unused = scanf("%s", S);
  unused = scanf("%s", T);

  Slen = strlen(S);
  Tlen = strlen(T);
  ans = Tlen; //ansを仮置きする．

  //Sの何文字目から調べるかを全探索する
  for(start=0; start<=Slen-Tlen; start++){
    dif = 0;
    for(i=0; i<Tlen; i++){
      if(T[i]!=S[start+i]) dif++;
    }
    ans = fmin(ans, dif);
  }
  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 2096
#include <bits/stdc++.h>
using ll = long long;

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
long long MX = 1.0e18;

int main() {
    ll a[200000];
    ll n;
    ll ans = 1;
    bool zero = false;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) zero = true;
    }
    // ゼロかどうかの判定
    if (zero) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, n) {
        // 最大値に達してるかどうかの判定
        if (ans > MX / a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4420
from itertools import product
N = int(input())
F = [ list( map( int, input().split())) for _ in range(N)]
P = [ list( map( int, input().split())) for _ in range(N)]
ans = - 10**10
for X in product( range(2), repeat = 10):
    if X == tuple([0]*10):
        pass
    else:
        c = 0
        for i in range(N):
            n = 0
            for j in range(10):
                if F[i][j] == 1 and X[j] == 1:
                    n += 1
            c += P[i][n]
        ans = max(ans, c)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] result = new int[100];
        int c = 0;
        while (sc.hasNext()) {
            Integer[] l = Stream.of(sc.nextLine().split(",")).map(Integer::parseInt).toArray(Integer[]::new);
            if (l.length == 1 && c == 0) {
                result[0] = l[0];
            } else if (c < l.length) {
                int[] temp = result.clone();
                for (int i = 0; i < l.length - 1; i++) {
                    result[i] = Math.max(result[i], temp[i] + l[i]);
                    result[i + 1] = Math.max(result[i + 1], temp[i] + l[i + 1]);
                }
            } else {
                for (int i = 0; i < l.length; i++) {
                    result[i] = Math.max(result[i] + l[i], result[i + 1] + l[i]);
                }
            }
            c = l.length;
        }
        System.out.println(result[0]);
    }
}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

ll ans[10000];

int main(){

  ll n;cin>>n;

  if(n%2==1)out(0);
  else{

    ll ans=0;
    ll k=n/2;

    while(k!=0){
      k/=5;
      ans+=k;
    }

    out(ans);//+((n-2)/50+(n-2)/10)
  }



  return 0;
}


Measured memory_bytes: 256
// 14/06/19 // 02:02 AM //

#include <iostream>
#include <cmath>

using namespace std;

#define MAXN 100010

int n;
int h[MAXN];
int memo[MAXN];

int bottom_up(){

    memo[0] = MAXN;

    for(int i=2; i<=n; i++){
        memo[i] = min(memo[i-1]+abs(h[i]-h[i-1]), memo[i-2] + abs(h[i]-h[i-2]) );
    }

    return memo[n];
}

int main(){

    cin >> n;

    for(int i=1; i<=n; i++) cin >> h[i];

    cout << bottom_up() << "\n";

    return 0;
}



Measured memory_bytes: 1024
N=int(input())
if N==0:
    print(0)
    exit()
ans = ""
tmp = N
while tmp != 0:
    div, mod = divmod(tmp, -2)
    if mod == -1:
        div += 1
        mod = 1
    ans += str(mod)
    tmp = div

print(ans[::-1])


Measured memory_bytes: 61924
n, p = map(int, input().split())
s = input()

ans = 0

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    mod = [-1 for i in range(p)]
    mod[0] = 0
    mp = 0
    m10 = 1
    
    for i in range(n-1, -1, -1):
        mp = (mp + int(s[i]) * m10) % p
        mod[mp] += 1
        m10 = (10 * m10) % p

    for m in mod:
        ans += m*(m+1)//2

print(ans)

Measured memory_bytes: 3500
/*
ID: amagica1
TASK: ariprog
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NINF -INF
#define mp make_pair
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define For(i, a, b) for(int i=a; i<b; i++)
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define Rev(i, a, b) for(int i=a; i>b; i--)
#define REV(i, a, b) for(int i=a; i>=b; i--)
typedef long long ll;
typedef long double ld;
typedef int64_t l;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int MAXN = 1000005;
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
int main() {
    //-----------FILE------------//
    // freopen("ariprog.in", "r", stdin);
    // freopen("ariprog.out", "w", stdout);
    //----------------------------//
    ll a, b; scanf("%lld %lld", &a, &b);
    printf("%lld\n", lcm(a, b));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
	int cnt=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)cnt+=s[i]-'0';
	if(s[0]-'0'-1+(s.size()-1)*9<cnt)cout<<cnt<<endl;
	else cout<<s[0]-'0'-1+(s.size()-1)*9<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(abs(b-c)%2==0)
	{
		cout<<"Alice";
	}
	else
	{
		cout<<"Borys";
	}
	return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define llMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

//Union-find
vector<ll> parent, size, depth;
void init(ll n){
  for(ll i = 0; i < n; i++){
    parent.push_back(i);
    depth.push_back(0);
    size.push_back(1);
  }
}

ll root(ll x){
  if(parent[x] == x)return x;
  else return root(parent[x]);
}

void unite(ll x, ll y){
  x = root(x);
  y = root(y);
  if(x == y) return; //一緒の連結成分であった時
  if(depth[x] < depth[y]){
    parent[x] = y; //yの方が深いので，xの親をyに変更
    size[y] += size[x];
  }else{
    parent[y] = x;
    size[x] += size[y];
    if(depth[x] == depth[y])depth[x]++; //xとyの深さが同じ時は，xの下にyを付け加えることに
  }
}
ll treesize(ll x){
  return size[root(x)];
}

//Union-find部分ここまで
ll n, m;
int main(){
  cin >> n >> m;
  vector<ll>p(n);
  for(int i = 0; i<n; i++){
    int tmp; cin >> p[i];
  }
  init(n);
  for(int i = 0; i < m; i++){
    int x, y;
    cin >> x >> y;
    unite(x-1,y-1);
  }
  ll ans = 0;
  for(int i = 0; i<n; i++){
    if(root(p[i]-1) == root(i)) ans++;
  }
  cout << ans << endl;

}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int s,w;
  cin >> s >> w;
  if(s<=w){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		sum += a[i];
	}
	
	int cnt = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] * 4 * m >= sum)
		{
			cnt++;
		}
	}
	
	if (cnt >= m)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
h,w = map(int, input().split())
s = [input() for _ in range(h)]
ans = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if ((i==0 or s[i-1][j] == ".") and (i==h-1 or s[i+1][j] == ".") and 
                (j==0 or s[i][j-1] == ".") and (j==w-1 or s[i][j+1] == ".")):
                    ans = "No"
print(ans)


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

using namespace std;

typedef long long ll;

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;
}

vector<int> v;
vector<int> w;
vector<vector<int>> dp;

int solve(const int N, const int W) {
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= W; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - w[i] >= 0) {
                chmax(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }
    return dp[N][W];
}

int main(void) {
    int N, W;
    cin >> N >> W;

    v.resize(N + 1);
    w.resize(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> v[i + 1] >> w[i + 1];
    }

    dp.resize(N + 1, vector<int>(W + 1, 0));
    cout << solve(N, W) << endl;

    return 0;
}



Measured memory_bytes: 6796
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin>>d;
   if(d==25){
    cout<<"Christmas"<<'\n';
  }
   if(d==24){
    cout<<"Christmas Eve"<<'\n';
  }
   if(d==23){
    cout<<"Christmas Eve Eve"<<'\n';
  }
   if(d==22){
    cout<<"Christmas Eve Eve Eve"<<'\n';
  }
  return(0);
}


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


// int N = 9;
// int Y = 45000;

int N, Y;

int main() {
    cin >> N >> Y;
    int result;
    for (int i = 0; i <= N; i++) {
        result = i * 10000;
        if (result > Y) {
            continue;
        } 

        for (int j = 0; j <= N - i; j++) {
            result += j * 5000;
            if (result > Y) {
                continue;
            }
            int k = N - i - j;
            result += k * 1000;
            // printf("%d %d %d\n", i, j, k);
            // cout << result << endl;
            // printf("%d %d %d %d\n", i, j, k, result);
            if (result == Y) {
                printf("%d %d %d\n", i, j, k);
                return 0;
            }
            result = i * 10000;
        }
    }
    printf("%d %d %d\n", -1, -1, -1);
}

Measured memory_bytes: 256
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;

int main()
{
    int n;
    int a[200005];
    int ans=0;
    int cnt = 1;

    cin >> n;

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

    for (int i = 0; i < n; i++) {
        if (a[i] == cnt) {
            cnt++;
        }
        else {
            ans++;
        }
    }

    if (cnt == 1) {
        cout << -1 << endl;
    }
    else {
        cout << ans << endl;
    }


    
}



Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	int n;
	cin >> n;
	vector<int> v(n + 1);
	for (int i = 2; i <= n; i++) {
		int x;
		cin >> x;
		v[x]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << v[i] << endl;
	}
}
int32_t main() {
	BOLT;
	int t;
	t = 1;
	while (t--) {
		solve();
	}
}


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

int main() {
	int n, l;

	cin >> n >> l;

	int ans = 0;
	int min = l;

	for (int i = 0; i < n; i++) {
		if (abs(min) > abs(l + i))
			min = l + i;
		ans += l + i;
	}

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

Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Console;

namespace AtCoder1
{
	class Program
	{
		static int[] Note;
		static void Main(string[] args)
		{
			int N = int.Parse(ReadLine());
			int[] H = ReadLine().Split().Select(s => int.Parse(s)).ToArray();
			Note = Enumerable.Repeat(-1, N).ToArray();

			WriteLine(Func(N-1, N, H));
		}

		static int Func(int i, int N, int[] H)
		{
			// メモ
			if(Note[i] != -1)
				return Note[i];
			if(0 == i)
				return 0;
			if(1 == i)
				return Math.Abs( H[0] - H[1]);

			int a = Func(i - 1, N, H) + Math.Abs(H[i] - H[i - 1]);
			int b = Func(i - 2, N, H) + Math.Abs(H[i] - H[i - 2]);
			Note[i] = Math.Min(a, b);
			return Note[i];
		}
	}
}


Measured memory_bytes: 25312
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int a, b;

	scanf("%d%d", &a, &b);
	if (a < b) printf("a < b\n");
	else if (a > b) printf("a > b\n");
	else printf("a == b\n");
	return 0;
}



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


int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
  
    int64_t ans = 100000*10000;
  
    for (int i = 0; i <= max(X, Y)*2; i += 2) {
        int64_t ans2 = i*C + max(0,X-i/2)*A + max(0,Y-i/2)*B;
        ans = min(ans, ans2);
    }
    cout << ans << endl;
}

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

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    ll N;
    ll cnt =0;

    cin >> N;

    vector <ll> d(N);

    REP(i,N)
    {
        cin >> d[i];
    }

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

    ll f;

    f = N/2; 
    ll K;
    K = d[f] - d[f-1];
    cout << K << endl;

}



Measured memory_bytes: 1024
import java.io.IOException
import java.io.InputStream
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val (n, m) = sc.nextInts(2)
    var types = Array(m) { it + 1 }.toSet()
    repeat(n) {
        val k = sc.nextInt()
        val a = sc.nextIntArray(k)
        types = types.intersect(a.toSet())
    }
    println(types.size)
}

class Scanner(private val `in`: InputStream) {
    private val buffer = ByteArray(1024)
    private var ptr = 0
    private var buflen = 0

    companion object {
        private fun isPrintableChar(b: Byte): Boolean = b in 33..126
        private fun isNumericChar(b: Byte): Boolean = b in 48..57
        private fun digit(b: Byte): Int = b - 48
    }

    fun hasNextByte(): Boolean {
        if (ptr < buflen) return true
        ptr = 0
        try {
            buflen = `in`.read(buffer)
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return 0 < buflen
    }

    private fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        return buildString {
            var b = readByte()
            while (isPrintableChar(b)) {
                appendCodePoint(b.toInt())
                b = readByte()
            }
        }
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextInts(n: Int): Array<Int> = Array(n) { nextInt() }

    fun nextIntArray(n: Int): IntArray = IntArray(n) { nextInt() }

    fun nextIntArrays(n: Int, m: Int): Array<IntArray> {
        val arrays = Array(m) { IntArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextInt() } }
        return arrays
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextLongs(n: Int): Array<Long> = Array(n) { nextLong() }

    fun nextLongArray(n: Int): LongArray = LongArray(n) { nextLong() }

    fun nextLongArrays(n: Int, m: Int): Array<LongArray> {
        val arrays = Array(m) { LongArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextLong() } }
        return arrays
    }

}

Measured memory_bytes: 33736
<?php

$input = trim(fgets(STDIN));
$strpos = strpos($input,"A");
$length = strlen($input);
$input = str_split($input);

for($i=0; $i<$length;$i++){
    if($input[$i] == "Z"){
        $z = $i;
    }
}
echo $z - $strpos+1;



Measured memory_bytes: 38828
// Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

int cur[1005][12][22];

main(){
    int day=1;
    int n,m,k;
    for(int i = 1 ; i <= 1000 ; i++){
        for(int j = 1 ; j <= 10 ; j++){
            if(i%3 ==0 || j%2 == 1) k = 20;
            else k = 19;
            
            for(int kk = 1 ; kk <= k ; kk++){
                cur[i][j][kk]=day;
                day++;
                //cout << i << " " << j << " " << kk << endl;
            }
        }
    }
            
    int t;
    
    cin >> t;
    while(t--){
        cin >> n >> m >> k;
        cout << cur[1000][1][1]-cur[n][m][k] << endl;
    }
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}

Measured memory_bytes: 2192
#include<bits/stdc++.h>
#define MAX 1000001
#define Max 1600
#define index 1000
#define f first
#define s second
#define mp make_pair
using namespace std;

int y[MAX],x[MAX];
bool prime[MAX];
int pc[Max][Max]={};
int dp[Max][Max]={};
int Y[4]={0,-1,0,1};
int X[4]={1,0,-1,0};

bool isPrime(int n){
  if(n<2)return false;
  if(n==2)return true;
  if(n%2==0)return false;
  for(int i=3;i<=n/i;i+=2){
    if(n%i==0)return false;
  }
  return true;
}

void init(){
  for(int i=0;i<MAX;i++)prime[i]=isPrime(i);
  
  int nowi=index,nowj=index,muki=0;
  for(int i=1;i<MAX;i++){
    pc[nowi][nowj]=i;
    y[i]=nowi;
    x[i]=nowj;
    nowi+=Y[muki];
    nowj+=X[muki];
    if(pc[nowi+Y[(muki+1)%4]][nowj+X[(muki+1)%4]]==0)muki=(muki+1)%4;
  }
}

int main()
{
  int a,b;

  init();

  while(1){
    cin>>a>>b;
    if(a+b==0)break;

    for(int i=0;i<Max;i++){
      for(int j=0;j<Max;j++)dp[i][j]=-1;
    }

    queue<pair<int,int> > q;
    dp[y[b]][x[b]]=prime[b];
    q.push(mp(y[b],x[b]));
    pair<int,int> ans(prime[b],b);
    while(!q.empty()){
      pair<int,int> u=q.front();
      q.pop();
      for(int i=-1;i<=1;i++){
	int ni=u.f+1,nj=u.s+i;
	if(pc[ni][nj]<=a && pc[ni][nj]!=0){
	  if(dp[ni][nj]<dp[u.f][u.s]+prime[pc[ni][nj]]){
	    if(dp[ni][nj]==-1)q.push(mp(ni,nj));
	    dp[ni][nj]=dp[u.f][u.s]+prime[pc[ni][nj]];
	    if(prime[pc[ni][nj]]==0)continue;
	    if(ans.f<dp[ni][nj]){
	      ans=mp(dp[ni][nj],pc[ni][nj]);
	    }
	    else if(ans.f==dp[ni][nj] && ans.s<pc[ni][nj]){
	      ans=mp(dp[ni][nj],pc[ni][nj]);
	      }
	  }
	}
      }
    }
    if(ans.f==0)cout<<0<<" "<<0<<endl;
    else cout<<ans.f<<" "<<ans.s<<endl;
  }
  return 0;
}

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rep2(i, j, N, M) rep(i, N) rep(j, M)
#define rep3(i, j, k, N, M, L) rep(i, N) rep(j, M) rep(k, L)
#define REP(i, init, N) for (int i = (init); i < (N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int N;
VI R, W;

int solve() {
    // ?????§r???idx
    int max_r_i;
    {
        auto it = max_element(ALL(R));
        max_r_i = it - R.begin();
    }

    // ?????§r????????????sum
    int other_sum = accumulate(ALL(R), 0) - R[max_r_i];

    // calc time
    int r_time;
    int w_time;
    if (other_sum >= R[max_r_i]) {
        r_time = other_sum + R[max_r_i];
        w_time = accumulate(ALL(W), 0);
    } else {
        r_time = R[max_r_i] * 2;

        int T = R[max_r_i] - other_sum;

        VB dp(T + 1);
        dp[0] = true;

        rep(i, N) {
            if (i == max_r_i) continue;
            for (int j = T; j >= 0; --j) {
                if (dp[j]) {
                    int t = j + W[i];
                    if (t <= T) {
                        dp[t] = true;
                    }
                }
            }
        }

        int t = 0;
        rep(i, T + 1) {
            if (dp[i]) {
                t = i;
            }
        }

        w_time = accumulate(ALL(W), 0) - t;
    }

    return r_time + w_time;
}

int main(void) {
    while (cin >> N, N) {
        R = VI(N);
        W = VI(N);

        rep(i, N) {
            cin >> R[i] >> W[i];
        }

        cout << solve() << endl;
    }

	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
using namespace std;
long long n, A, B, C, D;
int main(){
	cin>>n>>A>>B>>C>>D;
	for(int i=0;i<=n-1;i++)
		if(C*i-D*(n-1-i)<=B-A&&B-A<=D*i-C*(n-1-i)){
			puts("YES"); return 0;
		}
	puts("NO");
	return 0;
}

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

using namespace std;



int main(){

	int N;

	while (cin >> N){

		if (N == 0){

			break;

		}else if(N % 1111 == 0){
			cout << "NA\n";
			continue;
		}
		int cnt = 0;
		while(N != 6174){
			int n[4];
			for(int i = 0; i < 4; i++){
				n[i] = N / pow(10,3 - i);
				N %= (int)pow(10,3 - i);
			}
			sort(n,n + 4,greater<int>());
			int L = n[0]*1000 + n[1]*100 + n[2]*10 + n[3];
			sort(n,n + 4);
			int S = n[0]*1000 + n[1]*100 + n[2]*10 + n[3];
			N = L - S;
			cnt++;
		}
		cout << cnt << endl;

	}

	return 0;

}


Measured memory_bytes: 1224
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<queue>
#define ll long long
using namespace  std;
int a[100005];
void mmain()
{
    int t;
    int n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(n&1)
        {
            int ans=0;
            for(int i=1;i<=n;i+=2)
                ans=ans^a[i];
            printf("%d\n",ans);
        }
        else
            puts("0");

    }

}
int  gcd(int x,int y)
{
    int r;
    r=y%x;
    while(r!=0)
    {
        y=x;
        x=r;
        r=y%x;
    }
    return x;
}
int main()
{
    int n;
    ll sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int k=1;k<=n;k++)
            for(int j=1;j<=n;j++)
            sum+=gcd(gcd(i,k),j);
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 3236
N, M = [int(i) for i in input().split()]
A = {int(input()) for _ in range(M)}

dp = [0] * 100100
dp[0] = 1
dp[1] = 0 if 1 in A else 1
for i in range(N):
    if i+2 in A:
        continue
    dp[i+2] = dp[i] + dp[i+1]

print(dp[N] % 1000000007)


Measured memory_bytes: 460020
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	string s;
	cin >> s;
	int dp[100030] = {};
	char r = 'R';
	char l = 'L';
	char a = 'R';
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == a) {
			cnt++;
		}
		else {
			dp[i] = dp[i]+cnt / 2;
			dp[i - 1] = dp[i-1] +cnt % 2 + cnt / 2;
			cnt = 0;
		}
	}
	reverse(s.begin(), s.end());

	a = 'L';
	cnt = 0;
	
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == a) {
			cnt++;
		}
		else {
			dp[s.size()-1-i] = dp[s.size()-1-i] + cnt / 2;
			dp[s.size()-1-i+1] = dp[s.size()-1-i+1] + cnt % 2 + cnt / 2;
			cnt = 0;
		}
	}

	for (int i = 0; i < s.size(); i++) {
		cout << dp[i] << " ";
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int N; cin >> N;
    double totalB, totalS;
    totalB = totalS = 0;
    for (int i = 0; i < N; i++)
    {
        double Ai; cin >> Ai;
        totalB += (1 / Ai); 
    }
    totalS = 1 / totalB;
    cout << setprecision(10) << totalS << endl;
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    string ans = "No";
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i * j == N){
                ans = "Yes";
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3624
/*
ID: Aman Raj
LANG: C++
TASK: preface
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

	   //vector<ll > vten(7),vfive(7),vfifty(7),vhundred(7),vfivehundred(7),vthousand(7);
int main()
{
      ll n;cin>>n;vector<double> v(n);
      for(ll i=0;i<n;i++)
      {
          cin>>v[i];
      }
      vector<double> phead(n+2,0.00),ptail(n+2,0.00);
       phead[1]=v[0];ptail[1]=(1-v[0]);phead[0]=0.00;ptail[0]=0.00;
        for(ll i=1;i<n;i++)
        {
            vector<double> phead2(n+2,0),ptail2(n+2,0);
             phead2[0]=ptail2[0]=phead[1]*(1-v[i])+ptail[1]*v[i];
               ll j=1;while(j<=i+1&&j<=n)
                      {
                          phead2[j]=phead[j-1]*v[i]+phead[j+1]*(1-v[i]);j++;
                      }
               j=1;while(j<=i+1&&j<=n)
                      {
                          ptail2[j]=ptail[j-1]*(1-v[i])+ptail[j+1]*(v[i]);j++;
                      }
                      phead=phead2;ptail=ptail2;
        }double ans=0.00000000;
        cout<<setprecision(12);
        for(ll i=1;i<=n;i++)ans+=phead[i];
        cout<<ans;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/


constexpr long long fi = 5000000000000000ll;

ll h_pow(ll x,ll n){
    ll ret=1;
    while(n>0){
        if(n&1) ret = ret * x;
        x = x * x;
        n>>=1;
    }
    return ret;
}

int main(){
    string s,k;
    cin >> s >> k;

    ll idx=0;
    while(idx < s.size() and s[idx]=='1'){
        idx++;
    }


    if(stoll(k) <= idx){
        cout << 1 << endl;
    }else{
        cout << s[idx] << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>           // printf(), scanf()
#include <vector>
#include <algorithm>        // sort()

using namespace std;
static const int MAX_N = 1000000;
static const int nil = -1;

class node
{
public:
	int location;
	int l, r;
	node() {}
};

class point
{
public:
	int id;
	int x, y;

	point() {}
	point(int id, int x, int y): id(id), x(x), y(y) {}
	bool operator < (const point &p) const {
		return id < p.id;
	}

	void print() {
		printf("%d\n", id);
	}
};

int n;
point p[MAX_N];
node t[MAX_N];
int np;

bool lessX(const point &p1, const point &p2) { return p1.x < p2.x; }
bool lessY(const point &p1, const point &p2) { return p1.y < p2.y; }

int
makeKDTree(int l, int r, int depth)
{
	if (l >= r)
		return nil;

	int mid = (l + r) / 2;
	if (depth % 2 == 0)
		sort(p + l, p + r, lessX);
	else
		sort(p + l, p + r, lessY);

	int s = np++;
	t[s].location = mid;
	t[s].l = makeKDTree(l, mid, depth + 1);
	t[s].r = makeKDTree(mid + 1, r, depth + 1);
	return s;
}

void
find(int v, int sx, int tx, int sy, int ty, int depth, vector<point> &ans)
{
	int x = p[t[v].location].x;
	int y = p[t[v].location].y;

	if (sx <= x && x <= tx && sy <= y && y <= ty)
		ans.push_back(p[t[v].location]);

	if (depth % 2 == 0)
	{
		if (t[v].l != nil)
		{
			if (sx <= x)
				find(t[v].l, sx, tx, sy, ty, depth + 1, ans);
		}

		if (t[v].r != nil)
		{
			if (x <= tx)
				find(t[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
	else
	{
		if (t[v].l != nil)
		{
			if (sy <= y)
				find(t[v].l, sx, tx, sy, ty, depth + 1, ans);
		}

		if (t[v].r != nil)
		{
			if (y <= ty)
				find(t[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
}

int
main(int argc, char** argv)
{
	vector<point> ans;
	int x, y;
	int sx, sy;
	int tx, ty;
	int q;
	int i;
	unsigned j;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%d %d", &x, &y);
		p[i] = point(i, x, y);
		t[i].l = t[i].r = nil;
	}

	np = 0;
	int root = makeKDTree(0, n, 0);

	scanf("%d", &q);
	for (i = 0; i < q; ++i)
	{
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());

		for (j = 0; j < ans.size(); ++j)
			ans[j].print();

		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 15368
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    int x3, y3, x4, y4;
    
    int a = x2 - x1;
    int b = y2 - y1;
    x3 = x2 - b;
    y3 = y2 + a;
    x4 = x1 - b;
    y4 = y1 + a;
    
    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}



int main(void) {
  ll a, b;
  cin >> a >> b;
  
  if(b%a==0) pt(a+b);
  else pt(b-a);
  
  
}


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

int main() {
    string a = "111";
    string b = "";
    int c;
    cin >> b;

    string intersection;
    set_intersection(begin(a), end(a), begin(b), end(b), back_inserter(intersection));
    c = intersection.size();

    cout << c << endl;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(void) {
  FILE *fp;
  //fp = fopen("input/drken_001_02.txt", "r");
  fp = stdin;
  char line[1024];
  if(!fgets(line, 1024, fp)) return 0;
  int num1, num2;
  sscanf(line, "%d %d\n", &num1, &num2);
  int flag = (num1&1) && (num2&1);
  printf("%s\n", flag ? "Odd" : "Even");
  return 0;
}


Measured memory_bytes: 128