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

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;


typedef pair<int,int> pa;

ll n,c;

ll l[N],L[N],r[N],R[N],w[N];
ll x[N],y[N];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n>>c;
    for(int i=1;i<=n;i++){
         cin>>x[i]>>y[i];
         w[i]+=w[i-1]+y[i];
         l[i]=w[i]-x[i];
         L[i]=max(L[i-1],l[i]-x[i]);

    }
    memset(w,0,sizeof w);
    for(int i=n;i>=1;i--){
         w[n-i+1]=w[n-i]+y[i];
         r[n-i+1]=w[n-i+1]-(c-x[i]);
         R[n-i+1]=max(R[n-i],r[n-i+1]-(c-x[i]));
    }
   /* for(int i=1;i<=n;i++) {
        cout<<R[i]<<" ";
    }
    cout<<endl;/*/
    ll ans=0;

    for(int i=1;i<=n;i++){
        ans=max(ans,l[i]+R[n-i]);
        ans=max(ans,r[i]+L[n-i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9900
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;

    reverse(all(s));
    stack<int> ans;

    rep(i, n) {
        int j = min(m, n-i);
        while(1) {
            if(s[i+j] == '0') {
                ans.push(j);
                i = i+j-1;
                break;
            }
            j--;
            if(!j) {
                ans.push(-1);
                i = n-1;
                break;
            }
        }
    }

    if(ans.top() == -1) {
        cout << -1 << endl;
    } else {
        while(!ans.empty()) {
            int now = ans.top();
            ans.pop();

            cout << now << (ans.empty() ? '\n':' ');
        }
    }
}

Measured memory_bytes: 868
// d_vishal
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin>>s;
  cin>>s;
  char a = s[0];
  cin>>s;

  /*
  char str[105];
  scanf("%s",str);
  char a = str[8];
  */
  cout<<"A"<<a<<"C"<<endl;
  //cout<<s<<endl;
  return 0;
}


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

#define REP(i,n,m) for(int i=n;i<m;i++)
#define REPR(i,n,m) for(int i=n;i>m;i--)
#define ALL(v) v.begin(),v.end()
#define elif else if
using ll=long long;

int gcd(int x,int y){
    int a;
    while(y!=0){
        a=x%y;
        x=y;
        y=a;
    }
    return x;
}

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

/*----------template----------*/

int main(){
    int n,cnt=0;
    string s;
    cin>>n>>s;

    REP(i,2,s.size()){
        if(s.at(i-2)=='A'&&s.at(i-1)=='B'&&s.at(i)=='C') cnt++;
    }

    cout<<cnt<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int arr[10001];
int main()
{
    int cs=0;

    {
        int n;
       scanf("%d",&n);


    memset(arr,0,sizeof(arr));

        for(int i=0;i<n;i++)
        {
            int a;
            scanf("%d",&a);
        arr[a]++;

        }
        }

    int i=0;
        for( i=0;i<10001;i++)
        {
            if(arr[i]>0){

           printf("%d",i);
           arr[i]--;

           break;
            }



        }
 for(int j=0;j<10001;j++)
        {
            if(arr[j]>0){
                    for(int k=1;k<=arr[j];k++)
           printf(" %d",j);
            }



        }


printf("\n");




    }

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

long long n;
string s;
vector<int> p, res;
vector<vector<int>> memo;

void prepair(int dep, int id, const vector<int> &v);
int calc(int x, int y);

int main() {
  cin >> n >> s;
  p.resize(1 << n);
  res.assign(1 << n, 0);
  memo.assign(n, vector<int>(2, -1));
  for(int i = 0; i < (1 << n); ++i) cin >> p[i];
  prepair(0, 0, p);
  for(int i = 0; i < (1 << n); ++i) cout << res[i] << endl;
  return 0;
}

void prepair(int dep, int id, const vector<int> &v) {
  if(dep == n) {
    assert(v.size() == 1);
    res[id] = v[0];
    return;
  }
  int vsize = v.size();
  vector<int> to;
  // pattern 0
  for(int i = 0; i < vsize; i += 2)
    to.push_back(calc(v[i], v[i + 1]));
  prepair(dep + 1, id, to);
  // pattern 1
  to.clear();
  for(int i = 0; i < vsize; i += 2)
    to.push_back(calc(v[i + 1], v[(i + 2) % vsize]));
  prepair(dep + 1, id + (1 << dep), to);
}

int calc(int x, int y) {
  if(x > y) swap(x, y);
  return (s[y - x - 1] == '1') ? y : x;
}


Measured memory_bytes: 6240
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
A_d = []
for col in zip(*A):
    one_cnt = col.count('1')
    A_d.append(one_cnt*(n-one_cnt))

ans = 0
for d in range(60):
    ans = ans + A_d[d]*pow(2, d, MOD) % MOD
print(ans % MOD)


Measured memory_bytes: 68012
#include "bits/stdc++.h"
  using namespace std;
  #define ll long long
  
  int main()
  {
    ios::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);

    char ch;
    cin >> ch;
    if((int)ch <= 90) cout << 'A';
    else cout << 'a';

    return 0;
  }

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

int main(){
  long double a,b,c;
  cin>>a>>b>>c;
  if(c-a-b-2*sqrt(a*b)>-0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)
    puts("Yes");
  else
    puts("No");
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, m, i, j, k, x, s, ans;
	cin >> n >> m;
	map<long long, long long> ct;
	ct[0] = 1;
	s = 0;
	for (i = 0; i < n; i++) {
		cin >> x;
		s += x;
		ct[s % m]++;
	}

	ans = 0;
	for (auto p : ct) {
		ans += p.second * (p.second - 1) / 2;
	}

	cout << ans << "\n";
	   
	return 0;
}


Measured memory_bytes: 4224
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())

ans = 0
for i in range(1, n + 1):
    if i % 15 != 0 and i % 3 != 0 and i % 5 != 0:
        ans += i

print(ans)


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

int main(){
   string S;
   cin >> S;
   S[0] = '2';
   S[1] = '0';
   S[2] = '1';
   S[3] = '8';
   cout << S << endl;
   return 0;
}

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

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
string s;

bool read() {
    if (!(cin >> s))
        return false;

    return true;
}

void solve() {
    n = s.size();
    auto ans = 0ll;

    for (int l = 0; l < n; )
        if (s[l] == 'A') {
            auto cnt = 0;

            for (; l < n; ++l)
                if (s[l] == 'A') {
                    ++cnt;
                } else if (l + 1 < n && s[l] == 'B' && s[l + 1] == 'C') {
                    ans += cnt;
                    ++l;
                } else {
                    break;
                }
        } else {
            ++l;
        }

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 720
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        lower, upper = [], []
        i = 1
        while i * i <= n:
            if n % i == 0:
                lower.append(i)
                if i != n // i:
                    upper.append(n // i)
            i += 1
        return lower + upper[::-1]

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    A, B = Scanner.map_int()
    div_A = Math.divisor(A)
    div_B = Math.divisor(B)
    X = set(div_A) & set(div_B)
    ans = 0
    for x in X:
        if Math.is_prime(x):
            ans += 1
    print(ans + 1)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0239

int cal(int p, int q, int r) {
	return (p + r) * 4 + q * 9;
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		int ad[n], ap[n], aq[n], ar[n];
		for (int i = 0; i < n; i++) {
			cin >> ad[i] >> ap[i] >> aq[i] >> ar[i];
		}
		int p, q, r, c;
		cin >> p >> q >> r >> c;
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (ap[i] > p) continue;
			if (aq[i] > q) continue;
			if (ar[i] > r) continue;
			if (cal(ap[i], aq[i], ar[i]) > c) continue;
			cout << ad[i] << endl;
			count++;
		}
		if (count == 0) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <stack>
#include <deque>
using namespace std;

struct p {int f; int s;};

int main()
{
        char c;
        int A = 0;
        deque<p> L;
        stack<int> s;

        for (int i = 0; cin >> c; i++)
                if (c == '\\')
                        s.push(i);
                else if (c == '/' && !s.empty()) {
                        int j = s.top(), a = i - j;
                        s.pop();
                        A += a;
                        while (!L.empty() && L.back().f > j) {
                                a += L.back().s;
                                L.pop_back();
                        }
                        L.push_back({j, a});
                }

        cout << A << endl << L.size();
        for (p x: L)
                cout << " " << x.s;
        cout << endl;
}


Measured memory_bytes: 3212
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  int a,b,k,cnt=0;
  std::vector<int> v;
  std::cin >> a >> b >> k;
  for(int i=1; i<a*b+10; i++){
    if(a%i==0 && b%i==0){
      v.push_back(i);
    }
  }
  sort(v.begin(),v.end(),greater<int>());
  std::cout << v[k-1] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

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

int N;
vector<ll> T;
int main() {
  cin >> N;
  T.resize(N);
  rep(i, N) cin >> T[i];

  ll g = 1, ans = 1;
  rep(i, N) {
    g = gcd(ans, T[i]);
    ans = ans * (T[i] / g);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto ab = readints;
    int a = ab[0], b = ab[1];

    int ans = 0;
    for (int i = 1; i <= 12; i++) {
        if (i > a) break;
        if (i == a && i > b) break;

        ans++;
    }

    writeln(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
const ll INF = 1e18;

int main()
{
  int N;
  cin >> N;
  vector<int> A(3*N);
  REP(i,0,3*N) cin >> A[i];

  // From Left..
  // L[i+1]: A[i]まで(左から)で大きい順にN個の総和 (iはN~2N)
  vector<ll> L(2*N+1);
  L[0] = 0;
  // A[N-1]までをpqueに突っ込む(小さい順に出す)
  priority_queue<ll,vector<ll>,greater<ll>> pque1;
  REP(i,0,N) {
    L[i+1] = L[i] + A[i];
    pque1.push(A[i]);
  }
  REP(i,N,2*N) {
    ll mi = pque1.top();
    if (A[i] > mi) {  // miの代わりにA[i]を入れる
      pque1.pop(); // miを破棄
      pque1.push(A[i]);
      L[i+1] = L[i] - mi + A[i];
    } else {  // A[i]を無視
      L[i+1] = L[i];
    }
  }

  // From Right..
  // R[i]: A[i+1]まで(右から)で小さい順にN個の総和
  vector<ll> R(3*N+1);
  R[3*N] = 0;
  // A[3N-1]から[2N]までをpqueに突っ込む(大きい順に取り出す)
  priority_queue<ll> pque2;
  RREP(i,3*N,2*N) {
    R[i] = R[i+1] + A[i];
    pque2.push(A[i]);
  }
  RREP(i,2*N,N) {  // A[i]を入れるか？
    ll ma = pque2.top();
    if (A[i] < ma) {
      pque2.pop();
      pque2.push(A[i]);
      R[i] = R[i+1] - ma + A[i];
    } else {
      R[i] = R[i+1];
    }
  }

  // Compute..
  ll ans = -INF;  // 最大値
  REP(k,N,2*N+1) {
    chmax(ans, L[k] - R[k]);
  }
  cout << ans << endl;

  return 0;
}


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

void mapinsert(map<int,int> &m,int i){
    if( m.find(i) != m.end() ){
        m[i]++;
    } else {
        m.emplace(i,1);
    }
    return; 
} 

const long long MOD = 1e9+7;
long long fact[210000];
long long inv[210000];
long long finv[210000];
long long init(){
	fact[0]=finv[0]=1;
	inv[1]=1;
	for(int i=2;i<210000;i++){
		inv[i]=(MOD-(MOD/i)*inv[MOD%i]%MOD)%MOD;
	}
	for(int i=1;i<210000;i++){
		fact[i]=fact[i-1]*i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
long long comb(long long n, long long k){
    if( n < k || k < 0 )return 0;
    return fact[n]*finv[n-k]%MOD*finv[k]%MOD;
}
        
int main(){
    int N,M; cin >> N >> M;
    map<int,int> powseq;
    powseq.emplace(0,0);
    init();


    for( int i = 2; i*i <= M; i++ ){
        if( M % i != 0 ) continue;
        while( M % i == 0 ){ mapinsert(powseq,i); M /= i; }
    }
    if( M != 1 )mapinsert(powseq,M);


    long long ans = 1;

    for( pair<int,int> k : powseq ){
        ans *= comb(N-1+k.second,k.second);
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5120
#include<iostream>

using namespace std;
int main(){

    int k,m,n,tmp,out=0;
    int* a;

    cin >> n;
    cin >> m;

    a=new int[m];
    for(int i=0;i<m;i++)a[i]=0;

    for(int i=0;i<n;i++){
        cin >> k;
        for(int j=0;j<k;j++){
            cin >> tmp;
            a[tmp-1]+=1;
        }
    }

    for(int i=0;i<m;i++){
        if(a[i]>=n){
            out++;
        }
    }

    cout << out << endl;

    return 0;
}

Measured memory_bytes: 256
// ABC118_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    double N, M;
    cin >> N >> M;
//    vector<ll> vec(N);
//    REP(i, N) cin >> vec[i];
    
    // calculation
    cout << N/M << "\n";
    
    return 0;
}


Measured memory_bytes: 768
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N;
vector<int> a;

pair< int, vector<int> > solve(int mo) {
    priority_queue< pair<int, int> > que;
    for(int i=0; i<N; i++) {
        if(i % 2 == mo) que.push(make_pair(a[i], i));
    }

    // 何を取るか
    int ans = 0;
    vector<int> mark(N);
    pii cur = que.top(); que.pop();
    ans += cur.first;
    mark[ cur.second ] = 1;
    while(que.size()) {
        pii tmp = que.top(); que.pop();
        if(tmp.first < 0) break;
        ans += tmp.first;
        mark[ tmp.second ] = 1;
    }

    vector<int> operate, vec = mark;
    int stage = 0;
    while(vec.size() != 1) {
        stage++;
        /*
        if(stage < 5) {
            for(size_t i=0; i<vec.size(); i++) {
                printf("%lld%c", vec[i], (i+1 == vec.size() ? '\n' : ' '));
            }
        }
        */
        int idx = 0;
        while(idx < vec.size()) {
            bool is_edge = (idx == 0 || idx+1 == vec.size());
            if(is_edge) {
                // 削除する
                if(!vec[idx]) {
                    operate.push_back(idx + 1);
                    vec.erase(vec.begin() + idx);
                }
                else idx++;
            }
            else {
                // 両隣がいらないやつ or 両隣がいるやつ なら操作が必要
                bool match = (!(vec[idx-1] ^ vec[idx+1])) && (!vec[idx]);
                if(match) {
                    operate.push_back(idx + 1);
                    if(vec[idx-1]) vec[idx] = 1;
                    vec.erase(vec.begin() + idx + 1);
                    vec.erase(vec.begin() + idx - 1);
                }
                else idx++;
            }
        }
    }
    // printf("mo = %lld, ans = %lld\n", mo, ans);
    return make_pair(ans, operate);
}
 
signed main() {
    cin >> N;
    a.resize(N);
    rep(i,0,N) {
        cin >> a[i];
    }
    pair< int, vector<int> > ans = solve(0);
    ans = max(ans, solve(1));
    cout << ans.first << endl;
    cout << ans.second.size() << endl;
    for(auto x : ans.second) {
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
ans = 0
n_max = int(math.sqrt(N))
for n in range(1,n_max+1):
	if N%n == 0:
		a = N//n
		if a+1 < n:
			ans += n-1
		elif n+1 < a:
			ans += a-1
print(ans)


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

int main()
{
  int a, b;
  char c;
  cin>>a>>c>>b;
  if(c == '+')
  cout<<a+b<<endl;
  else cout<<a-b<<endl;
  return 0;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a , p;

int main()
{
    _FastIO;
    cin >> a >> p;
    p += (a * 3);
    cout << p / 2 << endl;
    return 0;
}


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

int main() {
    ll n,k;
    std::cin >> n>>k;
    vector<ll> h(n);
    ll cnt= 0;
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
        if(h[i]>=k){
            cnt++;
        }
    }
    std::cout << cnt << std::endl;
}


Measured memory_bytes: 1024
/*#define _USE_MATH_DEFINES
#include<cmath>*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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

template<class T> class segtree {
	int n = 1;
	vector<T> dat;
	T def = INF; //Default value

public:
	segtree(int _n) {
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, def);
	}
	segtree(vector<T> a) {
		int _n = a.size();
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, def);
		REP(i, 0, _n)dat[i + n - 1] = a[i];
		rREP(i, 0, n - 1)dat[i] = fun(dat[2 * i + 1], dat[2 * i + 2]);
	}


	//sum,min,max,etc...
	T fun(T x, T y) { return min(x, y); }

	//assignment,chmin,chmax,etc...
	void update(int i, T a) {
		i += n - 1;
		dat[i] = a;
		while (i > 0) {
			--i /= 2;
			dat[i] = fun(dat[2 * i + 1], dat[2 * i + 2]);
		}
	}


	T value(int a, int b, int k, int l, int r) {
		if (b <= l || r <= a)return def;
		if (a <= l && r <= b)return dat[k];
		T s = value(a, b, 2 * k + 1, l, (l + r) / 2);
		T t = value(a, b, 2 * k + 2, (l + r) / 2, r);
		return fun(s, t);
	}
	T value(int a, int b) { return value(a, b, 0, 0, n); }

	T operator[](int k) { return dat[k + n - 1]; }
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, q; cin >> n >> q;
	segtree<int>seg(n);
	vector<int>ans;
	rep(i, q) {
		int a, b, c; cin >> a >> b >> c;
		if (a == 0) {
			seg.update(b, c);
		}
		if (a == 1) {
			ans.push_back(seg.value(b, c + 1));
		}
	}
	for (auto p : ans) {
		cout << p << "\n";
	}

	return 0;
}



Measured memory_bytes: 4344
#include <iostream>
#include <vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#define ff(i,m,n) for(int i=m;i<n;i++)
#define i64 int64_t
using namespace std;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b) * c / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 100000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
#define sor sort 
#define cl clear
#define m_p make_pair 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
int main()
{
	ll a,n;
	cin>>a>>n;
	mapll mp;
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		mp[a] = inf;
	}
	ll l = a,r = a;
	ll al=inf,ar=inf;
	while(1)
	{
		if(mp[l] == 0)break;
		l--;
	}
	if(mp[l] == 0)al = abs(l-a);
	while(1)
	{
		if(mp[r] == 0)break;
		r++;
	}
	ar = abs(r-a);
	if(ar<al)cout<<r<<endl;
	else cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 3644
a = list(map(int,input().split()))
if a[1] == 0:
    print(a[0])
else:
    l = list(map(int, input().split()))

    for i in range(100):
        if a[0]-i not in l:
            print(a[0]-i)
            break
        elif a[0]+i not in l:
            print(a[0]+i)
            break

Measured memory_bytes: 9192
import collections

cou = int(input())
a = []
momo = []

for i in range(cou):
    s = str(input())
    a.append(s)

c = collections.Counter(a)
values, counts = zip(*c.most_common())

d = counts.count(counts[0])

for i in range(d):
    momo.append(values[i])
    
ans = sorted(momo)

for i in ans:
    print(i)

Measured memory_bytes: 125136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int H, W;
    cin >> H >> W;
    char c[H][W];
    for (int i = 0; i < H; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < W; j++) {
            c[i][j] = s[j];
        }
    }
    int ans = 0;
    int dx[4] = {1, -1, 0, 0};
    int dy[4] = {0, 0, 1, -1};
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int d[H][W]{};
            for (int k = 0; k < H; k++) {
                for (int l = 0; l < W; l++) {
                    d[k][l] = -1;
                }
            }
            if (c[i][j] == '#') continue;
            deque<pair<int, int>> q;
            d[i][j] = 0;
            q.push_back(make_pair(i, j));
            while (!q.empty()) {
                pair<int, int> p = q.front();
                q.pop_front();
                int y = p.first;
                int x = p.second;
                for (int k = 0; k < 4; k++) {
                    int ny = y + dy[k];
                    int nx = x + dx[k];
                    if (ny >= H || ny < 0 || nx >= W || nx < 0) continue;
                    if (c[ny][nx] == '.' && d[ny][nx] == -1) {
                        d[ny][nx] = d[y][x] + 1;
                        ans = max(ans, d[ny][nx]);
                        q.push_back(make_pair(ny, nx));
                    }
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

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

bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof) {
    return firstElof.first > secondElof.first;
}

int main(void) {
    int n, m;
    cin >> n >> m;
    
    int k, stmp;
    vector<vector<int>> s(m, vector<int>(n,-1));
    vector<int> p(m);
    for(int im=0;im<m;im++) {
        cin >> k;
        for(int ik=0;ik<k;ik++) {
            cin >> stmp; stmp--;
            s.at(im).at(stmp) = 1;
        }
    }
    for(int im=0;im<m;im++) {
        cin >> p.at(im);
    }

    int modulo, ans=0;
    bool flg;
    for(int isw=0;isw<(1<<n);isw++) {
        flg = true;
        for(int im=0;im<m;im++) {
            modulo = 0;
            for(int in=0;in<n;in++) {
                if(s.at(im).at(in)==-1) continue;
                modulo += (isw>>in) & s.at(im).at(in);
            }
            if(modulo%2!=p.at(im)) { 
                flg = false;
                break;
            }
        }
        if(flg) ans++;
    }

    cout << ans << endl;

    return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a, b, c, d;
  	cin >> a >> b >> c >> d;
  	a = max(a, c); b = min(b, d);
  	if (a > b)
      cout << 0;
  	else
      cout << b - a;
}

Measured memory_bytes: 256
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)

const int M=1000000007;
const int MM=998244353;


 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;




int main()
{ 

IOS;


string s;cin>>s;

vl a(13);

ll n=s.size();

ll ini=0;

for(ll i=0;i<n;i++){
  if(s[i]=='?')continue;
  ll dig=s[i]-'0';
  ll d=powM(10,n-i-1,13)*dig%13;
  ini=(ini+d)%13;
}

a[ini]=1;

//cout<<ini<<endl;

for(ll i=0;i<n;i++){
  if(s[i]=='?'){

   vl temp(13);

   ll ex=powM(10,n-i-1,13);
   for(ll j=0;j<10;j++){
    ll f=ex*j%13;
    for(ll k=0;k<13;k++){
        //f=(f+k)%13;
       // (temp[f]+=a[k])%=M;
      (temp[(f+k)%13]+=a[k])%=M;
    }
  }
  for(ll j=0;j<13;j++)a[j]=temp[j];
}
else continue;

}

cout<<a[5]<<endl;


return 0;
 
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    ld ans = 0;
    rep(i, N) {
        ld temp;
        cin >> temp;
        ans += 1.0L / temp;
    }
    cout << fixed << setprecision(5) << 1.0L / ans << endl;
    return 0;
}


Measured memory_bytes: 3744
def main():
    # import sys
    # readline = sys.stdin.buffer.readline
    # readlines = sys.stdin.buffer.readlines
    N = int(input())
    L = input()

    A = [None] * (N + 2)
    for a0, a1 in [(0, 0), (0, 1), (1, 0), (1, 1)]:
        A[0] = a0
        A[1] = a1
        for i in range(2, N + 1):
            a = A[i - 1]
            s = (L[i - 1] == 'x')
            A[i] = A[i - 2] ^ (a ^ s)
        A[N + 1] = A[N - 1] ^ (A[N] ^ (L[0] == 'x'))
        if A[0] == A[N] and A[1] == A[N + 1]:
            exists = True
            break
    else:
        exists = False

    if exists:
        ans = []
        for i in range(N):
            c = 'W' if A[i] else 'S'
            ans.append(c)
        print(''.join(ans))
    else:
        print(-1)


if __name__ == "__main__":
    main()


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

#define N 100

static char d[N];
static int w;
static int q;
static struct {
  int id;
  int b;
  int e;
} memq[N];
static int sp;

static
gc_alloc(id, sz)
{
  int cont = 0;
  int i, j;
  for (i = 0; i < w; ++i) {
    cont += (d[i] == 0 ? 1 : -cont);
    if (cont == sz) {
      memq[sp].id = id;
      memq[sp].b = i - cont + 1;
      memq[sp].e = i;
      for (j = memq[sp].b; j <= memq[sp].e; ++j)
        d[j] = 1;
      return memq[sp++].b;
    }
  }
  return -1;
}

static void
gc_free(id)
{
  int i, j;
  for (i = 0; i < sp; ++i) {
    if (memq[i].id == id) {
      for (j = memq[i].b; j <= memq[i].e; ++j)
        d[j] = 0;
      break ;
    }
  }
}

main()
{
  int i;
  
  for (;;) {
    scanf("%d%d", &w, &q);
    if (w == 0 && q == 0) break ;
    
    sp = 0;
    memset(d, 0, w);
    for (i = 0; i < q; ++i) {
      char ch;
      int id;
      scanf(" %c%d", &ch, &id);
      if (ch == 's') {
        int sz, rv;
        scanf("%d", &sz);
        rv = gc_alloc(id, sz);
        if (rv < 0) {
          puts("impossible");
        } else {
          printf("%d\n", rv);
        }
      } else {
        gc_free(id);
      }
    }
    puts("END");
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 620
mod = 10 ** 9 + 7
N, K = map(int, input().split())

ans = 0
memo = [0] * (K + 1)
for i in range(K, 0, -1):
    x = K // i
    cnt = pow(x, N, mod)

    a = i
    while a <= K:
        cnt -= memo[a]
        a += i

    memo[i] = cnt
    ans += i * cnt
    ans %= mod

print(ans)

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

using namespace std;

int main(void)
{
	int mm=0,kk=0,i,j,a,b,c[2001],d[2001],e[11][2001],f[11][2001],h[11][2001],k=0,g[11];
	scanf("%d %d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%d %d",&c[i],&d[i]);
	}
	for(i=0;i<=10;i++){
		for(j=0;j<=b;j++){
			f[i][j]=0;
			h[i][j]=0;
			e[i][j]=-1;
		}
		g[i]=0;
	}
	for(i=1;i<=10;i++){
		for(j=0;j<a;j++){
			if(i==d[j]){
				f[i][g[i]]=c[j];
				g[i]++;
			}
		}	
		sort(f[i],f[i]+g[i],greater<int>());
	}
	for(i=1;i<=10;i++){
		for(j=0;j<g[i];j++){
			h[i][j+1]+=h[i][j]+f[i][j];
			h[i][j+1]+=j*2;
		}
	}
	/*for(j=1;j<=g[1];j++){
			e[0][j]=h[1][j];
			printf("AA_%d\n",h[1][j]);
	}
	for(i=0;i<=10;i++){
		for(j=0;j<=b;j++){
			printf("h[%d][%d]=%d\n",i,j,h[i][j]);
		}
	}*/
	e[0][0]=0;
	for(i=0;i<=9;i++){
		for(j=0;j<=b;j++){
			if(e[i][j]!=-1){
				for(k=0;k<=g[i+1];k++){
					if(e[i][j]+h[i+1][k]>e[i+1][j+k] && j+k<=b){
						e[i+1][j+k]=e[i][j]+h[i+1][k];
					}
					if(e[i][k]>e[i+1][k]){
						e[i+1][k]=e[i][k];
					}
				}
			}
		}
	}
	for(i=0;i<=10;i++){
		for(j=0;j<=b;j++){
			//printf("e[%d][%d]=%d\n",i,j,e[i][j]);
			if(e[i][j]>mm){
				mm=e[i][j];
			}
		}
	}
	printf("%d\n",mm);
	return 0;
}

Measured memory_bytes: 1480
dataList = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

input_k = input('')
k_index = int(input_k)
print(dataList[k_index - 1])


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

int main() {
  int A, B, T, X, Total_biscuit;
  cin >> A >> B >> T;
  
  T = T + 0.5; 
  
  X = T / A;

  Total_biscuit = X * B;

  cout << Total_biscuit << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
count = 0

for x in A:
    if x % 2 == 0:
        if x % 3 == 0 or x % 5 == 0:
            count += 1
    else:
        count += 1

print("APPROVED" if count == N else "DENIED")

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

neighbors = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    neighbors[a].append(b)
    neighbors[b].append(a)
c = list(map(int, input().split()))
sorted_c = sorted(c)

closed = [0 for _ in range(N)]
use = [0 for _ in range(N)]
q = []
q.append(0)
use[0] = sorted_c.pop()
M = 0


while len(q) > 0:
    parent = q.pop()
    closed[parent] = use[parent]
    for neighbor in neighbors[parent]:
        if closed[neighbor] == 0:
            c2 = use[neighbor] = sorted_c.pop()
            c1 = closed[parent]
            M += c2
            q.append(neighbor)

print(M)
print(*use)

Measured memory_bytes: 6172
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $n);
$t = [$n];
$x = $n - ($n % $b + 1);
//echo $x . PHP_EOL;
$cnt = 0;
for ($i = $x; $i > 0; $i -= $b, $cnt++) {
    if ($cnt > 10000) break;
    $t[] = $i;
    //echo $i . PHP_EOL;    
}
$ans = [];
foreach ($t as $v) {
    $ans[] = calc($a, $b, $v);
}
//var_dump($ans);
printf("%d", max($ans));
exit;

for ($i = 1; $i <= $n; $i++) {
    echo calc($a, $b, $i) . PHP_EOL;
}


function calc($a, $b, $n) {
    $c = intdiv($a * $n, $b);
    $d = $a * intdiv($n, $b);
    $e = $c - $d;
    //printf("n = %d , [ %d * %d ] / %d - %d * [ %d / %d ] , %d - %d\n", $n, $a, $n, $b, $a, $n, $b, $c, $d);
    return $e;
}


Measured memory_bytes: 16348
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int N, a[3333];

long long memo[3333][3333][2];


long long dfs(int i, int j, int k)
{
  if (memo[i][j][k] < INF)
    return memo[i][j][k];

  if (i == j)
    return memo[i][j][k] = k == 0 ? a[i] : - a[i];

  if (k == 0) {
    return memo[i][j][k] = std::max(dfs(i + 1, j,     1 - k) + a[i],
                                    dfs(i,     j - 1, 1 - k) + a[j]);
  }
  else {
    return memo[i][j][k] = std::min(dfs(i + 1, j,     1 - k) - a[i],
                                    dfs(i,     j - 1, 1 - k) - a[j]);
  }

  assert(false);
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> a[i];

  for (int i = 0; i < 3333; i ++)
    for (int j = 0; j < 3333; j ++)
      for (int k = 0; k < 2; k ++)
        memo[i][j][k] = INF;

  std::cout << dfs(0, N - 1, 0) << std::endl;

  return 0;
}


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

int main(){
    int x, y; cin >> x >> y;
    if( ((4*x-y)>=0 && (4*x-y)%2==0) && ( ((-2)*x+y)>=0 && ((-2)*x+y)%2==0 ) ) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3580
MOD = 10 ** 9 + 7
MAX = 2 * 10 ** 5

def comb(n, k)
  @fac[n] * (@finv[k] * @finv[n - k] % MOD) % MOD
end

def modpow(a, n)
  res = 1
  while n > 0
    res = res * a % MOD if n & 1 == 1
    a = a * a % MOD
    n >>= 1
  end
  res
end

@fac = []
@finv = []
@inv = []
@fac[0] = @fac[1] = 1
@finv[0] = @finv[1] = 1
@inv[1] = 1
2.upto(MAX) do |i|  
  @fac[i] = @fac[i - 1] * i % MOD
  @inv[i] = MOD - @inv[MOD % i] * (MOD / i) % MOD
  @finv[i] = @finv[i - 1] * @inv[i] % MOD
end

N, K = gets.split.map(&:to_i)
kk = K < N - 1 ? K : N - 1
ans = 0
(kk+1).times do |i|
  ans += comb(N, i) * comb(N-1, i)
end

puts ans % MOD

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

#define endl '\n'
#define ll long long
#define rint register int

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000007
#define infl LLONG_MAX

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

ll f[hell];

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t, i, x, j, y, 	z = 0, k, n;
	cin >> n;
	ll a[n];
	rep(i, 0, n, 1) {
		cin >> a[i];
		f[a[i]]++;
	}

	rep(i, 0, n, 1) {
		x = a[i];
		if (f[x] > 1)	continue;
		if (x == 1 && f[1] == 1)	{z++; continue;}
		else if (x != 1 && f[1]) {
			continue;
		}
		bool br = true;

		for (j = 2; j * j <= x; j++) {
			if (x % j == 0) {
				t = x / j;
				if (f[j] || f[t]) {
					br = false;
				}
			}
		}
		z += br;
	}
	ce(z)
}


Measured memory_bytes: 12900
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  int n;
  cin >> n;
  int A=pow(10,5);
  for (int i=0; i<n; i++) {
    A*=(1.05);
    A = (A + 999) / 1000 * 1000;
  }
  
  printf("%d\n",A);
  return 0;
}

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

using namespace std;

int culc(int x,int y){
  int ans;
  ans=x-y;

  if(ans<0)ans*=-1;
  return ans;
}

int main(){
  int N,L;
  cin >> N >> L;
  vector<int> apple_taste(N,0);
  int pie_taste=0;
  for(int i=0;i<N;i++){
    apple_taste[i]=L+i;
  }

  for(int x:apple_taste){
    pie_taste+=x;
  }
  int min=10000;
  int i=0;
  int index=0;
  for(int x:apple_taste){
    if(min>abs(x)){
      min=abs(x);
      index=i;
    }
    i++;
  }
  cout << pie_taste-apple_taste[index] << endl;
  return 0;
}


Measured memory_bytes: 256
x = int(input())
l = []
st = 0
ans = 0
k = 0
for i in range(x-1):
  a,b,c = map(int,input().split())
  l.append([a,b,c])

for i in range(x):
  st = 0
  ans = 0
  k = i + 1
  if i == x - 1:
    print(0)
  else:
    ans += l[i][0] + l[i][1]
    while k < x - 1:
#      print("mod:" + str(ans % l[k][2]))
      if ans < l[k][1]:
        ans = l[k][1] + l[k][0]
      elif ans >= l[k][1] and ans % l[k][2] != 0:
        ans += l[k][2] - ans % l[k][2] + l[k][0]
      else:
        ans += l[k][0]
#      print("ans:" + str(ans))
      k += 1
    print(ans)


Measured memory_bytes: 3188
N = int(input())
h = list(map(int,input().split()))
H = h[:]

base = min(h)
count = 0
already_zero = 0
more = 0

while 1:
  if max(H) == 0:
    break
  else:
    for i in range(N):
      if H[i] == 0 and more == 1:
        count += 1
        more = 0
        if i == N - 1:
          break
      else:
        if H[i] != 0:
          H[i] -= 1
          if more == 0:
            more = 1
      
      if more == 0 and i == N - 1:
        break
      
    else:
      count += 1
      more = 0
      already_zero = 0
      
print(count)

Measured memory_bytes: 3064
from collections import deque

n, q = list(map(int, input().split()))

adj = [[] for _ in range(n+1)]

for i in range(n-1):
    a, b = list(map(int, input().split()))
    adj[a].append(b)
    adj[b].append(a)

c = [0] * (n+1)

for i in range(q):
    p, x = list(map(int, input().split()))
    c[p] += x

#BFS 
q = deque([1])
visited = [False] * (n+1)
visited[1] = True


while len(q) > 0:
    v = q.popleft()
    for w in adj[v]:
        if not visited[w]:
            q.append(w)
            c[w] += c[v]
            visited[w] = True

c_str = [str(c[i+1]) for i in range(n)]
print(" ".join(c_str))



Measured memory_bytes: 131316
#include <string>
#include <iostream>
#include <vector>
#include <cassert>
#include <random>
#include <algorithm>
#include <deque>
#include <cstring>
#include <time.h>
#include <cstdio>
#include <tuple>
#include <utility>

main() {
  long long N,K;
  double ans=0;
  std::cin>>N>>K;
  for (int src=1;src<=N;++src) {
    int sz=0;
    long long cur=src;
    while (cur<K) {
      cur=2*cur;
      ++sz;
    }
    ans+=std::pow(0.5,sz)/N;
  }
  printf("%.20f\n",ans);
}


Measured memory_bytes: 256
import scala.math.pow

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val max = sc.nextInt() match {
    case 1 => 1
    case x => 
      (for (i <- 2 to x; j <- 2 to x) yield pow(i, j).toInt).filter(_ <= x).max
  }
  println(max) 
}

Measured memory_bytes: 76912