akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;



int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i,n) {cin >> a.at(i);b.at(i)=a.at(i);}
  sort(a.begin(),a.end());
  rep(i,n){
    if (a.at(n-1)==b.at(i)) cout << a.at(n-2) << endl;
    else cout << a.at(n-1) << endl;
  }
  }

Measured memory_bytes: 3200
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    
    if (K <= A) {
        cout << A - K << " " << B << "\n";
    } else if (K <= A + B) {
        cout << 0 << " " << B - (K - A) << "\n";
    } else {
        cout << 0 << " " << 0 << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);


map<pii,int> cnt[1111][1111];
struct tile
{
	int c[4];
	tile(int a1,int a2,int a3,int a4){c[0]=a1;c[1]=a2;c[2]=a3;c[3]=a4;}
	tile(){}
	void add(int x){for(int i=0;i<4;i++)cnt[c[i]][c[i+1&3]][mp(c[i+2&3],c[i+3&3])]+=x;}
	int getnum()
	{
		if(cnt[c[0]][c[1]].find(mp(c[2],c[3]))==cnt[c[0]][c[1]].end())
			return 0;
		return cnt[c[0]][c[1]][mp(c[2],c[3])];
	}
	tile rev()
	{
		tile ret;for(int i=0;i<4;i++)ret.c[i]=c[i^3];
		return ret;
	}
	tile rotate(int x)
	{
		tile ret;for(int i=0;i<4;i++)ret.c[i+x&3]=c[i];
		return ret;
	}
	tile print(){printf("tile %d %d %d %d\n",c[0],c[1],c[2],c[3]);}
}a[411],tmp[4];

LL getnum(const tile up,const tile down)
{
	bool hehe[4]={};
	LL ret=1;
	for(int i=0;i<4;i++)
	{
		tile cur(up.c[i+1&3],up.c[i],down.c[i],down.c[i+1&3]);
//		cur.print();printf("num= %d\n",cur.getnum());
		int t=cur.getnum();
		ret *=t;
		if(t)cur.add(-1);
		else hehe[i]=1;
	}
	for(int i=0;i<4;i++)
	{
		tile cur(up.c[i+1&3],up.c[i],down.c[i],down.c[i+1&3]);
		if(!hehe[i])cur.add(1);
	}
	return ret;
}
int n;
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<4;j++)
			get1(a[i].c[j]);
		a[i].add(1);
	}
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		a[i].add(-1);
		for(int j=i+1;j<=n;j++)
		{
			if(i==j)continue;
			a[j].add(-1);
			for(int k=0;k<4;k++)ans+=getnum(a[i],a[j].rev().rotate(k));
			a[j].add(1);
		}
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 58240
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll MOD = 998244353;
int n, s, a[MAXN];
ll dp[MAXN][MAXN], dp2[MAXN][MAXN];

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

ll sub(ll a, ll b) {
    return (a - b) % MOD;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> s;
    FOR(i,1,n) cin >> a[i];
    dp[0][0] = 1;
    FOR(i,1,n)
        FOR(j,0,s) {
            dp[i][j] = dp[i-1][j];
            if (j >= a[i]) {
                if (j == a[i]) dp[i][j] = add(dp[i][j], i * dp[i-1][j-a[i]]);
                else dp[i][j] = add(dp[i][j], dp[i-1][j-a[i]]);
            }
        }
    ll res = 0;
    FOR(i,1,n) res = add(res, dp[i][s]);
    cout << res;
    return 0;
}


Measured memory_bytes: 72064
#include<cstdio>
#include<algorithm>
#include<deque>

using namespace std;

int main(){
	int n; scanf("%d", &n);
	deque<int> b;
	for(int i = 0; i < n; i++){
		int a; scanf("%d", &a);
		if(i & 1) b.push_front(a);
		else b.push_back(a);
	}
	if(n & 1) reverse(b.begin(), b.end());
	for(int i = 0; i < n; i++) printf("%d%c", b[i], i + 1 == n ? '\n' : ' ');
	return 0;
}

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

int main(void) {
  int n,i;
  char buf1[22];
  char *buf2;
  scanf("%s",buf1);
  n = strlen(buf1);
  buf2 = malloc((n+1)*sizeof(char));
  for (i=0;i<n;i++) buf2[i] = buf1[n-1-i];
  printf("%s\n",buf2);
  
  return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <vector>
using namespace std;
#define MAP_SIZE 10

class Pos {
  public:
    Pos(int x, int y) : x(x), y(y) {}
    int x;
    int y;
    bool alive(Pos p) { return p.x - 1 <= this->x && this->x <= p.x + 1 && p.y - 1 <= this->y && this->y <= p.y + 1; }
};

int dx[12] = {-2, -2, -2, 2, 2, 2, -1, 0, 1, -1, 0, 1}; 
int dy[12] = {-1, 0, 1, -1, 0, 1, -2, -2, -2, 2, 2, 2}; 
bool move(Pos p, vector<Pos> sc, int n) {
  if (p.x < 0 || MAP_SIZE <= p.x || p.y < 0 || MAP_SIZE <= p.y) return false;
  if (n == -1) return true;
  if (!p.alive(sc[n--])) return false;
  sc.pop_back();
  bool result = false;
  for (int i = 0; i < 12; i++) {
    if (move(Pos(p.x + dx[i], p.y + dy[i]), sc, n)) result = true;
    if (result) break;
  }
  return result;
}

int main() {
  int x, y, n;
  while (cin >> x >> y) {
    if (x == 0 && y == 0) break;
    Pos p = Pos(x, y); 

    cin >> n;
    vector<Pos> sc = { p };
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      sc.insert(sc.begin(), Pos(x, y));
    } 
    cout << (move(p, sc, n) ? "OK" : "NA") << endl;
  }
  return 0;
}

Measured memory_bytes: 3032
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>


using namespace std;

long long n, k;
long long a[500000];

long long solve(int l, int r)
{
    if (l + 1 == r)
    {
        if (a[l] < 0) return 0;
        return 1;
    }
    int m = (l + r) / 2;
    long long res = solve(l, m) + solve(m, r);
    vector<long long> s, p;
    long long counter = 0;
    for (int i = m - 1; i >= l; i--)
    {
        counter += a[i];
        s.push_back(counter);
    }
    counter = 0;
    for (int i = m; i < r; i++)
    {
        counter += a[i];
        p.push_back(counter);
    }
    sort(s.begin(), s.end());
    sort(p.begin(), p.end());
    int pointer = s.size() - 1;
    int cnt = 0;
    for (int i = 0; i < p.size(); i++)
    {
        long long d = p[i];
        // s[j] >= -d
        while (pointer >= 0 && s[pointer] >= -d)
        {
            cnt++;
            pointer--;
        }
        res += cnt;
    }
    return res;
}

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] -= k;
    }
    cout << solve(0, n);
}


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

using namespace std;

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

int main(){
	string str;
	cin>>str;
	
	str += "#";
	vector<pair<char,int> > len;
	
	char bef = str[0];
	int cont = 1; 
	reps(i,1,str.size()){
		
		if(bef==str[i]){
			cont++;
		}else{
			len.push_back(make_pair(bef,cont));
			bef = str[i];
			cont = 1;
		}
	}
	
	int level = 0;
	
	reps(i,1,len.size()-1){
		if(len[i].first=='O'){
			if(len[i-1].first!='J')continue;
			if(len[i+1].first!='I')continue;
			
			int m = min(len[i-1].second, len[i+1].second);
			if(m < len[i].second)continue;
			
			level = max(level, len[i].second);
		}
	}
	
	printf("%d\n",level);
}

Measured memory_bytes: 12280
#D
from collections import Counter
n, x, y = map(int, input().split())
ans=[]
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        k = min(abs(j - i), abs(x - i) + abs(y - j) + 1, abs(y - i) + abs(x - j) + 1)
        # print(i,j,k)
        ans.append(k)
# print(ans)
ans=Counter(ans)
# print(ans)
for i in range(1, n):
    print(ans[i])

Measured memory_bytes: 67440
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pb  push_back
ll N=1e3+3,M=1e9+7;
vector<ll>v;
ll a[1003],c[1003];
int main()
{
    ft
    ll t,i,j,n,m,l,r;
    for(i=3;i<=(N/i);i++)
    {
        for(j=i*i;j<=N;j+=2*i)
        {
            a[j]=1;
        }
    }
    v.pb(2);
    for(i=3;i<N;i+=2)
    {
        if(a[i]==0)
        {
            v.pb(i);
        }
    }
    ll sz=v.size();
    cin>>n;
    for(i=2;i<=n;i++)
    {
        m=i;
        for(j=0;j<sz && v[j]<=(m/v[j]);j++)
        {
            l=v[j];
            while(m%l==0)
            {
                m/=l;
                c[l]++;
            }
        }
        if(m>1)
        {
            c[m]++;
        }
    }
    r=1;
    for(i=0;i<sz;i++)
    {
        r=(r*(c[v[i]]+1ll))%M;
    }
    cout<<r<<"\n";
    return 0;
}

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

using namespace std;

int main()
{
	int x;
	cin >> x;

	if (x >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}


Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])

	}

	flag := make(map[int]int, N)
	for i, j := range A {
		flag[j] = i + 1
	}

	for i := 1; i <= N; i++ {
		fmt.Printf("%d ", flag[i])
	}
	fmt.Printf("\n")
}


Measured memory_bytes: 8884
x,y,a,b,c=gets.split(' ').map(&:to_i)
p=gets.split(' ').map(&:to_i).sort!.reverse!
q=gets.split(' ').map(&:to_i).sort!.reverse!
r=gets.split(' ').map(&:to_i).sort!
inf = 10**15
ans_a = x
ans_b = y
for i in 0..(a-1)
  point = a-i
  p[point]=p[point-1]
end

for i in 0..(b-1)
  point = b-i
  q[point]=q[point-1]
end

for i in 0..(c-1)
  point = c-i
  r[point]=r[point-1]
end
p[0]=inf
q[0]=inf
r[0]=0
=begin
puts p
puts q
puts r
=end
while  (r[c]>p[x] || r[c]>q[y])
  if p[x]>=q[y]
    q[y]=r[c]
    y-=1
    c-=1
  else
    p[x]=r[c]
    x-=1
    c-=1
  end
end

ans=0
for i in 1..ans_a
  ans+=p[i]
end

for i in 1..ans_b
  ans+=q[i]
end
puts ans

Measured memory_bytes: 23952
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int A,B,flag =1;
    string S;
    cin >> A >> B >> S;
    if(S[A] == '-'){
        FOR(i,0,A+B+1){
            if(i != A){
                if('0' <=S[i] && S[i] <= '9'){}
                else{
                    flag =0;
                }
            }
        }
    }else{
        flag =0;
    }
    if(flag == 1){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    if(a + b == c || b + c == a || c + a == b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){

  int h, w;
  cin >> h >> w;
  char c[101][101];

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin >> c[i][j];
    }
  }

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cout << c[i][j];
    }
    cout << endl;
    for(int k=0; k<w; k++){
      cout << c[i][k];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long int lcm(long long int a, long long int b) {
    return a / gcd(a,b) * b;// divide first to avoid overflow
}

int main(){
    int a, b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
namespace algo
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] i1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = i1[0];
            int M = i1[1];

            int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int result = 0;
            for(int i = 0; i < M; ++i){
                result += A[i];
            }

            if(N >= result){
                Console.WriteLine(N - result);
            }else{
                Console.WriteLine(-1);
            }

        }
    }
}


Measured memory_bytes: 29024
def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

import sys
input = sys.stdin.readline

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

par = [-1]* n
rank = [0]*n

for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    Unite(a, b, par, rank)

ans = 1
for i in range(n):
    if par[i] < 0:
        ans = max(ans, -par[i])
print(ans)


Measured memory_bytes: 74856
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;


int main(){

	int R[MAX],n;
		
	cin >> n;

	for (int i = 0; i < n; i++) cin >> R[i];

	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++){
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;

	return 0;

}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        ans += (N-1) / i;
    }
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

// int gcd(int a, int b){
//   if (a%b==0){
//     return(b);
//   }
//   else{
//     return(gcd(b,a%b));
//   }
// }





int main(){
  int x,y;
  cin >> x >> y;
  cout << x + y/2 << endl;
  
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 50005
#define re register
#define ll long long
#define P 998244353
using namespace std;
bool m1;
int n,m,K;
inline void Rd(int &res){
	re char c;res=0;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
}
struct Point{
	double x,y;
	Point operator+(const Point&a)const{return (Point){x+a.x,y+a.y};}
	Point operator-(const Point&a)const{return (Point){x-a.x,y-a.y};}
	Point operator*(const double&v)const{return (Point){x*v,y*v};}
	double operator*(const Point&a)const{return x*a.x+y*a.y;}
	double operator^(const Point&a)const{return x*a.y-y*a.x;}
	double len(){return sqrt(x*x+y*y);}
}p1,p2,p;
bool m2;
int main(){
	scanf("%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y);
	Point p3=p2-p1;
	double l=p3.len();
	int q;Rd(q);
	while(q--){
		scanf("%lf%lf",&p.x,&p.y);
		double l1=((p-p1)*p3)/l;
		Point q=p3*(l1/l);
		q=p1+q;
		printf("%.12lf %.12lf\n",q.x,q.y);
	}
	return 0;
}


Measured memory_bytes: 3232
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(n):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = abs(h[1]-h[0])
    else:
        dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]))
print(dp[n-1])


Measured memory_bytes: 13980
#include <iostream>                                
#include <string>                                  
#include <algorithm>                               
                                                   
using namespace std;                               
int Hmap[2000][2000]={0};                          
int Wmap[2000][2000]={0};                          
                                                   
int main(){                                        
  int H,W;                                         
  string map[2000];                                
  cin >> H >> W;                                   
  for(int i=0;i<H;i++){                            
    cin >> map[i];                                 
  }                                                
  for(int i=0;i<W;i++){                            
    for(int j=0;j<H;j++){                          
      if(map[j][i]!='#'){                          
        if(j-1>=0&&Hmap[j-1][i]!=0){               
          Hmap[j][i]=Hmap[j-1][i];                 
        }else{                                     
          int k;                                   
          for(k=0;j+k<H;k++){                      
            if(map[j+k][i]=='#'){                  
              break;                               
            }                                      
          }                                        
          Hmap[j][i]=k;                            
        }                                          
      }                                            
    }                                              
  }                                                
  for(int i=0;i<H;i++){                            
    for(int j=0;j<W;j++){                          
      if(map[i][j]!='#'){                          
        if(j-1>=0&&Wmap[i][j-1]!=0){               
          Wmap[i][j]=Wmap[i][j-1];                 
        }else{                                     
          int k;                                   
          for(k=0;j+k<W;k++){                      
            if(map[i][j+k]=='#'){                  
              break;                               
            }                                      
          }                                        
          Wmap[i][j]=k;                            
        }                                          
      }                                            
    }                                              
  }                                                
  int M=0;                                         
  for(int i=0;i<H;i++){                            
    for(int j=0;j<W;j++){                          
      M=max(M,Hmap[i][j]+Wmap[i][j]-1);            
    }                                              
  }                                                
  cout << M << endl;                               
}                                                  

Measured memory_bytes: 35584
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
static const int MAX_N = 100000;
static const int NIL = -1;
struct edge{int to, cost;};

int N, M;
vector<edge> G[MAX_N];

bool flag;
bool visited[MAX_N];
int dist[MAX_N];

void dfs(int s){
  visited[s] = true;
  for(int i = 0; i < G[s].size(); i++){
    if(visited[G[s][i].to] && dist[G[s][i].to] != dist[s] + G[s][i].cost){
      flag = false;
      return ;
    }else if(!visited[G[s][i].to]){
      dist[G[s][i].to] = dist[s] + G[s][i].cost;
      dfs(G[s][i].to);
    }
  }
  return ;
}
int main(){
  cin >> N >> M;
  fill(visited, visited + N, false);
  fill(dist, dist + N, NIL);
  for(int i = 0; i < M; i++){
    int L, R, D;
    cin >> L >> R >> D;
    L--; R--;
    G[L].push_back((edge){R, D});
    G[R].push_back((edge){L, -D});
  }
  flag = true;
  for(int i = 0; i < N; i++){
    dfs(i);
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 12032
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int a[1000];
int main(){
    int n;
    int d;
    int x;
    cin>>n>>d>>x;
    int cnt=x;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    int b=1;
    int c=1;
    for (int i=1;i<=n;i++)
         {
            while (b<=d)
            {
                cnt++;
                b=a[i]*c+1;
                c++;
            }
            b=1;
            c=1;
         }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
main(){int a[5],e,x,t;for(e=0;e<5;)scanf("%d",&a[e++]);for(e=0;e<4;e++)for(x=e+1;x<5;x++){if(a[e]<a[x]){t=a[e];a[e]=a[x];a[x]=t;}}for(e=0;e<5;){printf("%d",a[e++]);(e == 5)?printf("\n"):printf(" ");}return 0;}

Measured memory_bytes: 0
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int n = s.length();
        t = t.concat(t);
        String check = "No";
        for(int i=0; i<n; i++){
            if(s.equals(t.substring(i,i+n))){
                check = "Yes";
            }
        }
        System.out.println(check);
    }
}

Measured memory_bytes: 21844
#-------------------------------------------------------------------
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors
#-------------------------------------------------------------------
import random
def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False
 
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1
 
    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
 
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1
 
        if y != n - 1 and t & 1 == 0:
            return False
 
    return True

#-------------------------------------------------------------------
#Python -3.4.x
from fractions import gcd
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
a,b = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

g=gcd(a,b)
#p('g ', g)
L=make_divisors(g)

#p( gcd(a,b) )
#p( L )

ans=1
for l in L:
	#if a%l==0 and b%l==0: ans+=1
	if is_prime(l): ans+=1

print(ans)


Measured memory_bytes: 67180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> l(Q), r(Q);
  rep(i,Q) cin >> l[i] >> r[i];
  int num[100010]={0};
  rep(i,N-1){
    num[i+1]=num[i];
    if(S[i]=='A'&&S[i+1]=='C') num[i+1]++;
  }
  rep(i,Q){
    int L=l[i]-1, R=r[i]-1;
    int ans=num[R]-num[L-1];
    if(L>0&&S[L-1]=='A'&&S[L]=='C') ans--;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll N,Q;
string s;
char t[200020],d[200020];
int check(ll x){
    for(int i = 0; i < Q; i++){
        if(s[x] == t[i]){
            if(d[i] == 'L') x--;
            if(d[i] == 'R') x++;
        }
        if(x == -1) return -1;
        if(x == N) return 1;
    }
    return 0;
}
int main(){
    cin >> N >> Q;
    cin >> s;
    for(int i = 0; i < Q; i++){
        cin >> t[i] >> d[i];
    }
    ll mid;
    ll ls = -1;
    ll rs = N;
    while(ls < rs-1){
        mid = (ls + rs)/2;
        if(check(mid) == -1) ls = mid;
        else rs = mid; 
    }
    ll lt = -1;
    ll rt = N;
    while(lt < rt-1){
        mid = (lt + rt)/2;
        if(check(mid) == 1) rt = mid;
        else lt = mid;
    }
    cout << rt-ls-1 << endl;
    return 0;
}



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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100010, maxnode = 400010, maxq = 100010;

int tot = 0, rt;
int num[maxnode + 5], sz[maxnode + 5];
int go[maxnode + 5][26];

int n, qn;
string s[maxn + 5];

inline void add(const string &x)
{
	int cur = 0;
	REP(i, 0, SZ(x))
	{
		++sz[cur];
		int tmp = x[i] - 'a';
		if (!~go[cur][tmp]) go[cur][tmp] = tot++;
		cur = go[cur][tmp];
	}
	++sz[cur], ++num[cur];
}

vector<int> all[maxn + 5];

int ans[maxq + 5];

int rk[maxq + 5][26];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	memset(go, -1, sizeof go);
	scanf("%d", &n);
	rt = 0;
	tot = 1;
	REP(i, 0, n) 
	{
		cin >> s[i];
		add(s[i]);
	}
	scanf("%d", &qn);
	REP(i, 0, qn)
	{
		static int id;
		static string ss;
		scanf("%d", &id), --id;
		cin >> ss;
		all[id].pb(i);
		REP(j, 0, 26) rk[i][ss[j] - 'a'] = j;
	}
	REP(i, 0, n)
	{
		int cur = 0;
		REP(j, 0, SZ(s[i]))
		{
			if (num[cur])
			{
				for (auto u : all[i]) ans[u] += num[cur];
			}
			int tmp = s[i][j] - 'a';
			REP(k, 0, 26) if (k != tmp && ~go[cur][k])
			{
				for (auto u : all[i]) if (rk[u][k] < rk[u][tmp]) ans[u] += sz[go[cur][k]];
			}
			cur = go[cur][tmp];
		}
	}
	REP(i, 0, qn) printf("%d\n", ans[i] + 1);
	return 0;
}


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

double length(int x1,int y1,int x2,int y2){
  int p=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
  double q=sqrt((double)p);
  
  //cout<<q<<endl;
  
  return q;
}

int main() {
  int N;
  cin>>N;
  vector<vector<int>> xy(N,vector<int>(2));
  rep(i,N){
    cin>>xy.at(i).at(0)>>xy.at(i).at(1);
  }
  vector<int> o(0);
  rep(i,N){
    o.push_back(i);
  }
  double ans=0.0;
  do{
    rep(i,N-1){
      ans+=length(xy.at(o.at(i)).at(0),xy.at(o.at(i)).at(1),xy.at(o.at(i+1)).at(0),xy.at(o.at(i+1)).at(1));
    }
  }while (next_permutation(o.begin(),o.end()));
  
  int x=1;
  for(int i=1;i<N+1;i++){x*=i;}
  ans/=x;
  cout << fixed << setprecision(10);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n, d, ans = 0;
    int x[10][10];
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int sum = 0;
            for(int k = 0; k < d; k++){
                sum += pow(x[i][k] - x[j][k], 2);
            }
            if(sum == pow(int(sqrt(sum)), 2)) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

    map<string,int> s;
    string str;
    int max_cnt = 0, s_size = 0;
    for (int i = 0; i < n; i++) {
        cin >> str;
        if (s.find(str) == s.end()) {
            s[str] = 0;
            s_size++;
        } else {
            s[str]++;
        }
        if (s[str] > max_cnt) max_cnt = s[str];
    }

    for (const auto& [key, value] : s) {
        if (value == max_cnt) cout << key << endl;
    }

    return 0;
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define R(i,n) for(int i = 0; i < (n); i++)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}

template<class T> ostream &operator<<(ostream& os, set<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int n;
  cin >> n;
  int os = 0;
  int res = 0;
  R(i,n){
    int pom;
    cin >> pom;
    if((pom != 0 && i == 0) || pom > os + 1){
      cout << "-1\n";
      return 0;
    }else if(pom == os + 1){
      res ++;
    }else {
      res += pom;
    }
    os = pom;
  }
  cout << res << "\n";
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}

int main(){
	long long x,k,d;read(x);read(k);read(d);
	long long ans=0;
	if(x>=0){
		long long tmp=x/d;
		if(tmp>k){ans=x-d*k;}
		else{
			if((k-tmp)%2==1){ans=d-(x-d*tmp);}
			else{ans=x-d*tmp;}
		}
	}else{
		long long tmp=(-x)/d;
		if(tmp>k){ans=abs(x+d*k);}
		else{
			if((k-tmp)%2==1){ans=x+d*(tmp+1);}
			else{ans=abs(x+d*tmp);}
		}
	}
	write(ans);
	return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define lli             long long int
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define INF             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v) v.begin(),v.end()
#define endl            "\n"


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

lli maxm(lli a, lli b)
{
  return (a >= b ? a : b);
}


lli minm(lli a, lli b)
{
  return (a <= b ? a : b);
}

lli power(lli x, lli y, lli p)
{
  lli res = 1;

  x = x % p;
  if (x == 0)
    return 0;

  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;


    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

lli nCrmodp(lli n, lli r, lli p)
{
  if (r == 0)
    return 1;
  if (r == 1)
    return n;


  lli pro = 1, k = n;
  while (k > r)
  {
    pro *= k;
    pro %= p;
    --k;
  }

  k = 2;
  while (k <= (n - r))
  {
    pro *= power(k, (p - 2), p);
    pro %= p;
    ++k;
  }

  return pro;
}


string num_str(lli n, lli k)
{
  string str = "";
  lli x = n;
  while (x != 0)
  {
    string s = to_string(x % k);
    str = s + str;
    x /= k;
  }

  return str;
}

void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif*/
}

#define MAXN 100010
int dp[MAXN][3];
int arr[MAXN][3];


int max_val(int ind, int cur, int n)
{
  if (ind > n)
    return 0;
  vector<int> v;

  for (int j = 0; j < 3; ++j)
    if (j != cur)
      v.pb(j);

  if (dp[ind][cur] == 0)
    dp[ind][cur] = (arr[ind][cur] + max(max_val(ind + 1, v[0], n), max_val(ind + 1, v[1], n)));

  v.clear();
  return dp[ind][cur];

}

int main()
{
  c_p_c();

  int n;
  cin >> n;

  memset(dp, 0, sizeof(dp));

  for (int j = 1; j <= n; ++j)
  {
    cin >> arr[j][0] >> arr[j][1] >> arr[j][2];
    /*  if (j == n)
      {
        dp[j][0] = arr[j][0];
        dp[j][1] = arr[j][1];
        dp[j][2] = arr[j][2];

       // cout << dp[j][0] << " " << dp[j][1] << " " << dp[j][2] << endl;
      }*/
  }
  int maxim = 0;

  maxim = max(maxim, max_val(1, 0, n));
  maxim = max(maxim, max_val(1, 1, n));
  maxim = max(maxim, max_val(1, 2, n));

  cout << maxim << endl;


  return 0;
}

Measured memory_bytes: 21516
#include<cstdio>

int main(){
	int d;
	int sum;
	while(scanf("%d", &d) + 1){
		sum = 0;
		for(int i = 1; i < 600 / d; i++){
			sum += i * d * i * d * d;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) puts("error")
    #define rep(i,l,r) for(int i=(l);i<=(r);i++)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;GG(e<0);
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e3+10;

    char str[N][N];int ct[N];vc<pr> tmp;
    void main()
    {
        int n=qread(),m=qread(),A=qread(),B=qread();
        for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) if(i*(m-A-A)+A*n==j*(n-B-B)+B*m)
        {
            // printf("i=%d j=%d\n",i,j);
            for(int x=1;x<=n;x++) for(int y=1;y<=m;y++) str[x][y]='0';

            for(int x=1;x<=n;x++) ct[x]=(x<=i?m-A:A);
            for(int y=1;y<=m;y++)
            {
                tmp.clear();for(int x=1;x<=n;x++) tmp.PB(MP(ct[x],x));sort(all(tmp));
                int ned=(y<=j?n-B:B);
                for(int t=n-ned;t<sz(tmp);t++)
                {
                    int pos=tmp[t].SE;str[pos][y]='1';
                    ct[pos]--;
                }
            }

            for(int x=1;x<=n;x++) puts(str[x]+1);
            return;
        }
    }
};//(ans+MOD)%MOD
int main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 2176
n = int(input())
s = input()

r = [0]*(n+1)
r2 = []
g = [0]*(n+1)
g2 = []
b = [0]*(n+1)
b2 = []

for i in range(n):
  if s[i] == "R":
    r[i+1] = 1
    r2.append(i+1)
  elif s[i] == "G":
    g[i+1] = 1
    g2.append(i+1)
  else:
    b[i+1] = 1
    b2.append(i+1)

ans = len(r2) * len(g2) * len(b2)
minC = r2
minC2 = g2
maxC = b

for i in minC:
  for j in minC2:
    id = max(i,j) + abs(i-j)
    if id <= n and maxC[id] == 1:
      ans -= 1
    id = min(i,j) - abs(i-j)
    if id >= 1 and maxC[id] == 1:
      ans -= 1
    id = i+j
    if id%2 == 0 and maxC[id//2] == 1:
      ans -= 1

print(ans)

Measured memory_bytes: 9340
import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i  in input().split()]
A=np.array(sorted(a))
F=np.array(sorted(f, reverse=True))
left=-1
right=10**12
while left+1<right:
    x=(left+right)//2
    if np.maximum(A-x//F , 0).sum()<=k:
        right=x
    else:
        left=x
print(right)

Measured memory_bytes: 43648
//============================================================================
// Name        : abc126B.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int a, b;
	scanf("%02d%02d", &a, &b);

	bool yymm, mmyy;
	yymm = mmyy = false;
	if(a <= 12 && 0 < a)mmyy = true;
	if(0 < b && b <= 12)yymm = true;

	if(yymm && !mmyy){
		cout << "YYMM" << endl;
	}
	else if(!yymm && mmyy){
		cout << "MMYY" << endl;
	}
	else if(yymm && mmyy){
		cout << "AMBIGUOUS" << endl;
	}
	else {
		cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
X = list(map(int,input().split()))

ans = 10000000000

for i in range(N-K+1):
    cost = 0
    cost += min(abs(X[i]),abs(X[i+K-1]))
    cost += X[i+K-1]-X[i]
    if ans > cost:
        ans = cost
print(ans)

Measured memory_bytes: 14384
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  double p[3010],dp[2][3010];
  int n,i,j;
  scanf("%d\n",&n);
  for(i=0;i<2;i++){
    for(j=0;j<=n;j++){
      dp[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%lf ",&p[i]);
  }
  dp[0][0]=1-p[0],dp[0][1]=p[0];
  for(i=1;i<n;i++){
    for(j=0;j<=n;j++){
      dp[1][j]+=dp[0][j]*(1-p[i]);
      dp[1][j+1]+=dp[0][j]*p[i];
    }
    for(j=0;j<=n;j++){
      dp[0][j]=dp[1][j];
      dp[1][j]=0;
    }
  }
  double ans=0;
  for(i=(n+1)/2;i<=n;i++){
    ans+=dp[0][i];
  }
  printf("%.13lf\n",ans);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextLong();
            var t = new long[5];
            for (int i = 0; i < 5; i++)
            {
                t[i] = cin.nextLong();
            }

            var min = t.Min();
            var max = t.Max();

            if(n <= min)
            {
                Console.WriteLine(5);
                return;
            }

            var time = (n + min - 1) / min;

            Console.WriteLine(time + 4);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N+ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }   

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13268
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import Data.Tuple (swap)

main :: IO ()
main = do
  let
    fromListN :: Int -> [(Int, Int)] -> VU.Vector Int
    fromListN n = VU.accum (flip const) (VU.replicate n 0)
    children :: Tree -> [(Int, Tree)]
    children (Node _ ts) = ts
    fromEdgesToAdjacencyVectorN :: Int -> [(Int, (Int, Int))] -> V.Vector [(Int, Int)]
    fromEdgesToAdjacencyVectorN n = V.accum (flip (:)) (V.replicate n [])
    fromAdjacencyVectorToTree :: V.Vector [(Int, Int)] -> Int -> Tree
    fromAdjacencyVectorToTree adjacency root = Node root (map (fmap (f root)) (adjacency V.! root))
      where
        f :: Int -> Int -> Tree
        f p i = Node i (map (fmap (f i)) . filter ((/= p) . snd) $ adjacency V.! i)
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  abs <- map (unsafeListToPair . map (pred . unsafeTextToInt) . T.words) . T.lines <$> T.getContents :: IO [(Int, Int)]
  let
    adjacency = fromEdgesToAdjacencyVectorN n . concatMap (uncurry (map . fmap . (,)) . fmap ((:) <$> id <*> pure . swap)) . zip [0 ..] $ abs :: V.Vector [(Int, Int)]
    root = V.maxIndex . V.map length $ adjacency :: Int
    k = length $ adjacency V.! root :: Int
    tree = fromAdjacencyVectorToTree adjacency root :: Tree
    queue = zip (children tree) [0 ..] ++ walk k queue :: [((Int, Tree), Int)]
      where
        walk :: Int -> [((Int, Tree), Int)] -> [((Int, Tree), Int)]
        walk 0 _ = []
        walk l (((_, t), c) : rest) = zip ts [(c + 1) ..] ++ walk (l - 1 + length ts) rest
          where
            ts = children t :: [(Int, Tree)]
  print k
  VU.mapM_ (print . succ . (`mod` k)) . fromListN (n - 1) . map ((,) <$> fst . fst <*> snd) $ queue

data Tree = Node Int [(Int, Tree)]

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair = (,) <$> head <*> head . tail
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 53036
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long
#define vi vector<int>

int main() {
    LL n, a, b;
    LL sum = 0;

    cin >> n >> a >> b;
    REP(i, n) {
        int j = i + 1;
        int s = 0;
        while (j != 0) {
            s += j % 10;
            if (s > b) break;
            j /= 10;
        }
        if (a <= s && s <= b) sum += i + 1;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,j,s[10003],n,q,k=0,t;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    for(j=0;j<n;j++){
      if(s[j]==t){
	k++;
	break;
      }
    }
  }
  printf("%d\n",k);
  return 0;
}

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

int main() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    
    ll p[a+1], q[b+1], r[c];
    p[0] = 1000000001;
    q[0] = 1000000001;
    
    rep(i, a){
        cin >> p[i+1];
    }
    rep(i, b){
        cin >> q[i+1];
    }
    rep(i, c){
        cin >> r[i];
    }
    
    ll res = 0;
    
    sort(p, p + a + 1, greater<ll>());
    sort(q, q + b + 1, greater<ll>());
    sort(r, r + c, greater<ll>());
    
    rep(i, x){
        res += p[i+1];
    }
    // cout << res << endl;
    rep(i, y){
        res += q[i+1];
    }
    // cout << res << endl;
    
    int idx_r = x;
    int idx_g = y;
    
    rep(idx_n, c){
        ll min_app = min(p[idx_r], q[idx_g]);
        if(r[idx_n] > min_app){
            if(min_app == p[idx_r]){
                res = res - p[idx_r] + r[idx_n];
                idx_r -= 1;
            }else{
                res = res - q[idx_g] + r[idx_n];
                idx_g -= 1;
            }
        }else{
            break;
        }
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2688