akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i], a[i]--;
	int ret=0;
	for (int i=0; i<n; i++) {
		if(a[i]<i) continue;
		if(a[a[i]]==i) ret++;
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 640
import Control.Applicative
import Data.List
import Control.Monad

main = do
    [n,x] <- map read. words <$> getLine
    ms <- f n
    let (v,rest) = (sum ms, x- sum ms)
    putStrLn.show $ n + (makeSweet rest ms)

makeSweet rest ms = rest `div` (head $ sort ms)

f :: Int -> IO [Int]
f 0 = return []
f n = do
    v <- read <$> getLine
    vs <- f (n-1)
    return (v:vs)

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define N 200050
using namespace std;
typedef long long ll;
int a[N],f[N],dp[N],n,ans=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
	{
		if (f[a[i]-1]) dp[a[i]]=dp[a[i]-1]+1;else dp[a[i]]=1;
		ans=max(ans,dp[a[i]]),f[a[i]]=1;
	}
	printf("%d\n",n-ans);
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int MOD = 1_000_000_007;
		char[] T = sc.next().toCharArray();
		long[] dp = new long[5];
		dp[1] = 1;
		for(int i = 0; i < T.length; i++) {
			if(T[i] == '?') {
				for(int j = 4; j >= 1; j--)
					dp[j] = (3 * dp[j] + dp[j-1]) % MOD;
			}
			else
				dp[T[i]-'A'+2] = dp[T[i]-'A'+2] + dp[T[i]-'A'+1];
		}
		System.out.println(dp[4] % MOD);
	}

}

Measured memory_bytes: 25496
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main(){
  int n, a, b;
  cin >> n >> a >> b;

  for(int i=a ; i<=b; i++)
    if(i%n == 0){
      cout << "OK" << endl;
      return 0;
    }
  cout<<"NG"<<endl;
  
  return 0;
}


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

int main ()
{
	map<string, bool> M;
	
	//輸入
	int n;
	cin >> n;
	
	while(n--)
	{
		//輸入
		string cmd, str;
		cin >> cmd >> str;
		
		//處理
		if (cmd == "insert")
		{
			M[str] = true;
		}
		else
		{
			//輸出
			if (M[str]) cout << "yes\n";
			else cout << "no\n";
		}
	}
	return 0;
}


Measured memory_bytes: 52500
#include <sstream>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cassert>
#include <bitset>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=1e9+7;
const LL maxn=1e6+7;
const double pi=acos(-1.0);
const double eps=0.0000000001;
LL gcd(LL a, LL b) {return b?gcd(b,a%b):a;}
template<typename T>inline void pr2(T x,int k=64) {ll i; REP(i,k) debug("%d",(x>>i)&1); putchar(' ');}
template<typename T>inline void add_(T &A,int B,ll MOD=M) {A+=B; (A>=MOD) &&(A-=MOD);}
template<typename T>inline void mul_(T &A,ll B,ll MOD=M) {A=(A*B)%MOD;}
template<typename T>inline void mod_(T &A,ll MOD=M) {A%=MOD; A+=MOD; A%=MOD;}
template<typename T>inline void max_(T &A,T B) {(A<B) &&(A=B);}
template<typename T>inline void min_(T &A,T B) {(A>B) &&(A=B);}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a, T b) {
	T ret=1;
	for (; b; b>>=1ll,a=(LL)a*a%M)
		if (b&1) ret=(LL)ret*a%M;
	return ret;
}
int n,m,q;
char str[maxn];
int startTime;
void startTimer() {startTime=clock();}
void printTimer() {debug("/--- Time: %ld milliseconds ---/\n",clock()-startTime);}

int MIN[maxn*4];
inline void update(int x,int pos,int val,int L,int R){
	if (L==R){MIN[x]=val; return;}
	int mid=(L+R)/2;
	if (pos<=mid) update(x<<1,pos,val,L,mid);
	else update(x<<1|1,pos,val,mid+1,R);
	MIN[x]=min(MIN[x<<1],MIN[x<<1|1]);
}
inline int query(int x,int l,int r,int L,int R){
	if (l<=L&&R<=r) return MIN[x];
	int mid=(L+R)/2,ret=INF;
	if (l<=mid) min_(ret,query(x<<1,l,r,L,mid));
	if (mid<r) min_(ret,query(x<<1|1,l,r,mid+1,R));
	return ret;
}
char A[maxn];
int cnt[maxn],ans[maxn];
int main() {
	int i,k;
	scanf("%d%d",&n,&k);
	scanf("%s",str+1);
	scanf("%s",A+1);
	FOR(i,1,n){
		cnt[i]=cnt[i-1];
		if (A[i]!=A[i-1]) cnt[i]++;//cnt[i]
	}
	FOR(i,1,n){
		if (str[i]==A[i]) ans[i]=ans[i-1];
		else ans[i]=INF;
		int now=query(1,max(1,i-k+1),i,1,n+1);
		// printf("query: %d - %d\n",max(1,i-k+1),i);
		min_(ans[i],(cnt[i]+now)/2+1);
		update(1,i+1,2*ans[i]-cnt[i+1]+1,1,n+1);
		// printf("update: %d: %d\n",i+1,2*ans[i]-cnt[i+1]+1);
		// printf("%d ",ans[i]);
	}
	printf("%d\n",ans[n]);
}
/*
8 1
BBWBBWBW
WBBWWWBB

10 5
WWWWWWBBBB
BWBWBWBWBW
*/



Measured memory_bytes: 12228
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << ' '
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;


int main(){
    int N, diff;
    cin >> N;
    vector<int> A(N+1),M(N+1);
    loop(i,N){
        cin >> A[i+1];
    }
    A[0] = A[N];
    M[1] = 0;
    for(int i = 2;i <= N;i++){
        M[i] = A[i-1] * 2 - M[i-1];
    }

    diff = (A[N] - (M[N] + M[1])/2);
    
    loop(i,N-1){
        cout << M[i+1] + diff << " ";
        diff *= -1;
    }
    cout << M[N] + diff << endl;
}

Measured memory_bytes: 2048
H, W = map(int,input().split())
S = [list(input()) for i in range(H)]

ans = "Yes"

for h in range(H) :
    for w in range(W) :
        if S[h][w] == "#" :
            check = False
            for a in [-1,1] :
                if h+a >= 0 and S[h+a:] :
                    if S[h+a][w] == "#" :
                        check = True
            for b in [-1,1] :
                if w+b >= 0 and S[h][w+b:] :
                    if S[h][w+b]== "#" :
                        check = True
            if check == False :
                ans = "No"

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chkmax(T& a,T b){return a<b?a=b,1:0;}
template<class T> inline bool chkmin(T& a,T b){return a>b?a=b,1:0;}
template<typename T> inline T& read(T& x){
    static char c; bool flag=0;
    while(!isdigit(c=getchar())) if(c=='-') flag=1;
    for(x=c-'0';isdigit(c=getchar());(x*=10)+=c-'0');
    if(flag) x=-x;
    return x;
}
const int mo=924844033,maxn=2010;
int n,k;
int fac[maxn],f[maxn<<1][maxn][2],len,ans;
bool vis[maxn][2],flag[maxn<<1];
int main(){
	read(n); read(k);
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mo;
	for(int i=1;i<=n;i++)
		for(int j=0;j<2;j++) if(!vis[i][j]){
			vis[i][j]=1;
			int p=i,side=j;
			while(p<=n){
				p+=k; side^=1; ++len;
				if(p<=n) vis[p][side]=1;
			}
			flag[len]=1;
		}
	f[0][0][1]=1;
	for(int i=1;i<=len;i++)
		for(int j=0;j<=n;j++){
			if(j&&!flag[i-1]) f[i][j][1]=f[i-1][j-1][0];
			f[i][j][0]=(f[i-1][j][0]+f[i-1][j][1])%mo;
		}
	for(int i=0;i<=n;i++) (ans+=1ll*((i&1)?-1:1)*(f[len][i][0]+f[len][i][1])%mo*fac[n-i]%mo)%=mo;
	cout<<(ans%mo+mo)%mo<<endl;
	return 0;
}


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

int main()
{
    int input_01[255];
    int input_02[255];
    int input_id = 0;
    while(1) {
        cin >> input_01[input_id] >> input_02[input_id];
        if(input_01[input_id] == 0 && input_02[input_id] == 0) break;
        input_id++;
    }

    int draw_id = 0;
    while(draw_id < input_id) {
        for(int i = 0; i < input_01[draw_id]; i++) {
            for(int j = 0; j < input_02[draw_id]; j++) {
                if(i%2==0 && j%2==0) cout << "#";
                else if(i%2==0 && j%2==1) cout << ".";
                else if(i%2==1 && j%2==0) cout << ".";
                else cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        draw_id++;
    }

    return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>

#include<string.h>


int main(void)


{


 int sum;


 char str[1100];


 int i;


 for(i=0;i<1100;i++){


    str[i]=0;


  }


  while(1){


     scanf("%s",str);


     if(strcmp(str,"0")==0){


        break;


     }


     sum=0;


     for(i=0;str[i]!='\0';i++){


        sum+=str[i]-'0';


      }


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


   }


   return 0;


}

Measured memory_bytes: 2700
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int a = d*2+1;
    int b = n%a==0 ? n/a:n/a+1;   
    System.out.println(b);
  } 
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    int base = 1; 
  
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
  
    return dec_value; 
} 

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

    int a[n], b[n];

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

    sort(b, b+n);

    for(int i=0;i<n;i++)
    {
        if(a[i] < b[n-1]) cout << b[n-1] << "\n";
        else cout << b[n-2] << "\n";
    }

    // cout << 

    
}




Measured memory_bytes: 8960
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-17 20:08:39
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

typedef tuple<int, int, int> P;
vector<P> V;
vector<int> W;
int N;

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    int a, b;
    cin >> a >> b;
    V.push_back(P(a, b, 0));
  }
  for (auto i = 0; i < N; i++)
  {
    int a, b;
    cin >> a >> b;
    V.push_back(P(a, b, 1));
  }
  sort(V.begin(), V.end());
  int ans = 0;
  for (auto e : V)
  {
    int x = get<0>(e);
    int y = get<1>(e);
    int c = get<2>(e);
    if (c == 0)
    {
      W.push_back(y);
    }
    else
    {
      sort(W.begin(), W.end());
      reverse(W.begin(), W.end());
      for (auto it = W.begin(); it != W.end(); it++)
      {
        if (*it < y)
        {
          ans++;
          W.erase(it);
          break;
        }
      }
    }
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 256
N = gets.to_i
ary = gets.split.map(&:to_i).sort{|a, b| b <=> a}

alice_sum = 0
bob_sum = 0
1.upto(N) do |n|
    if n.odd?
        alice_sum += ary[n - 1]
    else
        bob_sum += ary[n - 1]
    end
end

print alice_sum - bob_sum


Measured memory_bytes: 1788
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
            b[i] = scan.nextInt();
            c[i] = scan.nextInt();
        }
        int[][] dp = new int[n + 1][3];
        for(int i = 0; i < n; i++){
            dp[i + 1][0] = Math.max(dp[i][1] + b[i], dp[i][2] + c[i]);
            dp[i + 1][1] = Math.max(dp[i][0] + a[i], dp[i][2] + c[i]);
            dp[i + 1][2] = Math.max(dp[i][0] + a[i], dp[i][1] + b[i]);
        }
        System.out.println(Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2])));
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 61164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,d,x;cin >> n >> d >> x;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	int sum=0;
	rep(i,n){
		for(int j=1;j<=d;j+=a.at(i)){
			sum++;
		}
	}
	cout << x+sum << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
if n>=m:
    print(0)
    exit()
dis = [x[i+1]-x[i] for i in range(m-1)]
dis.sort()
if n>1:
    del dis[-(n-1):]
print(sum(dis))

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

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/


int main(){
  ll k, s;
  cin >> k >> s;
  
  ll count = 0;
  
  rep(i,k+1){
    rep(j,k+1){
		if(s-i-j>=0 && s-j-i <= k) count ++;
    }
  }

	cout << count << endl;
  

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
    int N;
    cin >> N;
    map<string, int> map;
    int maxv=0;
    rep(i, N)
    {
        string s;
        cin >> s;
        map[s]++;
        chmax(maxv, map[s]);
    }
    for (auto it = map.begin(); it != map.end();it++){
        if(it->second==maxv){
            cout << it->first << endl;
        }
    }
        return 0;
}

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


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a <= c && d <= b) {
		cout << d - c << endl;
		return 0;
	}

	if (c <= a && b <= d) {
		cout << b - a << endl;
		return 0;
	}

	cout << max(0, min(d - a, b - c)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)

using ll = int64_t;
using ld = long double;

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

constexpr ll inf = 2e18;
constexpr int M = 1e9 + 7;

constexpr int N = 301;
ld E[N][N][N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	int c[3] = {0, 0, 0};
	rep(i, 0, n) { int a; cin >> a; --a; ++c[a]; }
	
	rep(k, 0, n + 1)
		rep(j, 0, n + 1)
			rep(i, 0, n + 1) {
				ll s = i + j + k;
				if (n < s) break;
				if (s == 0) continue;
				auto &x = E[i][j][k];
				x = n;
				if (i > 0) x += i * E[i - 1][j][k];
				if (j > 0) x += j * E[i + 1][j - 1][k];
				if (k > 0) x += k * E[i][j + 1][k - 1];
				x /= s;	
			}
	cout << fixed << setprecision(18) << E[c[0]][c[1]][c[2]];
}

Measured memory_bytes: 426240
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

char a, b, c, d;
int ans;

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	cin >> a >> b >> c >> d;
	a -= '0';
	b -= '0';
	c -= '0';
	d -= '0';
	lp(2) {
		lop(2, j) {
			lop(2, k) {
				int ans = a;
				if (i)ans += b;
				else ans -= b;
				if (j)ans += c;
				else ans -= c;
				if (k)ans += d;
				else ans -= d;
				if (ans == 7) {
					cout << int(a) << (i ? '+' : '-') << int(b) << (j ? '+' : '-') << int(c) << (k ? '+' : '-') << int(d)<< "=7" << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))
last = [0] * 26
ans = []
S = []
prev_score = 0
maxsi_list = []

for d in range(1, D+1):
    s = list(map(int, input().split()))
    S += [s]
    maxs = float('-inf')
    maxss = float('-inf')
    maxi = -1
    maxii = -1
    cumsump = 0
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        cumsump += tmp
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        tmp2 = s[i] + cumsump - tmp
        if tmp2 > maxs:
            maxs = tmp2
            maxi = i
        if s[i] > maxss:
            maxii = i
            maxss = s[i]
    ans += [maxi+1]
    last[maxi] = d
    prev_score += maxs
    maxsi_list += [maxii+1]
best_ans = ans
best_score = prev_score
mergin = 1300
# mergin = 13000
for tt in range(31):
    for dd in range(D):
        last = [0] * 26
        score = 0
        for d in range(1, D+1):
            if dd == (d-1):
                maxc = 0
                maxci = -1
                for i in range(26):
                    cost = c[i] * (d - last[i])
                    if maxc < cost:
                        maxc = cost
                        maxci = i+1
                prev_a = ans[dd]
                ans[dd] = maxci
            td = ans[d-1] - 1
            cumsump = 0
            for i in range(26):
                if td != i:
                    tmp = -c[i] * (d - last[i])
                    cumsump += tmp
            last[td] = d
            score += S[d-1][td]+cumsump
        # if score <= prev_score-mergin:
        if score <= best_score-mergin:
            ans[dd] = prev_a
        elif best_score < score:
            best_ans = ans
            best_score = score
            prev_score = score
        else:
            prev_score = score

    for dd in range(D):
        last = [0] * 26
        score = 0
        prev_a = ans[dd]
        ans[dd] = maxsi_list[dd]
        for d in range(1, D+1):
            td = ans[d-1] - 1
            cumsump = 0
            for i in range(26):
                if td != i:
                    tmp = -c[i] * (d - last[i])
                    cumsump += tmp
            last[td] = d
            score += S[d-1][td]+cumsump
        # if score <= prev_score-mergin:
        if score <= best_score-mergin:
            ans[dd] = prev_a
        elif best_score < score:
            best_ans = ans
            best_score = score
            prev_score = score
        else:
            prev_score = score

for a in best_ans:
    print(a)

Measured memory_bytes: 73376
n = int(input())
a = list(map(int, input().split( )))

a.sort()

if n%2==0:
    a.sort()
    for i in range(n//2):
        if a[i*2]!=a[i*2+1] or a[i*2]!=2*i+1 or a[i*2+1]!=2*i+1:
            print(0)
            exit()
    print(pow(2,n//2,10**9+7))
else:
    a.append(0)
    a.sort()
    for i in range(n//2):
        if a[i*2]!=a[i*2+1] or a[i*2]!=i*2 or a[i*2+1]!=i*2:
            print(0)
            exit()
    print(pow(2,n//2,10**9+7))
        

Measured memory_bytes: 52332
S = input()
flg = False
for i in range(len(S)):
    if i % 2 != 0:
        if S[i] in ["L", "U", "D"]:
            continue
        else:
            flg = True
    else:
        if S[i] in ["R", "U", "D"]:
            continue
        else:
            flg = True

if flg:
    print("No")
else:
    print("Yes")

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

using namespace std;

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

int main() {
  int N, K;
  cin >> N >> K;

  vector<int> fruits(N);
  Rep(n, N) cin >> fruits[n];

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

  int answer = 0;
  Rep(k, K) {
    answer += fruits[k];
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;

namespace AtCoder
{
    public class Solver
    {
        private readonly IInputReader _inputReader;
        private readonly IOutputWriter _outputWriter;

        public Solver(IInputReader inputReader, IOutputWriter outputWriter)
        {
            _inputReader = inputReader;
            _outputWriter = outputWriter;
        }

        public void Solve()
        {
            var numbers = _inputReader.ReadLine().ToIntArray().ToList();
            var n = numbers[0];
            var k = numbers[1];
            var dList = string.Join("", _inputReader.ReadLine().ToIntArray().Select(i => i.ToString()).ToArray());

            var price = n;
            while (true)
            {
                var str = price.ToString();
                var ng = false;
                foreach (var c in str)
                {
                    if (dList.Contains(c))
                    {
                        ng = true;
                        break;
                    }
                }
                
                if (!ng)
                {
                    break;
                }

                price++;
            }

            _outputWriter.WriteLine(price.ToString());
        }
    }


    internal class Program
    {
        static void Main(string[] args)
        {
            var reader = new ConsoleInputReader();
            var writer = new ConsoleOutputWriter();
            new Solver(reader, writer).Solve();
        }
    }

    public interface IInputReader
    {
        string ReadLine();
    }

    public interface IOutputWriter
    {
        void WriteLine(string output);
    }

    internal class ConsoleInputReader : IInputReader
    {
        public string ReadLine() => Console.ReadLine();
    }

    internal class ConsoleOutputWriter : IOutputWriter
    {
        public void WriteLine(string output) => Console.WriteLine(output);
    }

    public static class StringExtensions
    {
        public static char ToChar(this string text) => text[0];
        public static int ToInt(this string text) => int.Parse(text);
        public static int[] ToIntArray(this string text) => text.Split(' ').Select(txt => txt.ToInt()).ToArray();
        public static long ToLong(this string text) => long.Parse(text);
        public static long[] ToLongArray(this string text) => text.Split(' ').Select(txt => txt.ToLong()).ToArray();
    }
}

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

class Main
{

    public static void main(String args[])throws IOException
    {
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	int N = Integer.parseInt(in.readLine());
	int[][] C = new int[N][N];
	String line;
	for(int i=0;i<N;i++)
	    {
		line = in.readLine();
		for(int j=0;j<N;j++){
		    String[] elements = line.split(" ");
		    C[i][j] = Integer.parseInt(elements[j]);
		}
	    }
	      
	    
	long cost = 0;

	for(int i=0;i<N;i++)
	    for(int j=i+1;j<N;j++)
		cost += Math.min(C[i][j],C[j][i]);

	System.out.println(cost);
    }

}

Measured memory_bytes: 67028
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	A := make([][]int, N)
	for i := 0; i < N; i++ {
		A[i] = make([]int, N)
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			fmt.Scan(&A[i][j])
		}
	}
	ans := 0
	var change bool
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			cost := A[i][j]
			for k := 0; k < N; k++ {
				if i == k || j == k {
					continue
				}
				if A[i][j] > A[i][k]+A[k][j] {
					change = true
				}
				if A[i][j] == A[i][k]+A[k][j] {
					cost = 0
				}
			}
			ans += cost
		}
	}
	if change {
		fmt.Println(-1)
		return
	}
	// fmt.Println(kruskal())
	fmt.Println(ans)
}


Measured memory_bytes: 5504
import math
A,B,H,M = map(float,input().split())

kaku = min(abs(30*(H+M/60)-6*M),360-abs(30*(H+M/60)-6*M))
if kaku == 180:
    print(A+B)
    exit()
cos = math.cos(math.radians(kaku))

ans = math.sqrt(A*A+B*B-2*A*B*cos)
print(ans)


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL N, M;
    cin >> N >> M;
    LL K;
    cin >> K;
    vector<LL> a(N), b(M + 1);
    b[0] = 0;
    for(int i = 0; i < N; ++i) cin >> a[i];
    for(int j = 1; j <= M; ++j) {
        cin >> b[j];
        b[j] += b[j - 1];
    }

    LL res = 0;
    LL sum = 0;
    for(int i = 0; i < N; ++i) {
        if(sum > K) continue;
        LL p = lower_bound(all(b), K - sum) - b.begin();
        if(b[p] + sum > K && p > 0 || p > M) p--;
        res = max(res, i + p);
        sum += a[i];
    }

    if(sum <= K) {
        LL p = lower_bound(all(b), K - sum) - b.begin();
        if(b[p] + sum > K && p > 0 || p > M) p--;
        res = max(res, N + p);
    }
    cout << res << endl;
    return 0;
}


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

int main(){
  string str;
  cin >> str;
  int len = 0, first, end;
  for(int i = 0; i < str.size(); i++){
    if(str.at(i) == 'A'){
      first = i;
      break;
    }
  }
  for(int i = 0; i < str.size(); i++){
    if(str.at(i) == 'Z'){
      end = i;
    }
  }
  cout << end - first + 1 << endl;
}
    

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

		int x = sc.nextInt();
		int y = sc.nextInt();

		if((x-1)*(x-3)*(x-5)*(x-7)*(x-8)*(x-10)*(x-12) == 0 &&
				(y-1)*(y-3)*(y-5)*(y-7)*(y-8)*(y-10)*(y-12) == 0) {
				//|| (x-4)*(x-6)*(x-9)*(x-11) == 0 ||
				//(y-4)*(y-6)*(y-9)*(y-11) == 0)
			System.out.println("Yes");
		}else if((x-4)*(x-6)*(x-9)*(x-11) == 0 &&
				(y-4)*(y-6)*(y-9)*(y-11) == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


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

int main() {
string S;
  int c=0;
  cin>>S;
 for(int i=0;i<3;i++){
     if(S[i]==S[i+1]){
     c++;
     }
   }
  if(c){
    cout<<"Bad";
  }
  else{
    cout<<"Good";
  }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    while(true){
        string s;
        cin>>s;
        if(s=="0") break;
        ll ans=0;
        FORR(i,0,s.size()){
            ans += (s[i]-48);
        }

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


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  int n=a.size();
  int b;
  int c;
  for(int i=0;i<n;i++){
    if(a[i]=='A'){
      b=i;
      break;
      }
    }
  for(int i=n-1;i>0;i--){
    if(a[i]=='Z'){
      c=i;
      break;
      }
    }
  cout<<c-b+1<<endl;
  return 0;
}   

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

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

    vector<long long>a(n+1);
    vector<long long>aa(n+1,0);
    rep2(i,1,n+1){
        cin>>a[i];
        aa[i]=a[i]+aa[i-1];
    }

    long long cnt=0,ans=0;

    sort(aa.begin(),aa.end());
    rep2(i,1,n+1){
        if(aa[i-1]==aa[i]){
            cnt++;
            ans+=cnt;
        }
        else {
            cnt=0;
        }
    }

    cout<<ans<<endl;
}


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

int main()
{
    long long n; 

    cin>>n; 

    long long int a[n],p = pow(10 ,9) + 7,sum =0,prod =0;


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

    for(int i=0  ; i<n;i++ )
    {
        sum -= a[i];

        if(sum < 0 )
        sum += p; 


        prod += sum*a[i];
        prod %= p ; 


    }

    

    cout<<prod; 


}

Measured memory_bytes: 5032
#!/usr/bin/ruby
N,M,*X=`dd`.split.map(&:to_i)
h=Hash.new{|h,k|h[k]=[]}
X.each{|e|
	h[e%M]<<e
}
r=0
pairs=[0]*M
(0..M/2).each{|i|
	opp=M-i
	opp=0 if opp==M
	if i==opp
		npairs=h[i].size/2
		pairs[i]=npairs*2
		r+=npairs
	else
		npairs=[h[i].size,h[opp].size].min
		pairs[i]=pairs[opp]=npairs
		r+=npairs
	end
}
(0...M).each{|i|
	s=h[i].group_by{|e|e}.reduce(0){|s,(k,v)|s+v.size/2}
	r+=[(h[i].size-pairs[i])/2,s].min
}
p r

Measured memory_bytes: 28032
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int c[5][5];
  int a[5],b[5];

  for(int t=1;t<=3;t++){
    for(int i=1;i<=3;i++){
      cin>>c[t][i];
    }
  }

  b[1]=c[1][1],b[2]=c[1][2],b[3]=c[1][3];
  a[2]=c[2][1]-b[1],a[3]=c[3][1]-b[1],a[1]=0;

  bool flag=true;
  for(int i=1;i<=3;i++){
    for(int j=1;j<=3;j++){
      if(a[i]+b[j]!=c[i][j]){
        flag=false;
        break;
      }
    }
  }

  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

#define rep(loop, N) for (int loop = 0; loop < N; loop++)

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Red_or_Not(void) {

	int a; string s; cin >> a >> s;

	cout << (a >= 3200 ? s : "red") << flush;
	return;
}

void B_Resistors_in_Parallel(void) {

	int N; cin >> N;
	double denominator = 0;
	rep(loop, N) {
		int A; cin >> A;
		denominator += (1.0 / A);
	}

	cout << setprecision(20) << 1.0 / denominator << flush;
	return;
}

int main(void) {
	
	//A_Red_or_Not();
	B_Resistors_in_Parallel();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int N = 111;

int n;
vi g[N];

int maxdep;
ll leaf[N];
int have[N], child[N], dd[N];

void dfs(int u, int dep, int par) {
	dd[u] = dep;
	FOR(i,SZ(g[u])) {
		int v = g[u][i];
		if (v == par) continue;
		have[u]++;
		dfs(v, dep+1, u);
	}
	child[dep] = max(child[dep], have[u]);
	maxdep = max(maxdep, dep);
}

int main() {
	scanf("%d", &n);
	FOR(i,n-1) {
		int a,b;
		scanf("%d%d", &a, &b);
		a--; b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	int bestdep = n+1;
	ll res = 0;
	FOR(i,n) {
		FOR(j,n+2) {
			child[j] = 0;
			have[j] = 0;
		}
		maxdep = 0;
		dfs(i, 0, -1);
		leaf[maxdep] = 1;
		for (int d = maxdep-1; d >= 0; d--) {
			leaf[d] = leaf[d+1] * child[d];
		}
		ll cur = leaf[0];
		//printf("%d : %d %lld\n", i, maxdep, cur);
		//FOR(j,n) printf("%d ", child[j]); printf("\n");
		//FOR(j,n) printf("%d ", leaf[j]); printf("\n");
		if (maxdep < bestdep || (maxdep == bestdep && res > cur)) {
			bestdep = maxdep;
			res = cur;
		}
	}
	FOR(u,n) FOR(k,SZ(g[u])) {
		int v = g[u][k];
		FOR(j,n+2) {
			child[j] = 0;
			have[j] = 0;
		}
		maxdep = 0;
		dfs(u,0,v);
		dfs(v,0,u);
		leaf[maxdep] = 1;
		for (int d = maxdep-1; d >= 0; d--) {
			leaf[d] = leaf[d+1] * child[d];
		}
		ll cur = leaf[0]*2;
		//printf("%d,%d : %d %lld\n", u, v, maxdep, cur);
		//FOR(j,n) printf("%d ", child[j]); printf("\n");
		//FOR(j,n) printf("%d ", leaf[j]); printf("\n");
		if (maxdep < bestdep || (maxdep == bestdep && res > cur)) {
			bestdep = maxdep;
			res = cur;
		}
	}
	printf("%d %lld\n", bestdep+1, res);
	return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)
    
    from itertools import accumulate

    n, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    check = [n] * n
    for i in range(k):
        memo = [0] * (n + 1)
        for j, aa in enumerate(a):
            memo[max(0, j - aa)] += 1
            memo[min(n, j + aa + 1)] -= 1
        a = list(accumulate(memo))[:-1]
        if a == check:
            break
    print(*a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 204252
#include <iostream>
#include <vector>

class union_find {
	int M;
	std::vector<int> parent, sz;

public :
	const int N;

	union_find(const int& n) : N(n), M(n) {parent.resize(N, -1); sz.resize(N, 1);}

	inline const int& size(const int& i) {return sz[root(i)];}
	inline const int& count_trees()const{return M;}

	int root(const int& i) {
		if (parent[i] == -1) return i;
		return parent[i] = root(parent[i]);
	}

	inline bool is_united(const int& i, const int& j) {return (root(i) == root(j));}

	bool unite(int i, int j) {
		if (is_united(i, j)) return false;
		if (size(i) < size(j)) std::swap(i, j);
		i = root(i); j = root(j);
		parent[j] = i;
		sz[i] += sz[j];
		M--;
		return true;
	}
};

int main() {
	int n, m;
	std::cin >> n >> m;
	union_find uf(n);
	while (m--) {
		int a, b;
		std::cin >> a >> b;
		uf.unite(a - 1, b - 1);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) ans = std::max(ans, uf.size(i));
	std::cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 4796
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] in = new int[3];
		for(int i = 0; i < 3; i++) {
			in[i] = sc.nextInt();
		}

		Arrays.sort(in);
		
		if(in[0] == 5 && in[1] == 5 && in[2] == 7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> u(n-1), v(n-1), w(n-1);
    REP(i, n-1) cin >> u[i] >> v[i] >> w[i];
    REP(i, n-1) u[i]--, v[i]--;


    vector<vector<int>> tree(n);
    vector<map<int, int>> dis(n);

    REP(i, n-1)
    {
        tree[u[i]].pb(v[i]);
        tree[v[i]].pb(u[i]);
        dis[u[i]][v[i]] = w[i];
        dis[v[i]][u[i]] = w[i];
    }

    vector<int> ans(n);
    vector<bool> used(n, false);
    queue<int> que;
    que.push(0);
    used[0] = true;
    ans[0] = 0;
    while(!que.empty())
    {
        queue<int> cur;
        while(!que.empty())
        {
            int top = que.front();
            que.pop();
            for (auto x : tree[top]) if (!used[x])
            {
                ans[x] = (dis[x][top] % 2 == 0 ? ans[top] : (ans[top] + 1) % 2);
                used[x] = true;
                cur.push(x);
            }
        }
        que = cur;
    }
    REP(i, n) cout << ans[i] << endl;
}


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

int main(){
  	int N,ans=0;
  	string S;
  	cin >> N >> S;
  	for(int i=0; i<N-2; i++){
    	if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
        	ans++;
        }
    }
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>


using namespace std;

#define debug false

int main(int argc, char *argv[]){

  int N;
  cin >> N;
  int tmp;
  int counter = 0;
  map<int, int> mp;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    if(mp[tmp] == 0){
      counter++;
      mp[tmp]++;
    }else{
      mp[tmp] = 0;
      counter--;
    }
  }
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
vector<ll> vec;
int n;
bool judge(){
  bool f=true;
  for(int i=0;i<n;i++){
    if(vec[i]>=n) f=false;
  }
  return f;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    vec.push_back(a);
  }
  ll ans=0;
  while(!judge()){
    sort(vec.begin(),vec.end());
    ll ma=vec[n-1]-n+1;
    ll cn=ma/n+(ma%n==0?0:1);
    ans+=cn;
    for(int i=0;i<n-1;i++) vec[i]+=cn;
    vec[n-1]-=cn*n;
  }
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

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

	int k, x;
	cin >> k >> x;

	for(int i = x - k + 1; i <= x + k - 1; i++){
		cout << i;
		cout << (i == x + k - 1 ? "\n" : " ");
	}
}


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

using namespace std;

int limit = 1e6 ;
double ar[(int) 1e6 + 20];

int main(){
	int n , x, t;
	cin >> n >> x >> t;
	int p = (n + x - 1) / x;
	cout << p * t << endl;
}


Measured memory_bytes: 3604
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
	int u, minv;
	int d[MAX], p[MAX], color[MAX];

	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
	}

	d[0] = 0;

	while (1) {
		minv = INFTY;
		u = -1;
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1)break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK&&M[u][v] != INFTY) {
				if (d[v] > M[u][v]) {
					d[v] = M[u][v];
					p[v] = u;
					color[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != -1)sum += M[i][p[i]];
	}

	return sum;
}

int main() {
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int e;
			cin >> e;
			M[i][j] = (e == -1) ? INFTY : e;
		}
	}

	cout << prim() << endl;

	return 0;
}


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

class node;
node *root, *NIL;

class node{
public:
  node *p = NIL, *l = NIL, *r = NIL;
  int key = 0;

  node(int x, node*parent) : key(x), p(parent){}
};


void insert(int key){
  node *x = root, *y = NIL;
  while(x != NIL){
      y = x;
      if(key >= x->key) x = x->r;
      else x = x->l;
  }

  if(y == NIL) root = new node(key, NIL);
  else if(key >= y->key) y->r = new node(key, y);
  else y->l = new node(key, y);
}

node* find(int key){
  node* x = root;

  while(x != NIL && x->key != key){
    if(key >= x->key) x = x->r;
    else x = x->l;
  }

  return x;
}


node* getMinimum(node* x){
  if(x == NIL) return NIL;
  while(x->l != NIL) x=x->l;
  return x;
}
node* getSuccesser(node* x){
  if(x == NIL) return NIL;
  if(x->r != NIL) return getMinimum(x->r);

  node* p = x->p;
  while(p != NIL && x != p->l){
    x = p;
    p = p->p;
  }
  return p;
}

void deleteNode(node* x){
  if(x == NIL) return;
  node *a = x, *b = NIL;

  if(x->l != NIL && x->r != NIL) a = getSuccesser(x);

  if(a->l != NIL) b = a->l;
  else b = a->r;

  if(b != NIL) b->p = a->p;

  node* p = a->p;
  if(p == NIL) root = b;
  else if(p->l == a) p->l = b;
  else p->r = b;

  if(x != a) x->key = a->key;
}

void preorder(node* n){
  if(n == NIL) return;
  cout << " " << n->key;
  preorder(n->l);
  preorder(n->r);
}

void inorder(node* n){
  if(n == NIL) return;
  inorder(n->l);
  cout << " " << n->key;
  inorder(n->r);
}

void print(){
  inorder(root);
  cout << endl;
  preorder(root);
  cout << endl;
}

int main(){
  root = NIL;

  int n; cin >> n;
  while(n--){
    string s; cin >> s;

    if(s == "insert"){
      int x; cin >> x;
      insert(x);
    }else if(s == "find"){
      int x; cin >> x;
      if(find(x) != NIL) cout << "yes" << endl;
      else cout << "no" << endl;
    }else if(s == "delete"){
      int x; cin >> x;
      deleteNode(find(x));
    }else{
      print();
    }
  }
}



Measured memory_bytes: 21960
#include <bits/stdc++.h>
using namespace std;
int n,m,x,i,j,a[111],c[111];
int main() {
  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%d",&a[i]);
    m=max(m,a[i]);
    c[a[i]]++;
  }
  if (m==1) {
    puts(n==2?"Possible":"Impossible");
    return 0;
  }
  for (x=m, i=0; i<=m; i++) {
    j=max(i,m-i);
    x=min(j,x);
    if (--c[j]<0) {
      puts("Impossible");
      return 0;
    }
  }
  for (i=0; i<n; i++) if (a[i]<=x && c[a[i]]>0) {
    puts("Impossible");
    return 0;
  }
  puts("Possible");
  return 0;
}


Measured memory_bytes: 256