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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) a[i] = s[i] == 'o';
    vector<int> l(n), r(n);
    l[0] = a[0];
    for (int i = 1; i < n; ++i) {
        l[i] = max(l[i - 1], a[i]);
        if (i - c - 1 >= 0) {
            l[i] = max(l[i], l[i - c - 1] + a[i]);
        }
    }
    r[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        r[i] = max(r[i + 1], a[i]);
        if (i + c + 1 < n) {
            r[i] = max(r[i], r[i + c + 1] + a[i]);
        }
    }
    vector<int> p(n, 0);
    for (int i = 0; i < n; ++i) {
        int cnt = a[i];
        if (i - c - 1 >= 0) cnt += l[i - c - 1];
        if (i + c + 1 < n) cnt += r[i + c + 1];
        if (cnt >= k) p[i] = 1;
    }
    vector<int> ans;
    int sum = 0;
    for (int i = 0; i < c; ++i) sum += p[i];
    for (int i = 0; i < n; ++i) {
        if (i - c - 1 >= 0) sum -= p[i - c - 1];
        if (i + c < n) sum += p[i + c];
        int cnt = 0;
        if (i - c - 1 >= 0) cnt += l[i - c - 1];
        if (i + c + 1 < n) cnt += r[i + c + 1];
        if (a[i] == 1 && cnt == k - 1 && sum - p[i] == 0) {
            ans.push_back(i + 1);
        }
    }
    for (auto x : ans) cout << x << endl;
    return 0;
}



Measured memory_bytes: 5772
# print('input >>')
N, K = map(int,(input().split()))

MOD = 10**9+7

# print('-----output-----')
ans = 0
for n in range(K, N+2):
    max_ = n * (N-n+1 + N) // 2
    min_ = n * (0 + n-1) // 2
    # print(n, max_, min_)
    ans += max_ - (min_ -1)

print(ans % MOD)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
const int mod = 1000000007;
void solve() {
	int n;
	cin >> n;
	vector<int64>v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<int64> dp(n+1, 0);
	dp[n-1] = v[n-1];

	for(int i = n-2; i >= 0; i--) {
		dp[i] = (dp[i + 1] + v[i]) % mod;
	}
	uint64 ans = 0;
	// for(int i: dp) cout << i << endl;
	for(int i = n-2; i >= 0; i--) {
		int64 num = (v[i]*dp[i+1])%mod;
		ans = (ans + num)%mod;
	}
	cout << ans;

}

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

	return 0;
}

Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, int arr[]){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}
int n, m;
vector<vector<int>> v;
ll dp[100005];
ll solve(int idx){
    if(dp[idx] != -1)
        return dp[idx];
    ll mx = 0;
    for(int i = 0; i < v[idx].size(); i++)
        mx = max(mx, solve(v[idx][i]) + 1);
    dp[idx] = mx;
    return mx;
}
int main()
{
    Hello
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    v.resize(n + 5);
    for(int i = 0, a, b; i < m; i++){
        cin >> a >> b;
        v[a].push_back(b);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++)
        ans = max(ans, solve(i));
    cout << ans;
    return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;
const ll N= 1e5+55,mod = 1e9+7;
int main() {
// 	freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
	string s;
	cin>>s;
	if(s[0]=='9' || s[1]=='9')cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string j="JPY";
    string b="BTC";
    string chk;
    double d,sum=0;
    while(n--)
    {
        cin>>d>>chk;
        if(chk==j)
            sum+=d;
        else
            sum+=(d*380000.0);
    }
    printf("%.8f",sum);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        int x=0;
        for(int i=a;i<=b;i++)
        {
            if(i%k==0)
            {
                x=1;
                System.out.println("OK");
                break;
            }
        }
        if(x==0)
            System.out.println("NG");
    }
}

Measured memory_bytes: 35740
<?php
list($A,$B,$C,$X,$Y)=explode(" ",trim(fgets(STDIN)));
$z=min($X,$Y);
$x=$X-$z;
$y=$Y-$z;
echo min($X*$A+$Y*$B,min($z*$A+$z*$B,$z*$C*2)+min($x*$A,$x*2*$C)+min($y*$B,$y*2*$C));

Measured memory_bytes: 4728
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    VLL cnt(n+1);
    REP(i,0,n) cnt[a[i]]++;
    LL sum = 0;
    REP(i,1,n+1) sum += cnt[i] * (cnt[i] - 1) / 2;
    REP(i,0,n) {
        LL diff = cnt[a[i]] * (cnt[a[i]] - 1) / 2 - (cnt[a[i]] - 2) * (cnt[a[i]] - 1) / 2;
        cout << sum - diff << endl;
    }
}

signed main() {
    solve();
    
    return 0;
}

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

int main()
{
    #ifndef ONLINE_JUDGE 
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif
    
    
    ll n;
    cin>>n;
    ll p=n%10;
    if(p==2 || p==4 || p==5 || p==7 || p==9)
    {
        cout<<"hon";
    }
    if(p==3)
    {
        cout<<"bon";
    }
    else if(p==1 || p==0 || p==6 || p==8)
        cout<<"pon";
    return 0;
}

Measured memory_bytes: 3600
N = int(input())
array = [input() for i in range(N)]
count_AC = 0
count_TLE = 0
count_RE = 0
count_WA = 0
for i in array:
    if i == "AC":
        count_AC += 1
    elif i == "TLE":
        count_TLE += 1
    elif i == "RE":
        count_RE += 1
    elif i == "WA":
        count_WA += 1
print("AC x "+str(count_AC))
print("WA x "+str(count_WA))
print("TLE x "+str(count_TLE))
print("RE x "+str(count_RE))

Measured memory_bytes: 16308
#include <bits/stdc++.h>
using namespace std;
int main(){
  int R,B,G,N,g,X=0;
  cin>>R>>B>>G>>N;
  for(int r=0;r<=N/R;r++){
    for(int b=0;b*B<=N-r*R;b++){
     g=(N-b*B-r*R)/G;
    
  if(N==r*R+g*G+b*B){
    X=X+1;
  }
      }
    }
 
  cout<<X<<endl;
}

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

#define ll long long
#define ii pair<ll, ll>
#define dd pair<double, double>
#define pb(i) push_back(i)
const double PI = 3.14159265359;
const ll inf = 1e18;
const int mod = 1e9+7;
const double eps = 1e-7;
//int dir1[8] = {0, 0, 1, -1, 1, -1, 1, -1};
//int dir2[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dir1[4] = {0, 0, 1, -1};
int dir2[4] = {1, -1, 0, 0};

ll cost(int a, int b);

ll solve(int l, int r);

ll pre[405];

ll dp[405][405];

int main()
{
    int i, j;

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

    pre[0] = v[0];
    for(i = 1; i < n; i++)
        pre[i] = pre[i-1] + v[i];
    
    memset(dp, -1, sizeof(dp));
    cout << solve(0, n-1) << '\n';
}

ll cost(int a, int b)
{
    if(a-1 >= 0)
        return pre[b] - pre[a-1];
    return pre[b];
}

ll solve(int l, int r)
{

    int i, j;

    ll &h = dp[l][r];
    if(l == r)
        return h = 0;

    if(h != -1)
        return h;
    
    h = inf;
    for(i = l; i <= r; i++)
        h = min(h, solve(l, i) + solve(i+1, r) + cost(l, r));

    return h;
}

Measured memory_bytes: 4952
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define X first
#define Y second
const int N = 1024, K = 31;
string solve_odd(int x,int y,int p=K-1)
{
    if (p == -1)
        return "";
    if (x < 0) {
        auto ret = solve_odd(-x,y,p);
        for (auto & c : ret)
            if (c == 'R')
                c = 'L';
            else if (c == 'L')
                c = 'R';
        return ret;
    }
    if (y < 0) {
        auto ret = solve_odd(x,-y,p);
        for (auto & c : ret)
            if (c == 'U')
                c = 'D';
            else if (c == 'D')
                c = 'U';
        return ret;
    }
    int v = 1<<p;
    if (x + y >= v) {
        if (x > y)
            return solve_odd(x-v,y,p-1) + "R";
        else
            return solve_odd(x,y-v,p-1) + "U";
    } else {
        auto ret = solve_odd(x,y,p-1);
        auto & c = ret.back();
        switch (c) {
        case 'L':
            c = 'R';
            return ret + 'L';
        case 'R':
            c = 'L';
            return ret + 'R';
        case 'U':
            c = 'D';
            return ret + 'U';
        case 'D':
            c = 'U';
            return ret + 'D';
        }
    }
}
pii p[N];
int main()
{
    int n;
    cin >> n;
    int s = 0;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].X >> p[i].Y;
        s += abs(p[i].X+p[i].Y)%2;
    }
    if (s == n) {
        cout << K << endl;
        for (int i = 0; i < K; ++i)
            cout << (1<<i) << " \n"[i==K-1];
        for (int i = 0; i < n; ++i)
            cout << solve_odd(p[i].X,p[i].Y) << endl;
    } else if (!s) {
        cout << K+1 << endl;
        for (int i = 0; i < K; ++i)
            cout << (1<<i) << " ";
        cout << "1\n";
        for (int i = 0; i < n; ++i)
            cout << solve_odd(p[i].X-1,p[i].Y) + "R" << endl;
    } else {
        cout << "-1\n";
    }
}


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

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k, q;
  cin >> n >> k >> q;
  vi cnt(n);
  REP(i, q) {
    int a; cin >> a;
    cnt[a - 1]++;
  }
  REP(i, n) {
    if (k - q + cnt[i] > 0)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int n, m;
bool q[100][100];
int r[100];
bool z[100];

bool dfs(int i) {
    if (z[i]) return false;
    z[i] = true;
    for (int j = 0; j < n; j++) {
        if (q[i][j]) {
            if (r[j] == -1 || dfs(r[j])) {
                r[j] = i;
                return true;
            }
        }
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);

    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    for (int k = 0; k < m; k++) {
        for (int i = 0; i < n; i++) {
            r[i] = -1;
            for (int j = 0; j < n; j++) {
                q[i][j] = false;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = k; j < m; j++) {
                q[a[i][j] / m][i] = true;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                z[j] = false;
            }
            if (!dfs(i)) {
                return 1;
            }
        }
        for (int i = 0; i < n; i++) {
            int x = r[i];
            for (int j = k; j < m; j++) {
                if (a[i][j] / m == x) {
                    swap(a[i][j], a[i][k]);
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m;j ++) {
            cout << a[i][j] + 1 << " ";
        }
        cout << "\n";
    }
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (a[i][j] / m == k) {
                    swap(a[i][j], a[k][j]);
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m;j ++) {
            cout << a[i][j] + 1 << " ";
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main() {
    string s,t;
    cin >> s >> t;
    int res=0;
    rep(i,s.size()){
        if(s[i]!=t[i])
            res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3916
from collections import Counter


n = int(input())
a = [int(x) for x in input().split()]
q = int(input())

dic = Counter(a)

ans = sum(a)
for i in range(q):
    b, c = map(int,input().split())
    if b in dic.keys():
        if c in dic.keys():
            dic[c] += dic[b]
            ans += (c - b) * dic[b]
            del dic[b]
        else:
            dic[c] = dic[b]
            ans += (c - b) * dic[b]
            del dic[b]
    
    print(ans)

Measured memory_bytes: 21216
#include <iostream>
#include <string>
#include <map>

using namespace std;

int N, M;
map<string, int> m;
map<string, int>::iterator it;

int main() {
    cin >> N;
    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        m[s]++;
    }
    cin >> M;
    for(int j = 0; j < M; j++) {
        string t;
        cin >> t;
        m[t]--;
    }
    int max = 0;
    for(it = m.begin(); it != m.end(); it++) {
        if(max < it->second) max = it ->second;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

while True:
    n, k, m = map(int, raw_input().split())
    if n == 0:
        break

    pos = 0
    for num in range(1, n):
        pos += k - 1
        pos %= num
        pos += 1
    ans = (m - (n - pos)) % n
    
    if ans == 0:
        print n
    else:
        print ans


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

int main(){
  long long ans=1,n,array[100];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
    ans=(ans/__gcd(ans,array[i]))*array[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;

int gcd(int a, int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

int main(){
    int n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    long long r[n], l[n];
    long long m = 0;
    r[n-1] = a[n-1];
    l[0] = a[0];
    for (int i = 1; i < n; i++){
        l[i] = gcd(l[i-1],a[i]);
        r[n-1-i] = gcd(r[n-i],a[n-1-i]);
    }
    long long d[n];
    d[0] = r[1];
    d[n-1] = l[n-2];
    for (int i = 1; i < n-1; i++){
       d[i] = gcd(l[i-1],r[i+1]);
    }
    for (int i = 0; i < n; i++){
        if (m < d[i]) m = d[i];
    }
    cout << m;

    return 0;
}

Measured memory_bytes: 3328
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        string s;
        int num = int.MaxValue;

        while((s = Console.ReadLine() ) != null)
        {
            if (num == int.MaxValue)
            {
                num = int.Parse(s);
            }
            else
            {
                long[] numbers = new long[num];
                numbers = s.Split(' ').Select(long.Parse).ToArray();
                num = int.MaxValue;
                Console.WriteLine("{0} {1} {2}", numbers.Min(), numbers.Max(), numbers.Sum());
            }
        }
    }
}

Measured memory_bytes: 10708
#include <stdio.h>
int main(void) {
    char s[101];
    char p[101];
 
    gets(s);
    gets(p);
 
    int i;
    int j;
    int k = 0;
    for(i = 0; s[i] != 0x00; i++) {
        for(j = 0; s[i + j] == p[j], s[i + j - k] == p[j]; j++) {
            if(p[j + 1] == 0x00) {
                printf("Yes\n");
                return 0;
            }
             
            if(k == 0 && s[i + j + 1] == 0x00) {
                k = i + j + 1;
            }
        }
    }
 
    printf("No\n");
    return 0;
}

Measured memory_bytes: 524
//54
#include<iostream>
#include<string>
#include<set>

using namespace std;

string c[10];
set<string> st;

void calc(string s,int n,int d,int u){
  if(d==0){
    st.insert(s);
  }else{
    for(int i=0;i<n;i++){
      if(!(u&1<<i)){
	calc(s+c[i],n,d-1,u|1<<i);
      }
    }
  }
}

int main(){
  for(int n,k;cin>>n>>k,n|k;){
    st.clear();
    for(int i=0;i<n;i++){
      cin>>c[i];
    }
    calc("",n,k,0);
    cout<<st.size()<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 1460
'''input
2
ABCXYZ
'''
# A coding delight https://ideone.com/m98Hht
from sys import stdin
input = stdin.readline


# main starts
n = int(input().strip())
string = list(input().strip())
for i in range(len(string)):
	if ord(string[i]) + n > 90:
		string[i] = chr(64 + n - (90 - ord(string[i])))
	else:
		string[i] = chr(ord(string[i]) + n)

print(''.join(string))

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

using namespace std;

int main() {
	int n, num, sum;

	while (cin >> n, n) {
		sum = 0;
		n /= 4;
		for (int i = 0; i < n; ++i) {
			cin >> num;
			sum += num;
		}
		cout << sum << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3068
import heapq

def dijkstra(graph, node, start):
    dist = [float("inf") for _ in range(node)]

    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))

    while q:
        cost, cur_node = heapq.heappop(q)

        if dist[cur_node] < cost:
            continue

        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heapq.heappush(q, (dist[nex_node], nex_node))

    return dist


n = int(input())
adj = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append((c, b))
    adj[b].append((c, a))
q, k = map(int, input().split())
shortest = dijkstra(adj, n, k - 1)
for i in range(q):
    x, y = map(int, input().split())
    print(shortest[x - 1] + shortest[y - 1])

Measured memory_bytes: 94928
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
int main()
{
    long long n,m;
    cin>>n>>m;
    int add=0;
    while(n<=m)
    {
        n*=2;
        add++;
    }
    cout<<add<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
)

func main() {

        acceptable := map[byte]struct{}{
                'A': struct{}{},
                'C': struct{}{},
                'G': struct{}{},
                'T': struct{}{},
        }

        var str string
        fmt.Scanf("%s", &str)

        var max int

        for i := 0; i < len(str); {
                subL := 0
                for j := i; j < len(str); j++ {
                        if _, ok := acceptable[str[j]]; !ok {
                                break
                        }
                        subL++
                }
                if max < subL {
                        max = subL
                }
                // next of broken point
                i = i + subL + 1
        }
        fmt.Printf("%d\n", max)
}

Measured memory_bytes: 512
H,W = map(int,input().split())
s = [list(input()) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
dp[0][0] = int(s[0][0]=="#")

for i in range(1, W):
    dp[0][i] = dp[0][i-1] + (int(s[0][i]=="#") if s[0][i-1]=="." else 0)
for h in range(1,H):
  dp[h][0] = dp[h-1][0] + (int(s[h][0]=="#") if s[h-1][0]=="." else 0)
  for w in range(1,W):
    dp[h][w] = min(dp[h-1][w]+(int(s[h][w]=="#") if s[h-1][w]=="." else 0), 
    dp[h][w-1]+(int(s[h][w]=="#") if s[h][w-1]=="." else 0))
print(dp[-1][-1])

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  REP(i,n+1){
    for(int j = 2; j <= 9; j++){
      int tmp = pow(i,j);
      if(tmp > n) continue;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
N = int(input())

a = 0
for i in range(N):
  S = input()
  if S == 'A':
    a += 1
  else :
    a -= 1

  if a < 0:
    print('NO')
    exit()
  
if a == 0:
  print('YES')
else:
  print('NO')

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

using namespace std;

const int MAXN=101;

int n,sum=0,ans=0,val;

int main() {
	scanf("%d",&n);
	for(int i=1,x; i<=n; ++i) {
		scanf("%d",&x);
		sum+=x,ans+=x*x;
	}
	val=n-2*sum;
	for(int i=2; i<=100; ++i)
		if(n*i*i-2*i*sum<val) val=n*i*i-2*i*sum;
	printf("%d\n",ans+val);
	return 0;
}

Measured memory_bytes: 256
nu1,nu2 = gets.chomp.split(" ").map(&:to_i)
count1 = nu1 / nu2
count2 = nu1 / 2
result = 0

if nu2 % 2 == 1
  print count1 ** 3
else
  if nu1 % nu2 >= nu2 / 2
    print (count1 + 1)**3 + count1**3
  else
    print count1**3*2
  end
end


Measured memory_bytes: 1788
#include<stdio.h>
using namespace std;
void t(int a[],int n)
{
    int i;
    for(int i=0;i<n;i++)
    {
        if(i>0)
            printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
}
void an(int a[],int n)
{
    int i,j,v;
    for(int i=1;i<n;i++)
    {
        v=a[i];
        j=i-1;
        while(j>=0 &&a[j]>v)
        {
            a[j+1]=a[j];
            j--;

        }
        a[j+1]=v;
        t(a,n);
    }
}
int main()
{
    int n,i,j;
    int a[100];
    scanf("%d",&n);
    for(i=0;i<n;i++)

        scanf("%d",&a[i]);
    t(a,n);
    an(a,n);
    return 0;
}

Measured memory_bytes: 2732
import itertools

n = int(input())
P = []

for i in range(n):
    x, y = map(int, input().split())
    P.append([x, y])
c = 0
for i in itertools.permutations(range(n)):
    for j in range(len(i)-1):
        c += ((P[i[j]][0] - P[i[j+1]][0])**2 + (P[i[j]][1] - P[i[j+1]][1])**2)**(1/2)
k = 1
for i in range(1, n+1):
    k *= i
print(c/k)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

vector<pair<ll, int>> v;

int main(){
	int n, m; scanf("%d%d", &n, &m);
	REP(i, n){
		ll a; int b; scanf("%lld%d", &a, &b);
		v.EB(a, b);
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	for(auto &p:v){
		int k = min(m, p.second);
		ans += p.first * k;
		m -= k;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

class union_find {
public:
vector<int> par,rank,lsize;
union_find(int n): par(n),rank(n),lsize(n){
   for (int i=0;i < n;i++){
      par[i]=i;
      rank[i]=0;
      lsize[i]=1;
   }
}

int find(int x){
   if (par[x]==x){
      return x;
   }
   else{
      return par[x] = find(par[x]); 
   }
}

void unite(int x ,int y){
   x=find(x);
   y=find(y);
   if (x==y) return;
   if (rank[x] < rank[y]){
      lsize[y] += lsize[x];
      lsize[x] = -1;
      par[x] = y;
   }else{
      lsize[x] += lsize[y];
      lsize[y] = -1;
      par[y]=x;
      if (rank[x]==rank[y]) rank[x]++;
   }   
}

bool same(int x, int y){
   return find(x) == find(y);
}

int size(int x){
   if (lsize[x] == -1){
      x=find(x);
   }
   return lsize[x];
}

int groups(){
   int res = 0;
   for (int i = 0;i < par.size();i++){
      if (i == par[i]) res++;
   }
   return res;
}

};



int main(){
  int n,m;
  cin >> n >> m;
  union_find tree(n);
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;y--;
    tree.unite(x,y);
  }
  
  cout << tree.groups()-1 << endl;

  
  return 0;
}

Measured memory_bytes: 4508
from collections import Counter
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
cou=Counter(a).most_common()
rem=len(cou)-k
i=-1
ans=0
while rem>0:
    ans+=cou[i][1]
    i-=1
    rem-=1;
print(ans)

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

#ifdef DEBUG
#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))

#define LOGM(msg) (cerr << (msg))

#define LOGV(vec, sep) {                                        \
    cerr << #vec << " =";                                       \
    for (const auto& v : (vec)) cerr << " " << v;               \
    cerr << (sep); }

#define LOGA(arr, N, sep) {                                     \
        cerr << #arr << " =";                                   \
        for (int i = 0; i < N; ++i) cerr << " " << (arr)[i];    \
        cerr << (sep); }

#define LOGA2(arr, N, M, sep) {                                 \
        cerr << #arr << " =\n";                                 \
        for (int i = 0; i < N; ++i) {                           \
            for (int j = 0; j < M; ++j)                         \
                cerr << (arr)[i][j] << " ";                     \
            cerr << endl;                                       \
        } cerr << (sep); }
#else
#define LOG(var, sep)
#define LOGM(msg)
#define LOGV(vec, sep)
#define LOGA(arr, N, sep)
#define LOGA2(arr, N, M, sep)
#endif

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(ll, ll D, const vector<ii>& xs)
{
    ll ans = 0;

    for (auto p : xs)
    {
        auto x = p.first, y = p.second;

        ans += (x*x + y*y <= D*D ? 1 : 0);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N, D;
    cin >> N >> D;

    vector<ii> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i].first >> xs[i].second;

    auto ans = solve(N, D, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6408
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
 		String tmp = ""+N;
     	int howlong = tmp.length();
      	String a = tmp.substring(howlong-1);
      	int n = Integer.parseInt(a);
      	String pon ="pon";
      	
      	if(n==2 || n==4 || n==5 || n==7 || n==9){
          pon = "hon";
        } else if (n==3){
          pon = "bon";
        }
      
		System.out.println(pon);
	}
 
}

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

#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,les=0,ans=0;
int a[200000],b[200000];
priority_queue<int>que;
signed main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n){
        cin>>b[i];
        if(a[i]<b[i]){
            les+=b[i]-a[i];
            a[i]=b[i];
            ans++;
        }
        else if(a[i]>b[i]){
            que.push(a[i]-b[i]);
        }
    }
    while(!que.empty()&&les>0){
        int n=que.top();
        que.pop();
        ans++;
        les-=n;
        if(que.empty()&&les>0){
            cout<<-1<<endl;
            return 0;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2424
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>

using namespace std;

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point {
public:
	double x, y;


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

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

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

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

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

};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

bool isOrthogonal(Vector a, Vector b) {
	return equals(dot(a, b), 0.0);
}

bool isParallel(Vector a, Vector b) {
	return equals(cross(a, b), 0.0);
}
struct Segment {
	Point p1, p2;
	Segment() {}
	Segment(Point p1, Point p2) :p1(p1), p2(p2) {}
};
typedef Segment  Line;

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

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

Point reflect(Segment s, Point p) {
	return p + (project(s, p) - p) * 2.0;
}
double getDistance(Point a, Point b) {
	return abs(a - b);
}

double getDistanceLP(Line l, Point p) {
	return fabs(cross(l.p2 - l.p1, p - l.p1)/abs(l.p2 - l.p1));
}

double getDistanceSP(Segment s, Point p) {
	if (dot(s.p2 - s.p1, p - s.p1) < 0.0)return abs(p - s.p1);
	if (dot(s.p1 - s.p2, p - s.p2) < 0.0)return abs(p - s.p2);
	return getDistanceLP(s, p);

}

double getDistance(Segment s1, Segment s2) {
	//if (intersect(s1, s2))return 0.0;
	return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
		min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2) {
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if (cross(a, b) > EPS)return COUNTER_CLOCKWISE;
	if (cross(a, b) < -EPS) return CLOCKWISE;
	if (dot(a, b) < -EPS)return ONLINE_BACK;
	if (a.norm()<b.norm()) return ONLINE_FRONT;

	return ON_SEGMENT;


}
bool intersect(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
	return intersect(s1.p1, s2.p2, s2.p1, s2.p2);
}


int main() {
	int q,x1,y1,x2,y2,x3,y3,x0,y0;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> x0>>y0>>x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		if (intersect(Point(x0, y0), Point(x1, y1), Point(x2, y2), Point(x3, y3))) {
			cout << "1" << endl;
		}
		else {
			cout << "0" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<iomanip> 
#define pi 3.1415926535898
using namespace std;
int main()
{
	double r;
	cin>>r;
	
	cout<<setiosflags(ios::fixed)<<setprecision(6)<<pi*r*r<<" "<<2*pi*r<<endl;
	return  0;
 } 


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

int main() {
  int N;
  cin>>N;
  std::vector<int> v(N),b(N);
  for(int i=0;i<N;i++)cin>>v[i];
  if(N%2==0){
    for(int i=0;i<N;i++){
      if(i%2==0)b[N/2+i/2]=i;
      else b[N/2-i/2-1]=i;
    }
  }
  else{
    for(int i=0;i<N;i++){
      if(i%2==0)b[N/2-i/2]=i;
      else b[N/2+i/2+1]=i;
    }
  }
  for(int i=0;i<N;i++)cout<<v[b[i]]<<" ";
  cout<<endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,ANS=0;
	vector<pair<ll,ll>>V;
	cin>>N;
	rep(i,N){
		pair<ll,ll>a;
		cin>>a.first>>a.second;
		V.push_back(a);
	}
	sort(V.begin(),V.end());
	ANS=ANS+V.back().first-V.front().first+1;
	ANS=ANS+V[0].first-1;
	ANS=ANS+V.back().second;
	cout<<ANS<<endl;
}

Measured memory_bytes: 2420
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

ll N, M;
const ll SIZE = 5000005;
ll c[SIZE];
ll A[SIZE];
ll Next[SIZE];
ll res[5000005];
ll show[5000005];
bool fir[SIZE];


struct Q
{
    ll l, r;
    ll pos;
}q[5000005];


ll lowbit(ll k)
{
    return k & (-k);
}


void modify(ll n, ll v)
{
    while (n <= N)
    {
        c[n] += v;
        n += lowbit(n);
    }
}


ll sum(ll n)
{
    ll ans = 0;
    while (n > 0)
    {
        ans += c[n];
        n -= lowbit(n);
    }
    return ans;
}


ll cmp(Q a, Q b)
{
    return a.l < b.l;
}


int main()
{
    cin >> N >> M;
    for (ll i = 1;i <= N;i++) cin>>A[i];
    for (ll i = N;i >= 1;i--)
    {
        if (!show[A[i]])
        {
            show[A[i]] = i;
            fir[i] = true;
        }
        else
        {
            Next[i] = show[A[i]];
            fir[Next[i]] = false;
            fir[i] = true;
            show[A[i]] = i;
        }
    }
    for (ll i = 1;i <= M;i++)
    {
        cin >> q[i].l >> q[i].r;
        q[i].pos = i;
    }
    sort(q + 1, q + 1 + M, cmp);


    for (ll i = 1;i <= N;i++)
        if (fir[i])
        {
            modify(i, 1);
        }
    ll qtemp = q[1].l;
    ll ptr = 1;
    for (ll i = 1;i <= M;i++)
    {
        for (;ptr < q[i].l;ptr++)
        {
            if (fir[ptr])
            {
                modify(ptr, -1);
                fir[ptr] = false;
                if (Next[ptr])
                {
                    fir[Next[ptr]] = true;
                    modify(Next[ptr], 1);
                }
            }
        }
        ptr = q[i].l;
        qtemp = q[i].l;
        res[q[i].pos] = sum(q[i].r) - sum(q[i].l - 1);
    }
    for (ll i = 1;i <= M;i++) printf("%lld\n", res[i]);
    return 0;
}

Measured memory_bytes: 34568
#include <stdio.h>
int main(void)
{
  int i,e;
  static int n[26];
  char st,al[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   
  do{
    e = scanf("%c", &st);
 
    for(i=0;i<52;i++)
      if(al[i] == st){
        n[ i%26 ]++;
      }
 
  }while(e != EOF);
 
  for(i=0;i<26;i++)
    printf("%c : %d\n", al[i] , n[i]);
 
  return 0;
}


Measured memory_bytes: 2028
#include <stdio.h>
#include <math.h>

int main(void) {                                                                
    int n, i;                                                                   
    double x1, x2, x3, y1, y2, y3, z1, z2, z3;                                  
    double xp, yp, r;                                                           
                                                                                
    scanf("%d", &n);                                                            
    for (i = 0; i < n; i++) {                                                   
        scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);         
        z1 = x1*x1 + y1*y1;                                                     
        z2 = x2*x2 + y2*y2;                                                     
        z3 = x3*x3 + y3*y3;                                                     
        xp = (z1*(y2-y3)+z2*(y3-y1)+z3*(y1-y2)) /                               
            (2*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)));                                     yp = (z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2)) /                               
            (2*(y1*(x2-x3)+y2*(x3-x1)+y3*(x1-x2)));                             
        r = sqrt((x1-xp)*(x1-xp)+(y1-yp)*(y1-yp));                              
        printf("%.3f %.3f %.3f\n", xp, yp, r);                                      }                                                                           
                                                                                
    return 0;                                                                   
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
using namespace std;
using Graph= vector<vector<int>>;

constexpr int64_t MOD= 1'000'000'007;
constexpr bool is_FACTORIAL_STORED= false; // 階乗を配列に格納をする前処理をする/しない
constexpr int Nfac= is_FACTORIAL_STORED ? 100'007
                                        : 0;
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }
  bool operator==(const mint x) const {
    return rep==x.rep;
  }
  bool operator!=(const mint x) const {
    return rep!=x.rep;
  }

  mint pow(int64_t d) const{
    assert(d >= 0); // ここで引っかかったら this.pow(d)= 0 or this.pow(-d).inv() のどちらかを選べ
    assert(!(*this==0 && d==0)); //   this.pow(d)= 0 or 1           　     のどちらかを選べ
    mint ans= 1;
    mint x= *this;
    while(d > 0){
      if(d&1){ ans*= x; }
      d >>= 1;
      x*= x;
    }

    return ans;
  }

  friend istream& operator >> (istream &is, mint& x) noexcept{
    int64_t a;
    is >> a;
    x= a;
    return is;
  }
  friend ostream& operator << (ostream &os, const mint& x) noexcept{
      return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};
// ^^^ テンプレここまで ^^^

void solve(const Graph &tree, int parent, int child, vector<int> *subs, vector<mint> *dp){
  static const int N= (int)tree.size();

  mint Nwhite_not_holed= 1; // 黒い頂点が0個の木
  // 黒い頂点が1つの枝だけの木を足し上げる
  for(auto ngh:tree.at(child)){
    if(ngh != parent){
      solve(tree, child, ngh, subs, dp);

      subs->at(child)+= subs->at(ngh);
      Nwhite_not_holed+= ((mint)2).pow(subs->at(ngh))- 1;
    }
  }
  subs->at(child)++;
  Nwhite_not_holed+= ((mint)2).pow(N- subs->at(child))- 1;

  dp->at(child)= ((mint)2).pow(N-1)- Nwhite_not_holed;
}

int main(){
  int N;
  cin >> N;
  const int M= N-1;

  Graph tree(N);

  int v1,v2;
  for(int j=0; j<M; j++){
    cin >> v1 >> v2;
    v1--; v2--; // 1-indexed -> 0-indexed
    tree.at(v1).emplace_back(v2);
    tree.at(v2).emplace_back(v1);
  }

  vector<int> subs(N);
  vector<mint> dp(N);

  solve(tree, -1, 0, &subs, &dp);

  mint Nholed= 0;
  for(auto holed_v:dp){
    Nholed+= holed_v;
  }
  mint ans= Nholed/ ((mint)2).pow(N);

  cout << ans << endl;
}

Measured memory_bytes: 31956
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int S[204][204];
struct data {
  int v;
  int d;
  int p;
};

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > edge[204];
  for (int i=0; i<N; i++){
    std::string s;
    std::cin >> s;
    for (int  j=0; j<N; j++){
      S[i][j]=int(s[j])-int('0');
      if (S[i][j]==1) {
	edge[i].push_back(j);
      }
    }
  }
  // 二部グラフ判定
  //dfs(0);
  
  int ans = -1;
  for (int i=0; i<N; i++){
    //printf("i=%d\n", i);
    std::vector<int > dist(N+3, -5);
    std::vector<int > group[204];
    dist[i]=0;
    group[0].push_back(i);
    std::queue<data> queue;
    queue.push((data){i, 0, -1});
    int maxdist=-1;
    bool ok=true;
    while(queue.size()>0){
      int v=queue.front().v;
      int d=queue.front().d;
      int p=queue.front().p;
      queue.pop();
      //printf("v=%d, edgenum=%d\n", v, edge[v].size());
      for (int i=0; i<edge[v].size(); i++){
	int tgt=edge[v][i];
	if (tgt==p) continue;
	if (dist[tgt]==d+1 || dist[tgt]==d-1) continue;
	if (dist[tgt]!=-5) {
	  //printf("dist[%d]!=-1\n", tgt);
	  ok=false;
	  std::queue<data> empty;
	  std::swap(empty, queue);
	  break;
	}
	dist[tgt]=d+1;
	//printf("dist[%d]=%d\n", tgt, dist[tgt]);
	group[d+1].push_back(tgt);
	queue.push((data){tgt,d+1,v});
	maxdist=std::max(maxdist, d+1);
	//printf("push (%d, %d)\n", tgt, d+1);
      }
    }
    //    printf("maxdist=%d\n", maxdist);
    if (!ok) continue;
    for (int i=0; i<group[maxdist].size(); i++){
      int v=group[maxdist][i];
      //printf("v=%d\n", v);
      for (int j=0; j<edge[v].size(); j++){
	//printf("dist[%d](=%d) != maxdist(=%d)-1\n", j,dist[j],maxdist);
	int vv = edge[v][j];
	if (dist[vv]!=maxdist-1){
	  ok = false;
	}
      }
    }
    if (ok) ans = std::max(ans, maxdist+1);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1016
import numpy as np
n = int(input())
p = [float(i) for i in input().split()]
dp  = np.array([0.0] * (n + 1))
dp[0] = 1
for i in range(n):
 ura = dp*(1-p[i])
 ura[1:] += dp[:-1] * p[i]
 dp = ura

print(sum(dp[n // 2 + 1:]))

Measured memory_bytes: 12536
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n;
    int k;
    
    int x;
    int A;

    cin >> n >> k;

    int a[n + 1];

    for(int i = 1; i <= n; i++){
        a[i] = 1;
    }

   
    for(int i = 0; i < k; i++){
        cin >> x;
        for(int j = 0; j < x; j++){
            cin >> A;
            a[A] = 0;
        }

    }

    int sum = 0;

    for(int i = 1; i <= n; i++){
        sum = sum + a[i];
    }

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

    return 0;
    
}

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

#define MAX_H 50
#define MAX_W 50
#define INF 2500

int main() {
    int H, W;
    cin >> H >> W;
    char field[MAX_H+1][MAX_W+1];
    for (int i = 1; i < H+1; i++) {
        for (int j = 1; j < W+1; j++) {
            cin >> field[i][j];
        }
    }
    int n_white = 0;
    for (int i = 1; i < H+1; i++) {
        for (int j = 1; j < W+1; j++) {
            if (field[i][j] == '.') n_white++;
        }
    }

    int dmap[MAX_H+1][MAX_W+1] = {INF};
    dmap[1][1] = 0;
    pair<int, int> s = {1, 1};
    pair<int, int> g = {H, W};
    queue<pair<int, int>> q;
    q.push(s);
    bool flag = false;
    while (q.size() > 0) {
        pair<int, int> p = q.front();
        q.pop();
        if (field[p.first][p.second] == '#') continue;
        field[p.first][p.second] = '#';
        if (p == g) {
            flag = true;
            break;
        }
        int dys[4] = {-1, 1, 0, 0};
        int dxs[4] = {0, 0, -1, 1};
        for (int i = 0; i < 4; i++) {
            pair<int, int> np = {p.first + dys[i], p.second + dxs[i]};
            if (1 <= np.first && np.first < H+1 &&
                1 <= np.second && np.second < W+1 &&
                field[np.first][np.second] == '.') {
                q.push(np);
                dmap[np.first][np.second] = dmap[p.first][p.second] + 1;
            }
        }
    }
    if (flag)
        cout << (n_white - dmap[g.first][g.second] - 1) << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256