akhauriyash/Code-Regression huggingface dataset:
#include <iostream>//cout
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>//swap
using namespace std;
static const int MAX = 200000;
#define rep(i,n) for(int i=0;i<n;i++)
#define GET_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
int main() {
  long long int n, h;
  string x, y, z;
  cin >> x >> y;
  z = x + y;
  int num = std::atoi(z.c_str());
  for (int i = 1; i < 10000; i++) {
    if (i*i == num) { 
      cout << "Yes" << endl;
      return 0;
	}
  }
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = Integer.parseInt(scn.next());
		int m = Integer.parseInt(scn.next());

		System.out.println((n + m) % 24);

		scn.close();
	}
}


Measured memory_bytes: 21716
def main():
    n = int(input())
    S = input()
    left_shortage = 0
    now = 0
    for s in S:
        if s == "(":
            now += 1
        else:
            now -= 1
            left_shortage = min(now, left_shortage)

    right_shortage = 0
    now = 0
    for s in S[::-1]:
        if s == ")":
            now += 1
        else:
            now -= 1
            right_shortage = min(now, right_shortage)

    print("("*-left_shortage + S + ")"*-right_shortage)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
import bisect
import collections

def read():
    N = int(input().strip())
    S = str(input().strip())
    return N, S


def solve(N, S):
    d = [collections.deque() for i in range(10)]
    count = 0
    for i in range(N):
        s = int(S[i])
        d[s].append(i)
    for p in range(1000):
        T = '{:03d}'.format(p)
        p0 = int(T[0])
        p1 = int(T[1])
        p2 = int(T[2])
        k0 = 0
        if len(d[p0]) > k0:
            idx0 = d[p0][k0]
            k1 = bisect.bisect_left(d[p1], idx0+1)
            if len(d[p1]) > k1:
                idx1 = d[p1][k1]
                k2 = bisect.bisect_left(d[p2], idx1+1)
                if len(d[p2]) > k2:
                    idx2 = d[p2][k2]
                    if  S[idx0] + S[idx1] + S[idx2] == T:
                        count += 1
    return count
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)


Measured memory_bytes: 40560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

bool arr[1000100];

bool prime = true;
set<ll> s;

void init(){ 
  
  
  for(ll i = 0; i < 1000100; i++){
    arr[i] = true;}
  
  arr[0] = false; arr[1] = false;
  
  
  for(ll i = 0; i < 1000100; i++){ 
    if( arr[i]){ 
      for(ll j = 2; i*j < 1000100; j++){
        arr[i*j] = false;} //10^6ぐらいまでの素因数列挙
    }
  }
}

void disjoint(ll N){
  ll M = N;
  if( M == 1){ prime = false; return;}
  ll c = (ll)sqrt(M);
  
  for(ll i = 1; i <= c; i++){
    if( !arr[i]){ continue;}
    while( M % i == 0){ s.insert(i); prime = false; M/= i;}
  }
  
  if( M != 1){ s.insert(M);}
  
  return;
}
  
  
  



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

int main(){
  ll A,B; cin >> A >> B; ll C = gcd( A,B);
  
  init();
  
  // 次に、Cの素因数の個数を数える
  
  disjoint(C);
  
  if(prime){ cout << 2 << endl;}
  else{
    cout << s.size()+1 << endl;}
  
 
  
  return 0;
  
  
  
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin>>n;
    map<ll,ll>mp;
    map<ll,ll>mp1;
    ll c=0;
    mp[n]++;
    while(1)
    {
        if(mp[n]==2)
        break;
        if(n%2)
        {
        n=3*n+1;
        //cout<<n<<endl;
        mp[n]++;
        }
        else
        {
          n/=2; 
          //cout<<n<<endl;
        mp[n]++;
        
        }
        c++;
    }
    cout<<c+1<<endl;
}

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

const int MAX = 1000000;
const int INF = 1<<29;

int main() {
    vector<int> dp(MAX, INF), odddp(MAX, INF);
    dp[0] = odddp[0] = 0;
    for (int i = 1;; ++i) {
        int num = i * (i+1) * (i+2) / 6;
        if (num >= MAX) break;
        for (int j = num; j < MAX; ++j) {
            dp[j] = min(dp[j], dp[j-num]+1);
            if (num % 2 == 1) odddp[j] = min(odddp[j], odddp[j-num]+1);
        }
    }
    int n;
    while (cin >> n) {
        if (n == 0) break;
        cout << dp[n] << " " << odddp[n] << endl;
    }
}


Measured memory_bytes: 10576
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int main(){
	ll n,ans=0;
	cin>>n;
	ll p = 1;
	ll fl = 0;
	if(n<10){
		cout<<n<<endl;
		return 0;
	}
	while( p*10 <= n){ p=p*10;}
	while( p>0 && n / p == 9){
		fl = 1;
		ans+=9;
		n = n - p*9;
		p = p/10;
	}
	if(p==0){
		cout<<ans<<endl;
		return 0;
	}
	else{
		if(fl==0){
			ans+=n/p;
			n = n - p*(n/p);
			p = p/10;
			ll f=1;
			while(p>0){
				ans+=9;
				if(n/p != 9)f=0;
				n = n - p*(n/p);
				p = p/10;
			}
			if(f==0)ans--;
			cout<<ans<<endl;
			return 0;
		}
		else{
			ans--;
			while(p>0){
				ans+=9;
				p = p/10;
			}
			cout<<ans<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
main(){
  int i, j, k, l, m = 0, A[N];
  scanf("%d", &k);
  for(i = 0;i < k;i++){
    scanf("%d", &A[i]);
  }
  for(i = 0;i < k;i++){
    for(j = k-1;j > i;j--){
      if(A[j] < A[j-1]){
	l = A[j];
	A[j] = A[j-1];
	A[j-1] = l;
	m++;
      }
    }
  }
  for(i = 0;i < k-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n", A[k-1], m);
  return 0;
}

Measured memory_bytes: 600
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

// 約数のvectorを返す
vector<ll> divisor(ll n) {
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != n / i) ret.push_back(n / i);
        }
    }
    return ret;
}

int main() {
    ll n;
    cin >> n;
    auto div = divisor(n);

    int ans = 10;
    for (ll d : div) {
        int f = max(to_string(d).size(), to_string(n / d).size());
        ans = min(ans, f);
    }

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

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  ll root=pow(n,0.5);
  if(n==1){
    cout << 0 << endl;
    return 0;
  }
  ll sum=0;
  for(int i=1; i<=root; i++){
    if(n%i==0){
      ll like=n/i-1;
      ll ans=n/like;
      ll remain=n%like;
      if(ans==remain)sum+=like;
      like=i;
      ans=n/like;
      remain=n%like;
      if(ans==remain)sum+=like;
    }
  }
  cout << sum << endl;
}
  
  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    --a;
    --b;
    --c;
    --d;

    string s;
    cin >> s;

    for (auto i : irange(a + 1, c - 1)) {
        if (s[i] == '#' && s[i + 1] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }

    for (auto i : irange(b + 1, d - 1)) {
        if (s[i] == '#' && s[i + 1] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }

    if (d < c) {
        for (auto i : irange(b, d + 1)) {
            if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    } else {
        cout << "Yes" << endl;
        return 0;
    }
}

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

int gcd(int a,int b){return b>0?gcd(b,a%b):a;}

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<a/gcd(a,b)*b<<endl;
}

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

int x, y, a, b, c, r[100005], g[100005], w[100005], p;
vector <int> v;
long long ans;

int main(){
    cin >> x >> y;
    cin >> a >> b >> c;
    for (int i = 0; i < a; i++){
        cin >> r[i];
    }
    for (int i = 0; i < b; i++){
        cin >> g[i];
    }
    for (int i = 0; i < c; i++){
        cin >> w[i];
    }
    sort(r, r+a);
    reverse(r, r+a);
    sort(g, g+b);
    reverse(g, g+b);
    sort(w, w+c);
    reverse(w, w+c);
    for (int i = 0; i < x; i++){
        ans += r[i];
        v.push_back(r[i]);
    }
    for (int i = 0; i < y; i++){
        ans += g[i];
        v.push_back(g[i]);
    }
    sort(v.begin(), v.end());
    for (int i:v){
        if (i < w[p]){
            ans -= i;
            ans += w[p];
            p++;
        }
        else break;
    }
    cout << ans << "\n";
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  
  int min = 1000000000;
  int min_index = -1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] < min) {
      min = a[i];
      min_index = i;
    }
  }

  while (true) {
     int next_min_index = -1;
     int next_min = min;
     for (int i = 0; i < n; ++i) {
       if (i == min_index) continue;
       a[i] %= min;
       if (a[i] > 0 && a[i] < next_min) {
         next_min = a[i];
         next_min_index = i;
       }
     }
     if (next_min_index == -1)
       break;
     min = next_min;
     min_index = next_min_index;
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

#define NIL -2000000001

typedef struct heap{
  int k;
  int pk;
  int lk;
  int rk;
}Heap;

int H;

void maxHeapify(Heap* A,int i){
  int l,r,largest,x;
  l = 2*i;
  r = 2*i+1;
  if ((l <= H) &&( A[l].k > A[i].k))
    largest = l;
  else 
    largest = i;
  if ((r<= H)&&( A[r].k > A[largest].k))
    largest = r;
  if (largest != i){
    x=A[i].k;
    A[i].k=A[largest].k;
    A[largest].k=x;
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(Heap* A){
  int i;
  for (i=H/2;i>=1;i--){
    maxHeapify(A, i);
  }
}

int main(){
  Heap A[500000];
  int i,p,r,l;
  
  scanf("%d",&H);

  for(i=1;i<=H;i++){
    scanf("%d",&A[i].k);
  }

  for(i=1;i<=H;i++){
    p=i/2;
    l=2*i;
    r=2*i+1;
    
    if(p!=0)
      A[i].pk=A[p].k;
    else
      A[i].pk=NIL;
    

    if(r<=H)
      A[i].rk=A[r].k;
    else
      A[i].rk=NIL;

    
    if(l<=H)
      A[i].lk=A[l].k;
    else
      A[i].lk=NIL;
  }

  buildMaxHeap(A);

  for(i=1;i<=H;i++){
    printf(" %d",A[i].k);
  }
    
    printf("\n");

  return 0;
}



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

#define int long long

const int N = 1e2+5 , M = 1e5+5;

int n , m , r , w[N] , v[N] , dp[N][M];

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

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

  for(int i = 1 ; i <= n ; i++){
    for(int j = 0 ; j < w[i] ; j++) dp[i][j] = max(dp[i-1][j],dp[i][j]);
    for(int j = w[i] ; j < M ; j++) 
      dp[i][j] = max(dp[i-1][j-w[i]]+v[i],max(dp[i-1][j],dp[i][j]));
  }

  for(int i = 0 ; i <= m ; i++) r = max(r,dp[n][i]);

  cout << r << "\n";

}


Measured memory_bytes: 81644
def main():
    n, m = map(int, input().split())
    s = []
    k = []
    for mm in range(m):
        s_ = list(map(int, input().split()))
        k += [s_.pop(0)]
        s += [s_]
    p = list(map(int, input().split()))

    count_ = []
    light_ = []
    ans = 0
    for i in range(2 ** n):
        light = 0
        for mm in range(m):
            count = 0
            for nn in range(n):  # このループが一番のポイント
                if ((i >> nn) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                    if (nn + 1) in s[mm]:
                        count += 1
            count_ += [count]
            if count % 2 == p[mm]:
                light += 1
        light_ += [light]
        if light == m:
            ans += 1
    # print(count_)
    # print(light_)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<ll> num(n,0);
    vector<ll> ans(q,0);
    ll count=0;
    for(int i=0;i<n-1;i++){
        if(s[i]=='A' && s[i+1]=='C'){
            count++;
        }
        num[i+1]=count;
    }
    for(int i=0;i<q;i++){
        ll l,r;
        cin>>l>>r;
        l--; r--;
        ans[i]=num[r]-num[l];
    }
    for(int i=0;i<q;i++) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 2688
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif


#ifdef _DEBUG
void init_global_C() { }
#else

#endif


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

    int N; cin >> N;
    vvvi F(N, vvi(5, vi(2, 0)));
    REP(i, N)
        REP(j, 5)
            cin >> F[i][j][0] >> F[i][j][1];

    vvi P(N, vi(11, 0));
    REP(i, N)
        REP(j, 11)
            cin >> P[i][j];

    int M = 0x01 << 10;
    int ans = -INF;
    FOR(i, 1, M) {
        int p = i;
        int mask = 0x01;
        vi cnt(N, 0);
        REP(j, 10) {
            if (p & mask) {
                REP(k, N) {
                    if (F[k][j / 2][j % 2]==1) cnt[k]++;
                }
            }
            mask <<= 1;
        }

        int profit = 0;
        REP(i, N) profit += P[i][cnt[i]];

        ans = max(ans, profit);
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int Q = sc.nextInt();
        int[][] train = new int[N+1][N+1];
        int[] count = new int[Q];
        for(int i = 0; i < M; i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            train[L][R] ++;
        }
        for (int i = 0; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                train[i][j] += train[i][j-1];
            }
        }
        for(int i = 0; i < Q; i++){
            int p = sc.nextInt();
            int q = sc.nextInt();
            for(int j = p; j <= q; j++){
                count[i] += train[j][q];
            }
            System.out.println(count[i]);
        }
    }
}


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

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

Measured memory_bytes: 4372
d = {"AC":0,"WA":0,"TLE":0,"RE":0}
for _ in range(int(input())):
    s = input()
    d[s] = d[s]+1

print("AC x",d["AC"])
print("WA x",d["WA"])
print("TLE x",d["TLE"])
print("RE x",d["RE"])

Measured memory_bytes: 74664
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll h, w; cin >> h >> w;
    vector<vector<string>> s(h, vector<string>(w));
    ll ans_h, ans_w;
    rep(i, h) rep(j, w){
        cin >> s[i][j];
        if(s[i][j] == "snuke") ans_h = i, ans_w = j;
    }
    cout << (char)('A'+ans_w) << ans_h+1 << endl;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

bool inputCheck(string s){
  // 文字数チェック
  if(!(s.length()>=4 && s.length()<=10))
    return false;

  int countC = 0;
  int countBigCharacter = 0;

  for (int i = 0; i < s.length();i++){
    if(i==0 && s[i]!='A')
      return false;

    if (i >= 2 && i <= s.length() - 2){
      if(s[i]=='C')
        countC++;
    }

    if(s[i]>='A' && s[i]<='Z')
      countBigCharacter++;
  }

  if(countC!=1 || countBigCharacter!=2)
    return false;

  return true;
}

int main(){
  string S;
  cin >> S;

  bool succeed = inputCheck(S);
  if(succeed)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000;
char str[maxn];
int main(){
    while(scanf("%s",str)==1){
        int len=strlen(str);
        for(int i=0;i<len;i++){
            if(str[i]=='9') str[i]='1';
            else if(str[i]=='1') str[i]='9';
        }
        printf("%s\n",str);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;cin>>n;
  	if(n==1 || n==2){
    	cout<<1<<endl;
      	return 0;
    }
  	for (int i=0;i<n;i++){
    	if(i*i>n){
        	cout<<(i-1)*(i-1)<<endl;
          	return 0;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int n , i , a , b , c , x , y , z , p , q , r , ans;
    cin >> n;
    a = b = c = 0;
    for(i = 0 ; i < n ; i++){
        cin >> p >> q >> r;
        x = max(b , c) + p;
        y = max(a , c) + q;
        z = max(a , b) + r;
        a = x;b = y;c = z;
    }
    ans = max({a , b , c});
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 1; i <= n - 1; ++i) {
		string tmp1 = s.substr(0, i);
		string tmp2 = s.substr(i, n - i);
		set<char> st;
		for (auto& c : tmp1) {
			bool ok = false;
			for (auto& p : tmp2) {
				if (c == p) ok = true;
			}
			if (ok) st.insert(c);
		}
		ans = max(ans, (int)st.size());
	}
	cout << ans << endl;
	return 0;
}


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

const int MAX_N = 309, INF = 0x3f3f3f3f3f3f3f3f;
int N;
ll a[MAX_N][MAX_N];

void solve()
{
    ll ans = 0;
	for(int i=0;i<N;++i)for(int j=0;j<N;++j)if(i!=j){
		ll best = INF;
		for(int k=0;k<N;++k)if(k!=i&&k!=j)best=min(best, a[i][k]+a[k][j]);
		if(best <a[i][j]){
		    cout<<-1<<'\n';
		    return;
		}
		if(best > a[i][j]){
		    ans+=a[i][j];
		}
	}
	cout<<ans/2;
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i)for(int j=0;j<N;++j)cin>>a[i][j];
	solve();
	return 0;
}

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

int main() {
    int k;
    cin >> k;
    vector<int> d = {1};
    for (int i = 1; i < k; i++) {
	int j = 0;
	while (d.at(j) == 9 || (d.size() > j + 1 && d.at(j) - d.at(j + 1) >= 1)) {
	    j++;
	    if (j == d.size()) {
		d.push_back(0);
	    }
	}
	d.at(j)++;
	while (j > 0) {
	    j--;
	    if (j == d.size() - 1) {
		d.at(j) = 0;
	    } else {
		d.at(j) = max(d.at(j + 1) - 1, 0);
	    }
	}
    }
    reverse(d.begin(), d.end());
    for (int x : d) {
	cout << x;
    }
    cout << endl;
}


Measured memory_bytes: 256
import numpy

N = int(input())

scores = {}
indexes = {}
for i in range(N):
    s, p = input().split()
    p = int(p)
    if s in scores:
        scores[s].append(p)
        indexes[s].append(i)
    else:
        scores[s] = [p]
        indexes[s] = [i]

# print(scores)
# print(indexes)

# scores = {'khabarovsk': [20, 40], 'moscow': [10, 60], 'kazan': [50, 35]}
# indexes = {'khabarovsk': [0, 5], 'moscow': [1, 4], 'kazan': [2, 3]}
# N = 6

for s in sorted(scores.keys()):
    for i in numpy.argsort(scores[s])[::-1]:
        print(indexes[s][i]+1)

Measured memory_bytes: 12424
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint, k = rint;
	long[] as = rlong(n);

	long[] sums = [0];
	foreach(a; as) sums ~= sums[$ - 1] + a;

	long maxsum = -1;
	foreach(i; 0 .. n - k + 1){
		long s = sums[i + k] - sums[i];
		maxsum.chmax(s);
	}

	real ans = (maxsum + k).to!real / 2.0;
	writefln("%10.10f", ans);
}

Measured memory_bytes: 11636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N;
    cin>>N;
    ll ans=0;
    rep(i,N){
        if(i%2) continue;
        ll yak=0;
        rep(j,i+1){
            if((i+1)%(j+1)==0) yak++;
        }
        if(yak==8) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
M[99][99],C[99][99];main(n,m,i,j,k,x){for(;scanf("%d%d",&m,&n),n;printf("%d\n",M[n][m])){
for(i=0;i<n;i++)scanf("%d",C[i]+i);
for(i=0;i<n;i++)for(j=i+1;j<n;j++)C[i][j]=C[i][j-1]+C[j][j];
memset(M,11,sizeof(M));
for(i=1;i<=n;i++)for(j=1;j<=m;j++)for(k=0;k<i;k++)if(!k){
	if(M[i][j]>C[k][i-1])M[i][j]=C[k][i-1];
}else{
	if(M[i][j]>(x=M[k][j-1]>C[k][i-1]?M[k][j-1]:C[k][i-1]))M[i][j]=x;
}
}exit(0);}

Measured memory_bytes: 664
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int main() {
  string str,compstr;
  int size;
  while(getline(cin , str)) {
    size = str.size();
    for(int i=0;i<size;i++) {
      if(str.substr(i,1) == "@") {
        for(int j=0;j<atoi(str.substr(i+1,1).c_str());j++) {
          //      cout << str.substr(i+2,1) << endl;
          compstr += str.substr(i+2,1);
        }
        i++;
        i++;
      }
      else {
        compstr += str.substr(i,1);
        //      cout << str.substr(i,1) << endl;
      }
    }
        cout << compstr << endl;
    compstr = "";
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)

typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
# define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/
const int N = 1e5 + 42;
vector<int> g[N];
vector<int> e[N];
int w[N], sz[N];
int cc = 1;

int dfs(int u) {
  int s = 1;
  w[u] = cc;
  for (int v : g[u]) if (!w[v]) {
    s += dfs(v);
  }
  return s;
}
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 0; i < k; ++i) {
    int u, v; cin >> u >> v;
    --u, --v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  for (int i = 0; i < n; ++i) {
    if (!w[i]) {
      sz[cc] = dfs(i);
      ++cc;
    }
  }
  for (int i = 0; i < n; ++i) {
    int ans = sz[w[i]] - 1;
    set<int> cur(ALL(g[i]));
    for (int v : e[i]) if (w[v] == w[i]) cur.insert(v);
    ans -= SZ(cur);
    cout << ans << ' ';
  }
  cout << '\n';
}


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

using namespace std;

vector<vector<int>> cost;
vector<int> d;
vector<bool> visited;
int n;

void dijkstra(int count) {
    for (int i = 0; i < count; i++) {
        int s;
        cin >> s;
        d[s - 1] = 0;
    }
    while (true) {
        int next = -1;
        for (int u = 0; u < n; u++) {
            if (!visited[u] && (next == -1 || d[u] < d[next]))next = u;
        }

        if (next == -1)break;
        visited[next] = true;

        for (int u = 0; u < n; u++) d[u] = min(d[u], d[next] + cost[next][u]);
    }
}

int main() {
    int m, k;
    cin >> n >> m >> k;
    cost = vector<vector<int>>(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j)continue;
            cost[i][j] = 1145141919;
        }
    }
    for (int i = 0; i < m; i++) {
        int a, b, l;
        cin >> a >> b >> l;
        a--;
        b--;
        cost[a][b] = l;
        cost[b][a] = l;
    }
    d = vector<int>(n);
    visited = vector<bool>(n);
    for (int i = 0; i < n; i++) {
        d[i] = 1145141919;
        visited[i] = false;
    }
    dijkstra(k);
    int ma = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (cost[i][j] < 1145141919) ma = max(ma, (d[i] + d[j] + cost[i][j] + 1) / 2);
        }
    }
    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 38256
inputs = readlines

reg_num = nil
reg_users = []
door_open = false

inputs.map(&:chomp).each_with_index do |line, i|
  if i == 0
    reg_num = line.to_i
  end

  if i >= 1 && i <= reg_num + 1
    reg_users << line
  end

  if i > reg_num + 1
    if reg_users.include?(line)
      puts "#{door_open ? 'Closed' : 'Opened'} by #{line}"
      door_open = !door_open
    else
      puts "Unknown #{line}"
    end
  end
end


Measured memory_bytes: 6880
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;
struct Data{
    int idx;
    string s;
    int p;
};
bool operator<(const Data& lhs, const Data& rhs){
    if(lhs.s < rhs.s){
        return true;
    }
    else if(lhs.s > rhs.s){
        return false;
    }
    else{
        return lhs.p > rhs.p;
    }
}
int main() {
    int n;
    cin >> n;
    vector<Data> dat(n);
    for(int i=0;i<n;i++){
        cin >> dat[i].s >> dat[i].p;
        dat[i].idx = i;
    }
    sort(dat.begin(), dat.end());
    for(auto d: dat){
        cout << d.idx + 1 << endl;
    }
    return 0;
}

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

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 1000000007ll
#define debug(x) cerr<<#x<<"="<<x<<'\n'

const int maxn=1e5+10;

int n,m;
int a[maxn];
ll sum[maxn];
ll pre[maxn];

ll inv(ll x,int y) {
	ll res=1;
	while (y) {
		if (y%2==1) (res*=x)%=mod;
		y/=2;
		(x*=x)%=mod;
	}
	return res;
}

ll getc(int x,int y) {
	if (x==y||y==0) return 1;
	return pre[x]*inv(pre[y],mod-2)%mod*inv(pre[x-y],mod-2)%mod;
}

int main(){
	scanf("%d%d",&n,&m);
	pre[1]=1;
	for (int i=2;i<maxn;i++) pre[i]=pre[i-1]*i%mod;
	if (m==1) {
		printf("0");
		return 0;
	}
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++) (sum[i]=sum[i-1]+(ll)a[i])%=mod;
	int ans=0;
	for (int i=m-2;i<=n-2;i++) (ans+=(sum[n]-sum[1+i]-sum[n-i-1]+mod+mod)%mod*getc(i,m-2)%mod)%=mod;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    double ans = 0.0;
    int prev = n + 1;
    for (int x = k, i = 0; x > 0; x = (x + 1) / 2, ++i) {
        if (x < prev) {
            ans += (prev - x) / pow(2.0, i);
            prev = x;
        }

        if (x == 1) {
            break;
        }
    }

    cout << setprecision(16) << ans / n << endl;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long a, b;
    scan(a, b);
    bool x = a <= 8 && b <= 8;
    writeln(x?"Yay!":":(");
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	long[] a;
	public void solve() {
		N = nextInt();
		a = new long[(int)1e7 + 1];
		for(int i = 1;i <= (1e7);i++){
			a[i] += a[i - 1] + i;
		}

		int low = 0;
		int high = (int)1e7;

		while(high - low > 1){
			int mid = low + high >> 1;
			if(N <= a[mid]){
				high = mid;
			}else{
				low = mid;
			}
		}

		for(int i = high;i >= 1;i--){
			if(N >= i){
				out.println(i);
				N -= i;
			}
		}
	}

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

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 87252
#include<cstdio>
#include<cstdlib>
#include<cstring>

#define M 1046527
#define Nil (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1+(key % (M-1)); }

int find(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i *h2(key)) % M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i *h2(key)) % M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 16984
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int  A,B,C,X,Y;
  cin  >> A >> B >> C >> X >> Y;
  int t=10000000000;
  int a,b;
  for(int i=0; i<=100000; i++){
    a=X-i;
    b=Y-i;
    if(a<0){a=0;}
    if(b<0){b=0;}
    if(A*a+B*b+C*2*i<=t){t=A*a+B*b+C*2*i;}
  }
  cout << t <<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 200005
  #define INF 1000000000000
  #define eps 1e-6

int32_t main()
{


    string s;
    cin >> s;

    for(int i = 0; i < s.length(); i++)
    {
      cout <<'x';
    }
   
    return 0;
}

Measured memory_bytes: 256
package main

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

const MAX = 100
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var M [MAX][MAX]int

func dijkstra() {
	var minv int
	var d [MAX]int
	var color [MAX]int

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}

	d[0] = 0
	color[0] = GRAY
	for {

		minv = INFTY
		u := -1
		for 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 v := 0; v < n; v++ {
			if color[v] != BLACK && M[u][v] != INFTY {
				if d[v] > d[u]+M[u][v] {
					d[v] = d[u] + M[u][v]
					color[v] = GRAY
				}
			}
		}

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			M[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		f, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())
			M[f][v] = c
		}
	}
	dijkstra()
}



Measured memory_bytes: 1228
/************************Code by Hardik Aggarwal!!!!***********************************/

#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;


int main()
{	
	

	IOS
	ll n;
	cin>>n;
	double p[n+1];
	for(ll i=1;i<=n;i++)
	{
		cin>>p[i];
	}


	double dp[n+1][n+1];
	dp[0][0]=1.0;
	for(ll i=1;i<=n;i++)
		{
			dp[0][i]=0.0;
		}

	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=n;j++)
		{
			if(j==0)
				dp[i][j]=dp[i-1][j]*(1-p[i]);
			else
			{
				dp[i][j]=dp[i-1][j-1]*p[i]+(dp[i-1][j]*(1-p[i]));
			}
		}
	}

	double ans=0;
	for(ll j=(n+1)/2;j<=n;j++)
		ans+=dp[n][j];

	cout<<setprecision(15)<<fixed<<ans;

}
    
 
    
    


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

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

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int N;
  cin >> N;

  int h[128];
  rep(i, N) cin >> h[i];

  h[N] = 0;

  int ans = 0;
  while (true) {
    bool allZero = true;
    for (int i = 1; i <= N; ++i) {
      if (h[i-1] != 0) allZero = false;
      if (!h[i] && h[i-1]) ++ans;
      if (h[i-1]) --h[i-1];
    }
    if (allZero) break;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int pow(int i, int exp){
    if(exp==0) return 1;
    return i*pow(i, exp-1);
}
int main(){
    int n;
    cin>>n;
    int answer=0;
    vector<vector<pair<int,int>>> in;
    for(int i =0; i< n ;i++){
        int a;
        cin>>a;
        vector<pair<int,int>> temp;
        for(int j=0; j< a; j++){
            int first, second;
            cin>>first>>second;
            temp.push_back({first, second});
        }
        in.push_back(temp);
    }
    for(int i=0; i<pow(2, n); i++){
        int buf = i;
        vector<int> version;
        while(buf>0){
            version.push_back(buf&1);
            buf/=2;
        }
        while(version.size()<n) version.push_back(0);
        bool ok=true;
        for(int z=0; z<version.size(); z++){
            if(version[z]==1){
                for(int k=0; k<in[z].size(); k++){
                    if(version[in[z][k].first-1]!=in[z][k].second) ok=false;
                }
            }
        }
        if(ok==true){
            int count=0;
            for(auto v: version){
                if(v==1) count++;
            }
            answer=max(count, answer);
        }
    }
    cout<<answer;


}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < e; i++)
#define rep(i, n) REP(i, 0, n)

static const int MAX_N = 1000000;
static const int MAX_P = 2000000000;

int N, M, Q, S[MAX_N];

map<int, int> PM; // point map
vector<int> ATI, ATV;
vector<int> MS;
set<int> R;
vector<pair<int, int> > seg;

void init(){
  MS.clear();
  for ( set<int>::iterator it = R.begin(); it != R.end(); it++ ){
    MS.push_back(S[*it]);
  }
  sort(MS.begin(), MS.end());
}

int getCount(int r){
  seg.clear();

  if ( MS.size() > 0 ) seg.push_back(make_pair(MS[0]-r, MS[0]));

  for ( int i = 1; i < MS.size(); i++ ){
    int b = MS[i]-r;
    int e = MS[i];
    if ( b <= seg[seg.size()-1].second){
      seg[seg.size()-1].second = max(seg[seg.size()-1].second, e);
    } else {
      seg.push_back(make_pair(b, e));
    }
  }

  int cnt = 0;

  for ( int i = 0; i < seg.size(); i++ ){
    int a = distance(ATI.begin(), lower_bound(ATI.begin(), ATI.end(), max(0, seg[i].first) )) - 1;
    int b = distance(ATI.begin(), lower_bound(ATI.begin(), ATI.end(), max(0, seg[i].second) ));
    cnt += ATV[b] - ATV[a];
  }

  return cnt;
}

void bsearch(int X){
  init();

  int l = 0;
  int r = MAX_P+2000000;
  int m;
  int diff = r - l;
  int cnt = getCount(r);
  if ( cnt < X ){
    cout << "NA" << endl;
    return;
  }
  bool ok = false;
  for (int i = 0; i < 100; i++ ){
    m = (l+r)/2;
    cnt = getCount(m);
    if ( cnt >= X ){
      r = m;
      ok = true;
    } else if ( cnt < X ){
      l = m;
    }
    if ( diff == l - r ) break;
    diff = l - r;
  }
  cout << r << endl;
}

main(){
  scanf("%d %d", &N, &Q);

  MS.clear();
  PM.clear();
  ATI.clear();
  ATV.clear();

  rep(i, N) {
    scanf("%d", &S[i]);
    PM[S[i]]++;
  }

  bool isR[MAX_N];
  rep(i, N) isR[i] = false;

  M = 0;

  ATI.push_back(-1);
  ATV.push_back(0);
  int pre = 0;
  for ( map<int, int>::iterator it = PM.begin(); it != PM.end(); it++ ){
    ATI.push_back((*it).first);
    ATV.push_back((*it).second + ATV[pre++]);
  }

  string com;
  int x;
  rep(i, Q){
    cin >> com >> x;
    if ( com[0] == 'C' ){
      bsearch(N - x);
    } else if ( com[0] == 'R' ){
      x--; // 0 base
      R.erase(R.find(x));
      M--;
    } else if ( com[0] == 'A' ){
      x--; // 0 base
      R.insert(x);
      M++;
    }
  }
}

Measured memory_bytes: 60676
#include<stdio.h>
int ex[1000001];
int main(void){
    int s,i;
    for(i=0;i<1000001;i++){
        ex[i]=0;
    }
    i=0;
    scanf("%d",&s);
    while(1){
        i++;
        ex[s]++;
        if(ex[s]==2){
            break;
        }
        if(s%2==0){
            s/=2;
        }else{
            s=s*3+1;
        }
    }
    printf("%d\n",i);
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ll n,x,a,now=0,ans=1;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		cin>>a;
		now+=a;
		if(now<=x)ans++;
	}
	cout<<ans;
	return 0;
}


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

int f(int n){
    if((n % 2) == 0){
        return n / 2 ;
    }
    else{
        return 3 * n + 1;
    }
}

int main(){
    //入力
    int s;
    cin >> s;
    int i=1, l;

    int A[10^6]; //覚えるやつ
    l=s;
    
    while(l!=1 && l!=2 && l!=4){
        l=f(l);
        i++;
    }

    cout << i+3 << endl;
}

Measured memory_bytes: 256
n, a, b = gets.split.map(&:to_i)
s = gets.chomp

count_a = 0
count_b = 0

s.each_char do |c|
  if c == 'a'
    if count_a + count_b < a + b
      count_a += 1
      puts 'Yes'
    else
      puts 'No'
    end
  elsif c == 'b'
    if count_a + count_b < a + b && count_b < b
      count_b += 1
      puts 'Yes'
    else
      puts 'No'
    end
  elsif c == 'c'
    puts 'No'
  end
end

Measured memory_bytes: 2300
def main():
    N, K = map(int, input().split())

    sunuke = {i:0 for i in range(N)}

    for i in range(K):
        d = int(input())
        a = list(map(int, input().split()))  # 整数のリスト
        for j in a:
            sunuke[j-1] += 1

    answer = 0

    for i in range(N):
        if sunuke[i] == 0:
            answer += 1

    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9132
#include<stdio.h>

int main(void){
	int a,b,c,m;
	scanf("%d%d%d",&a,&b,&c);
	if(a == 5 && b == 5 && c == 7){printf("YES\n");}
	else if(a == 5 && b == 7 && c == 5){printf("YES\n");}
	else if(a == 7 && b == 5 && c == 5){printf("YES\n");}
	else{printf("NO\n");}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    long long sum;
    for (int i = 0; i < n; i++) {
        long long r,l;
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256