akhauriyash/Code-Regression huggingface dataset:
N,Ma,Mb=map(int,input().split())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
c=[0 for i in range(N)]
M=401
dp=[[[10**4 for cb in range(M)]for ca in range(M)]for i in range(N+1)]
for i in range(N):
    a[i],b[i],c[i]=map(int,input().split())
dp[0][0][0]=0
for i in range(N):
    for ca in range(M):
        for cb in range(M):
            if dp[i][ca][cb]==10**4:
                continue
            dp[i+1][ca][cb]=min([dp[i+1][ca][cb],dp[i][ca][cb]])
            dp[i+1][ca+a[i]][cb+b[i]]=min([dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]])
ans=10**4
for i in range(1,M):
    for j in range(1,M):
        if i*Mb==j*Ma:
            if dp[N][i][j]<ans:
                ans=dp[N][i][j]
if ans!=10**4:
    print(ans)
else:
    print(-1)


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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }

  vector<bool> row(h, false);
  vector<bool> col(h, false);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    if (row[i] == true) {
      for (int j = 0; j < w; j++) {
        if (col[j] == true) {
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}

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

def li_input():
    A=[]
    B=[]
    C=[]
    a=input()
    for i in range(len(a)):
        A.append(a[i])
    b=input()
    for i in range(len(b)):
        B.append(b[i])
    c=input()
    for i in range(len(c)):
        C.append(c[i])
    return A,B,C


def main():
    A,B,C=li_input()
    card=A[0]
    del(A[0])
    while 1:
        if card=='a':
            try:
                card=A[0]
                del(A[0])
            except:
                break
        elif card=='b':
            try:
                card=B[0]
                del(B[0])
            except:
                break
        elif card=='c':
            try:
                card=C[0]
                del(C[0])
            except:
                break

    if card=='a':
        print('A')
    elif card=='b':
        print('B')
    elif card=='c':
        print('C')
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	say(min(a + b, min(b + c, c + a)));
}

Measured memory_bytes: 256
n, m = map(int, input().split())
D = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A = list(map(int, input().split()))
C = [(a, D[a]) for a in A]
C.sort(reverse=True)
dp = [-1]*(n+1)
dp[0] = 0
for i in range(1, n+1):
  for a, c in C:
    if i >= c and dp[i-c] >= 0:
      dp[i] = max(dp[i-c]+1, dp[i])
now = n
ans = ""
while now:
  for a, c in C:
    if now-c >= 0 and dp[now] == dp[now-c]+1:
      ans += str(a)
      now -= c
      break
print(ans)

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

int main(){
  int a,b,c,x,count=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
     if(500*i+100*j+50*k==x)
       count++;
      }
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
n,t=input().split()
n=int(n)
x=[[int(i) for i in input().split()] for j in range(n)] 
#print(n,t)
#print(x)
cost=1000000000
for i in range(n):
  if x[i][1]<=int(t):
    if x[i][0]<cost:
      cost=x[i][0]
if cost==1000000000:
  print('TLE')
else:
  print(cost)



Measured memory_bytes: 3060
import Control.Applicative
import Control.Monad

shuffle :: String -> Int -> String
shuffle str h = drop h str ++ take h str

solver :: String -> [Int] -> String
solver = foldl shuffle


main :: IO()
main = do
  str <- getLine
  unless (str == "-") $ do
    m <- (read :: String -> Int) <$> getLine
    hs <- map (read :: String -> Int) <$> replicateM m getLine
    putStrLn $ solver str hs
    main

Measured memory_bytes: 4180
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>

using namespace std;

void create_string_26(long long N, ostringstream& oss) {
	if (N == 0) {
		return;
	}
	const long long div = (N - 1) / 26;
	const long long mod = (N - 1) % 26;
	create_string_26(div, oss);
	oss << static_cast<char>('a' + mod);
}
 
int main(void) {
	long long N;
	cin >> N;
	ostringstream oss;
	create_string_26(N, oss);
	cout << oss.str() << endl;
	return 0; 
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define LOG_MAX 30
// 1つ先が無い(木の根など)場合、値を負かn以上とする
template <typename T>
class Doubling {
    const size_t n;
    vector<vector<T>> next;
public:
    Doubling() {}
    Doubling(vector<T> first_row) 
    : n(first_row.size()), 
      next(LOG_MAX, vector<T>(n)) {
        copy(first_row.begin(), first_row.end(), next[0].begin());
        for (size_t i=1; i<LOG_MAX; i++) {
            for (size_t j=0; j<n; j++) {
                next[i][j] = (
                    (0 <= next[i-1][j] && (size_t)next[i-1][j] < n)
                    ? next[i-1][(size_t)next[i-1][j]]
                    : next[i-1][j]
                );
            }
        }
    }

    T query(T i, int step=1) {
        for (int k=LOG_MAX-1; k>=0; k--) {
            if ((step >> k) & 1) i = next[(size_t)k][(size_t)i];
            if (i < 0 || n <= (size_t)i) break;
        }
        return i;
    }
};

int main() {
    int n, q;
    cin >> n;
    long x[n], l;
    for (auto &xi:x) cin >> xi;
    cin >> l >> q;
    vector<int> first_row(n);
    for (int i=0; i<n; i++) {
        int ub = upper_bound(x+i, x+n, x[i] + l) - x;
        first_row[i] = ub - 1;
    }
    Doubling<int> db(first_row);
    for (int i=0, a, b; i<q; i++) {
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        int l=0, r=n-1;
        while (r - l > 1) {
            int m = (l + r + 1) / 2,
                dest = db.query(a, m);
            if (b > dest) l = m;
            else r = m; 
        }
        cout << r << '\n';
    }
    return 0;
}


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

s = []
for _ in range(N):
    s.append(int(input()))
    
s = sorted(s)

if sum(s) % 10 == 0:
    for i in range(len(s)):
        if s[i] % 10 != 0:
            print(sum(s[:i]) + sum(s[i+1:]))
            break
    else:
        print(0)
        
else:
    print(sum(s))

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String args []){
        Scanner sc  = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int [] OPT = new int[N+1];
        int [] check = new int[N+1];
        int AC_sum = 0;
        int WA_sum = 0;
        for(int i=0;i<=N;i++){
            OPT[i]=0;
            check[i]=0;
        }
        for(int i=0;i<M;i++){
            int p = sc.nextInt();
            String s = sc.next();
            if(s.charAt(0)=='A'&&OPT[p]==0) OPT[p]=1;
            else if(s.charAt(0)=='W'&& OPT[p]==0) check[p]++;
        }
        for(int i=1;i<=N;i++){
            if(OPT[i]==1){
                WA_sum+=check[i];
                AC_sum++;
            }
        }
        System.out.print(AC_sum+" "+WA_sum);
    }
}

Measured memory_bytes: 64536
l, r = map(int, input().split())
def mod2019(x, y):
    ans=2019
    for i in range(x, y):
        for j in range(i + 1, y + 1):
            ans = min(ans, i * j % 2019)
    return ans

if r - l >= 2019:
    print(0)
else:
    print(mod2019(l,r))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    ll h, w; cin >> h >> w;
    ll ans = h * w / 2LL;
    if((h*w) & 1) ans++;
    if(h==1||w==1) ans = 1;
    cout << ans;
}


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

int main(){
  int A,B,count=0;
  cin >> A >> B;
  for(int i=A;i<=B;i++){
    if(i/10000 == i%10){
      if((i/1000)%10 == (i%100)/10)count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

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

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, X, T;
    cin >> N >> X >> T;
    prints()((N + X - 1) / X * T);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3616
inf = 10**12


def main():
    import sys
    from random import randint
    input = sys.stdin.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x + 1

    D = int(input())
    C = list(map(int, input().split()))
    S = [[]]
    for _ in range(D):
        S.append(list(map(int, input().split())))
    ans = 0
    last = [0] * 26
    days = [Bit(D+1) for _ in range(26)]
    for i in range(26):
        days[i].add(D+1, 1)
    T = [-1]
    # greedy
    for d in range(1, D+1):
        plus = -inf
        t = -1
        for tt in range(26):
            plus_new = S[d][tt] + C[tt] * (d - last[tt])
            if plus_new > plus:
                t = tt
                plus = plus_new
        T.append(t)
        ans += S[d][t]
        last[t] = d
        days[t].add(d, 1)
        for i in range(26):
            ans -= C[i] * (d - last[i])

    def calc(d_list, q_list, cur):
        for d, q in zip(d_list, q_list):
            t = T[d]
            cur += S[d][q]
            cur -= S[d][t]
            k = days[q].sum(d)
            i = days[q].lower_bound(k)
            j = days[q].lower_bound(k+1)
            cur += C[q] * (d - i) * (j - d)
            k = days[t].sum(d)
            i = days[t].lower_bound(k-1)
            j = days[t].lower_bound(k+1)
            cur -= C[t] * (d - i) * (j - d)

            T[d] = q
            days[q].add(d, 1)
            days[t].add(d, -1)
        return cur


    # climb
    size = 10
    try_num = 200
    loop_num = 13
    for _ in range(loop_num):
        for x in range(D // size):
            d_list = list(range(x*size+1, (x+1)*size+1))
            for _ in range(try_num):
                t_new = [randint(0, 25) for _ in range(size)]
                for i, d in enumerate(d_list):
                    if t_new[i] == T[d]:
                        t_new[i] = (t_new[i] + 1)%26
                t_ori = []
                for d in d_list:
                    t_ori.append(T[d])
                ans_new = calc(d_list, t_new, ans)
                if ans_new < ans:
                    for i in range(size-1, -1, -1):
                        d = d_list[i]
                        T[d] = t_ori[i]
                        days[t_ori[i]].add(d, 1)
                        days[t_new[i]].add(d, -1)
                else:
                    ans = ans_new
    # print(ans)
    for t in T[1:]:
        print(t+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 92768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#include <map>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD=1000000007;
lli f(lli b,lli n){
  if(n<b)return n;
  else{
    return f(b,(lli)(n/b))+n%b;
  }
}

int main(){
  lli n,s;
  cin >> n>>s;
  if(n<s){
    cout<<-1<<endl;
    return 0;
  }
  if(s==n){
    cout << n+1<<endl;
    return 0;
  }
  for(lli i = 2;i*i<=n;i++){
    if(f(i,n)==s){
      cout<<i<<endl;
      return 0;
    }
  }
  for(lli p = (lli)sqrt(n);p>0;p--){
    if((n-s)%p!=0)continue;
    lli b = (n-s)/p +1;
    if(f(b,n)==s){
      cout<<b<<endl;
      return 0;
    }
  }
  cout << -1 << endl;

  
}
  


Measured memory_bytes: 256
# include <bits/stdc++.h>
    # define fi first
    # define se second

    using namespace std ;

    int vc[110][110], cnt=1, cnt2;
    int W, B,x ;

    int main() {
        cin >> W >> B ;
        if( W > B ) x = true ;
        else x = false ;

        for( int j = 1 ; j <= 100 ; j += 2 ) {
            for( int i = 1 ; i <= 100 ; i += 2 ) {
                if( x == true && cnt == W) break ;
                if( x == false && cnt == B ) break ;

                vc[i][j+1] = true ;
                vc[i+1][j+1] = true ;
                vc[i+1][j] = true ;
                cnt ++ ;
            }
        }
        if( cnt > 1 ) cnt2 = 1;
        for( int i = 2 ; i <= 99 ; i ++ ) {
            for( int j = 2 ; j <= 99 ; j ++ ) {
                if( x == true && cnt2 == B) break ;
                if( x == false && cnt2 == W ) break ;
                if( vc[i][j] == false ) {
                    if( vc[i][j+1] == false && vc[i][j-1] == false && vc[i+1][j] == false && vc[i-1][j] == false && vc[i+1][j+1] == false && vc[i+1][j-1] == false && vc[i-1][j+1] == false && vc[i-1][j-1] == false ) {
                        cnt2 ++ ;
                        vc[i][j] = true ;

                    }
                }
            }
        }
        cout << 100 << ' ' << 100 << endl;
        for( int i = 1 ; i <= 100 ; i ++ ) {
            for( int j = 1; j <= 100 ; j ++ ) {
                if( x == true ) {
                   if( vc[i][j] == true ) cout << '#' ;
                   else cout << '.' ;
                }
                else {
                    if( vc[i][j] == true ) cout << '.' ;
                    else cout << '#' ;
                }
            }
            cout << endl;
        }
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);

namespace std {
    bool operator < (const P& a, const P& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}

template<class iter>
tuple<ld, P, P> closest_pair(iter left, iter right) {
    int n = distance(left, right);

    if(n <= 1){
        return make_tuple(numeric_limits<ld>::max(), *left, *left);
    }

    if(n == 2){
        if(left[0].imag() > left[1].imag()) swap(left[0], left[1]);
        return make_tuple(norm(left[0]-left[1]), left[0], left[1]);
    }

    iter middle = next(left, n/2);
    ld x = middle->real();
    auto d = min(closest_pair(left, middle), closest_pair(middle, right));
    inplace_merge(left, middle, right, [](const P &a, const P &b){
            return a.imag() < b.imag();
        });

    vector<iter> around;
    for(iter i = left; i != right; ++i){
        ld dx = fabs(i->real() - x);
        ld &opt = get<0>(d);
        if(dx*dx >= opt) continue;
        for(auto j = around.rbegin(); j != around.rend(); ++j){
            ld dx = i->real() - (**j).real();
            ld dy = i->imag() - (**j).imag();
            if(dy*dy >= opt) break;
            ld norm = dx*dx + dy*dy;
            if(get<0>(d) > norm){
                d = make_tuple(norm, *i, **j);
            }
        }
        around.push_back(i);
    }
    return d;
};

// http://www.spoj.com/problems/CLOPPAIR/
// 18124516

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(10) << endl;
    int n;
    cin >> n;
    vector<P> a;
    rep(i,n){
        ld x,y;
        cin >> x >> y;
        a.emplace_back(x,y);
    }
    ld z;
    P x, y;
    sort(all(a));
    tie(z, x, y) = closest_pair(all(a));
    cout << sqrt(z) << endl;
}

Measured memory_bytes: 6972
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(void) {
    int n[5];
    string str;
    
    scanf("%d %d %d %d %d", &n[0], &n[1], &n[2], &n[3], &n[4]);
    
    sort(n, n + 5);
    
    cout << n[4] << ' ' << n[3] << ' ' << n[2]
         << ' '  << n[1] << ' ' << n[0] << endl;
}


Measured memory_bytes: 3168
x, y = gets.chomp.split.map(&:to_i)

turtles = (y - 2 * x)/2.0
cranes = x - turtles

if turtles.to_i != turtles || turtles > 100 || turtles < 0 || cranes > 100 || cranes < 0
  puts "No"
else
  puts "Yes"
end

Measured memory_bytes: 14404
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef priority_queue<int> PQ;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	int sum = 0;
	VI W(N);
	REP(i, N) {
		cin >> W[i];
		sum += W[i];
	}
	//SORT(W);
	int cnt = 0;
	int ans = LLINF;
	REP(i, N) {
		//cout << cnt << " "<<sum<<endl;
		cnt += W[i];
		sum -= W[i];
		ans = min(ans, abs(sum - cnt));
		
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
    int n,i=0,s;
    double sum=0,b,a,ave,SM=0;
    while(scanf("%d",&n)==1){
        int si[1000]={};
        if(n==0) break;
    while(scanf("%d",&s)==1){
        si[i]=s;
        sum+=s;
         i++;
        if(i==n){
            break;
        }
    }    
            ave=sum/n;
            for(i=0;i<=n-1;i++){
            SM+=(si[i]-ave)*(si[i]-ave);
            }
            a=SM/n;
            b=sqrt(a);
            printf("%lf\n",b);
            i=0;sum=0;SM=0;
    }
    return 0;
}


Measured memory_bytes: 2112
def main():
    N, X = (int(i) for i in input().split())
    L = [int(i) for i in input().split()]
    from itertools import accumulate
    S = accumulate([0] + L)
    ans = 0
    for s in S:
        if s <= X:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define LL long long
using namespace std;


int main(void){

    vector<double> weight;
    int N, M, C;
    int ac = 0, sum = 0;

    cin >> N >> M >> C;

    for(int i = 0; i < M; i++){
        int tmp;
        cin >> tmp;
        weight.push_back(tmp);
    }

    for (int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            int tmp;
            cin >> tmp;
            sum += tmp * weight[j];
        }
        if(sum + C > 0){
            ac++;
        }
        sum = 0;
    }

    cout << ac << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   int n;
   string s;
   cin >> n >> s;
   
   vector<char> ans;
   char mae;
   
   mae = s[0];
   for(int i=1; i<n; i++){
      if(mae != s[i]){
         ans.push_back(mae);
         mae = s[i];
      }
   }
   ans.push_back(s[n-1]);
   
   cout << ans.size() <<  endl;
   
   
   
   return 0;
}

Measured memory_bytes: 640
for i in range(0,20001):

    line = list(map(str, input().split()))
    a = int(line[0])
    b = int(line[2])
    op = line[1]

    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)
    else:
        break












Measured memory_bytes: 5596
#include <stdio.h> 
 #include <ctype.h> 
 
 
 int main(){ 
     char ch; 
     while(1){ 
         scanf("%c", &ch); 
         if(ch=='\n'){ 
             printf("\n"); 
             break; 
         }else if(islower(ch)){ 
             printf("%c", toupper(ch)); 
         }else if(isupper(ch)){ 
             printf("%c", tolower(ch)); 
         }else{ 
             printf("%c", ch); 
         } 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2128
#include <iostream>
#include <algorithm>
using namespace std;
long long n,m,i,j,suma,pret;
struct magazin {
    long long cost,castig;
} v[100001];
bool cmp(magazin x, magazin y)
{
    return x.cost<y.cost;
}
int main() {

    ios_base::sync_with_stdio();
    cin >> n >> m;
    for(i = 1; i <= n; ++i)
        cin >> v[i].cost >> v[i].castig;
    sort(v+1,v+n+1,cmp);
    for(i = 1; i <= n; ++i) {
        if(m>=suma+v[i].castig) {
            suma+=v[i].castig;
            pret+=v[i].cost*v[i].castig;
        } else {
            if(m>suma)
                pret+=(m-suma)*v[i].cost;
            suma+=v[i].castig;
        }
    }
    cout<<pret;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <climits>
using namespace std;

#define rep(i,end)          rep2(i,0,(end))
#define rep2(i,beg,end)   for (int i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
#define INFMAX                   LLONG_MAX
#define INFMIN                   LLONG_MIN
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef list<ll> li;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<string, map<int, int>> d;
    rep(i, n)
    {
        string s;
        int x;
        cin >> s >> x;
        d[s][x] = i + 1;
    }
    for (auto i = begin(d); i != end(d); i++) {
        auto sec = i->second;
        for (auto j = rbegin(sec); j != rend(sec); j++) {
            cout << j->second << endl;
        }
    }
    return 0;
}

string gets(bool skipToNextline)
{
    if (skipToNextline) gets(false);
    const int BUFF_MAX = 1024;
    char buf[BUFF_MAX];
    cin.getline(buf, sizeof(buf));
    return buf;
}

vi get_n_array(int n)
{
    vi v;
    while (n-- > 0) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    return v;
}

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

int main() {
	// your code goes here
   for( int i=1 ; i<=9 ; i++){
   	 for( int j=1 ; j<=9 ; j++){
   	 	int val = i*j ;
   	 	
   	 	cout << i<<"x"<<j<<"="<<i*j<<endl;
   	 }	
   	 
   }
	  
	return 0;
}

Measured memory_bytes: 3120
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#define INF (1<<30)
#define mm 100005
#define clr(A) memset(A,0,sizeof(A))
using namespace std;
typedef long long LL;
int A[25][12][160];

int main()
{
    //freopen("BUAA.in","r",stdin);
    //int T;
    clr(A);
    for(int i = 0;i<=20;i++)A[i][0][0] = 1;

    for(int i = 1;i<=20;i++)
    for(int j = 1;j<=10;j++)
    for(int k = (i+1)*i/2;k>=0;k--)
    {
        A[i][j][k] = A[i-1][j][k];
        if(k>=i)A[i][j][k]+=A[i-1][j-1][k-i];
    }
    int n,k,s;
    while(~scanf("%d%d%d",&n,&k,&s) && n+k+s!=0)
    {
        printf("%d\n",A[n][k][s]);
    }
    return 0;
}

Measured memory_bytes: 1384
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
// typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

const int mod = 1e9+7, MAX = 2e5;
int a[MAX];
// fac[n]: n!, inv[n]:1/n, finv[n]:1/n!
int fac[MAX], inv[MAX], finv[MAX], rui[MAX];

// テーブルを作る前処理
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
    rui[0] = 1;
    repi(i,1,MAX){
      rui[i] = inv[i+1];
      ADD(rui[i], rui[i-1]);
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}


signed main(){
  int n;
  COMinit();
  scanf("%lld", &n);
  rep(i,n)scanf("%lld", &a[i]);
  int ans = 0;
  // rep(i,10)printf("%lld ", rui[i]);printf("\n");
  rep(i,n){
    int l = i, r = n-i-1;
    int sum = (mod+rui[l]+rui[r]-1)%mod;
    // printf("%lld\n", sum);
    int tmp = sum*fac[n]%mod;
    ADD(ans, tmp*a[i]%mod);
  }
  printf("%lld\n", ans);
	return 0;
}










Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define EB emplace_back

typedef long long ll;
typedef std::pair <int, int> pr;
const int N = 100054;

int n;
int o[N], size[N];
int p[N], fc[N], nc[N];
ll D[N];
std::vector <pr> edges;

inline bool Dcmp(const int x, const int y) {return D[x] > D[y];}

inline bool find(ll x, int &ret) {return *D = x, ret = std::lower_bound(o, o + n, 0, Dcmp) - o, D[o[ret]] == x;}

inline void link(int x, int px) {p[x] = px, nc[x] = fc[px], fc[px] = x, size[px] += size[x];}

void dfs(int x, int d) {*D += d; for (int y = fc[x]; y; y = nc[y]) dfs(y, d + 1);}

int main() {
	int i, j, u;
	scanf("%d", &n), std::iota(o, o + n, 1);
	for (i = 1; i <= n; ++i) scanf("%lld", D + i);
	std::sort(o, o + n, Dcmp), std::fill(size + 1, size + (n + 1), 1);
	for (i = 0; i < n - 1; link(u, o[j]), ++i)
		if (u = o[i], !find(D[u] + 2 * size[u] - n, j) || j <= i) return puts("-1"), 0;
	if (dfs(o[i], *D = 0), *D != D[o[i]]) return puts("-1"), 0;
	for (i = 1; i <= n; ++i) if (p[i]) edges.EB(std::minmax(i, p[i]));
	std::sort(edges.begin(), edges.end());
	for (const pr &e : edges) printf("%d %d\n", e.first, e.second);
	return 0;
}

Measured memory_bytes: 6644
#include <iostream>
//#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ld = long double;
using vld = vector<ld>;
#define loop(i, n) for (int i = 0; i < (int)n; i++)

int main() {
    int n; cin >> n;
	vi as(n, 0), bs(n, 0);
	loop(i, n) {
		cin >> as[i];
		cin >> bs[i];
	}
	sort(as.begin(), as.end());
	sort(bs.begin(), bs.end());
	if (n % 2 == 0) {
		int l = as[n / 2 - 1] + as[n / 2];
		int h = bs[n / 2 - 1] + bs[n / 2];
		cout << h - l + 1 << endl;
	}
	else {
		int l = as[n / 2];
		int h = bs[n / 2];
		cout << h - l + 1<< endl;
	}
}


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

int main() {
  ll n;
  cin >> n;
  // 5,6,5,6,5,6
  ll x = n / 11;
  ll y = n % 11;
  ll ans = 2LL*x;
  if(y>6) ans+=2;
  else if(y>0) ans+=1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define MAX 1e9+7
#define MIN -1e9-7
#define int long long
#define endl "\n"
#define max(x,y) (x>y)?x:y
#define min(x,y) (x<y)?x:y
#define s(n) scanf("%d",&n)
#define mem memset(a, 0, sizeof(a))
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
typedef vector<int> vi;
typedef vector<string> vs;
/*
* * * * * * * * * * * * * * * * * * * * * *
*       ☆꧁𝓑𝓐𝓒𝓚_𝓛𝓞𝓖꧂☆              **
*                                        ***
* * * * * * * * * * * * * * * * * * * * *****
*/ 

int32_t main()
{
  int mod=1e9+7;
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)cin>>arr[i];
  int cum[n];
  cum[0]=arr[0];
  for(int i=1;i<n;i++)
  {
	  cum[i]=(arr[i]+cum[i-1]);
  }
  int k=n-1,val=0;
  int ans=0;
  for(int i=0;i<n-1;i++)
  {
	  int sum=(cum[k]-cum[val])%mod;
	  //cout<<sum<<" ";
	  ans=(ans+(arr[i]%mod)*sum)%mod;
	 val++;
  }
  cout<<ans<<endl;
return 0;

}




Measured memory_bytes: 6668
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN + 1];
int head, tail, n;

void enqueue (P x) {
  Q[tail] = x;
  if(tail + 1 == LEN) tail = 0;
  else tail++;
}

P dequeue() {
  P x;
  x = Q[head];
  if(head + 1 == LEN) head = 0;
  else head++;
  return x;
}

int main () {
  int i, q, c;
  P u;

  scanf("%d %d", &n, &q);

  for(i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = i;
  u.t = 0;

  while(head != tail) {
    if (Q[head].t <= q) {
      u.t += Q[head].t;
      strcpy(u.name, Q[head].name);
      dequeue();
      printf("%s %d\n", u.name, u.t);
    }
    else {
      Q[head].t -= q;
      u.t += q;
      enqueue(dequeue());
    }
  }
  return 0;
}

Measured memory_bytes: 10768
x = int(input())

root = int(x**(0.2))

flag = 0
for i in range(root - 400, root + 400):
    for j in range(-100, root + 400):
        if i!=j:
            if x%(i-j) == 0:
                if i**5-j**5 == x:
                    print(i, j)
                    flag = 1
                    break
    if flag:
        break

Measured memory_bytes: 9352
#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
  lint N;
  cin >> N;
  vector<double> x(N);
  vector<double> y(N);
  REP(i,N){ cin >> x[i]; cin >> y[i];}
  vector<int> v(N);
  REP(i,N) v[i] = i;
  double su = 0;
  lint c = 0;
  do {  //0 based indexing
      c++;
      REP(i,N-1){
          double dx = x[v[i+1]] - x[v[i]];
          double dy = y[v[i+1]] - y[v[i]];
          su += sqrt(dx*dx + dy*dy);
      }
  }while(next_permutation(ALL(v)));
  cout<< su / c << endl;
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 256
from itertools import permutations

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

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

for a, b in ab:
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

perm = [i for i in range(N)]

ans = 0

for p in permutations(perm):
    # 1開始でないならNG（辞書順なのでbreakでOK）
    if p[0] != 0:
        break
    flag = False
    for i in range(len(p) - 1):
        if not p[i + 1] in graph[p[i]]:
            flag = True
            break

    if not flag:
        # print(p)
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

#define N 100

int main() {
  int flag,num,i,j,A[N],kari,count=0;

  scanf("%d",&num);
  for(i=0; i<num; i++){
    scanf("%d",&A[i]);
  }
  flag = 1;
 
  for(i=0; flag==1; i++){
    flag = 0;
    for(j=num-1; j>=i+1; j--){
      if(A[j] < A[j-1]){
	kari = A[j];
	A[j] = A[j-1];
	A[j-1] = kari;
	flag = 1;
	count++;
      }
    }
  }
  for(i=0; i<num-1; i++)    printf("%d ",A[i]);
  printf("%d\n",A[num-1]);
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		BinaryTree tree = new BinaryTree();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int count = Integer.parseInt(br.readLine());
		for(int i=0;i<count;i++) {
			String input = br.readLine();
			if(input.charAt(0) == 'i') {
				tree.insert(Long.parseLong(input.substring(7)));
			}else if(input.charAt(0) == 'f'){
				tree.find(Long.parseLong(input.substring(5)));
			}else if(input.charAt(0) == 'd'){
				tree.delete(Long.parseLong(input.substring(7)));
			}else{
				tree.inOrder(tree.root);
				System.out.println();
				tree.preOrder(tree.root);
				System.out.println();
			}
		}
	}
}

class BinaryTree {
	
	Node root;
	
	class Node{
		Node left;
		Node right;
		long value;
		public Node(long value) {
			super();
			this.value = value;
		}		
		
	}
	
	public void insert(long value) {
		Node node;
		Node parent = null;
		if(root == null) {
			root = new Node(value);
			return;
		}
		node = root;
		while(node !=null) {
			parent = node;
			if(node.value>value) {
				node = node.left;
			}else {
				node = node.right;
			}
		}
		
		node = new Node(value);
		if(parent.value>node.value) {
			parent.left = node;
		}else {
			parent.right = node;
		}
		
	}
	
	public void preOrder(Node n) {
		if(n == null) {
			return;
		}
		System.out.print(" "+n.value);
		preOrder(n.left);
		preOrder(n.right);
	}
	
	public void inOrder(Node n) {
		if(n == null) {
			return;
		}
		inOrder(n.left);
		System.out.print(" "+n.value);
		inOrder(n.right);
	}
	
	public void find(long value) {
		Node n = root;
		while(n!=null) {
			if(n.value==value) {
				System.out.println("yes");
				return ;
			}else if(n.value>value) {
				n = n.left;
			}else {
				n = n.right;
			}
		}
		System.out.println("no");
	}
	
	public void delete(long value) {
		Node parent = null;
		Node child = root;
		while(child!=null&&child.value!=value) {
			parent = child;
			if(child.value>value) {
				child = parent.left;
			}else {
				child = parent.right;
			}
		}
		if(child.left == null) {
			if(child.value<parent.value) {
				parent.left = child.right;
			}else {
				parent.right = child.right;
			}
		}else if(child.right == null) {
			if(child.value<parent.value) {
				parent.left = child.left;
			}else {
				parent.right = child.left;
			}
		}else {
			parent = child;
			Node next = child.right;
			while(next.left!=null) {
				parent = next;
				next = next.left;
			}
			child.value = next.value;
			if(next.value<parent.value) {
				parent.left = next.right;
			}else {
				parent.right = next.right;
			}
		}
	}
	
	

}



Measured memory_bytes: 137652
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine());
        String s;
        Map<String, Integer> map = new TreeMap<>();
        int max = 0;
        for (int i = 0; i < n; i++) {
            s = br.readLine();
            int val = map.containsKey(s) ? map.get(s) + 1 : 1;
            map.put(s, val);
            max = Math.max(max, val);
        }

        br.close();

        for (var entry : map.entrySet()) {
            if (entry.getValue() == max) {
                bw.write(entry.getKey() + "\n");
            }
        }

        bw.flush();

    }
}

Measured memory_bytes: 70568
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[200000];
	int cnt = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] == 1) {
			++cnt;
		}
	}
	if (cnt == 0) {
		cout << "-1" << endl;
		return 0;
	}
	int ans = 0;
	int now = 1;
	rep(i, n) {
		if (a[i] == now) {
			now += 1;
		}
		else {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int n, m;
vector<int> G[100];
int in[100];

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

    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        in[b]++;
    }

    queue<int> que;
    rep(i, n) if(in[i] == 0) que.push(i);

    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for(int e : G[v])
            if(--in[e] == 0) que.push(e);
    }

    cout << (count(in, in + n, 0) != n) << endl;

    return 0;
}


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

void solve();

int n, y;

int main() {
  cin >> n >> y;

  solve();

  return 0;
}

void solve() {

  for(int i=0; i<=n; ++i) {
    for(int j=0; j<=n-i; ++j) {
      for(int k=0; k<=n-i-j; ++k) {
        if(i*10000+j*5000+k*1000==y && i+j+k==n) {
          cout << i << " " << j << " " << k << endl;
          return;
        }
      }
    }
  }

  cout << "-1 -1 -1" << endl;

}


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

#define int long long
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; }

const int MOD = 1e9+7;
int pow_mod(int n, int m){
	int ans = 1;
	while(m > 0){
		if(m & 1) ans = (ans * n) % MOD;
		n = (n * n) % MOD;
		m >>= 1;
	}
	return ans;
}

signed main(){
	int n;
	cin >> n;
	if(n == 1){
		cout << 0 << endl;
		return 0;
	}
	int a = pow_mod(8, n);
	int b = (MOD + pow_mod(9, n) - a) % MOD * 2 % MOD;
	int ans = (MOD*2+pow_mod(10, n) - a - b) % MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3592
s = input()
n = len(s)

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

alphabet = ["a", "b", "c", "d", "e", "f", "g", "h","i", "j", "k","l","m","n","o", "p","q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for i in alphabet:
    if not i in s:
        print(s + i)
        exit()

flag = True
while n > 0 and flag:
    last = alphabet.index(s[-1])
    for i in alphabet[last + 1:]:
        if i not in s[:-1]:
            print(s[:-1] + i)
            flag = False
            break
    else:
        s = s[:-1]
    n = len(s)


Measured memory_bytes: 3064
N,X=map(int,input().split())
ans=0
def rec(x,n):
    global ans
    if n==0:
        if x>=1:
            ans+=1
    elif x>2**(n+1)-2:
        ans+=(2**n-1+1)
        rec(x-(2**(n+1)-1),n-1)
    else:
        rec(x-1,n-1)

rec(X,N)
print(ans)


Measured memory_bytes: 3060
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

int N, M;
bool visit[10];
int ans;
vector<vector<bool>> G(10, vector<bool>(10));

void dfs(int n) {

    bool ok = true;
    REP(i, N) {
        if (!visit[i]) {
            ok = false;
            break;
        }
    }
    if (ok) {
        ans++;
        return;
    }

    REP(i, G[n].size()) {
        if (!G[n][i]) continue;
        if (visit[i]) continue;
        visit[i] = true;
        dfs(i);
        visit[i] = false;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a][b] = true;
        G[b][a] = true;
    }

    ans = 0;
    visit[0] = true;
    dfs(0);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256