akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
#define pii pair<lli,lli>
#define vi vector <lli>
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
lli gcdExtended(lli a, lli b, lli *x, lli *y);
lli modInverse(lli b, lli m)
{
    lli x, y;
    lli g = gcdExtended(b, m, &x, &y);
    if (g != 1)
        return -1;
    return (x%m + m) % m;
}
lli modDivide(lli a, lli b, lli m)
{
    a = a % m;
    lli inv = modInverse(b, m);
    return (inv * a) % m;
}
lli gcdExtended(lli a, lli b, lli *x, lli *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }
    lli x1, y1;
    lli gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n;
    cin>>n;
    lli cnt[n+1];
    rep(i,n+1)
    cnt[i]=0;
    for(lli x=1;x*x<=n;x++){
    	for(lli y=1;y*y<=n;y++){
    		for(lli z=1;z*z<=n;z++){
    			if((x*x+y*y+z*z+x*y+y*z+z*x)<=n){
    				cnt[x*x+y*y+z*z+x*y+y*z+z*x]++;
				}
			}
		}
	}
	for(lli i=1;i<=n;i++)
	cout<<cnt[i]<<"\n";
    return 0;
}


Measured memory_bytes: 3608
import heapq
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(lambda x: x * (-1), a))

heapq.heapify(b)
for i in range(m):
    h = heapq.heappop(b)
    heapq.heappush(b, math.ceil(h / 2))

print(sum(b)*(-1))

Measured memory_bytes: 14536
#include<bits/stdc++.h>
using namespace std;
int N,M,a;
bool z[11];
string to_string(int n)
{
	stringstream ss;
	ss<<n;
	string s=ss.str();
	return s;
}
int main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)cin>>a,z[a]=1;
	for(int i=N;;i++)
	{
		string s=to_string(i);
		bool f=1;
		for(int j=0;j<s.size();j++)if(z[s[j]-48])f=0;
		if(f)
		{
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

struct Card {
  char suit, value;
};

void bubble(struct Card A[], int N) {
  for(int i = 0; i < N; i++) {
    for(int j = N - 1; j > i; j--) {
      if(A[j].value < A[j-1].value) {
        swap(A[j], A[j-1]);
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for(int i = 0; i < N; i++) {
    int minj = i;
    for(int j = i; j < N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    swap(A[i], A[minj]);
  }
}

void print(struct Card A[], int N) {
  for(int i = 0; i < N; i++) {
    if(i > 0) cout<<" ";
    cout<<A[i].suit<<A[i].value;
  }
  cout<<endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for(int i = 0; i < N; i++) {
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main() {
  Card C1[100], C2[100];
  int N;

  cin>>N;
  for(int i = 0; i < N; i++) {
    cin>>C1[i].suit>>C1[i].value;
  }

  for(int i = 0; i < N; i++) {
    C2[i] = C1[i];
  }

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout<<"Stable"<<endl;
  print(C2, N);
  if( isStable(C1, C2, N)) {
    cout<<"Stable"<<endl;
  } else {
    cout<<"Not stable"<<endl;
  }

  return 0;

}



Measured memory_bytes: 3076
program atcoder
    implicit none
    integer(8) :: n,k,i,j
    integer(8),allocatable,dimension(:,:) :: a,b
    read*,n,k
    allocate(a(n,n),b(n,n))
    do i=1,n
        read(*,*)(a(i,j),j=1,n)
    enddo
    do i=1,n
        do j=1,n
            b(i,j) = 0
            if(i==j)then
                b(i,j) = 1
            endif
        enddo
    enddo
    do while (k/=0)
        if(mod(k,2_8)==1)then
            b = my_matmul(b,a,n)
            b = mod(b,1000000007_8)
        endif
        a = my_matmul(a,a,n)
        a = mod(a,1000000007_8)
        k = ishft(k,-1)
    enddo
    write(*,'(I0)')mod(sum(b),1000000007_8)
    stop 
contains

function my_matmul(x,y,n) result(a)
    implicit none
    integer(8) :: i,j,k,n
    integer(8),dimension(n,n) :: x,y
    integer(8),allocatable,dimension(:,:) :: a
    allocate(a(n,n))
    a = 0
    do i=1,n
        do j=1,n
            do k=1,n
                a(i,j) = mod(a(i,j)+x(i,k)*y(k,j),1000000007_8)
            enddo
        enddo
    enddo
end function my_matmul

end program atcoder

Measured memory_bytes: 256
MAX_V = 100100
MAX_N = 101
INF = pow(2, 64)

N, W = map(int, input().split())
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[INF for _ in range(MAX_V)] for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for sum_v in range(MAX_V):
        # print(i, sum_v, sum_v - v[i] >= 0)
        if sum_v - v[i] >= 0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i])
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])
        # print(dp[i + 1][sum_v])

ans = max([i for i in range(len(dp[N])) if dp[N][i] <= W])
# for l in dp:
#     print([n for n in l if not n == INF])

print(ans)


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

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back
#define fir first
#define sec second
const db pi = atan(1)*4; 

const int maxn = 200006; 

using pii = pair<int,int>; 
pii a[maxn]; 
int X1, Y1, X2, Y2; 
int N, n; 
bool flag = false; 
int f[maxn]; 

int main() {
	scanf( "%d%d%d%d", &X1, &Y1, &X2, &Y2 ); 
	if (X1 >= X2) {
		swap(X1, X2); 
		swap(Y1, Y2); 
	}
	if (Y1 > Y2) {
		flag = true; 
		Y1 = -Y1; 
		Y2 = -Y2; 
	}
	n = 0; 
	scanf( "%d", &N ); 
	for (int i = 1; i <= N; ++i) {
		int x, y; 
		scanf( "%d%d", &x, &y ); 
		if (flag) y = -y; 
		if (X1 <= x && x <= X2 && Y1 <= y && y <= Y2) {
			a[n++] = make_pair(x,y); 
		}
	}
	//if (X1 == X2 || Y1 == Y2) {
		//printf( "%.12f\n", db(Y2-Y1+X2-X1)*100 + (pi*10-20)*(n>0)); 
		//return 0; 
	//}
	sort(a,a+n); 
	int ans = 0; 
	set<int> S; 
	for (int i = 0; i < n; ++i) {
		f[i] = 1; 
		auto u = S.lower_bound(a[i].sec); 
		if (u != S.end()) S.erase(u); 
		S.insert(a[i].sec); 
		//for (int j = 0; j < i; ++j) 
			//if (a[j].sec < a[i].sec) f[i] = max(f[i],f[j]+1); 
		//ans = max(ans, f[i]); 
	}
	ans = S.size(); 
	int bb = min(X2-X1, Y2-Y1); 
	printf( "%.13f\n", db(Y2-Y1+X2-X1)*100 + (pi*5-20)*min(ans,bb)+(ans>bb)*(pi*10-20) ); 
	
}


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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    lld a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max({a * c, a * d, b * c, b * d}) << '\n';
    return 0;
}

// g++ sol.cpp -o sol.out -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
using namespace std;
#define MAX 100005
int main(){
    int n;
    cin >> n;
    vector<int> imos(MAX);
    imos[0]++;
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        imos[a]++;
        imos[b+1]--;
    }
    for(int i = 0; i < MAX-1; i++)imos[i+1] += imos[i];
    for(int i = MAX-1; i > 0; i--){
        if(imos[i] >= i){
            cout << i-1 << endl;
            return 0;
        }
    }

}



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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;

vector<set<ll>> g;
vector<ll> h;

void solve(){
    int n, m, u, v;
    cin>>n>>m;
    g.resize(n+1);
    h.resize(n+1);
    rep(i, 1, n) cin>>h[i];
    fr(i, m) {
        cin>>u>>v;
        g[u].insert(h[v]);
        g[v].insert(h[u]);
    }

    int cnt = 0;
    rep(i, 1, n) {
        if(!g[i].size() || h[i] > *g[i].rbegin()) cnt++;
    }
    cout<<cnt;

}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



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

int main(){
    int N;
    cin >> N;
    int t[100010]={}, x[100010]={}, y[100010]={};
    for(int i=1; i<=N; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    
    int dt=0, distance=0;
    bool frag=true;
    
    for(int i=0; i<N; i++){
        dt=t[i+1]-t[i];
        distance=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        if(dt<distance){
            frag=false;
            break;
        }
        if((dt-distance)%2==0){
            frag=true;
            continue;
        }else{
            frag=false;
            break;
        }
    }
    
    if(frag==true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1408
K,N = list(map(int,input().split()))
A = list(map(int,input().split()))
m = 0
for i in range (N - 1):
    m = max(m,A[i + 1] - A[i])
m = max(m,A[0] + K - A[N - 1])
print(K - m)

Measured memory_bytes: 25836
<?php
$nx = explode(' ', trim(fgets(STDIN)));
$n  = $nx[0];
$x  = $nx[1];
$m  = [];
while (true) {
    $input = trim(fgets(STDIN));
    if (empty($input)) {
        break;
    }
    array_push($m, $input);
}

$remain_x     = $x - array_sum($m);
$min          = min($m);
$remain_count = floor($remain_x / $min);

print count($m) + $remain_count;

Measured memory_bytes: 4604
#include "bits/stdc++.h"
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int incorrect = 0;
    for(int i = 0; i < n; i++){
        if(a[i] != i+1) incorrect++;
    }
    if(incorrect <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int ans = min(a*n, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3556
/* AtCoder Panasonic Programming Contest 2020. Task C. */
#include <bits/stdc++.h>

using namespace std;

#define COUT_PRECISION 10

namespace abreto {

typedef long long int ll;

char const *judge(ll a, ll b, ll c)
{
    ll d = c - a - b;
    if (d <= 0) return "No";
    ll l = 4ll * a * b;
    ll r = d * d;
    if (l >= r) return "No";
    return "Yes";
}

void main(void) {
    ll a, b, c;
    cin >> a >> b >> c;
    cout << judge(a, b, c) << '\n';
}

}

int main(void) {
    cin.sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(COUT_PRECISION);
    abreto::main();
    return 0;
}


Measured memory_bytes: 256
program probD
  implicit none
  integer(8) :: n
  integer(16), allocatable :: f(:)
  integer(8) :: i, j

  
  read(*,*) n
  allocate(f(n))
  
  do i = 1, n
     do j = i, n, i
        f(j) = f(j) + j
     end do
  end do
  
  write(*,*) sum(f)
  stop
end program probD


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

int main() {
  long N, M, X;

  std::cin >> N;
  std::cin >> M;
  std::cin >> X;

  long cost_l = 0;
  long cost_r = 0;

  for (long i=0; i<M; i++) {
    long A;
    std::cin >> A;

    if (A < X)
      cost_l++;
    else
      cost_r++;
  }

  std::cout << (cost_l<cost_r ? cost_l : cost_r) << std::endl;

  return 0;
}


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

int main() {
    int D;
    double E;
    while (cin >> D >> E) {
        if (D == 0) break;

        double mn = 1e9;
        for (int i=0; i<=D; ++i) {
            double x = i;
            double y = D-x;
            if (abs(E - sqrt(x*x + y*y)) < mn) {
                mn = abs(E - sqrt(x*x + y*y));
            }
        }
        printf("%.10lf\n", mn);
    }
    return 0;
}


Measured memory_bytes: 3208
# -*- coding: utf-8 -*-

N = int(input().strip())
#-----

class Recursion():
    def __init__(self, N :int):
        self.N = N
        self.all_pattern=[]
        
        self.check("")
        
    def check(self, num_str :str):
        for word in "753":
            next_num = num_str + word
            if int(next_num) > self.N:
                continue
            else:
                if all(s in next_num for s in "753"):
                    self.all_pattern.append(next_num)
                self.check(next_num)
        

rec = Recursion(N)
print(len(rec.all_pattern))


Measured memory_bytes: 4864
import math

x = int(input())

#y以上の値は候補とならない
y = int(math.sqrt(x))

k_max = 1
if y >= 2:
    for i in range(2, y + 1):
        j = int(math.log10(x) / math.log10(i))
        k = i ** j
        
        
        if k > k_max:
            k_max = k
    
print(k_max)

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

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  ll n, m;
  cin >> n >> m;
  ll res = 1LL * (1900 * m + 100 * (n - m)) * (1LL << m);
  cout << res;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  int res = 0;
  if (x <= y) {
    if (x < 0 && y > 0) {
      res = abs(abs(x) - y) + 1;
    } else {
      res = y - x;
    }
  } else {
    res = abs(abs(x) - abs(y)) + 1 + ((x < 0 && y < 0) || (x > 0 && y > 0));
  }
  printf("%d\n", res);
}

Measured memory_bytes: 3212
# include <cstdio>
# include <iostream>
# define R register int

using namespace std;

int n,m,mm,ans;

void check (int x)
{
	if(m/x>=n) ans=max(ans,x);
}

int main()
{
	scanf("%d%d",&n,&m);
	mm=m;
	check(1);
	for (R i=2;i*i<=m;++i)
	{
		if(m%i) continue;
		check(i);
		check(m/i);
	}
	check(m);
	printf("%d",ans);
	return 0;
}

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

using namespace std;

int main () {
    int N, M;

    while (cin >> N >> M) {
        long long A;
        priority_queue<long long> pq;

        for (int i = 0;i < N;i++) {
            cin >> A;
            pq.push(A);
        }
        while (M--) {
            if (pq.empty())
                break;
            long long t = pq.top();
            pq.pop();
            t /= 2;
            if (t != 0)
                pq.push(t);
        }
        long long ans = 0;
        while (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b) {a = b; return true;}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b) {a = b; return true;}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
    string s; cin >> s;
    ll n = s.size();
    rep(i,n) cout << "x";
    cout << endl;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
class SCC{//cmp(0 - kk-1) is scc's return. Same number is group. The number is no relatoin.
	public:
	int n;
	vvi G,rG,tG;
	vector<bool>used;
	vi vs,cmp;
	SCC(int size){
		n=size;
		G=rG=vvi(n);
		used=vector<bool>(n);
		cmp=vi(n);
		vs=vi(0);
	}
	void add_edge(int s,int t){
		G[s].pb(t);
		rG[t].pb(s);
	}
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		rep(i,rG[v].size())if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
	void dfs(int v){
		used[v]=true;
		rep(i,G[v].size())if(!used[G[v][i]])dfs(G[v][i]);
		vs.pb(v);
	}
	int scc(){
		rep(i,n)used[i]=false;
		rep(v,n)if(!used[v])dfs(v);
		rep(i,n)used[i]=false;
		int kk=0;
		for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]])rdfs(vs[i],kk++);
		return kk;  
	}
	void make(int size){
		int N=size;
		tG=vvi(N);
		rep(i,n)rep(j,G[i].size())if(cmp[i]!=cmp[G[i][j]]){
//			tG[cmp[i]].pb(cmp[G[i][j]]);
			tG[cmp[G[i][j]]].pb(cmp[i]);
		}
	}
};
int main(){
	int n;
	while(cin>>n,n){
		vd d(n);
//		vvi G(n);
		SCC scc(n);
		rep(i,n){
			cin>>d[i];
			int a;cin>>a;
			rep(j,a){
				int b;cin>>b;
				b--;
				scc.add_edge(i,b);
			}
		}
		int N=scc.scc();
		scc.make(N);
		vvi rG=scc.tG;
		vi c=scc.cmp;
		vd nd(N);
		rep(i,N){
			double t=1;
			rep(j,n)if(c[j]==i)t*=d[j];
			nd[i]=t;
		}
		double out=1;
		rep(i,N)if(!rG[i].size())
			out*=(1-nd[i]);
		
		cout<<shosu(9)<<out<<endl;
	}
}







Measured memory_bytes: 3420
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D 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 (LLONG_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>;
// functions

#endif


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

    int H, W; cin >> H >> W;
    vs S(H); REP(i, H) cin >> S[i];

    vector<vector<int>> cnt(H, vector<int>(W,0));
    REP(i,H){
        vb done(W, false);
        REP(j,W) {
            if (S[i][j] == '#') continue;
            if (done[j]) continue;

            int l = 0;
            while(j+l<W) {
                if (S[i][j + l] == '#') break;
                l++;
            }
            for(int k=0; k<l; k++) {
                cnt[i][j + k] = l;
                done[j + k] = true;
            }
        }
    }

    REP(j,W) {
        vb done(H, false);
        REP(i,H){
            if (S[i][j] == '#') continue;
            if (done[i]) continue;

            int l = 0;
            while(i+l<H) {
                if (S[i + l][j] == '#') break;
                l++;
            }
            for(int k=0; k<l; k++) {
                cnt[i + k][j] += l - 1;
                done[i + k] = true;
            }
        }
    }

    int ans = 0;
    REP(i,H)
        REP(j,W)
            ans = max(ans, cnt[i][j]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int as [4] [3] [10];

int main() {
    int n, b, f, r, v;
    cin >> n;

    for (int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        b--;
        f--;
        r--;
        as[b] [f] [r] += v;      
    }
    for (int i = 0; i < 4; i++){  
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 10; k++){
                cout << " " << as[i] [j] [k];
            }
        cout << endl;
        }
        if (i < 3){
            for (int j = 0; j < 20; j++){
                cout << '#';
            }
        cout << endl;
        }
    } 
}


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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

const int INF = (int)1e9;

using namespace std;

signed main(){
	string s1, s2; cin >> s1 >> s2;
	vector<vector<int> > dp(s1.size()+1, vector<int>(s2.size()+1,INF));
	for(int i = 0; i <= s1.size(); i++)dp[i][0] = i;
	for(int i = 0; i <= s2.size(); i++)dp[0][i] = i;
	for(int i = 1; i <= s1.size(); i++){
		for(int j = 1; j <= s2.size(); j++){
			dp[i][j] = min(dp[i-1][j], dp[i][j-1])+1;
			dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (s1[i-1] == s2[j-1] ? 0 : 1));
		}
	}
	//for(auto v: dp){for(auto e : v)cerr << e; cerr << endl;}
	cout << dp[s1.size()][s2.size()] << endl;


	return 0;
}




Measured memory_bytes: 6868
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(void){
  int n;
  double dp[100001]={0},p,w;
  
  dp[1]=1;

  for(int i=2;i<100001;i++){
    p=1;
    w=0.5;
    for(int j=1; j<i && 0.00000000001<p; j++){
      dp[i]+=p*(1-w)*(j+dp[i-j-1]);
      p*=w;
      w/=2;
    }
    dp[i]+=i*p;
  }

  while(cin >> n,n)
    printf("%.8f\n",dp[n]);

  return 0;
}

Measured memory_bytes: 1976
import Data.Char
import Control.Applicative

type Card = (Char, Int)

cardFromString :: String -> Card
cardFromString [m, v] = (m, digitToInt v)

cardToString :: Card -> String
cardToString (m, v) = [m, intToDigit v]

cardMark :: Card -> Char
cardMark (m, _) = m

cardNum :: Card -> Int
cardNum (_, v) = v

bubbleSort :: [Card] -> [Card]
bubbleSort [card] = [card]
bubbleSort cards =
    card1:(bubbleSort cards1)
    where
        (card1:cards1) = bubbling cards

bubbling :: [Card] -> [Card]
bubbling [card] = [card]
bubbling (card:cards) =
    if cardNum card <= cardNum card1
        then (card:card1:cards1)
        else (card1:card:cards1)
    where
        (card1:cards1) = bubbling cards

minCard :: [Card] -> Card
minCard (c:cs) =
    loop c cs
    where
        loop :: Card -> [Card] -> Card
        loop c [] = c
        loop c1 (c2:cs)
          | cardNum c1 <= cardNum c2 = loop c1 cs
          | otherwise                = loop c2 cs

select :: [Card] -> [Card]
select (card:cards) =
    if card == mcard
       then mcard:cards
       else mcard:(replace mcard card cards)
    where
        mcard = minCard (card:cards)
        replace :: Card -> Card -> [Card] -> [Card]
        replace _ _ [] = []
        replace old new (c:cs)
          | old == c  = new:cs
          | otherwise = c:(replace old new cs)

selectionSort :: [Card] -> [Card]
selectionSort [card]       = [card]
selectionSort cards =
    card1:(selectionSort cards1)
    where
        (card1:cards1) = select cards

marks :: Int -> [Card] -> [Char]
marks n = map cardMark . filter (\c -> cardNum c == n)

isStable :: [Card] -> [Card] -> Bool
isStable cards orders =
    loop (map cardNum cards) cards orders
    where
        loop :: [Int] -> [Card] -> [Card] -> Bool
        loop [] _ _ = True
        loop (n:ns) cards orders
          | marks n cards == marks n orders = loop (remove n ns) cards orders
          | otherwise = False
        remove :: Int -> [Int] -> [Int]
        remove n = filter (/=n)

printResult :: [Card] -> [Card] -> IO ()
printResult cards orders = do
    putStrLn $ unwords (cardToString <$> orders)
    if isStable cards orders
       then putStrLn "Stable"
       else putStrLn "Not stable"

main :: IO ()
main = do
    getLine
    cards <- map cardFromString . words <$> getLine :: IO [Card]
    printResult cards (bubbleSort cards)
    printResult cards (selectionSort cards)



Measured memory_bytes: 3880
#include<stdio.h>
int search(int[], int, int);

int main(){
  int i, n, q, key, C=0;
  int S[10000], T[500];

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);

  for( i = 0 ; i < q ; i++ ){
    scanf("%d", &T[i]);
    if( search(S, n, T[i])) C++;
  }
  printf("%d\n", C);
  return 0;
}


int search(int S[], int n, int t){
  int i=0;
  S[n] = t;
  while( S[i] != t ) i++;
  return i != n;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main(){
    int x;
    cin >> x;
    int n_500 = x/500;
    x -= n_500 * 500;
    int n_5 = x/5;
    int ans = n_500 * 1000 + n_5 * 5;
    cout << ans << endl;
}


Measured memory_bytes: 256
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.root = [-1]*(n+1)
		self.rank = [0]*(n+1)

	def find(self, x):
		if(self.root[x] < 0):
			return x
		else:
			self.root[x] = self.find(self.root[x])
			return self.root[x]
			
	def unite(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if(x == y):
			return 0
		elif(self.rank[x] > self.rank[y]):
			self.root[x] += self.root[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.root[x] = y
			if(self.rank[x] == self.rank[y]):
				self.rank[y] += 1

	def isSame(self, x, y):
		return self.find(x) == self.find(y)

V,E,*t = map(int,open(0).read().split())
edges = sorted([(w,s,t) for s,t,w in zip(*[iter(t)]*3)])
uf = UnionFind(V)
ans = 0
for w,s,t in edges:
	if not uf.isSame(s,t):
		ans += w
		uf.unite(s,t)
print(ans)
		



Measured memory_bytes: 37696
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  list<int> b;
  for(int i=0; i<N; i++){
    if(i%2 == 0){
      b.push_front(a.at(i));
    }else{
      b.push_back(a.at(i));
    }
  }
  if(N%2 == 0){
    reverse(b.begin(),b.end());
  }
  list<int>::iterator itr;
  for(itr=b.begin(); itr != b.end(); itr++){
    cout << *itr << " ";
  }
  cout << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  array<int, 5> x;
  for (auto &in: x) {
    cin >> in;
  }

  for (int i = 1; i <= 5; ++i) {
    if (x[i - 1] == 0) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string n;
    int a,i;
    cin>>n;
    a=n.length();
    for(i=0;i<a;i++)
    {
        if(n[i]==',') cout<<" ";
        else cout<<n[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
#pragma region Imports
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#pragma endregion
#pragma region Macros
#pragma GCC optimize (2)
#define uns unsigned
#define out cout
#define in cin
#define au auto
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define elif else if
#define sz(x) x.size()
#define fl(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define fli(i, a, b, c) for(int (i)=a;(i)<(b);(i)+=(c))
#define fr(i, x) for(int (i)=(x)-1;(i)>=0;(i)--)
#define fb(i, x) for(int (i)=0;(i)<(x);(i)++)
#define fa(i, x) for(auto& (i):(x))
#define ia(a, n) for(int qw=0;qw<(n);qw++)cin>>(a)[qw];
#define oa(a, n) for(int qw=0;qw<(n);qw++)cout<<(a)[qw]<<" ";
#define im(a, n, m) fb(i,(n))fb(j,(m))cin>>(a)[i][j];
#define om(a, n, m) fb(i,(n))fb(j,(m))cout<<(a)[i][j]<<" \n"[j==(m)-1];
#define eb(v, x) (v).emplace_back(x);
#define seb(s, x) (s).emplace(x);
#define pr(x, y) pair<x,y>
#define vr(x) vector<x>
#define mp(x, y) make_pair(x,y)
#define hm(x, y) map<x,y>
#define um(x, y) unordered_map<x,y>
#define stk(x) stack<x>
#define qu(x) queue<x>
#define dq(x) deque<x>
#define pq(x) priority_queue<x>
#define pqm(x) priority_queue<x,vector<x>,greater<(x)>>
#define mem(a, x) memset(a,(x),sizeof(a));
#define fi(x) (x).first
#define se(x) (x).second
#define ql(x) int tc;tc=(x);if(tc==-1)cin>>tc;while(tc--)
#define srt(x) sort((x).begin(),(x).end());
#define pops(y, x) auto (y)=(x).front();(x).pop();
#define ppc(x) __builtin_popcount((x))
#define all(x) (x).begin(),(x).end()
#define sieve(b, n) bool (b)[(n)];mem((b),true);int sq=int(sqrt(n))+1;(b)[0]=(b)[1]=false;fl(i,2,sq)if((b)[i])fli(j,i*i,n,i)(b)[j]=false;
#define dbg(x) cout<<#x<<" "<<(x)<<"\n";
#pragma endregion
#pragma region Typedefs and Consts
typedef long long int ll;
typedef unsigned long long int ull;
typedef string stg;
typedef float flo;
typedef char chr;
typedef vector<int> vi;
const ull mod = 1000000007;
const int imx = INT_MAX;
const int imn = INT_MIN;
const ll lmx = LLONG_MAX;
const ll lmn = LLONG_MIN;
#pragma endregion
#pragma region Functions
inline ull powm(ull x,ull y,bool b=false,ull m=mod){ if(b){ ull t=1;x%=m;while(y>0){ if(y%2)t=(t*x)%m;y=y>>1;x=(x*x)%m; }return t; }else
    { ull t=1;while(y>0){ if(y&2)t*=x;y=y>>1;x*=x; }return t;}}
inline ll gcd(ll a,ll b){a=abs(a);b=abs(b); while(b!=0){ ll c=a%b;a=b;b=c;}return a;}
#pragma endregion

//cout<<"Case #"+to_string(tc+1)+": "+to_string(z)<<endl;
double d[3000][6000];
double f(double a[],int n,int i,int s){
  if(s+(n-i)<=0)
    return 0.0;
  if(i==n)
    return 1.0;
  if(d[i][s+n]==-1.0)
    d[i][s+n]=a[i]*f(a,n,i+1,s+1)+(1.0-a[i])*f(a,n,i+1,s-1);
  return d[i][s+n];
}
int main() {
  fio
  int n;
  in>>n;
  double a[n];
  ia(a,n)
  fb(i,3000)
    fb(j,6000)
    d[i][j]=-1.0;
  out<<setprecision (10)<<f(a,n,0,0);
  return 0;
}


Measured memory_bytes: 141184
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t r,c,k,x,y,z,i,j,l;
  cin>>r>>c>>k;
  vector<vector<int64_t>> v(r+1,vector<int64_t>(c+1));
  vector<vector<vector<int64_t>>> dp(r+1,vector<vector<int64_t>>(c+1,vector<int64_t>(4)));
  for(i=0;i<k;i++){
    cin>>x>>y>>z;
    v.at(x).at(y)=z;
  }
  for(i=1;i<=r;i++){
    for(j=1;j<=c;j++){
      if(v.at(i).at(j)==0){
        for(l=0;l<4;l++){
          dp.at(i).at(j).at(l)=max(dp.at(i-1).at(j).at(3),dp.at(i).at(j-1).at(l));
        }
      }
      else if(v.at(i).at(j)>0){
        dp.at(i).at(j).at(0)=max(dp.at(i-1).at(j).at(3),dp.at(i).at(j-1).at(0));
        for(l=1;l<4;l++){
          dp.at(i).at(j).at(l)=max(max(dp.at(i-1).at(j).at(3),dp.at(i).at(j-1).at(l-1))+v.at(i).at(j),dp.at(i).at(j-1).at(l));
        }
      }
    }
  }
  cout<<dp.at(r).at(c).at(3)<<endl;
}

Measured memory_bytes: 707104
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k,q = inpl()
a = inpln(q)
d = defaultdict(int)
for i in range(q):
    d[a[i]] += 1
for i in range(1,n+1):
    # print(d[i])
    if q - d[i] < k:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 20704
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int t = sc.nextInt();
    int s = sc.nextInt();
    sc.close();
    int r = 0;
    

    if( d % s == 0) r = d / s;
    else r = d / s + 1;

    

    if(r <= t){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }

}
}

Measured memory_bytes: 35736
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1<<30;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
int main(){
  string s; cin >> s;
  string t="";
  rep(i,0,s.size()-1){
    if(s[i]=='B'&&s[i+1]=='C'){
      t += 'X';
      i++;
    }else{
      t += s[i];
    }
  }
  vector<int> v(t.size()+1,0);
  ll cnt=0, ans = 0;
  rep(i,0,t.size()){
    if(t[i]=='A') cnt++;
    else if(t[i]=='X') ans += cnt;
    else cnt = 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1544
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll z;
    cin >> z;

    ll ans = (z / 11) * 2;
    if(z % 11 > 0 && z % 11 <= 6){
        ans += 1;
    }else if(z % 11 > 6){
        ans += 2;
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  int D; cin >> D;
  vector<int> c(26);
  for(int i=0; i<26; i++) cin >> c[i];
  vector<vector<int>> s(D,vector<int>(26));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }
  vector<vector<int>> lastc(D+1,vector<int>(26,0));
  vector<int> t(D);
  
    srand(std::time(nullptr));
  
  for(int i=1; i<=D; i++){
    
    int cont; /*cin >> cont;
    cont--;*/ cont=rand()%26;
    t[i-1]=cont;
    
    //lastcの更新
    for(int j=0; j<26; j++){
      if(j==cont) lastc[i][j]=i;
      else lastc[i][j]=lastc[i-1][j];
    }
  }
  
  int M=1000000;//調整
  for(int i=0; i<M; i++){
    int d,q; /*cin >> d >> q; q--;
    */
    d=rand()%D+1; 
    q=rand()%26;
    int qold=t[d-1];
    
    int sat=0;
    
    sat = sat - s[d-1][qold];
    sat = sat + s[d-1][q];
    
    int lastcold = lastc[d-1][qold];
    for(int j=d; j<=D; j++){
      if(j==d){
        sat-=c[qold]*(j-lastcold);
      }
      else if(lastc[j][qold]==j){
        break;
      }
      else{
        sat-=c[qold]*(lastc[j][qold]-lastcold);
      }
    }
    
    for(int j=d; j<=D; j++){
      if(lastc[j][q]==j){
        break;
      }
      else{
        sat+=c[q]*(d-lastc[j][q]);
      }
    }
    
    if(sat>0||rand()%1000==0){
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][qold]=lastc[j-1][qold];
        }
        else if(lastc[j][qold]==j){
          break;
        }
        else{
          lastc[j][qold]=lastc[j-1][qold];
        }
      }
      
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][q]=d;
        }
        else if(lastc[j][q]==j){
          break;
        }
        else{
          lastc[j][q]=lastc[j-1][q];
        }
      }
      
      t[d-1]=q;
    }
  }
  
  for(int i=0; i<D; i++){
    cout << t[i]+1 << endl;
  }
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, K;
  cin >> N >> K;
  long long ans = 0;
  for (int i = 1; i <= N; i++){
    int r1 = i % K;
    int r2 = (K - r1) % K;
    int r3 = (K - r1) % K;
    if ((r2 + r3) % K == 0){
      if (r2 == 0){
        ans += (N / K) * (N / K);
      } else {
        ans += ((N - r2) / K + 1) * ((N - r3) / K + 1);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
(* O(|s|^2) *)
let s = read_line ()
let t = read_line ()
let n = String.length s
let rotate s = String.make 1 s.[n - 1] ^ String.sub s 0 (n - 1)
let s' = ref s
let _ =
  for i = 1 to n do if !s' = t then (print_endline "Yes"; exit 0); s' := rotate !s' done;
  print_endline "No"

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

int main(void){
    int n;
    cin >> n;
    
    char s[102];
    cin >> s;
    
    int cnt[101] = {0};
    int begin = 0, end = 0;
    int min = 0;
    int i;
    for(i = 1; i <= n; i++){
        if(s[i - 1] == '('){
            cnt[i] = cnt[i - 1] + 1;
            begin++;
        }else{
            cnt[i] = cnt[i - 1] - 1;
            end++;
            if(cnt[i] < min){
                min = cnt[i];
            }
        }
    }
    
    if(min < 0){
        i = min;
        while(i != 0){
            cout << '(';
            i++;
        }
        begin -= min;
    }
    
    if(begin == end){
        cout << s;
    }else if(begin > end){
        cout << s;
        i = begin - end;
        while(i != 0){
            cout << ')';
            i--;
        }
    }else{
        i = end - begin;
        while(i != 0){
            cout << '(';
            i--;
        }
        cout << s;
    }
    
    cout << endl;
    
    return 0;
}


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

#define ll long long

#define loop(i,start,end,in) for (int i=start;i<end ;i = i+in)
#define rloop(i,start,end,in) for (int i=start;i>end ;i = i-in)

int main()
{

  ll n;
  cin>>n;
  ll ar[n];
  loop(i,0,n,1)
  {
      cin>>ar[i];
  }
  sort(ar,ar+n);
  ll c = 0;
  loop(i,0,n-2,1)
  {
      loop(j,i+1,n-1,1)
      {
          loop(k,j+1,n,1)
          {
              if(ar[i]!=ar[j]&&ar[j]!=ar[k]&&ar[i]+ar[j]>ar[k])
              {
                 c++;
              }
          }
      }
  }
  cout<<c<<endl;

}




Measured memory_bytes: 3600
def solve():
    n = int(input())
    p = list(map(int,input().split()))
    cnt = 0
    for i in range(1,n-1):
        if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
            cnt+=1
    print(cnt)
if __name__=='__main__':
    solve()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <climits>
using namespace std;

bool comp(pair<int, string> a, pair<int, string> b){
  if(a.first != b.first) return a.first > b.first;
  else return a.second < b.second;
}
 
int main(){
  string sa,sb,sc;
  cin >> sa >> sb >> sc;

  vector<char> va;
  vector<char> vb;
  vector<char> vc;

  for(int i = sa.size()-1;i >= 0;--i){
    va.push_back(sa[i]);
  }
  for(int i = sb.size()-1;i >= 0;--i){
    vb.push_back(sb[i]);
  }
  for(int i = sc.size()-1;i >= 0;--i){
    vc.push_back(sc[i]);
  }
  char ch = va.back();
  va.pop_back();
  while(true){
        if(ch == 'a' && va.size() == 0){
      cout << 'A' << endl;
      break;
    }else if(ch == 'b' && vb.size() == 0){
      cout << 'B' << endl;
      break;
    }else if(ch == 'c' && vc.size() == 0){
      cout << 'C' << endl;
      break;
    }
    if(ch == 'a'){
      ch = va.back();
      va.pop_back();
    }else if(ch == 'b'){
      ch = vb.back();
      vb.pop_back();
    }else{
      ch = vc.back();
      vc.pop_back();
    }

  }
}

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

template < typename T > std::string to_string( const T& n )
{
  std::ostringstream stm ;
  stm << n ;
  return stm.str() ;
}

int main(){
  unsigned int n, sum = 0;
  string s;
  cin >> n;
  s = to_string(n);
  for(int i = 0; i < s.size(); ++i){
    sum += s[i] - '0';
  }
  if(n%sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
/*
	##############################
	## Author: Pratyush Gaurav ###
	## College: NIT ROURKELA #####
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long/*--------------------*/lli;
typedef long double/*------------------*/ld;
typedef unsigned long long/*-----------*/ulli;
typedef pair<lli, lli >/*--------------*/plli;
typedef vector<plli >/*----------------*/vplli;

#define rep(i,a)/*---------------------*/for(i = 0 ; i < a ; i++)
#define repr(i,a)/*--------------------*/for(i = a ; i >= 0 ; i--)
#define REP(i,a,b)/*-------------------*/for(i = a ; i <= b ; i++)
#define REPR(i,a,b)/*------------------*/for(i = a ; i >= b ; i--)

#define scan(N)/*----------------------*/scanf("%lld",&N)
#define print(N)/*---------------------*/printf("%lld",N)
#define scan2(N1,N2)/*-----------------*/scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2)/*----------------*/printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3)/*--------------*/scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3)/*-------------*/printf("%lld %lld %lld",N1,N2,N3)

#define lb/*---------------------------*/lower_bound
#define ub/*---------------------------*/upper_bound
#define pb/*---------------------------*/push_back
#define popb/*-------------------------*/pop_back

#define mem(a,b)/*---------------------*/memset(a,b,sizeof(a))
#define opt/*--------------------------*/ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz/*---------------------------*/size()

#define MP/*---------------------------*/make_pair
#define bs/*---------------------------*/binary_search
#define gcd(a, b)/*--------------------*/__gcd(a, b)
#define lcm(a, b)/*--------------------*/((a)*((b)/gcd(a,b)))
#define sqr(x)/*-----------------------*/(x)*(x)
#define all(a)/*-----------------------*/a.begin(),a.end()

#define ff/*---------------------------*/first
#define ss/*---------------------------*/second

#define endl/*-------------------------*/'\n'
#define inf/*--------------------------*/(lli)2000000000000
#define MOD/*--------------------------*/(lli)1000000007
#define MAXN/*-------------------------*/100005

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0)
    {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else
    {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}

int main()
{
	opt;
	lli n;
	cin >> n;
	vector<lli> v(n);
	lli i,cnt = 0,ans = 0;
	rep(i,n) { cin >> v[i]; if(v[i] & 1) cnt++;}
	if(cnt > 0)
        cout << 0 << endl;
    else
    {
        lli tmp,ans = inf;
        rep(i,n)
        {
            tmp = 0;
            while(v[i] % 2 == 0)
            {
                v[i] = v[i]/2;
                tmp++;
            }
            ans = min(ans,tmp);
        }
        cout << ans << endl;
    }

	return 0;
}










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

int N;
string S[100];
int P[100];

bool comp(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }

    return true;
}

int main() {
    cin >> N;
    rep(i, N) cin >> S[i] >> P[i];


    vector<pair<string, int>> v;
    vector<pair<string, int>> v222;
    rep(i, N) {
        pair<string, int> p = make_pair(S[i], P[i]);
        v.push_back(p);
        v222.push_back(p);
    }
    sort(v.begin(), v.end(), comp);

    // cout << endl;
    // rep(i, N) {
    //     pair<string, int> target = make_pair(S[i], P[i]);
    //     int idx = find(v.begin(), v.end(), target) - v.begin(); 
    //     printf("idx: %d %s %d\n", idx, v[i].first.c_str(), v[i].second);
    // }
    rep(i, N) {
        pair<string, int> target = v[i];
        int idx = find(v222.begin(), v222.end(), target) - v222.begin(); 
        // printf("idx: %d\n", idx + 1);
        printf("%d\n", idx + 1);
    }


    // vector<string> cities;
    // rep(i, N) {
    //     cities.push_back(S[i]);
    // }
    // sort(cities.begin(), cities.end());
    // cities.erase(unique(cities.begin(), cities.end()), cities.end());

    // // 
    // vector<pair<string, int>> ans;
    // while (v.size() > 0) {
    //     // 名前順で何回もみる
    //     rep(i, cities.size()) {
    //         // idx 
    //         pair<string, int> target = make_pair(cities[0], P[i]);
    //         int idx = find(v.begin(), v.end(), target) - v.begin(); 
    //     }
    // }

    // pair<string, int> target = make_pair("moscow", 10);
    // int idx = find(v.begin(), v.end(), target) - v.begin(); 
    // cout << idx << endl;;

    // rep(i, N) {
    //     // cout << v[i].first << endl;
    //     // printf("%s %d\n", v[i].first.c_str(), v[i].second);
    //     pair<string, int> target = make_pair(S[i], P[i]);
    //     int idx = find(v.begin(), v.end(), target) - v.begin(); 
    //     cout << idx << endl;
    // }

    // vector<string> cities;
    // rep(i, N) {
    //     cities.push_back(S[i]);
    // }
    // sort(cities.begin(), cities.end());
    // cities.erase(unique(cities.begin(), cities.end()), cities.end());
    // // 
    // rep(i, cities.size()) {
    //     cout << cities[i] << endl;
    // }

    // 
    // map<string, vector<int>> ans;
    // rep(i, N) {
    //     ans[S[i]].push_back(P[i]);
    // }
    // rep(i, cities.size()) {
    //     for (int j = 0; j < ans[cities[i]].size(); j++) {
    //         printf("%s %d\n", cities[i].c_str(), ans[cities[i]][j]);
    //     }
    // }

}

Measured memory_bytes: 256
h,w=map(int,input().split())
a=[]
for _ in range(h):
  s=list(input())
  a.append(s)

ch1=0

for x in range(h):
  for y in range(w):
    b=a[x][y]
    ch=0
    if b=='#':
      if 0<=x-1<=h-1 and a[x-1][y]=='#':
        ch+=1
      if 0<=x+1<=h-1 and a[x+1][y]=='#':
        ch+=1
      if 0<=y-1<=w-1 and a[x][y-1]=='#':
        ch+=1
      if 0<=y+1<=w-1 and a[x][y+1]=='#':
        ch+=1
      
      if ch==0:
        ch1+=1
   
  
if ch1==0:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 9144