akhauriyash/Code-Regression huggingface dataset:
#define ONLINE_JUDGE

#include <cstdio>
#include <cstring>
#include <map>
#define MAXN 200010
using namespace std;

namespace Pre_Gao{
	map<int,int> S;

	void insert(int x){ S[x]=0; }

	void pre_gao(){
		int now=0;
		for(map<int,int>::iterator it=S.begin();it!=S.end();it++)
			it->second=++now;
	}

	int get(int x){
		return S[x];
	}
}

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

int n,m,S,T;
int g[MAXN],nume;
int e2[MAXN][2];
int d[MAXN];
int visit[MAXN];

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

void dfs(int x){
	visit[x]=1;
	for(int i=g[x];~i;i=e[i].next)
		if(!visit[e[i].to])
			dfs(e[i].to);
}

int gao(){
	int res=0;
	for(int i=0;i<=n;i++)
		if(g[i]!=-1 && !visit[i]){
			dfs(i);
			res++;
		}
	if(visit[S]) res--;
	res+=nume;
	return res;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("g016d.in","r",stdin);
#endif
	memset(g,-1,sizeof g);
	scanf("%d",&m);
	n=150000;
	for(int i=1;i<=m;i++){
		scanf("%d",&e2[i][1]);
		S^=e2[i][1];
		Pre_Gao::insert(e2[i][1]);
	}
	for(int i=1;i<=m;i++){
		scanf("%d",&e2[i][0]);
		Pre_Gao::insert(e2[i][0]);
	}
	Pre_Gao::insert(S);
	Pre_Gao::pre_gao();
	for(int i=1;i<=m;i++){
		e2[i][0]=Pre_Gao::get(e2[i][0]);
		e2[i][1]=Pre_Gao::get(e2[i][1]);
	}
	S=Pre_Gao::get(S);
	for(int i=1;i<=m;i++){
		d[e2[i][0]]++;
		d[e2[i][1]]--;
		if(e2[i][0]^e2[i][1])
			addEdge(e2[i][0],e2[i][1]);
	}
	bool flag=0;
	if(d[S]==1){
		T=-1;
		for(int i=1;i<=n;i++)
			if(d[i]==-1){
				if(T!=-1){
					puts("-1");
					return 0;
				}
				T=i;
			}
		d[S]--;
		d[T]++;
		addEdge(T,S);
		flag=1;
	}else{
		T=S;
		for(int i=0;i<=n;i++)
			if(d[i]!=0){
				puts("-1");
				return 0;
			}
	}
	int ans=gao();
	if(flag) ans--;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 12800
#include <stdio.h>
#include <string.h>
int main(){
    char a[11], b[11], c[11];
    scanf("%s %s %s", a, b, c);
    int lenA = strlen(a);
    int lenB = strlen(b);
    int lenC = strlen(c);
    if (a[lenA-1] == b[0] && b[lenB-1] == c[0]){
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }





return 0;
}


Measured memory_bytes: 3140
#include "stdio.h"

int main()
{
	int a,b,d,r;
	double f;
	scanf("%d %d", &a, &b);
	d=a/b;
	r=a%b;
	f=d+r*1./b;
	printf("%d %d %.10f\n", d, r, f);
	return 0;
}

Measured memory_bytes: 640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 29)
#define LLINF (1LL << 61)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) : x(x), y(y) {}

	Point operator+(Point p) { return Point(x + p.x, y + p.y); }
	Point operator-(Point p) { return Point(x - p.x, y - p.y); }
	Point operator*(double k) { return Point(x * k, y * k); }
	Point operator/(double k) { return Point(x / k, y / k); }

	bool operator<(const Point& p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator==(const Point& p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

	friend istream& operator>>(istream& stream, Point& p) {
		double x, y;
		stream >> x >> y;
		p.x = x;
		p.y = y;
		return stream;
	}

	friend ostream& operator<<(ostream& stream, const Point& p) {
		stream << fixed << setprecision(10) << p.x << " " << p.y;
		return stream;
	}

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y; }

	double dot(Point v) {
		return x * v.x + y * v.y;
	}

	double cross(Point v) {
		return x * v.y - y * v.x;
	}
};

class Segment {
public:
	Point p1, p2;

	Segment(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}
	
	friend istream& operator>>(istream& stream, Segment& s) {
		Point p1, p2;
		stream >> p1 >> p2;
		s.p1 = p1;
		s.p2 = p2;
		return stream;
	}

	friend ostream& operator<<(ostream& stream, const Segment& s) {
		stream << fixed << setprecision(10) << s.p1.x << " " << s.p1.y << " ";
		stream << fixed << setprecision(10) << s.p2.x << " " << s.p2.y;
		return stream;
	}

	Point project(Point p) {
		Point base = p2 - p1;
		double r = (p - p1).dot(base) / base.norm();
		return p1 + base * r;
	}

	Point refrect(Point p) {
		return p + (project(p) - p) * 2;
	}
};

class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0) : c(c), r(r) {}
};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;

int main() {
	Segment s;
	int q;
	Point p;

	cin >> s >> q;
	while (q--) {
		cin >> p;
		cout << s.refrect(p) << endl;
	}

	return 0;
}

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

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(C.begin(), C.end());
    ll ans = 0;
    rep(i, N) {
        int x = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        int y = upper_bound(C.begin(), C.end(), B[i]) - C.begin();
        ans += 1LL * x * (N - y);
    }
    cout << ans << "\n";
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    std::vector<int> l;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        l.push_back(tmp);
    }
    std::sort(l.begin(), l.end());
    
    int sum = 0;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n; j++){
            int tmp = l[i]+l[j];
            for(int k=j+1; k<n; k++){
                if(tmp > l[k]){
                    sum++;
                }else{
                    break;
                }
            }
        }
    }

    cout << sum << endl;
}

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

int main(){
  int a;
  cin >> a;
  vector<vector<int>> A(a,vector<int>(2));
  rep(i,a){
    cin >> A.at(i).at(0);
    A.at(i).at(1) = i+1;
  }
  sort(A.begin(),A.end());
  rep(i,a) cout << A.at(i).at(1) << " ";
  
}

Measured memory_bytes: 6272
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from bisect import bisect_left, bisect_right

A,B,Q = II()
s = [I() for _ in range(A)]
t = [I() for _ in range(B)]
x = [I() for _ in range(Q)]

for i in range(Q):
    val = float('inf')
    a = bisect_left(s,x[i])
    if a<=A-1:
        b = bisect_left(t,s[a])
        if b<=B-1:
            val = min(val, abs(x[i]-s[a]) + abs(s[a]-t[b]))
        if b>=1:
            val = min(val, abs(x[i]-s[a]) + abs(s[a]-t[b-1]))
    if a>=1:
        b = bisect_left(t,s[a-1])
        if b<=B-1:
            val = min(val, abs(x[i]-s[a-1]) + abs(s[a-1]-t[b]))
        if b>=1:
            val = min(val, abs(x[i]-s[a-1]) + abs(s[a-1]-t[b-1]))

    b = bisect_left(t,x[i])
    if b<=B-1:
        a = bisect_left(s,t[b])
        if a<=A-1:
            val = min(val, abs(x[i]-t[b]) + abs(t[b]-s[a]))
        if a>=1:
            val = min(val, abs(x[i]-t[b]) + abs(t[b]-s[a-1]))
    if b>=1:
        a = bisect_left(s,t[b-1])
        if a<=A-1:
            val = min(val, abs(x[i]-t[b-1]) + abs(t[b-1]-s[a]))
        if a>=1:
            val = min(val, abs(x[i]-t[b-1]) + abs(t[b-1]-s[a-1]))
    
    print(val)

Measured memory_bytes: 111708
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vec(k) vector<k>
#define vecvec(k) vector<vector<k> >
#define pai(k) pair<k,k>
#define mod 1000000007
#define mpai make_pair
#define p1 first
#define p2 second
#define umap(x,y) unordered_map<x,y>
ll dp[3001][3001];
ll solve(vector<ll>&arr, int n,int i, int j, bool turn)
{
	// this DP table is acctually for player 1 ..if the turn is 0 then player 2 turn will try to make player 1 total minimum.
	//

	if(i>j)
		return 0;

	if(dp[i][j]!=-1)
		return dp[i][j];

	if(turn==1)
 		dp[i][j]= max(arr[i]+solve(arr,n,i+1,j,0), arr[j]+solve(arr,n,i,j-1,0));// here arr[i] is added since it is pl1 turn
 	else
 		dp[i][j]=min(solve(arr,n,i+1,j,1), solve(arr,n,i,j-1,1)); // here arr[i] is not added since it will be added to score of player two but we are adding for player 1 only.

 	// else
 	// 	dp[i][j]=min(arr[i] +max(solve(arr,n,i+1,j-1,1),solve(arr,n,i+2,j,1)),
		// 				arr[j]  +max( solve(arr,n,i+1,j-1,1),solve(arr,n,i,j-2,1)));
 	return dp[i][j];

}
ll solveagain(vector<ll>&arr, int n,int i, int j)
{
	if(i>j)
		return 0;

	if(dp[i][j]!=-1)
		return dp[i][j];

	return dp[i][j]=max(arr[i]+ min(solveagain(arr,n,i+1,j-1), solveagain(arr,n,i+2,j)),
						 arr[j]+ min(solveagain(arr,n,i+1,j-1), solveagain(arr,n,i,j-2)));
}

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


    ll n,x,sum=0;
    cin>>n;
    vec(ll) arr;
    for(int i=0;i<n;i++){
	cin>>x;
	arr.push_back(x);
	sum+=x;
}
memset(dp,-1,sizeof(dp));
ll ans=solveagain(arr, n,0,n-1);

 // cout<<ans<<"\n";
cout<<(2*ans-sum)<<"\n";

return 0;
}


Measured memory_bytes: 70912
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
//#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


#define huge 1000000007
typedef long long ll;

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll K = 0;
	ll Y = 0;
	ll X = 0;
	ll m[100000] = {};
	//ll c[10000] = {};
	//ll d[10000] = {};
	//ll *x, *c, *d;
	string S;
	ll count = 0;
	ll sum = 0;
	ll min = 1000;
	ll i = 0;
	cin >> N >> X;
	
	rep(i, 0, N) {
		cin >> m[i];
	}
	
	rep(i, 0, N) {
		X -= m[i];

		if (min > m[i]) min = m[i];
	}

	count += N;

	count += X / min;

	cout << count << endl;
	return 0;

}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, k, x, y, a, b = 0, c = 0;
    cin >> n >> m >> k;
    while (k--) {
        cin >> x >> y >> a;
        if (a == 1) b = max(b, x);
        if (a == 2) n = min(n, x);
        if (a == 3) c = max(c, y);
        if (a == 4) m = min(m, y);
    }
    cout << max(0, n - b) * max(0, m - c);
}


Measured memory_bytes: 256
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}


fn main(){
    let mut scan = Scanner::new();
    let k: usize = scan.next();
    let a: usize = scan.next();
    let b: usize = scan.next();

    if a <= b/k*k{
        println!("OK");
    }else{
        println!("NG");
    }
}


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

int fib(int n){
  int a = 1, b = 1, tmp;
  for(int i = 1; i < n; i++){
    tmp = a;
    a = b;
    b = tmp+b;
  }

  return b;
}

int main(){
  int n, ans;
  cin >> n;

  ans = fib(n);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3104
package main

import "fmt"

func main() {
	var h, w, k int
	fmt.Scan(&h, &w, &k)

	cs := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&cs[i])
	}

	ans := 0
	for hb := 0; hb < 1<<h; hb++ {
		for wb := 0; wb < 1<<w; wb++ {
			c := 0
			for i := 0; i < h; i++ {
				for j := 0; j < w; j++ {
					if hb>>i&1 == 0 && wb>>j&1 == 0 && cs[i][j] == '#' {
						c++
					}
				}
			}
			if c == k {
				ans++
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1768
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>
#include <stack>
#include <unordered_map>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

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

    double M = N;

    std::cout << std::setprecision(10) << (N % 2 == 0 ? 0.5 : 1.0 - (M - 1.0) / 2.0 / M) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll MOD=1e+9+7;
const int MAX = 100010;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n,int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(){
	COMinit();
	int N;
	ll A[100001];
	scan(N);
	rep1(i,N){
		scan(A[i]);
	}
	ll ans=0;
	ll psum[100001]={0};
	rep1(i,N){
		psum[i]=(psum[i-1]+inv[i])%MOD;
	}
	rep1(i,N){
		ans+=A[i]*(psum[i]+psum[N-i+1]-1)%MOD;
		ans%=MOD;
	}
	prin(ans*fac[N]%MOD);
	return 0;
}


Measured memory_bytes: 4096
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		/**
		 * エラトステネスの篩
		 */
		int MAX = 101010;
		boolean[] isPrime = new boolean[MAX];
		Arrays.fill(isPrime, true);
		isPrime[0] = false;
		isPrime[1] = false;

		for (int i = 2; i <= Math.sqrt(MAX); i++) {
			if (!isPrime[i]) { // 素数でない場合は見ない
				continue;
			}
			for (int j = i * 2; j < MAX; j += i) { // 倍数を除く
				isPrime[j] = false;
			}
		}

		// 2017-like number
		int[] isLike = new int[MAX];
		for (int i = 3; i < MAX; i = i + 2) {
			if (isPrime[i] && isPrime[(i + 1) / 2]) {
				isLike[i] = 1;
			}
		}

		// 累積和
		int[] cs = new int[MAX + 1];
		for (int i = 1; i < MAX; i++) {
			cs[i] = cs[i - 1] + isLike[i];
		}

		int Q = sc.nextInt();
		int[] numLikeCnt = new int[Q];

		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			numLikeCnt[i] = cs[r] - cs[l - 1];
		}

		for (int c : numLikeCnt) {
			System.out.println(c);
		}

		sc.close();
	}

}


Measured memory_bytes: 66692
/*	works correctly*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int  mod =1e9+7;
char grid[10000][10000];
int r,c;
int dp[1000][1000];	
	
	//using memoization
	int path(int x,int y)
	{
			if(x>=r||y>=c)
			return 0;
			
			if(grid[x][y]=='#')
			return 0;
			
			if(x==r-1&&y==c-1)
			return 1;
			
			if(dp[x][y]!=-1)
			return dp[x][y];
			
			return  dp[x][y]= (path(x+1,y)+path(x,y+1))%mod;
			 
			
	}
	
	
	int pathTabulation(int x,int y)
	{
			memset(dp,-1,sizeof(dp));
			
			//initialize dp with first row and column
			for(int j=0;j<c;j++)
			{
					(grid[0][j]=='.')?dp[0][j]=1:dp[0][j]=0;
			}
			
			for(int i=0;i<r;i++)
			{
					(grid[i][0]=='.')?dp[i][0]=1:dp[i][0]=0;
			}
			
			//now process our dp table
			for(int i=1;i<r;i++)
			{
					for(int j=1;j<c;j++)
					{
							if(grid[i][j]=='#')continue;
							else{
								dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
								}
					}
			}
			
			return dp[r-1][c-1];
	} 

signed main(){
	
	cin>>r>>c;
	
	for(int i=0;i<r;i++)
	{
		for(int j=0;j<c;j++)
			cin>>grid[i][j];
	}
	
	memset(dp,-1,sizeof(dp));
	
	//cout<<pathTabulation(0,0);
	cout<<path(0,0);
	
	return 0;}



Measured memory_bytes: 16396
def main():
    mod = 998244353
    max_A = 10**6
    N = int(input())
    A = list(map(int, input().split()))

    is_prime = [False, True, False, False, False, True] * (max_A//6+1)
    del is_prime[max_A+1:]
    is_prime[1:4] = False, True, True
    for i in range(5, int(max_A**0.5)+1):
        if is_prime[i]:
            is_prime[i*i::i] = [False] * (max_A//i-i+1)
    primes = [p for p, is_p in enumerate(is_prime) if is_p]  # max_A 以下の素数のリスト

    g = [0] * (max_A+1)
    for a in A:
        g[a] += a
    for p in primes:
        # 倍数集合の高速ゼータ変換みたいなやつ  O((max_A)loglog(max_A))
        # 参考: http://noshi91.hatenablog.com/entry/2018/12/27/121649
        # 大量に約数列挙みたいなことをするときはこれで高速化できる場合が多そう？（みんぷろ 2018 本戦 A - Uncommon など）
        for k in range(max_A//p, 0, -1):
            g[k] += g[k*p]
    g = [v * v % mod for v in g]
    for p in primes:
        for k, g_kp in enumerate(g[p::p], 1):
            g[k] -= g_kp

    modinv = [0, 1]
    for i in range(2, max_A+1):
        modinv.append(mod - mod//i * modinv[mod%i] % mod)
    ans = sum((gg * minv % mod for gg, minv in zip(g, modinv)))
    ans %= mod
    ans -= sum(A)
    ans *= modinv[2]
    ans %= mod
    print(ans)
main()


Measured memory_bytes: 87988
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(snip_i, h) cin >> s.at(snip_i);
  vector<vector<int>> ans(h, vector<int>(w, 0));
  rep(i, h){
    int co = 0, num = -1;
    vector<int> tot;
    rep(j, w){
      if(s.at(i).at(j) == '#'){
        if(co == 0) continue;
        num--;
        tot.push_back(co);
        co = 0;
      }else{
        co++;
        ans.at(i).at(j) = num;
      }
    }
    if(co != 0) tot.push_back(co);
    rep(j, w){
      int &now = ans.at(i).at(j);
      if(now == 0) continue;
      else now = tot.at(-1*now-1);
    }
  }

  int a_a = 0;
  vector<vector<int>> t(h, vector<int>(w, 0));
  rep(i, w){
    int co = 0, num = -1;
    vector<int> tot;
    rep(j, h){
      if(s.at(j).at(i) == '#'){
        if(co == 0) continue;
        num--;
        tot.push_back(co);
        co = 0;
      }else{
        co++;
        t.at(j).at(i) = num;
      }
    }
    if(co != 0) tot.push_back(co);
    rep(j, h){
      int &add = ans.at(j).at(i);
      int now = t.at(j).at(i);
      if(now == 0) continue;
      add += tot.at(-1*now-1);
      a_a = max(a_a, add);
    }
  }
  cout << a_a-1 << endl;

  return 0;
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define loop(i, a, b) for(ll i = a; i < b; i++)
#define rloop(i, e, s) for(ll i = e; i >= s; i--)
#define mod 1000000007
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);

int main()
{
  // //REMAINDER MINIMIZATION
    ll l, r;
    cin >> l >> r;
    if(r-l>2019) {
        cout << "0\n";
        return 0;
    }
    ll ans = l*r;
    loop(i, l, r){
        loop(j, l+1, r+1){
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;

}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;

int dx[4]={1, 0, -1, 0};
int dy[4]={0, 1, 0, -1};
vector<vector<bool>> visit;
int m, n;

int dfs(vector<vi> ice, int x, int y){
    int MAX=1;
    visit[x][y]=true;
    for(int i=0; i<4; i++){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx<0 || nx>=n || ny<0 || ny>=m) continue;
        if(ice[nx][ny] == 0 || visit[nx][ny]) continue;
        MAX=max(MAX, dfs(ice, nx, ny)+1);
    }
    visit[x][y]=false;
    return MAX;
}

int main(){
    while(cin >> m >> n){
        if(m==0 && n==0) break;
        visit.assign(n, vector<bool>(m));
        vector<vi> ice(n, vi(m));
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                cin >> ice[i][j];
            }
        }
        int res=0;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(ice[i][j] == 0) continue;
                res=max(res,dfs(ice, i, j));
            }
        }
        cout << res << endl;
    }
    return 0;
}




Measured memory_bytes: 3884
//Name: Bridge Removal
//Level: 3
//Category: 木,Tree,動的計画法,DP
//Note:

/**
 * ある部分木を壊すときは、
 * ・その部分木を壊した後、親にもう一度戻ってくる必要がある
 * ・部分木を壊しっぱなしで、親には戻らなくてよい
 * の2つのパターンがある。
 * したがって、注目している頂点をvとすると、それぞれのコストは
 * ・dp[v][戻る必要がある] = Σdp[vの子][戻る必要がある] + d_{v,子}×3
 * ・dp[v][戻る必要がない] = min_{w} Σdp[vの子≠w][戻る必要がある] + d_{v,子×3} + dp[w][戻る必要がない] + d_{v,w}×2
 * となる。
 * あとは、始点を全ての頂点で試せばよい。
 *
 * オーダーは O(N^2)。
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <array>

using namespace std;
typedef unsigned long long ULL;
const ULL INF = 100000ULL * 800 * 4 * 2;

pair<ULL,ULL> calc(int root, int p, const vector<vector<pair<int,int>>> &graph) {
    ULL back = 0, noback = 0;
    pair<ULL,ULL> wspec(0, 0);
    int wd = 0;
    for(const auto &c : graph[root]) {
        if(c.first == p) {
            continue;
        }
        const auto spec = calc(c.first, root, graph);
        if(spec.first == 0) { // 葉は常に直接刈ってよい
            back += c.second;
            noback += c.second;
        } else {
            back += spec.first + c.second*3;
            const ULL tmp1 = noback + spec.first + c.second*3;
            const ULL tmp2 = noback - wspec.second + wspec.first + wd + spec.second + c.second*2;
            if(tmp1 <= tmp2) {
                noback = tmp1;
            } else {
                noback = tmp2;
                wspec = spec;
                wd = c.second;
            }
        }
    }
    //cout << root << ' ' << back << ' ' << noback << endl;
    return make_pair(back, noback);
}

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<vector<pair<int,int>>> graph(N);
    vector<int> ps, ds;
    for(int i = 1; i < N; ++i) {
        int p;
        cin >> p;
        --p;
        ps.push_back(p);
    }
    for(int i = 1; i < N; ++i) {
        int d;
        cin >> d;
        ds.push_back(d);
    }
    for(int i = 0; i < N-1; ++i) {
        graph[ps[i]].emplace_back(i+1, ds[i]);
        graph[i+1].emplace_back(ps[i], ds[i]);
    }

    ULL ans = INF;
    for(int root = 0; root < N; ++root) {
        ans = min(ans, calc(root, -1, graph).second);
        //cout << "-----" << endl;
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1384
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN (int)1e6+5
#if !testing
#define cerr if(0)cout
#endif
string str;
ll dp[MAXN][2];
int32_t main() {
	IAMSPEED
	cin>>str;
	dp[0][1] = 1;
	int n = str.size();
	str = "A"+str;
	FOR(i,1,str.size()-1) {
		if(str[i]=='1') {
			dp[i][0]+=dp[i-1][0]*3+dp[i-1][1];
			dp[i][1]+=dp[i-1][1]*2;
		} else {
			dp[i][0]+=dp[i-1][0]*3;
			dp[i][1]+=dp[i-1][1];
		}
		dp[i][0]%=MOD;
		dp[i][1]%=MOD;
	}
	cout<<(dp[n][0]+dp[n][1])%MOD;
	
}


Measured memory_bytes: 1900
using System;
using System.Linq;
using System.Text;

namespace _074_Videotape
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			StringBuilder output = new StringBuilder (9 * 50);
			TimeSpan limit = new TimeSpan (2, 0, 0);

			while ((inputStr = Console.ReadLine ()) != "-1 -1 -1")
			{
				int[] inputNum = inputStr.Split (' ').Select (int.Parse).ToArray ();

				TimeSpan time = new TimeSpan (inputNum[0], inputNum[1], inputNum[2]);
				TimeSpan span = limit - time;
				TimeSpan span2 = span + span + span;

				output.AppendLine (span.ToString ());
				output.AppendLine (span2.ToString ());
			}

			Console.Write (output);
		}
	}
}

Measured memory_bytes: 9440
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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 n, k; cin >> n >> k;
    int ma = (n-1)*(n-2) / 2;
    if(k > ma) cout << -1 << ln;
    else{
        vector<pii> edges;
        for(int i=1; i<n; i++) edges.emplace_back(i, n);

        int cnt = 0;
        for(int i=1; i<n-1; i++){
            for(int j=i+1; j<=n-1; j++){
                if(cnt == ma - k)break;
                edges.emplace_back(i, j);
                cnt++;
            }
        }
        cout << edges.size() << ln;
        for(auto e: edges) cout << e.first << " " << e.second << ln;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld n, m;
      cin >> n;
      cin >> m;
      lld i, r;
      string s;
      lld A[n+1];
      lld W[n+1];
      foi(i, n+1)
      {
      	A[i] = 0;
      	W[i] = 0;
      }
      foi(i, m)
      {
      	cin >> r;
      	cin >> s;
      	if (s == "AC")
      	{
      		if (A[r] == 0)
      		{
      			A[r] =1;
      		}
      	}
      	if (s == "WA")
      	{
      		if (A[r] == 0)
      		{
      			W[r]+=1;
      		}
      	}
      }
      lld c, d;
      c = 0;
      d = 0;
      foi(i, n+1)
      {
      	if (A[i] == 1)
      		c+=1;
      }
      foi(i, n+1)
      {
      	if (A[i] == 1)
      		d+=W[i];
      }
      cout << c << " " << d;
      return 0;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
An = list(map(int, input().split()))

#K = 1
#N = 3
#An = [4,1,5]

import numpy as np

if N<=K:
    print(0)
else:
    remain = N - K
    An.sort()
    print(np.sum(An[:remain]))

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

bool compare_second(pair<ll, ll> a, pair<ll, ll> b)
{
    if(a.second != b.second) {
        return a.second > b.second;
    } else {
        return a.first > b.first;
    }
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    vector<pair<ll, ll>> BC(M);
    rep(i, N) cin >> A[i];
    rep(i, M) {
        ll f, s;
        cin >> f >> s;
        BC[i] = make_pair(f, s);
    }
    sort(A.begin(), A.end());
    sort(BC.begin(), BC.end(), compare_second);
    /*rep(i, M) cout << BC[i].second << " ";
    cout << endl;*/

    int f = 0;
    int seq = 0;
    rep(i, M) {
        rep(j, BC[i].first) {
            if(A[seq] >= BC[i].second || seq > N-1)  {
                f = 1;
                break;
            } else {
                A[seq++] = BC[i].second;
            }
        }
    }

    ll sum = 0;
    rep(i, N) {
        sum += A[i];
    }
    cout << sum <<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
	char str1[7],str2[4];
	int num,i,root;
	scanf("%s%s",str1,str2);
	strcat(str1,str2);
	num=atoi(str1);
	root=(int)sqrt((double)num);
	if(root*root == num) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}


fn main(){
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i64> = scan.next_vec(n);

    let mut ord: Vec<(i64,usize)> = Vec::with_capacity(n);
    for i in 0..n {
        ord.push((a[i], i));
    }
    ord.sort_by_key(|x| -x.0);

    let mut dp: Vec<Vec<i64>> = vec![vec![-1; n+1]; n+1];
    dp[0][0] = 0;
    for i in 0..n {
        for j in 0..n {
            if dp[i][j] < 0 {
                continue;
            }
            let (a, idx) = ord[i];
            dp[i+1][j+1] = std::cmp::max(dp[i+1][j+1], dp[i][j] + a* (j as i64 - idx as i64).abs());
            dp[i+1][j] = std::cmp::max(dp[i+1][j], dp[i][j] + a* ((n - 1 - (i - j)) as i64 - idx as i64).abs());
        }
    }
    
    println!("{}", dp[n].iter().fold(0, |sum, x| std::cmp::max(sum, *x)) );
}


Measured memory_bytes: 33580
def popcount_parity(x, a):
    x ^= x >> 2
    x ^= x >> 4
    x ^= x >> 8
    x ^= x >> 16
    x ^= x >> 32
    x ^= x >> 64
    x ^= x >> 128
    x ^= x >> 256
    x ^= x >> 512
    x ^= x >> 1024
    x ^= x >> 2048
    x ^= x >> 4096
    x ^= x >> 8192
    x ^= x >> 16384
    x ^= x >> 32768
    x ^= x >> 65536
    x ^= x >> 131072
    x ^= x >> 262144
    x ^= x >> 524288
    x ^= x >> 1048576
    return x & a

def include_2(a):
    x = (~a) & (a >> 1)
    x |= x >> 2
    x |= x >> 4
    x |= x >> 8
    x |= x >> 16
    x |= x >> 32
    x |= x >> 64
    x |= x >> 128
    x |= x >> 256
    x |= x >> 512
    x |= x >> 1024
    x |= x >> 2048
    x |= x >> 4096
    x |= x >> 8192
    x |= x >> 16384
    x |= x >> 32768
    x |= x >> 65536
    x |= x >> 131072
    x |= x >> 262144
    x |= x >> 524288
    x |= x >> 1048576
    return x & 1

N = int(input()) - 1 << 1
s = 1
while N:
    l = N & -N
    s |= s << l
    N ^= l

a = int(input(), 4)
if include_2(a):
    print(popcount_parity((~a) & s, 1))
else:
    print(popcount_parity(a & (s << 1), 2))

Measured memory_bytes: 5496
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;

    class Program
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            var k = int.Parse(Console.ReadLine());
            var cnt = 0;
            var ans = "No";
            //緑のカードに書かれている整数は、赤のカードに書かれている整数より真に大きい。
            //青のカードに書かれている整数は、緑のカードに書かれている整数より真に大きい。
            while (true)
            {
                if (a >= b)
                {
                    b = b * 2;
                    cnt++;
                    continue;
                }
                if (b >= c)
                {
                    c = c * 2;
                    cnt++;
                    continue;
                }
                if (b > a && c > b)
                {
                    break;
                }
            }
            if (cnt <= k)
            {
                ans = "Yes";
            }
            Output(ans.ToString());

        }
        private static void Output(string str)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            Console.WriteLine(str);

            Console.Out.Flush();
        }

    }

Measured memory_bytes: 27460
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef unsigned long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
bool isPrime(int x) {
	int i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;
	return 1;
}vector<ll> a;
void prime(ll n) {
	ll m = n, sum = 0, k = 0;
	if (n == 1) return;
	if (n % 2 == 0) {
		while (n % 2 == 0) {
			k++;
			n /= 2;
		}
		a.push_back(k);
	}
	for (ll i = 3; i * i <= m; i += 2){
		if (n % i == 0) {
			k = 0;
			while (n % i == 0) {
				k++;
				n /= i;
			}
			a.push_back(k);
		}
	}
	if (n * n >= m) a.push_back(1);
}
int main(void) {
	ll n,sum = 0; cin >> n;
	prime(n);
	for (ll i : a) {
		ll k = 1,cnt = 1;
		for (;;) {
			if (cnt > i) {
				k--;
				break;
			}
			k++; cnt += k;
		}sum += k;
	}cout << sum << endl;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N= gi();
	    int K= gi();
	    int X= gi();
	    int Y= gi();

	    if (N <=K) {
            System.out.print(N*X);
	    } else {
	    	System.out.print(K*X+(N-K)*Y);
	    }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35692
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int cntg(int y, int k) {
    int cnt = 0;
    while (y < k) {
        y *= 2;
        cnt++;
    }
    return cnt;
}

int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    long double ans = 0.0;
    REP(i,n) {
        int I = i+1;
        int x = cntg(I, k);
        ans = ans + ((long double)(1.0/n)*(long double)pow(0.5, x));
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int a;
	for (int i=1;i<=5;i++){
		cin>>a;
		if (a==0)  cout<<i;
	}
	re 0;
}

Measured memory_bytes: 3632
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var k     = int.Parse(spl[0]);
        var r     = int.Parse(spl[1]);

        if (k >= 10) return r;
        //r = x - 100 * (10-k)
        return (double)r + 100.0 * (10.0-(double)k);
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 11092
N = int(input())
A = list(map(int, input().split()))

# ans = 1000
# for i in range(N-1):
#     if A[i] < A[i+1]:
#         ans += (A[i+1] - A[i]) * (ans // A[i])
# print(ans)

ans = 1000
dp = [-1 for i in range(N)]
dp[0] = 1000

for i in range(1, N):
    m = dp[i-1]
    for j in range(i):
        stock = dp[j] // A[j]
        m = max(m, (dp[j] // A[j] * A[i] + dp[j] % A[j]))
    dp[i] = m
print(dp[N-1])


Measured memory_bytes: 65568
import math

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

h1 = 30*h+0.5*m

m1 = 6*m

if abs(h1-m1)>180:
    if m1>180:
        x = 360-m1+h1
    else:
        x = 360-h1+m1
else:
    x = abs(h1-m1)

cosx = math.cos(math.radians(x))

ans2 = a*a+b*b-2*a*b*cosx

ans = ans2**(0.5)

print(ans)

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

struct tt {
	int a, b, ind;
};

bool cmp_a(const tt &tt1, const tt &tt2) {
	return tt1.a < tt2.a;
}

bool cmp_b(const tt &tt1, const tt &tt2) {
	return tt1.b < tt2.b;
}

tt tta[MAXN], ttb[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d", &tta[i].a);
	}
	REP(i, 0, n) {
		scanf("%d", &tta[i].b);
	}
	sort(tta, tta + n, cmp_a);
	REP(i, 0, n) {
		tta[i].ind = i;
		ttb[i] = tta[i];
	}
	sort(ttb, ttb + n, cmp_b);
	REP(i, 0, n) {
		if (tta[i].a > ttb[i].b) {
			printf("No\n");
			return;
		}
	}
	REP(i, 1, n) {
		if (tta[i].a <= ttb[i - 1].b) {
			printf("Yes\n");
			return;
		}
	}
	int cnt = 0;
	for(int i = 0; ; ) {
		cnt++;
		i = ttb[i].ind;
		if (i == 0) {
			break;
		}
	}
	//printf("%d\n", cnt);
	if (cnt < n) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb((a))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 3*1e3+5,M = 105;
using namespace std;
ll memo[N][N];
string a,b;
vector<char>ans;
ll solve(ll i,ll j)
{
    if(i == a.sz() || j == b.sz())
        return 0;
    ll &ans = memo[i][j];
    if(~ans)
        return ans;
    ans = 0;
    if(a[i] == b[j])
        ans = max(ans,solve(i+1,j+1) + 1);
    else
        ans = max(ans,max(solve(i+1,j),solve(i,j+1)));
    return ans;
}
void build(ll i,ll j)
{
    if(i == a.sz() || j == b.sz())
        exit(0);
    if(a[i] == b[j])
        cout << a[i],build(i+1,j+1);
    if(solve(i+1,j) == memo[i][j])
        build(i+1,j);
    build(i,j+1);
}
int main()
{
    abdelrahman001
    memset(memo,-1,sizeof memo);
    cin >> a >> b;
    solve(0,0);
    build(0,0);
    return 0;
}


Measured memory_bytes: 71168
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;



int main(void) {
    ll n;
    cin>>n;
    vl a(n+2);
    ll sum = 0;
    rep(i,n) cin>>a[i+1];
    rep(i,n+1) sum += abs(a[i]-a[i+1]);
    rep(i,n){
        cout<<(sum-abs(a[i]-a[i+1])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))<<endl;;
    }
	return 0;
}


Measured memory_bytes: 3988
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

bool isPrime(long num){
	if(num < 2)
		return false;
	else if(num == 2 )
		return true;
	else if(num % 2 == 0)
		return false;

	double sqrtNum = sqrt(num);
	for(int i = 3 ; i <= sqrtNum ; i += 2 ){
		if(num % i == 0 )
			return false;
	}
	
	return true;
}

int main(){
	int MAX_N = 100000;
	
	vector<int> v(MAX_N+1,0);
	v[0] = 0;

	for(int i = 1 ; i < MAX_N+1 ; i++ ){
		if(isPrime(i) && isPrime((i+1)/2)){
			v[i]++;
		}
		v[i] += v[i-1];
	}
	
	int q;
	cin >> q;
	

	rep(i,0,q){
		int l,r;
		cin >> l >> r;
		P(v[r]-v[l-1]);
	}
	

	ret 0;
}

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


int main() {
    string s;cin >> s;
    long long  ans=0;
    for(int bit=0;bit < (1<<(s.length()-1)); bit++)
    {
        long long num = s[0] - '0';
        for(int i=0; i<s.length()-1;i++){
            if(bit & (1<<i)){
                ans += num;
                num=0;
            }
            num = num*10 + s[i+1]-'0';
        }
        ans += num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256