akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n;
P p[100001];
vector<int> y[100001];
vector<int> xi;
vector<P> query;
vector<PP> edge;
int rankk[100001];
int par[100001];

void init(){
	for(int i=0;i<n;i++){
		par[i]=i;
		rankk[i]=0;
	}
}

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

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

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

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&p[i].first,&p[i].second);
		xi.push_back(p[i].first);
	}
	sort(xi.begin(),xi.end());
	xi.erase(unique(xi.begin(),xi.end()),xi.end());
	sort(p,p+n);
	for(int i=0;i<n;i++){
		p[i].first=lower_bound(xi.begin(),xi.end(),p[i].first)-xi.begin();
		query.push_back(P(p[i].second,p[i].first));
	}
	for(int i=0;i<(int)xi.size()-1;i++){
		edge.push_back(PP(xi[i+1]-xi[i],P(i,i+1)));
	}
	sort(query.begin(),query.end());
	for(int i=0;i<(int)query.size()-1;i++){
		int f=query[i+1].second;
		int t=query[i].second;
		int cost=query[i+1].first-query[i].first;
		edge.push_back(PP(cost,P(f,t)));
	}
	sort(edge.begin(),edge.end());
	init();
	ll res=0;
	for(int i=0;i<edge.size();i++){
		if(!same(edge[i].second.first,edge[i].second.second)){
			unite(edge[i].second.first,edge[i].second.second);
			res=(ll)res+edge[i].first;
		}
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 9968
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdlib>
#include<set>

using namespace std;

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

#include<iostream>

int main(){
    int n, k;
    cin >> n >> k;
    int a[n];
    int idx;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 1){
            idx = i;
        }
    }
    int ans = 0;
    if (idx % (k - 1) == 0){
        ans += idx / (k - 1);
    }else{
        ans += idx / (k - 1) + 1;
        idx += k - idx % (k - 1) - 1;
    }

    if (idx < n - 1){
        if ((n - 1 - idx) % (k - 1) == 0){
            ans += (n - 1 - idx) / (k - 1);
        }else{
            ans += (n - 1 - idx) / (k - 1) + 1;
        }
    }
    

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vector
#include <set> // set
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#include <iomanip> //cout<<setprecision(n)
#define rep(i,n) for(int i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

int main() {
  int n,a,b,c,d;
  std::string s;
  std::cin >> n >> a >> b >> c >> d;
  std::cin >> s;
  s = s+"#";
  char last = '.';
  rep(i,c-a-1) {
    if (last == '#' && s[a+i] == '#') {
      std::cout << "No" << "\n";
      return 0;
    }
    last = s[a+i];
  }
  last = '.';
  rep(i,d-b-1) {
    if (last == '#' && s[b+i] == '#') {
      std::cout << "No" << "\n";
      return 0;
    }
    last = s[b+i];
  }
  if(c<d) {
    std::cout << "Yes" << "\n";
    return 0;
  }
  char last1 = b-2>=0?s[b-2]:'#';
  char last2 = '.';
  rep(i,d-b+1) {
    if(last1 == '.' && last2 == '.' && s[b+i] == '.') {
      std::cout << "Yes" << "\n";
      return 0;
    }
    last1 = last2;
    last2 = s[b+i];
  }
  std::cout << "No" << "\n";

  return 0;
}

Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;


int32_t main(){
	ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int r=0,p=0;
    int ans=0;
    REP(i,0,s.size()){
        if(s[i]=='p'){
            if(r>p){
                p++;
            }
            else{
                ans--;
                r++;
            }
        }
        else{
            if(r>p){
                ans++;
                p++;
            }
            else{
                r++;
            }
        }
    }
    cout<<ans<<"\n";


	return 0;
}

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

int main() {
  for(;;) {
    int n;
    std::cin >> n;
    if (n == 0) {
      break;
    }
    std::vector<int> xs(n);
    std::vector<int> ys(n);
    xs[0] = 0;
    ys[0] = 0;
    for(int i = 1; i < n; ++i) {
      int k, d;
      std::cin >> k >> d;
      int dx[] = {-1, 0, 1, 0};
      int dy[] = {0, 1, 0, -1};
      xs[i] = xs[k] + dx[d];
      ys[i] = ys[k] + dy[d];
    }
    int inf = 1 << 28;
    int min_x = inf;
    int max_x = -inf;
    for(int i = 0; i < n; ++i) {
       min_x = std::min(min_x, xs[i]);
       max_x = std::max(max_x, xs[i]);
    }
    int min_y = inf;
    int max_y = -inf;
    for(int i = 0; i < n; ++i) {
      min_y = std::min(min_y, ys[i]);
      max_y = std::max(max_y, ys[i]);
    }
    printf("%d %d\n", max_x - min_x + 1, max_y - min_y + 1);
  }
}





Measured memory_bytes: 3048
def main():
    N, K = map(int, input().split())
    tlst = [i for i in range(1, N+1)]
    coef = []
    for t in tlst:
        for x in range(0, 21):
            if t*(2**x) >= K:
                tmpx = x
                break
        coef.append(pow(1/2, tmpx))

    ans = 0
    for c in coef:
        ans += (1/N)*c
    print(ans)
main()

Measured memory_bytes: 10136
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N, K;
  invec<ll> A(N);
  
  ll l = 1, r = 1000000000;
  
  while (r - l > 0) {
    ll m = (l + r) / 2, sum = 0;
    for (auto i : A) {
      sum += i / m;
      if (i % m == 0) sum--;
    }
    
    if (sum > K)
      l = m+1;
    else
      r = m;
  }


  return r;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
int n,a[2005],ans; 
int main()
{
	cin>>n;
	for(int i=0;i<n;++i)
	 cin>>a[i];
	sort(a,a+n);
	for(int m=1;m<n;++m)
	{
		int s=0;
		for(int b=m+1;b<n;++b)
		{
			while(s<m&&a[s]+a[m]<=a[b]) ++s;
			ans+=m-s;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()

ans = [[[0],[0]]]

i = 0
while len(ans[i][0])<n:
    a = ans[i]
    for x in a[1]:
        ans.append([a[0]+[x],a[1]])
    x = a[1][-1]+1
    ans.append([a[0]+[x],a[1] + [x]])
    i+=1

a_ = ord('a')

for i in range(len(ans)):
    a = ans[i][0]
    if len(a)<n:
        continue
    for x in a[:-1]:
        print(chr(x+a_),end='')
    print(chr(a[-1]+a_))
    


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
string s;
string res;

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

    cin>>n>>s;
    int acc=0;
    for (char c: s) {
	if (c=='(') acc++;
	if (c==')') acc--;
	if (acc<0) {
	    res+='(';acc=0;
	}
    }

    res += s;
    while (acc--) res+=')';
    out(res);
  

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                try(Scanner sc = new Scanner(System.in)){
                        while(sc.hasNext()){
                                double t1 = sc.nextDouble(), t2 = sc.nextDouble();
                                if(t1 < 35.5 && t2 < 71.0){
                                        System.out.println("AAA");
                                }else if(t1 < 37.5 && t2 < 77.0){
                                        System.out.println("AA");
                                }else if(t1 < 40.0 && t2 < 83.0){
                                        System.out.println("A");
                                }else if(t1 < 43.0 && t2 < 89.0){
                                        System.out.println("B");
                                }else if(t1 < 50.0 && t2 < 105.0){
                                        System.out.println("C");
                                }else if(t1 < 55.0 && t2 < 116.0){
                                        System.out.println("D");
                                }else if(t1 < 70.0 && t2 < 148.0){
                                        System.out.println("E");
                                }else{
                                        System.out.println("NA");
                                }
                        }
                }

        }
}

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

int cnt[100005];
bool ac[100005];
 
char s[5];
 
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
 
    int pen = 0;
    int res = 0;
 
    for (int i = 0; i < m; i++) {
        int x;
        scanf("%d%s", &x, s);
 
        if (s[0] == 'A') {
            if (!ac[x]) {
                res++;
                pen += cnt[x];
            }
            ac[x] = 1;
        }
        else {
            cnt[x]++;
        }
    }
 
    printf("%d %d\n", res, pen);
}


Measured memory_bytes: 4156
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    REP(i, T) cin >> a[i];
    int tmp = *max_element(All(a));
    cout << max((int)0, 2*(*max_element(All(a)))-K-1) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    if(K == 1) return 0;
    N -= K;
    res = N;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <bitset>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
 
using namespace std;
typedef long long ll;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)

#define MOD 1000000007

ll fact[4040404], frev[4040404];
ll invs[4040404];

ll comb(int n, int k)
{
	if (n < k) return 0;
	return fact[n] * frev[k] % MOD * frev[n - k] % MOD;
}

void fill_factorial_table(){
	fact[0] = 1; frev[0] = 1;
	invs[0] = 1;
	invs[1] = 1;
	for (int i = 2; i < 4040404; ++i) invs[i] = MOD - MOD / i * invs[MOD % i] % MOD;
	for (int i = 1; i < 4040404; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		frev[i] = frev[i - 1] * invs[i] % MOD;
	}
}

ll dp[4040][2020];

int main(){
    ll n,k;
    cin >> n >> k;
    if(k==1){ cout << "1" << endl; return 0;}
    dp[1][1] = 1;
    dp[0][1] = 1;
    fill_factorial_table();
    FOR(j,2,n+1){
        dp[0][j] =  comb((j * (k - 1)) - 1, k - 2) * dp[0][j-1] % MOD;

    }
    FOR(i,1,n+1){
        FOR(j,i,n+1){
            dp[i][j] =  (dp[i-1][j] + ((comb(i + (j * (k - 1)) - 1, k - 2) * dp[i][j-1]) % MOD)) % MOD ;
        }
    }
    cout << (dp[n][n] * fact[n]) % MOD << endl;

    return 0;
}

Measured memory_bytes: 128000
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
	ll N, K;
	cin >> N;
	cin >> K;
	vector<ll> p(N);
	vector<double> prob(N);
	double ans = 0;
	for (ll i = 0; i < N; i++)
	{
		cin >> p[i];
		prob[i] += (double)(p[i] + 1) / (double)2;
	}
	for (ll i = 0; i < K; i++)
	{
		ans += prob[i];
	}
	double temp = ans;
	for (ll i = 1; i < N - K + 1; i++)
	{
		temp = temp - prob[i - 1] + prob[i + K - 1];
		ans = max(ans, temp);
	}
	cout << fixed;
	cout << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>

using namespace std;

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

    bool flag = true;
    for (int i = 1; i < s.length(); ++i) {
        if (s[i - 1] == s[i]) {
            flag = false;
            break;
        }
    }

    if (flag)
        cout << "Good\n";
    else
        cout << "Bad\n";
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AtCoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string moji = Console.ReadLine();
                if (moji == null || moji.Length < 1) return;
                int ans = 0;
                Dictionary<char, int> table = new Dictionary<char,int>();
                table.Add('I', 1);
                table.Add('V', 5);
                table.Add('X', 10);
                table.Add('L', 50);
                table.Add('C', 100);
                table.Add('D', 500);
                table.Add('M', 1000);
                for (int i = 0; i < moji.Length; i++)
                {
                    int keisuu = 1;
                    if (i < moji.Length - 1)
                    {
                        if (table[moji[i]] < table[moji[i + 1]])
                        {
                            keisuu = -1;
                        }
                    }
                    ans += keisuu * table[moji[i]];
                }
                Console.Out.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 6076
#include<cstdio>

int main() {
    int a,b,c;

    scanf("%d%d%d",&a,&b,&c);

    int h,m;
    if(a < b) {
        h = a;
        m = b;
    }else {
        h = b;
        m = a;
    }

    int p,q;
    if(m < c) {
        p = m;
        q = c;
    }else {
        p = c;
        q = m;
    }

    int x,y;
    if(h < p) {
        x = h;
        y = p;
    }else {
        x = p;
        y = h;
    }

    printf("%d %d %d\n",x,y,q);
}



Measured memory_bytes: 2668
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <sstream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EPS 1e-12
#define pri_max 60000
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

/*
bool memo[pri_max] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < pri_max; i++)
	{
		if (memo[i] == false)
		{
			pri.push_back(i);
			for (int l = i; l < pri_max; l += i)
			{
				memo[l] = true;
			}
		}
	}
}*/
double len(pdd a, pdd b)
{
	return sqrt((b.first - a.first)*(b.first - a.first) + (b.second - a.second)*(b.second -a.second));
}

int main()
{
	pdd p1, p2, q;
	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &p1.first, &p1.second, &p2.first, &p2.second, &q.first, &q.second) != EOF)
	{
		pdd p = p1;
		double R = atan2((p2.second - p1.second),(p2.first - p1.first));
		double r = atan2((q.second - p1.second), (q.first - p1.first));
		double L = sin(r-R)*len(q, p1);
		double l = cos(r-R)*len(q, p1);
		p.first += cos(R)*l;
		p.second += sin(R)*l;
		R = atan2((p.second - q.second), (p.first - q.first));
		L = fabs(L);
		p.first += cos(R)*L;
		p.second += sin(R)*L;

		printf("%.5f %.5f\n", p.first, p.second);
	}
}

Measured memory_bytes: 1300
fun main(args: Array<String>) {
    val (N, K, Q) = readLine()!!.split(" ").map(String::toInt)
    val A = IntArray(Q) { readLine()!!.toInt() }

    val result = IntArray(N) { K }
    A.forEach {
        result[it-1]++
    }

    result.forEach {
//        println(it)
        if (it - Q > 0) {
            println("Yes")
        } else {
            println("No")
        }
    }

}

Measured memory_bytes: 44240
#include <climits>
#include <cmath>
#include <iostream>

// 1  2  3  4  5
// 2  4  6  8 10

int main(int argc, char *argv[]) {
  long n;
  std::cin >> n;

  long min = LONG_MAX;
  for (int i = 1; i <= sqrt(n); ++i) {
    if (n % i == 0)
      min = std::min(min, (i - 1) + (n / i - 1));
  }
  std::cout << min << std::endl;
}


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

int main(){
	ll a;
	string s;
	cin >> a >> s;
	int b = 0;
	b += (s.at(0) - '0')*100 ;
	b += (s.at(2) - '0')*10 ;
	b += (s.at(3) - '0') ;

	cout << a*b/100 << endl;
	return 0;
}

Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
#ifdef LOCAL
mt19937 rng(unsigned(70));
#else
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif
#define rand rng


int main() {
	// fios;
	int a, b, c, d;
	cin >>  a >> b >> c >> d;
	while(1) {
		c -= b;
		if(c <= 0) {
			puts("Yes");
			break;
		}
		a -= d;
		if(a <= 0) {
			puts("No");
			break;
		}
	}

}

Measured memory_bytes: 3588
#include <stdio.h>
int S[100000000];
int T[100000000];
int s,t;
int serch(int);
int main(){
  int i=0,count=0;
  scanf("%d",&s);
  while(i<s){
    scanf("%d",&S[i]);
    i++;
  }
  i=0;
  scanf("%d",&t);
  while(i<t){
    scanf("%d",&T[i]);
    i++;
  }
  for(i=0;i<t;i++) count+=search(T[i]);
  printf("%d\n",count);
  return 0;
}

int search(int x){
  int l=0,r=s,m;
  while(l<r){
    m=(l+r)/2;
    if(S[m]==x) return 1;
    else if(x<S[m]) r=m;
    else l=m+1;
  }
  return 0;
}

Measured memory_bytes: 2844
#include <bits/stdc++.h>
const int M =998244353; 
#define int long long int
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define MAX 1e15+1
#define pi  pair<int,int>  
const int mod = 1e9 + 7;
const int N = 2e2 + 7;
 
int n,k;
int a[N];
int dp[100010][2];
int s=MAX;
int solve(int sum,int cha) {

	if(dp[sum][cha]!=-1)return dp[sum][cha];
	for(int i=0;i<n;i++){
		if(sum-a[i]<0){
			break;
		}
		int x = solve(sum-a[i],(cha+1)%2);
		if(x==(cha+1)%2){
			dp[sum][cha] = x;
			return x;
		}
	}

	dp[sum][cha]=cha;
	return cha;

 
 
}
 
signed main() {
  fast;
  
  cin>>n>>k;
  for(int i=0;i<n;i++){
  	cin>>a[i];
  	s=min(s,a[i]);
  }
  memset(dp,-1,sizeof(dp));
  int x = solve(k,0);
  //cout<<x;

  if(x==0)cout<<"Second";
  else cout<<"First";



  	
}

Measured memory_bytes: 6528
from heapq import heappush, heappop

N = int(input())
A = list(map(int, input().split()))

q = list()
for i, num in enumerate(A):
    heappush(q, (num, i + 1))

ans = list()
while len(q) > 0:
    _, num = heappop(q)
    ans.append(num)

print(' '.join([str(x) for x in ans]))


Measured memory_bytes: 74476
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class DGreedyCustomers {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<int> a(n);
      rep(i, n) {
        cin >> a[i];
      }
      ll ans = 0;
      ans = a[0]-1;
      int now = 2;
      for(int i=1; i<n; i++) {
        ans += (a[i]-1)/now;
        if (a[i] == now) {
          now++;
        }
      }
      cout << ans << endl;
    }
};

signed main() {
  DGreedyCustomers solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main(){
  int n,m;
  int s=0;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int l;
    cin >> l;
    s+=l;
  }
  if(s>n){
    cout << "-1";
  }
  else{
    cout << n-s;
  }
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {


	int n;
	string x;
	cin >> n >> x;

	map<int, int> memo;

	rep_lr(i, 1, n + 1) {
		int ii = i;
		int pop = 0;
		while (ii) {
			if (ii % 2)pop++;
			ii /= 2;
		}
		memo[i] = memo[i % pop] + 1;
	}

	int p = 0;
	rep(i, n)if (x[i] == '1')p++;
	int pp = p + 1, pm = max(p - 1, 1);
	int modp = 0, modm = 0;
	int kp = 1, km = 1;

	rep(i, n) {
		modp += kp * (x[n - 1 - i] - '0');modp %= pp;
		modm += km * (x[n - 1 - i] - '0');modm %= pm;
		kp *= 2;kp %= pp;
		km *= 2;km %= pm;
	}
	

	vi ans(n);
	int kkp = 1, kkm = 1;
	rep(i, n) {
		if (x[n - 1 - i] == '0') {
			//0を1に
			int md = (modp + kkp) % pp;
			ans[n - 1 - i] = memo[md] + 1;
		}
		else if (p == 1)ans[n - 1 - i] = 0;
		else {
			//1を0に
			int md = (modm - kkm) % pm;
			if (md < 0)md += pm;
			ans[n - 1 - i] = memo[md] + 1;
		}
		kkp *= 2;kkp %= pp;
		kkm *= 2;kkm %= pm;
	}

	rep(i, n)cout << ans[i] << endl;

}

Measured memory_bytes: 13616
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

bool prim(int x) {
    if (x < 2)
        return 0;
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0)
            return 0;
    return 1;
}

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

    int x;
    cin >> x;
    while (!prim(x))
        x++;
    cout << x;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int N, A[100000], B[100000], C[100000]; 
ll ans = 0;

ll getlo(int ind) {
    int lo = -1, hi = N-1; // last one < 
    while (lo < hi) {
        int mid = (lo+hi+1)/2;
        if (A[mid] < ind) lo = mid;
        else hi = mid-1;
    }
    return lo+1;
}

ll gethi(int ind) {
    int lo = 0, hi = N; // first one >
    while (lo < hi) {
        int mid = (lo+hi)/2;
        if (C[mid] > ind) hi = mid;
        else lo = mid+1;
    }
    return N-hi;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N;
	F0R(i,N) cin >> A[i];
	F0R(i,N) cin >> B[i];
	F0R(i,N) cin >> C[i];
	sort(A,A+N);
	sort(C,C+N);
	F0R(i,N) {
	    ans += getlo(B[i])*gethi(B[i]);
	}
	cout << ans;
}

// read!
// ll vs. int!

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

int main(){
    int N;  cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++)
        cin >> A[i];
    
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(A[i] == cnt + 1){
            cnt++;
        }
    }

    if(cnt == 0){
        cout << -1 << endl;
    }else{
        cout << N - cnt << endl;
    }
}

Measured memory_bytes: 1024
from itertools import accumulate

MOD = 10 ** 9 + 7
N, *A = map(int, open(0).read().split())

B = list(accumulate(A)) # cumsum

ans = 0
for i in range(N-1):
    ans += A[i] * (B[-1] - B[i]) % MOD
    ans %= MOD
print(ans)

Measured memory_bytes: 31648
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

ll calc(ll a, ll b, ll p) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = calc(a, b / 2, p);
        return (d * d) % p;
    } else {
        return (a * calc(a, b - 1, p)) % p;
    }
}


int main(){
    ll N;
    cin >> N;
    static const ll mod = 1000000000 + 7;
    ll ans;

    ans = (calc(10, N, mod) - (calc(9, N, mod) * 2) % mod + calc(8, N, mod)) % mod;
    if(ans < 0){ans += mod;}
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 3160
#include <stdio.h>
#define MAX 101

main(){
  int i, j, n, k, u, v;
  int adj[MAX][MAX];

  for( i = 0; i < MAX; i++){
    for( j = 0; j < MAX; j++){
      adj[i][j] = 0;
    }
  }

  scanf("%d", &n);

  for( i = 0; i < n; i++){
    scanf("%d%d", &u, &k);
    for( j = 0; j < k; j++){
      scanf("%d", &v);
      adj[i][v-1] = 1;
    }
  }

  for( i = 0; i < n; i++){
    for( j = 0; j < n; j++){
      if( j == n-1 ) printf("%d", adj[i][j]);
      else printf("%d ", adj[i][j]);
    }
    printf("\n");
  }

  return 0;

}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(all(a), greater<int>());
    int res = 0;
    rep(i,n){
        if(mp[a[i]] == 0) continue;
        int b = 1;
        while(true){
            b *= 2;
            if(b > a[i]) break;
        }
        mp[a[i]]--;
        if(mp[b-a[i]]){
            mp[b-a[i]]--;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 19712
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char[] S = scan.next().toCharArray();
		char[] T = scan.next().toCharArray();
		int count = 0;
		for(int i = 0; i < S.length; i++) {
			if(S[i] != T[i]) {
				count++;
			}
		}
		System.out.println(count);
	}

}

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

#define ll long long 
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<ll>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";


ll n,m;
int main() {
    fastInOut
    cin>>n;
    vi a(n);
    vi b(n);
  
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    vi t=a;
    sort(t.begin(),t.end());
    int x=0,y=0;
    int u=1;
    do{
        if(t==a)
           x=u;
        if(t==b)
           y=u;
        u++;
    } while(next_permutation(t.begin(),t.end()));
   cout<<abs(x-y);     
  return 0;
}

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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define FI ios_base::sync_with_stdio(0); cin.tie(NULL);


#define LL long long

const int MX = 1e6 + 5;

int n;
vector<int> inp;
int freq[MX];
int mark[MX];

int main() {
	FI;
	cin >> n;
	int num;
	for(int i=0;i<n;i++) {
		cin >> num;
		freq[num]++;
		inp.push_back(num);
	}

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

	if(inp[0] == 1) {
		if(freq[1] == 1) {
			cout << 1 << endl;
		} else {
			cout << 0 << endl;
		}
		return 0;
	}


	int ans = 0;
	for(int i=0;i<inp.size();i++) {
		if(mark[inp[i]] == 1) continue;

		if(freq[inp[i]] == 1) {
			ans++;
		}
		for(int j=inp[i];j<MX;j+=inp[i]) {
			mark[j] = 1;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11780
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if((a-b)&1)printf("Borys\n");
	else printf("Alice\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int h, w, n;
  cin >> h >> w >> n;
  int r, c;
  cin >> r >> c;
  string s, t;
  cin >> s >> t;
  map<char, int> sc, tc;
  sc['L'] = 0;
  sc['R'] = 0;
  sc['U'] = 0;
  sc['D'] = 0;
  tc['L'] = 0;
  tc['R'] = 0;
  tc['U'] = 0;
  tc['D'] = 0;
  REP(i, n) {
    sc[s[i]]++;
    tc[t[i]]++;
  }

  int er = r, ec = c;

  /* Lに落とす */
  REP(i, n) {
    if (s[i] == 'L') {
      ec--;
    }
    if (ec == 0) {
      cout << "NO" << endl;
      return;
    }
    if (ec < w && t[i] == 'R') {
      ec++;
    }
  }

  ec = c;
  /* Rに落とす */
  REP(i, n) {
    if (s[i] == 'R') {
      ec++;
    }
    if (ec == w + 1) {
      cout << "NO" << endl;
      return;
    }
    if (ec > 1 && t[i] == 'L') {
      ec--;
    }
  }

  /* Uに落とす */
  REP(i, n) {
    if (s[i] == 'U') {
      er--;
    }
    if (er == 0) {
      cout << "NO" << endl;
      return;
    }
    if (er < h && t[i] == 'D') {
      er++;
    }
  }

  er = r;
  /* Dに落とす */
  REP(i, n) {
    if (s[i] == 'D') {
      er++;
    }
    if (er == h + 1) {
      cout << "NO" << endl;
      return;
    }
    if (er > 1 && t[i] == 'U') {
      er--;
    }
  }
  cout << "YES" << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

bool judge(string s)
{
  string t=s;
  reverse(t.begin(), t.end());
  bool flag=true;
  for (int i = 0; i < s.size(); ++i)
  {
    if(s[i]!=t[i]) return false;
  }
  return true;
}

int main()
{
  string s;
  cin>>s;
  string t=s;
  string ans="Yes";
  //回文判定
  if(!judge(s)) ans="No";
  
  //前半回文判定
  string s1=s.substr(0,s.size()/2),s2=s.substr(s.size()/2+1);

  if((!judge(s1))||(!judge(s2))) ans="No";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
A.sort()
sA = [0]
for i in range(n):
    sA.append(sA[i]+A[i])

A = A[::-1]
sA = sA[::-1]
ans = 1
for i in range(1,n):
    if 2*sA[i]>=A[i-1]:
        ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 20500
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr ll INF = 1e18 + 10;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

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

    ll x;
    cin >> x;
    int year = 0;
    ll money = 100;
    while (true)
    {
        year++;
        money *= 1.01;
        if (money >= x)
            break;
    }

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


Measured memory_bytes: 3608
#include<stdio.h>

void maxHeapify(int);
void buildMaxHeap();
int n;
int A[500000];

int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%d",&A[i]);

    buildMaxHeap();

    for(i=1;i<n;i++)printf(" %d",A[i]);
    printf(" %d\n",A[i]);
    return 0;
}

void maxHeapify(int i){
    int l,r;
    int largest;
    int tmp;
    l=2*i;
    r=2*i+1;
    if(l<=n && A[l]>A[i])largest=l;
    else largest=i;
    if(r<=n && A[r]>A[largest])largest=r;
    if(largest!=i){
        tmp=A[i];
        A[i]=A[largest];
        A[largest]=tmp;
        maxHeapify(largest);
    }
}

void buildMaxHeap(){
    int i;
    for(i=n/2;i>=1;i--)maxHeapify(i);
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"
lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<lli> a(1<<n);
	vector<multiset<int>> dp(1<<n);
	for(int i=0;i<(1<<n);i++){
		cin>>a[i];
		dp[i].insert(a[i]);
	}
	for(int i=0;i<n;i++){
		for(int mask=0;mask<(1<<n);mask++){
			if((mask&(1<<i))&&(dp[mask^(1<<i)].size())){
				for(auto x:dp[mask^(1<<i)]){
					dp[mask].insert(x);
				}
				vector<lli> tmp;
				for(auto x:dp[mask]){
					tmp.pb(x);
				}
				dp[mask].clear();
				for(int i=0;i<min(2,SZ(tmp));i++){
					dp[mask].insert(tmp[SZ(tmp)-i-1]);
				}
			}
		}
	}
	lli mxtn=0;
	for(int i=1;i<(1<<n);i++){
		lli ans=0;
		for(auto x:dp[i]){
			ans+=x;
		}
		mxtn=max(mxtn,ans);
		cout<<mxtn<<endl;
	}
}


Measured memory_bytes: 41984
S = input()
N = len(S)

MOD = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for _ in range(N)]

if S[0] == "?":
  for j in range(10):
    dp[0][j] = 1
else:
  k = int(S[0])
  dp[0][k] = 1

for i in range(1, N):
  if S[i] == "?":
    for j in range(13):
      for k in range(10):
        dp[i][(j * 10 + k) % 13] += dp[i - 1][j]
  else:
    k = int(S[i])
    for j in range(13):
      dp[i][(j * 10 + k) % 13] += dp[i - 1][j]
  for j in range(13):
    dp[i][j] %= MOD

print(dp[-1][5])

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

int main()
{
    int n = 0;
    int m = 0;
    int l = 0;
    
    // input
    std::cin >> n;
    std::cin >> m;
    std::cin >> l;
    
    if(n < 1 || n > 100 || m < 1 || m > 100 || l < 1 || l > 100)
    {
        std::cout << "Error : out of range!" << std::endl;
        return -1;
    }
    
    std::vector< std::vector<int> > tableA(n, std::vector<int>(m, 0));
    std::vector< std::vector<int> > tableB(m, std::vector<int>(l, 0));
    std::vector< std::vector<long long int> > tableC(n, std::vector<long long int>(l, 0));
    
    // input
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            std::cin >> tableA.at(i).at(j);
            if(tableA.at(i).at(j) < 0 || tableA.at(i).at(j) > 10000)
            {
                std::cout << "Error : out of range!" << std::endl;
                return -2;
            }
        }
    }
    
    for(int i = 0; i < m; ++i)
    {
        for(int j = 0; j < l; ++j)
        {
            std::cin >> tableB.at(i).at(j);
            if(tableB.at(i).at(j) < 0 || tableB.at(i).at(j) > 10000)
            {
                std::cout << "Error : out of range!" << std::endl;
                return -3;
            }
        }
    }    
    
    // manipulation
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < l; ++j)
        {
            for(int k = 0; k < m; ++k)
            {
                tableC.at(i).at(j) += tableA.at(i).at(k) * tableB.at(k).at(j);
            }
        }
    }
    
    // output
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < l; ++j)
        {
            std::cout << tableC.at(i).at(j);
            if(l - 1 == j)
            {
                std::cout << std::endl;
            }
            else
            {
                std::cout << " ";
            }
        }
    }

    return 0;
}



Measured memory_bytes: 3260
#include <cstdio>
using namespace std;
char A, B, C, D; int x[4]; char op[4];
int found = 0;
void rec(int sum, int p) {
  if(found || p > 3) return;
  sum += x[p]; op[p] = '+';
  if(p == 3 && sum == 7) found = 1;
  rec(sum, p+1);
  if(found) return;
  sum -= 2*x[p]; op[p] = '-';
  if(p == 3 && sum == 7) found = 1;
  rec(sum, p+1);
  sum += x[p];
}
int main() {
  scanf("%c%c%c%c", &A, &B, &C, &D);
  x[0] = A-'0'; x[1] = B-'0'; x[2] = C-'0'; x[3] = D-'0';
  rec(0, 0);
  printf("%d%c%d%c%d%c%d=7", x[0], op[1], x[1], op[2], x[2], op[3], x[3]);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double

#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}

typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

const ll mod =1e9+7;
const ll maxn=1e5+10;
bool comp(pll a,pll b)
{
  if(a.ff==b.ff)
    return a.ss>b.ss;
  return a.ff<b.ff;
}
ll dp[3001][3001];
pll a[3000+1];
ll n,t;
ll solve(ll i,ll j)
{
  if(i==n+1)
    return 0;
  if(j>=t)
    return 0;
  if(dp[i][j]!=-1)
    return dp[i][j];
  ll &res=dp[i][j];
  res=max(solve(i+1,j),solve(i+1,j+a[i].ff)+a[i].ss);
  return res;
}
int main()
{ 
 
   IOS
   
   cin>>n>>t;
   for(ll i=1;i<=n;i++)
   {
     cin>>a[i].ff>>a[i].ss;
   }
   sort(a+1,a+n+1,comp);
   memset(dp,-1,sizeof(dp));
   
  cout<<solve(1,0);
 
}


Measured memory_bytes: 70912
t = []
t.append(list(input().rstrip()))
t.append(list(input().rstrip()))
t.append(list(input().rstrip()))

i = 0
r = 'A'
while True:
    item = t[i]
    if len(item) == 0:
        break

    c = item.pop(0)
    if c == 'a':
        i = 0
        r = 'A'
    elif c == 'b':
        i = 1
        r = 'B'
    elif c == 'c':
        i = 2
        r = 'C'


print(r)


Measured memory_bytes: 3064