akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += bisect_left(L, L[i] + L[j]) - j - 1
print(cnt)

Measured memory_bytes: 3188
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f,N=1e5+5;
ll n1,n2,n3;
ll X,Y;
ll a[N],b[N],c[N];
priority_queue<int> q;
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	cin>>X>>Y>>n1>>n2>>n3;
	for(i=1;i<=n1;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n2;i++)
		scanf("%d",&b[i]);
	for(i=1;i<=n3;i++)
		scanf("%d",&c[i]);
		
	sort(a+1,a+n1+1);
	sort(b+1,b+n2+1);
	sort(c+1,c+n3+1);
	
	ll ans=0;
	for(i=n1;i>=n1-X+1;i--)
		q.push(-a[i]),ans+=a[i];
	for(i=n2;i>=n2-Y+1;i--)
		q.push(-b[i]),ans+=b[i];
	
	for(i=n3;i>0;i--)
	{
		ll x=-q.top();q.pop();
		if(x<c[i])
		{
			ans+=c[i]-x;
		}
		else 
			break;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long k;cin>>k;

    queue<long long> q;
    for(long long i=1;i<=9;i++)
        q.push(i);

    long long ans;
    while(k--){
        ans=q.front();
        q.pop();

        long long m=ans%10;
        
        if(m>0) q.push(ans*10+m-1);
        q.push(ans*10+m);
        if(m<9) q.push(ans*10+m+1);
    }
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 1792
s = raw_input().split()
n = int(s[0])
p = int(s[1])
s = raw_input().split()

ans = 0
cnt = [0, 0]

def f(b, e):
	c = 1
	while e:
		if e%2:
			c = (c*b)
		e /= 2
		b = (b*b)
	return c

for i in range(n):
	j = int(s[i])
	cnt[j%2] += 1

if p == 0:
	if cnt[1] == 0:
		ans = f(2, cnt[0])
	else:
		ans = f(2, n-1);
else:
	if cnt[1] != 0:
		ans = f(2, n-1)

print ans

Measured memory_bytes: 28012
s = input()

k = ['L','U','D']
g = ['R','U','D']

for i in range(len(s)):
	if i % 2 == 0:
		if s[i] in g:
			pass
		else:
			print('No')
			exit()
	else:
		if s[i] in k:
			pass
		else:
			print('No')
			exit()
print('Yes')
		

Measured memory_bytes: 2940
#include <cstdio>

using namespace std;

char ans[1000][1001];

void puta(int x, int y, int &a) {
    if (a == 0) return;
    a--;
    ans[x][y] = '<';
    ans[x][y + 1] = '>';
}

void putb(int x, int y, int &b) {
    if (b == 0) return;
    b--;
    ans[x][y] = '^';
    ans[x + 1][y] = 'v';
}

int main() {
    int n, m, a, b, na, nb, s, i, j;
    
    scanf("%d %d %d %d", &n, &m, &a, &b);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            ans[i][j] = '.';
        }
    }
    
    if (n % 2 == 1 && m % 2 == 1) {
        s = (n - 1) * (m - 1);
        
        for (i = 0; i < m - 3; i += 2) puta(n - 1, i, a);
        for (i = 0; i < n - 3; i += 2) putb(i, m - 1, b);
        
        if (a % 2 == 0 && b % 2 == 0 && n > 1 && m > 1) {
            s -= 4;
            puta(n - 3, m - 3, a);
            puta(n - 1, m - 2, a);
            putb(n - 3, m - 1, b);
            putb(n - 2, m - 3, b);
        } else {
            if (m - 3 >= 0) puta(n - 1, m - 3, a);
            if (n - 3 >= 0) putb(n - 3, m - 1, b);
        }
        
        na = a, nb = b;
        
        if (a % 2 == 1) na++;
        if (b % 2 == 1) nb++;
        
        if (s < (na + nb) * 2) {
            puts("NO");
            return 0;
        }
        
        for (i = 0; i + 1 < n; i += 2) {
            for (j = 0; j + 1 < m; j += 2) {
                if (a > 0) {
                    puta(i, j, a);
                    puta(i + 1, j, a);
                } else {
                    putb(i, j, b);
                    putb(i, j + 1, b);
                }
            }
        }
    } else {
        s = n * m;
        
        if (n % 2 == 1) {
            s -= m;
            for (i = 0; i < m; i += 2) puta(n - 1, i, a);
        }
        
        if (m % 2 == 1) {
            s -= n;
            for (i = 0; i < n; i += 2) putb(i, m - 1, b);
        }
        
        na = a, nb = b;
        if (a % 2 == 1) na++;
        if (b % 2 == 1) nb++;
        
        if (s < (na + nb) * 2) {
            puts("NO");
            return 0;
        }
        
        for (i = 0; i + 1 < n; i += 2) {
            for (j = 0; j + 1 < m; j += 2) {
                if (a > 0) {
                    puta(i, j, a);
                    puta(i + 1, j, a);
                } else {
                    putb(i, j, b);
                    putb(i, j + 1, b);
                }
            }
        }
    }
    
    puts("YES");
    for (i = 0; i < n; i++) printf("%s\n", ans[i]);
    
    return 0;
}


Measured memory_bytes: 2176
import math

n,x=map(int,input().split())

X=list(map(int,input().split()))

for i in range(n):
    X[i]=abs(X[i]-x)

#print(X)

an=X[0]



def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a


def lcm(a,b):
    return a*b//gcd(a,b)



#print(lcm(2,9))

for i in range(n):
    an=gcd(an,X[i])

    #print(str(an)+" "+str(X[i]))

print(an)


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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long lcm;
  int C = c;
  int D = d;
  while(C != 0 && D != 0){
    lcm = D;
    D = C % D;
    C = lcm;
  }
  lcm = c * d / lcm;
  
  long long ans = b / c + b / d - b / lcm - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;
  cout << b - a + 1 - ans << endl;
}

Measured memory_bytes: 256
import math

N = int(input())
num = 55555
input_list = [False if i%2 == 0 or i%3 == 0 or i%5==0 else True for i in range(num)]
input_list[0] = input_list[1] = False
input_list[2] = input_list[3] = input_list[5] = True
sqrt = math.sqrt(num)

for serial in range(3, num, 2):
    if serial >= sqrt:
        break
    for s in range(serial ** 2, num, serial):
        input_list[s] = False

ans = []
count = 0
for i in range(11111):
    if input_list[5*i-1]:
        ans.append(5*i-1)
    if len(ans) == N:
        break

ans2 = ""
for i in range(len(ans)):
    ans2 += str(ans[i])
    if i != len(ans)-1:
        ans2 += " "

print(ans2) 

         


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int n,m;
vector <pair<pii,int> >vec;

//may not completely correct
struct SegmentTreeMinInterval//[)
{
	ll* data;
	ll* tag;
	int nn;
	int size()
	{
		return nn;
	}
	void init(int size)
	{
		nn=1;
		while(nn<size)
		{
			nn<<=1;
		}
		data=new ll[nn*2+5];
		tag=new ll[nn*2+5];
		for(int i=0;i<=nn*2;i++)
		{
			data[i]=1e18;
			tag[i]=1e18;
		}
	}
	void pushdown(int x)
	{
		if(x>=nn) return;
		data[x*2]=min(data[x*2],tag[x]);
		data[x*2+1]=min(data[x*2+1],tag[x]);
		tag[x*2]=min(tag[x*2],tag[x]);
		tag[x*2+1]=min(tag[x*2+1],tag[x]);
	}
	void update(int ql,int qr,ll value)
	{
		update(1,0,nn,ql,qr,value);
	}
	void update(int x,int l,int r,int ql,int qr,ll value)
	{
		if(l>=qr || r<=ql) return;
		pushdown(x);
		if(l>=ql && r<=qr)
		{
			data[x]=min(data[x],value);
			tag[x]=min(tag[x],value);
			return;
		}
		update(x*2,l,l+r>>1,ql,qr,value);
		update(x*2+1,l+r>>1,r,ql,qr,value);
		data[x]=min(data[x*2],data[x*2+1]);
	}
	ll query(int ql,int qr)
	{
		return query(1,0,nn,ql,qr);
	}
	ll query(int x,int l,int r,int ql,int qr)
	{
		if(l>=qr || r<=ql) return 1e18;
		pushdown(x);
		if(l>=ql && r<=qr)
		{
			return data[x];
		}
		return min(query(x*2,l,l+r>>1,ql,qr),query(x*2+1,l+r>>1,r,ql,qr));
	}
}dist;

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>m;
	int x,y,z;
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		x--;
		vec.push_back(mp(mp(x,y),z));
	}
	sort(all(vec));
	dist.init(n);
	dist.update(0,1,0);
	for(int i=0;i<m;i++)
	{
		ll x=dist.query(vec[i].first.first,vec[i].first.first+1);
		dist.update(vec[i].first.first,vec[i].first.second,x+vec[i].second);
	}
	ll res=dist.query(n-1,n);
	if(res==1e18)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<res<<endl;
	}
	return 0;
}

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

int main() {
    char b;
    cin>>b;
    if(b=='A') cout<<'T'<<endl;
    else if(b=='T') cout<<'A'<<endl;
    else if(b=='G') cout<<'C'<<endl;
    else if(b=='C') cout<<'G'<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 200003;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define fr(s,n) for (int i=(int)(s);i<(int)(n);i++)
#define lc cout<<"\n"
double pi=2*acos(0.0);
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll sum=0;
    if(k){
        if(k>=a){
            sum+=a;
            k-=a;
        }
        else{
            sum+=k;
            k-=k;
        }
       
    }
    if(k){
        if(k>=b){
            k-=b;
        }
        else{
            k-=k;
        }
        
    }
    if(k){
        if(k==c){
            sum-=c;
        }
        else{
            sum-=k;
        }
        
    }
   
    cout<<sum;
}


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

int main() {
	int D, N;
	long long A=1;
	cin >> D >> N;
	for (int i=0; i<D; i++){
	    A*=100;
	}
	if (N<=99) cout << A*N << endl;
	else cout << A*101 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n;
    int k;
    cin>>n>>k;
    map<int,int> mp;
    for(int i=0;i<k;i++)
    {
    	int d;
    	cin>>d;
    	for(int j=0;j<d;j++)
    	{
    		int a;
    		cin>>a;
    		mp[a]++;
		}
	}
	int nb=0;
	for(int i=1;i<=n;i++)
	{
		if(!mp[i])nb++;
	}
	cout<<nb<<endl;
}



Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>
#include <utility>

using namespace std;

unsigned long long int gcd(unsigned long long int a, unsigned long long int b)
{
    unsigned long long int v0 = a, v1 = b, v2 = a % b;
    while (v2 != 0)
    {
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    }
    return v1;
}

int main()
{
    unsigned long long int a;
    unsigned long long int sum = 0;
    cin >> a;

    for (unsigned long long int i = 1; i <= a; i++)
    {
        for (unsigned long long int j = 1; j <= a; j++)
        {
            unsigned long long int gcd2 = gcd(i, j);
            for (unsigned long long int k = 1; k <= a; k++)
            {
                sum += gcd(gcd2, k);
            }
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3636
def christmas_eve(N: int, K: int, H: list) -> int:
    sorted_H = sorted(H, reverse=True)
    return min(sorted_H[i] - sorted_H[i + K - 1] for i in range(N - K + 1))


if __name__ == "__main__":
    N, K = [int(s) for s in input().split()]
    H = [int(input()) for _ in range(N)]
    ans = christmas_eve(N, K, H)
    print(ans)


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:
ll power(ll a, ll n, ll m) {
	ll b = 1LL;
	while (n) {
		if (n & 1) b = b * a % m;
		a = a * a % m;
		n >>= 1;
	}
	return b;
}

inline ll extgcd(ll a, ll b, ll& x, ll& y) {
	x = 1, y = 0;
	ll g = a;
	if (b != 0) {
		g = extgcd(b, a % b, y, x);
		y -= a / b * x;
	}
	return g;
}

ll phi(ll n) {
	ll cur = n, ret = n;
	for (ll i = 2; i * i <= n; ++i) {
		if (cur % i) continue;
		while (cur % i == 0) cur /= i;
		ret = ret / i * (i - 1);
	}

	if (cur != 1) ret = ret / cur * (cur - 1);
	return ret;
}


ll solve(ll a, ll m) {
	if (m == 1) return 1LL;
	const ll pm = phi(m);
	const ll gm = __gcd(m, pm);

	ll y =  solve(a, gm);
	ll ay = power(a, y, m);

	ll minv, dummy;
	//ll minv = linear_solve(m, 1LL, pm);
	extgcd(m, pm, minv, dummy);
	ll k = minv * ((y - ay) / gm)  % pm;
	if (k < 0) k += pm;
	ll x = m * (k + pm) + ay;
	return x;
}


int main(void) {
	int q;
	cin >> q;

	rep(loop, q) {
		ll a, m;
		cin >> a >> m;
		ll k = solve(a % m, m);
		cout << k << endl;
		//cerr << k % m << endl;
		//cerr << power(a, k, m) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    private static final boolean N_CASE = false;

    private void solve() {
        int N = sc.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }

        for (int i = 0; i < N; i++) {
            if (A[i] == 0) {
                out.println(0);
                return;
            }
        }

        long max = 1000000000000000000L;
        long ans = 1;
        for (int i = 0; i < N; i++) {
            if (max / ans + 1 < A[i]) {
                ans = -1;
                break;
            }
            ans = ans * A[i];
        }
        out.println(ans > max ? -1 : ans);
    }

    private void run() {
        int T = N_CASE ? sc.nextInt() : 1;
        for (int t = 0; t < T; ++t) {
            solve();
        }
    }

    private static MyWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        List<Integer> nextList(int n) {
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(nextInt());
            }
            return list;
        }
    }

    private static class MyWriter extends PrintWriter {
        private MyWriter(OutputStream outputStream) {
            super(outputStream);
        }

        void printArray(int[] a) {
            for (int i = 0; i < a.length; ++i) {
                print(a[i]);
                print(i == a.length - 1 ? '\n' : ' ');
            }
        }

        void printlnArray(int[] a) {
            for (int v : a) {
                println(v);
            }
        }

        void printList(List<Integer> list) {
            for (int i = 0; i < list.size(); ++i) {
                print(list.get(i));
                print(i == list.size() - 1 ? '\n' : ' ');
            }
        }

        void printlnList(List<Integer> list) {
            list.forEach(this::println);
        }
    }

    public static void main(String[] args) {
        out = new MyWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().run();
        out.close();
    }
}

Measured memory_bytes: 49224
main :: IO()
main = getContents >>= mapM_ (print . solve . read) . lines

solve :: Int -> Int
solve n | n < 100     = length $ takeWhile (<= n) primes
        | n < 1000    = (25 +)     . f $ [101, 103..n]
        | n < 10000   = (168 +)    . f $ [1001, 1003..n]
        | n < 100000  = (1229 +)   . f $ [10001,10003..n]
        | n < 200000  = (9592 +)   . f $ [100001, 100003..n]
        | n < 300000  = (17984 +)  . f $ [200001, 200003..n]
        | n < 400000  = (25997 +)  . f $ [300001, 300003..n]
        | n < 500000  = (33860 +)  . f $ [400001, 400003..n]
        | n < 600000  = (41538 +)  . f $ [500001, 500003..n]
        | n < 700000  = (49098 +)  . f $ [600001, 600003..n]
        | n < 800000  = (56543 +)  . f $ [700001, 700003..n]
        | n < 900000  = (63951 +)  . f $ [800001, 800003..n]
        | n >= 999983 && n < 1000000 = 78498
        | n < 1000000 = (71724 +)  . f $ [900001, 900003..n]
        | otherwise   = (78498 +)  . f $ [1000001, 1000003..n]
    where f = length . (filter isPrime)

primes :: [Int]
primes = (2 :) . (3 :) . (5 :) . (7 :) $ filter isPrime [11, 13..] 

isPrime :: Int -> Bool
isPrime 2 = True
isPrime n
    | n < 2            = False
    | (n `mod` 2) == 0 = False
    | otherwise        = testDiv 3 n
    where testDiv :: Int -> Int -> Bool
          testDiv i n
              | i * i > n      = True
              | n `mod` i == 0 = False
              | otherwise      = testDiv (i + 2) n


Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main ()
{
	ll a, b, c;
    cin>>a>>b>>c;
    ll o = c % b;
    for (ll i = a; i < 100000; i += a)
    {
        if(i%b == o)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false




int main()
{
	//clock_t start, end;
	//start = clock();

	ll n, m, l;
	cin >> n >> m >> l;

	vector<vector<ll> > A(n, vector<ll>(m, 0));
	vector<vector<ll> > B(m, vector<ll>(l, 0));
	vector<vector<ll> > C(n, vector<ll>(l, 0));

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

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> B[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			for (int k = 0; k < m; k++) {
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << C[i][0];
		for (int j = 1; j < l; j++) {
			cout << " " << C[i][j];
		}
		cout << endl;
	}

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  // ここでストリームに obj を書き込みます。
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}


li fact(li a){
  static unordered_map<li,li> f;
  f[0]=1;
  if(f.find(a)!=f.end())return f[a];
  return f[a]=fact(a-1)*a%MOD;
}

li inv(li a){
  static unordered_map<li,li> f;
  f[1]=1;
  if(f.find(a)!=f.end())return f[a];
  if(df)  print("inv",a);
  li s=MOD-inv(MOD%a);
  (s*=MOD/a)%=MOD;
  return f[a]=s;
}

const int M = 2e5 + 100;
vector<vector<int>> adj(M);
vector<pair<li,int>> w(M);
vector<li> ans(M);
int n;


void init(int parent=-1,int a=0){
  if(df)print("init",a);
  li s=1;
  int cnt=0;
  for(int x:adj[a]){
    if(df)print("x:",x);
    if(x==parent) continue;
    init(a,x);
    (s*=w[x].first)%=MOD;
    (s*=inv(fact(w[x].second)))%=MOD;
    cnt+=w[x].second;
  }
  (s*=fact(cnt))%=MOD;
  w[a]={s,cnt+1};
  if(df)print(w[a]);
}

void reverse(int a,int b){
  li& s=w[a].first;
  (s*=inv(fact(w[a].second-1)))%=MOD;
  (s*=fact(w[a].second-1-w[b].second))%=MOD;
  (s*=inv(w[b].first))%=MOD;
  (s*=fact(w[b].second))%=MOD;
  w[a].second-=w[b].second;
  //  w[b].second+=w[a].second;

  if(df)print("b/",w[b].second-1,"! *",w[a].second-1+w[b].second,"! *",w[a].first,"/",w[a].second,"!");
  li& t=w[b].first;
  (t*=inv(fact(w[b].second-1)))%=MOD;
  (t*=fact(w[a].second-1+w[b].second))%=MOD;
  (t*=w[a].first)%=MOD;
  (t*=inv(fact(w[a].second)))%=MOD;
  w[b].second+=w[a].second;
  if(df)print(a,"->",w[a],b,"->",w[b]);
}

void dfs(int parent=-1,int a=0){
  for(int x:adj[a]){
    if(x==parent) continue;
    reverse(a,x);
    if(df)print("w:",w);
    ans[x]=w[x].first;
    dfs(a,x);
    reverse(x,a);
  }
}
int main(){
  cin >>n;
  ans.resize(n);
  w.resize(n);
  adj.resize(n);
  rep(i,n-1){
    int a,b; cin >>a >>b; a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  if(df)rep(i,n)print(adj[i]);
  init();
  if(df)print("w:",w);
  
  ans[0]=w[0].first;
  dfs();
  rep(i,n) print(ans[i]);
  
}


Measured memory_bytes: 86324
import java.util.Scanner;

public class Main
{
    private final static Main main = new Main();

    public static void main(String[] args)
    {
        long l = System.currentTimeMillis();
        main.contest();
        //System.out.println("処理時間：" + (System.currentTimeMillis() - l));
    }

    private void contest()
    {
        Scanner sc = new Scanner(System.in);
        String orig = "CODEFESTIVAL2016";
        String s = sc.nextLine();
        int res = 0;
        for(int i=0; i<s.length(); ++i)
        {
            res += s.charAt(i) != orig.charAt(i) ? 1 : 0;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 9680
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector <int> vi;
typedef pair <int, int> pi;
typedef vector <pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int) x.size()
#define f first
#define s second
#define MAXN 100100
int N;

void edge(int a, int b){
	cout<<a<<' '<<b<<'\n';
	// cout<<a%N<<' '<<b%N<<'\n';
}

int main(){
	cin>>N;
	if (N == 1){cout<<"No";return 0;}
	if (N%2 == 1){
		cout<<"Yes\n";
		edge(1,2);
		edge(2,3);
		edge(3,N+1);
		edge(N+1,N+2);
		edge(N+2,N+3);
		for (int i=4;i<N;i+=2){
			edge(i,i+1);
			edge(i+1,1);
			edge(1,i+N);
			edge(i+N, i+N+1);
		}
		return 0;
	}
	int h = 1;
	while (h*2 <= N)h *= 2;
	if (h == N){
		cout<<"No";
		return 0;
	}
	cout<<"Yes\n";
	edge(h+2,h+1);
	edge(h,h+1);
	edge(h+1,3);
	edge(3,1);
	edge(1,2);
	edge(3,2+N);
	edge(2+N,N+h);
	edge(1+N,2+N);
	edge(3,h+N+2);
	edge(h+N+2, h+N+1);
	edge(h+N+1, N+3);
	for (int i=4;i<h;i+=2){
		int t = (i) ^ (i+1);
		edge(i,i+1);
		edge(i+1,1);
		edge(1,i+N);
		edge(i+N, i+N+1);
	}
	for (int i=h+3;i<N;i+=2){
		int t = (i) ^ (i+1);
		edge(i,i+1);
		edge(i+1,t);
		edge(t,i+N);
		edge(i+N, i+N+1);
	}
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
int main()
{
    string a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=0;i<min(a.length(),b.length());i++)
        if(a[i]==b[i]) ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define ll long long
using namespace std;
int n;
int sumN;
ll ans=0;
int w[102][102];
bool p[102];
int wn[102];
int f[105][105];

bool prime(int x)
{
    for (int i=2; i<=sqrt(x); ++i)
        if (x%i==0) return 0;
    return 1;
}

void factor(int x)
{
    int thex=x;
    for (int i=2; i<=x; ++i)
        while (p[i] && (x%i==0))
        {
            w[thex][i]++;
            x/=i;
        }
}
ll factorN(int x)
{
    int ans=1;
    for (int i=2; i<=x; ++i)
        if (w[x][i])
        ans*=(w[x][i]+1);
    return ans;
}

int factorSum(int n)
{
    for (int i=2; i<=n; ++i)
        for (int j=2; j<=n; ++j)
            wn[j]+=w[i][j];
    for (int i=2; i<=n; ++i)
        wn[i]+=1;
/*
    for (int i=2; i<=n; ++i)
        if (wn[i]>0)
        cout<<i<<' '<<wn[i]<<endl;
        */
    return 0;
}

void dp()
{
    memset(f,0,sizeof(f));
    for (int i=1; i<=wn[2]; ++i)
        if (75%i==0)
            f[2][75/i]=i;
        else f[2][75/i]=0;


    for (int i=3; i<=n; ++i)
        for (int j=1; j<=75; ++j)
            if (f[i-1][j])
            {
                for (int k=1; k<=wn[i]; ++k)
                    if (j%k==0)
                        f[i][j/k]+=(f[i-1][j]*k);
            }
    cout<<f[n][1]/75<<endl;
}
void init()
{
    memset(w,0,sizeof(w));
    for (int i=2; i<=100; ++i)
        p[i]=prime(i);
    for (int i=2; i<=100; ++i)
        factor(i);

    /*
    for (int i=2; i<=100; ++i)
    {
        cout<<i<<":";
        for (int j=1; j<=100; ++j)
            if (w[i][j]) cout<<j<<':'<<w[i][j]<<' ';
        cout<<endl;
    }
    */
}

int main()
{
    
    init();
    cin>>n;
    factorSum(n);
    dp();
    return 0;
}




Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	static int n = 0;

	public static void main(String[] args) {


		int anser = 100000000;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

		ArrayList<Integer> address = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		}

		Collections.sort(address);

		for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		}

		System.out.println(anser);
	}

	private static int sumList(ArrayList<Integer> array,int j) {

		int sum =0;

		for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		}

		return sum;

	}

}


Measured memory_bytes: 22740
#include <cstdio>

int main(){
	int n,m,max,jud;
	int event[1000];
	int com[1000];
	int judge[1000]={0};

	scanf("%d %d",&n,&m);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&event[i]);
	}

	for (int i = 0; i < m; ++i)
	{
		scanf("%d",&jud);
		for(int j = 0; j < n; j++){
			if(event[j] <= jud) {
				judge[j]++;
				break;
			}
		}
	}
	max = 0;
	int cnt;
	for (int i = 0; i < n; ++i)
	{
		if(judge[i] > max) {
			max = judge[i];
			cnt = i;
		}
	}
	printf("%d\n",cnt+1 );

	return 0;
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
using namespace std;
int main() {
  	int N, Q, K;
  	cin>>N>>K>>Q;
  	vector<int> store(N, (K-Q));
  	for(int i=0;i<Q;i++) {
    	int temp;
      	cin>>temp;
      	store[temp-1] += 1;
    }
  	
  	for(int i=0;i<N;i++) {
    	if(store[i] <= 0)
          	cout<<"No"<<endl;
      	else 
          	cout<<"Yes"<<endl;
    }
  	
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#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
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n,k,q;
  cin >> n >> k >> q;
  vector<ll> cnt(n,0);

  rep(i,q){
    ll p;
    cin >> p;
    p--;
    cnt[p]++;
  }
  rep(i,n){
    if(q-cnt[i]<k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }



  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	llong n;
	cin>>n;
	
	llong cnt=n/11*2;
	n%=11;
	if(n>0){
		n-=6;
		cnt++;
	}
	if(n>0) cnt++;
	
	cout<<cnt<<endl;
	return 0;
}

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


int main(){
	int N; cin >> N;
	if(1<=N&&N<=9) cout << N << endl;
	if(10<=N&&N<=99) cout << 9;
	if(100<=N&&N<=999) cout << N - 99 + 9 << endl;
	if(1000<=N&&N<=9999) cout << 909 << endl;
	if(10000<=N&&N<=99999) cout << N - 9999 + 909 << endl;
	if(N==100000) cout << 90909 << endl;
	return 0;
}













Measured memory_bytes: 3496
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Dwango5
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            int all = n * (n + 1) / 2;
            long[] array = ReadLongs();
            var sumList = new List<long>();
            for (int i = 0; i < n; i++)
            {
                sumList.Add(array[i]);
                for (int j = i+1; j < n; j++)
                {
                    sumList.Add(sumList[sumList.Count - 1] + array[j]);
                }
            }
            long res = 0;
            for(long i = 40; i >= 0; i--)
            {
                long div = (long)Math.Pow(2, i);
                int cnt = 0;
                for(int j = 0; j < sumList.Count; j++)
                {
                    if ((sumList[j] & div) > 0) cnt++;
                }
                if (cnt < k) continue;

                res += div;
                var nextList = new List<long>();
                for(int j = 0; j < sumList.Count; j++)
                {
                    if ((sumList[j] & div) > 0) nextList.Add(sumList[j]);
                }
                sumList = nextList;
            }

            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

char a[4][4];

int main() {
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            cin >> a[i][j];
        }
    }
    cout<<a[1][1]<<a[2][2]<<a[3][3];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long t,a,pt,pa,px;
long long UpDiv(long long a,long long b){
	return (a+b-1)/b;
}
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	px=1LL;
	for(int i=1;i<=n;i++){
		cin>>t>>a;
		if(i!=1){
			px=max(UpDiv(px*pt,t),UpDiv(px*pa,a));
		}
		pt=t;pa=a;
	}
	cout<<(pa+pt)*px<<endl;
	return 0;
}



Measured memory_bytes: 256
#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,string>;

int main() {
    int n,m; cin >> n >> m;
    vector<int> a;
    int sum = 0;
    rep(i,m) {
        int ai; 
        cin >> ai;
        sum += ai;
    }
    if(sum <= n) cout << n-sum << "\n";
    else cout << "-1" << "\n";
}

Measured memory_bytes: 3592
def run():
  N, K = map(int, input().split())
  h_li = [int(h) for h in input().split()]
  cost_li = [0] * (N)
  cost_li[1] = abs(h_li[0] - h_li[1])
  for n in range(2, N):
    if n < K: k = n
    else: k = K
    cost = float('inf')
    h = h_li[n]
    for _k in range(1, k+1):
      cost = min(cost, cost_li[n-_k] + abs(h_li[n-_k]-h))
    cost_li[n] = cost
  print(cost_li[N-1])
  
if __name__ == '__main__':
  run()

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

using namespace std;
using ll = long long;
constexpr int INF = numeric_limits<int>::max();
template<typename T, typename... Args>
const T& min(const T& a, Args... args) { return min(a, min(args...)); }
template<typename T, typename... Args>
const T& max(const T& a, Args... args) { return max(a, max(args...)); }

#pragma GCC optimize("O3")
static const auto __ = [] {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return nullptr;
}();

string str;

int main(int argc, char* argv[]) {
  cin >> str;
  for (char& ch : str) ch -= 48;
  int f = 10 * str[0] + str[1];
  int s = 10 * str[2] + str[3];
  if (f > 0 && f < 13) {
    if (s > 0 && s < 13) {
      cout << "AMBIGUOUS" << '\n';
    } else {
      cout << "MMYY" << '\n';
    }
  } else {
    if (s > 0 && s < 13) {
      cout << "YYMM" << '\n';
    } else {
      cout << "NA" << '\n';
    }
  }
  return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
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;}

signed main(){
    int n;
    cin>>n;
    cout<<n*(n+1)/2<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int H,W,K;
vector<string> s;

int main ()
{
    cin >> H >> W >> K;
    s.resize(H);
    REP(i,H) cin >> s[i];
    vector<vector<int>> a = vector<vector<int>>(H, vector<int>(W, 0));

    int pre_H = 0;
    int cnt = 1;
    for (int i = 0; i < H; i++) {
        vector<int> pos;
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                pos.push_back(j);
            }
        }
        if (pos.size() == 0) {
            continue;
        }
        int pre_W = 0;
        bool flag = ((cnt + pos.size() - 1) == K) ? true : false;
        for (int j = 0; j < pos.size(); j++) {
            for (int x = pre_H; x <= (flag ? H - 1 : i); x++) {
                for (int y = pre_W; y <= (j == pos.size() - 1 ? W - 1 : pos[j]); y++) {
                    a[x][y] = cnt;
                }
            }
            pre_W = pos[j] + 1;
            cnt++;
        }
        pre_H = i + 1;
    }

    REP(i,H) {
        REP(j,W) {
            cout << a[i][j];
            cout << ((j < W - 1) ? " " : "\n");
        }
    }

    return 0;
}


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

using namespace std;

int main (void) {
    int M, N;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for ( int i = 0; i < N; i++ ) cin >> A.at(i);
    for ( int i = 0; i < M; i++ ) cin >> B.at(i);

    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            bool found = true;
            for ( int k = 0; k < M; k++ ) {
                for ( int l = 0; l < M; l++ ) {
                    if ( i + k >= N || j + l >= N ) {
                        found = false;
                        break;
                    }
                    if ( A.at(i+k).at(j+l) != B.at(k).at(l) ) {
                        found = false;
                        break;
                    }
                }
                if ( !found ) break;
            }
            if ( found ) goto FOUND;
        }
    }

    cout << "No" << endl;
    return 0;
FOUND:
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3580
s = input()
if s[:7] == 'keyence':
    print('YES')
    exit()
if s[-7:] == 'keyence':
    print('YES')
    exit()
for i in range(len(s)):
    if s[:i] + s[-(7-i):] == 'keyence':
        print('YES')
        exit()
print('NO')

Measured memory_bytes: 3060
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
#include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=3e3+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
double dp[N][N];int n;double a[N],ans;
void solve(){
  cin>>n;dp[0][0]=1;
  rep(i,1,n)cin>>a[i];
  rep(i,1,n)
    rep(j,0,i){
      if(j!=0)dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
      else dp[i][j]=dp[i-1][j]*(1-a[i]);
    }
  rep(i,0,n)
    if(i>n-i)
      ans+=dp[n][i];
  cout<<setprecision(20)<<ans;
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 139776
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int flag=0;
    for(int i=n-1;i>=1;i--)
    {
        if(a[i]>=a[i-1])
            continue;
        else
        {
            if(abs(a[i]-a[i-1])==1)
                a[i-1]-=1;
            else
            {flag=1;break;}
        }
    }
    if(flag==1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3932
n = gets.to_i
a = gets.split.map(&:to_i)
sum = 0;
(n).times do |i|
    sum += a[i]
end
half = 0
rec = 0
(n).times do |i|
    half += a[i]
    rec = i
    break if half >= sum/2
end
if half >= sum - half
    ans = [half-(sum-half), (sum-half)+a[rec]-(half-a[rec])].min
else
    ans = [(sum-half)-half, half+a[rec+1]-(sum-half-a[rec+1])].min
end
puts ans

Measured memory_bytes: 16140
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)
	b1, b2 := []int{}, []int{}
	f := true
	for i := 0; i < n; i++ {
		if f {
			b1 = append(b1, a[i])
			f = false
		} else {
			b2 = append(b2, a[i])
			f = true
		}
	}

	if !f {
		b1, b2 = b2, b1
	}
	for i := 0; i < len(b2); i++ {
		fmt.Fprint(wr, b2[len(b2)-1-i], " ")
	}
	for i := 0; i < len(b1); i++ {
		fmt.Fprint(wr, b1[i], " ")
	}

}


Measured memory_bytes: 10828
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int x,a;
    cin >> x >> a;
    cout << (x < a ? 0 : 10) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll ch[103][4][2];
int main() {
	string s;
	cin>>s;
	ll m;
	cin>>m;
	ch[0][0][0]=1;
	for(ll i=0;i<s.size();i++){
		for(ll j=0;j<=9;j++){
			ll now=s[i]-'0';
			if(j==0){
				for(ll k=0;k<=3;k++){
					ch[i+1][k][1]+=ch[i][k][1];
					if(now!=0){
						ch[i+1][k][1]+=ch[i][k][0];
					}
					else{
						ch[i+1][k][0]+=ch[i][k][0];
					}
				}
			}
			else{
				for(ll k=0;k<3;k++){
					ch[i+1][k+1][1]+=ch[i][k][1];
					if(j<now){
						ch[i+1][k+1][1]+=ch[i][k][0];
					}
					else if(j==now){
						ch[i+1][k+1][0]+=ch[i][k][0];
					}
				}
			}
		}
	}
	cout << ch[s.size()][m][0]+ch[s.size()][m][1];
	// your code goes here
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void)
{
    int N, C;
    int p;
    int i;
    int sum, cake;
    
    scanf("%d%d", &N, &C);
    
    sum = 0;
    for (i = 0; i < C; i++){
        scanf("%d", &p);
        sum += p;
    }
    
    cake = sum / (N + 1);
    if ((sum % (N + 1)) > 0){
        cake++;
    }

    printf("%d\n", cake);

    return (0);
}



Measured memory_bytes: 2104
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    
    int ans = 0;
    for(int i = 1 ; i <= N ; i++){
      int next = i;
      ans += next;
    }
      System.out.println(ans);
  }  
}

Measured memory_bytes: 35440