akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;


int main(){
    int n; cin>>n;
    vi v(n);
    for(int i = 0; i < n; i++) cin>>v[i];
    sort(all(v));
    int sum = v[n-1]/2;
    for(int i = 0; i <= n-2; i++) sum+=v[i];
    cout<<sum;
}

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

const int mod = 1e9 + 7;

void add_mod(int& a, int b) {
  a += b;
  if (a > mod) {
    a -= mod;
  }
}

int main() {
  int w, h;
  cin >> h >> w;
  vector<vector<bool>> g(h + 1, vector<bool>(w + 1, false));
  for (int y = 1; y <= h; ++y) {
    for (int x = 1; x <= w; ++x) {
      char ch;
      cin >> ch;
      g[y][x] = ch == '.';
    }
  }
  vector<vector<int>> dp(h + 1, vector<int>(w + 1));

  dp[1][1] = 1;
  for (int y = 1; y <= h; ++y) {
    for (int x = 1; x <= w; ++x) {
      if (g[y - 1][x]) {
        add_mod(dp[y][x], dp[y - 1][x]);
      }
      if (g[y][x - 1]) {
        add_mod(dp[y][x], dp[y][x - 1]);
      }
    }
  }
  cout << dp[h][w];
  return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

bool checkWay(vector<ll> &argA, ll target, ll &freq)
{
    freq++;
	
	if (argA.at(target - 1) == -1) {
		return false;
	}
	else if (argA.at(target - 1) == 2) {
		return true;
	}

	ll next = argA.at(target - 1);
	argA.at(target - 1) = -1;

	return checkWay(argA, next, freq);
}

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

	vector<ll> argA(argN);
	for (ll i = 0; i < argN; ++i) {
		cin >> argA.at(i);
	}

	ll freq = 0;
	bool ret = checkWay(argA, 1LL, freq);

	if (ret) {
		cout << freq << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 1152
N = int(input())
W = list(map(int, input().split()))

S = [0]
L = [0]
s = 0
l = 0
for i in range(N):
    s += W[i]
    l += W[N-1-i]
    S.append(s)
    L.append(l)

MIN = 100000000
for i in range(N):
    now = abs(S[i] - L[N-i])
    MIN = min(MIN, now)

print(MIN)


Measured memory_bytes: 3064
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define REPR(i, x, n) for(int i = n - 1 ; i >= x ; i--)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) REPR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector< pair<int, int> > e(m);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        e[i] = make_pair(a, b);
    }
    int ans = 0;
    rep(i, m){
        vector< vector<int> > dis(n);
        rep(j, n){
            dis[j].resize(n, 1e8);
            dis[j][j] = 0;
        }
        rep(j, m){
            if(i == j){
                continue;
            }
            dis[e[j].first][e[j].second] = 1;
            dis[e[j].second][e[j].first] = 1;
        }
        rep(l, n){
            rep(j, n){
                rep(k, n){
                    dis[j][k] = min(dis[j][k], dis[j][l] + dis[l][k]);
                }
            }
        }
        bool flag = false;
        rep(j, n){
            rep(k, n){
                if(dis[j][k] > 100){
                    ans++;
                    flag = true;
                    break;
                }
            }
            if(flag){
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        int stacks = 0;
        int res = 0;
        foreach (var i in s)
        {
            if (i == 'S') stacks++;
            else if (stacks >= 1) stacks--;
            else res++;
        }
        Console.WriteLine(res * 2);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define here(x) cout << " #x = " << x << endl;
#define show(x) {for( auto ii : x) cout << ii << setw(4); cout << endl;}
#define shop(n,x) {for(int i = 0; i < n; i++) cout << x << setw(4); cout << endl;}
#define ff first
#define ss second
#define sq(x) (x*x)
#define endl '\n'
#define en " "
#define pb push_back
#define mpair make_pair
ll mod=1000000007;
double pi=3.1415926536;
int main()
{
	fastio();
	int tt = 1;
	//cin >> tt;
	while(tt--)
	{
		// go fast 		check		//		CHECK -> if()   else if()
		
		ll n, x=0, m=0, y=0, d=1, k=mod;
		cin >> n >> k;
		ll a[n], dp[k + 1] = {};
		for(ll i = 0; i < n; i++)
		{
			cin >> a[i];
			dp[a[i]] = 1;
		}
		dp[0] = 2;
		for(ll i = 1; i <= k; i++)
		{
			if(dp[i] != 0)
				continue;
			x = 0;
			for(ll j = 0; j < n; j++)
			{
				if(i - a[j] >= 0 && dp[i - a[j]] == 2)
				{
					dp[i] = 1;
					x = 1;
				}
			}
			if(x == 0)
				dp[i] = 2;
		}
		if(dp[k] == 1)
			cout << "First" << endl;
		else
			cout << "Second" << endl;
	}
}

Measured memory_bytes: 1024
#c
import copy

S = input()
T = input()

def change(string, c1, c2):
    ret = []
    for s in string:
        if s is c1:
            ret.append(c2)
        elif s is c2:
            ret.append(c1)
        else:
            ret.append(s)
    return ret

S_ = copy.deepcopy(S)
history = []

while True:
    if S_ in history:
        print('No')
        exit()
    history.append(S_)
    for i, s in enumerate(S_):
        if s is not T[i]:
            S_ = copy.deepcopy(''.join(change(S_, s, T[i])))
            break
        if i == len(S_)-1:
            print('Yes')
            exit()


Measured memory_bytes: 7956
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int s, w;
    cin >> s >> w;
    if (w >= s)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
    GAME_OVER;
}

Measured memory_bytes: 3652
#include <stdio.h>
#define k 2000001
int a[k],b[k],c[k];


int main()
{

  int n,i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&a[i]);
    }
  for(i=0;i<k;i++)
    {
      c[i] = 0;
    }
  for(j=1;j<=n;j++)
    {
      c[a[j]]++;
    }
  for(i=1;i<k;i++)
    {
      c[i] = c[i] + c[i-1];
    }
  for(j=n;j>=1;j--)
    {
      b[c[a[j]]] = a[j];
      c[a[j]]--;
    }
  for(i=1;i<=n;i++)
    {
      printf("%d",b[i]);
      if(i!=n)
	{
	  printf(" ");
	}
      else
	{
	  printf("\n");
	} 
    }
  return 0;
}

Measured memory_bytes: 24040
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
    
    size_t n;
    std::cin >> n;

    std::vector<size_t> h(n);

    for(auto&& e : h){
        std::cin >> e;
    }

    for(size_t i = 1; i < n; i++){
        if(h.at(i) > h.at(i - 1)){
            h.at(i)--;
        }
    }

    if(std::is_sorted(h.begin(), h.end())){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    
    return 0;
}


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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

const int MAX_N = 100005;
int dp[MAX_N];
v<int> used, temp;
vv<int> to;

void dfs(int s) {
    if (used[s]) return;
    used[s] = 1;
    for (int ns: to[s]) dfs(ns);
    temp.push_back(s);
}

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

    int n, m; cin >> n >> m;
    int s, g;
    int ans = 0;

    to = vv<int>(n); used = v<int>(n);

    rep(i,m) {
        cin >> s >> g;
        s--; g--;
        to[s].push_back(g);
    }

    rep(i,n) dfs(i);
//    rep(i, temp.size()) cout << temp[i]<< ' ';

    for (int i: temp) {
        for (int j: to[i]) {
            chmax(dp[i], dp[j] + 1);
        }
        chmax(ans, dp[i]);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9080
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REP1(i, n) for(int i = 1; i <= (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define ZERO(a) memset(a, 0, sizeof(a))

#define RAD(d) (PI * (d) / 180)
#define DEG(r) (180.0 * (r) / PI)

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

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> T accumulate(const vector<T> &v)
{
	T sum = 0;
	REP(i, SZ(v)){ sum += v[i]; }
	return sum;
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

string &to_upper(string &s)
{
	REP(i, s.length()){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] -= 32;
		}
	}

	return s;
}

string &to_lower(string &s)
{
	REP(i, s.length()){
		if('A' <= s[i] && s[i] <= 'Z'){
			s[i] += 32;
		}
	}

	return s;
}

// すべての約数を列挙する
template <class T> vector<T> get_divisors(T n)
{
	vector<T> ret;
	for(T i = 1; i * i <= n; i++){
		if(n % i == 0){
			ret.push_back(i);
			if(i * i != n)
				ret.push_back(n / i);
		}
	}
	sort(ALL(ret));
	return ret;
}

// 1-sqrt(N)までの約数を列挙する
template <class T> vector<T> get_divisors2(T n)
{
	vector<T> ret;
	for(T i = 1; i * i <= n; i++){
		if(n % i == 0){
			ret.push_back(i);
		}
	}
	return ret;
}

int F(ll A, ll B)
{
	return LEN(to_string(max(A, B)));
}

int main()
{
	int N;
	cin >> N;

	set<string> S;

	REP(i, N){
		string s;
		cin >> s;

		S.insert(s);
	}

	cout << S.size() << endl;
	
	return 0;
}


Measured memory_bytes: 19176
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=1e9+7;
ll pow(ll a,ll b){
    ll r=1;
    while(b>0){
        if(b%2==1)r=r*a%mod;
        a=a*a%mod;
        b/=2;
    }
    if(r<0)cout<<"rrr"<<r<<endl;
    return r;
}
ll c(ll a,ll b){
    ll x=1,y=1;
    rep(i,b){
        x*=(a-i);
        x%=mod;
        y*=(b-i);
        y%=mod;
    }
    if(x<0||y<0)cout<<x<<" "<<y<<endl;
    ll res= x*pow(y,mod-2)%mod;
    res%=mod;
    if(res<0)cout<<res<<endl;
    return res;
}
ll f(ll a,ll b){
    if(a>0&&b==0)return 0;
    if(b>a)return 0;
    if(b==a)return 1;
    return c(a-1,b-1);
}

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans;
    arep(i,1,k+1){
        ll blue=f(k,i);
        //cout<<"blue"<<blue<<endl;
        blue%=mod;
        ll red=0;
        red+=f(n-k,i-1);
        red%=mod;
        red+=f(n-k,i);
        red%=mod;
        red+=f(n-k,i);
        red%=mod;
        red+=f(n-k,i+1);
        red%=mod;

        ans=red*blue%mod;
        cout<<ans<<endl;

    }
   
    return 0;
}

Measured memory_bytes: 256
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    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 <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int max_=max(H,W);
    cout << N/max_+(N%max_>0) << endl;
}

Measured memory_bytes: 256
x,k,d=map(int,input().split())
if x==0:
    if k%2:
        print(d)
    else:
        print(0)
else:
    x=abs(x)
    if k<=x//d:
        print(x-d*k)
        exit()
    k-=x//d
    if k%2:
        print(-(x%d-d))
    else:
        print(x%d)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int n, k;
string s;

int main() {
    //freopen("sample.in", "r", stdin);
    cin >> n >> k;
    cin >> s;
    int ret = 0;
    for(int i = 1; i < n; i++)
        if (s[i] == s[i - 1]) ret++;
    cout << min(ret + 2 * k, n - 1) << endl; 
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	char x,y;
	cin>>x>>y;
	if(x-'A'>y-'A') cout<< ">" <<endl;
	else if(x-'A'<y-'A') cout<< "<" <<endl;
	else cout<< "=" <<endl;
}

Measured memory_bytes: 256
import bisect
from itertools import product

A, B, Q = map(int, input().split())
S = [-10**12] + [int(input()) for _ in range(A)] + [10**12]
T = [-10**12] + [int(input()) for _ in range(B)] + [10**12]

for _ in range(Q):
    x = int(input())
    idx1 = bisect.bisect_left(S, x)
    s_cand = [S[idx1 - 1], S[idx1]]
    idx2 = bisect.bisect_left(T, x)
    t_cand = [T[idx2 - 1], T[idx2]]
    dist = 10**15
    for s, t in product(s_cand, t_cand):
        temp = min(abs(s - x), abs(t - x)) + abs(s - t)
        if temp < dist:
            dist = temp
    print(dist)

Measured memory_bytes: 12824
n, m = map(int, input().split())

if max(n, m) == 1:
    print(1)
elif min(n, m) == 1:
    print(n * m - 2)
elif min(n, m) == 2:
    print(0)
else:
    print(n * m - 2 * (n + m) + 4)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=200005,Mod=1e9+7;
int fac[N],inv[N];
inline int qpow(int a,int b){
	int ans=1;
	while (b){
		if (b&1) ans=1ll*ans*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return ans;
}
inline void init(){
	fac[0]=1;for (int i=1;i<=200000;i++) fac[i]=1ll*fac[i-1]*i%Mod;
	inv[200000]=qpow(fac[200000],Mod-2);
	for (int i=199999;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%Mod;
}
inline int C(int n,int m){
	return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
inline int calc(int x1,int y1,int x2,int y2){
	return C(x2-x1+y2-y1,x2-x1);
}
int main (){
	int n,m,a,b;scanf ("%d%d%d%d",&n,&m,&a,&b);
	init();
	int ans=0,lst=0;
	for (int i=1;i<=n-a;i++){
		ans=(ans+1ll*(calc(1,1,i,b+1)-lst+Mod)%Mod*calc(i,b+1,n,m)%Mod)%Mod;
		lst=calc(1,1,i,b+1);
	}
	printf ("%d",ans);
	return 0;
}


Measured memory_bytes: 1792
n = int(raw_input())
bricks = raw_input().split()
bricks = [int(i) for i in bricks]
smash = 0
result = []
pos = 1
if 1 not in bricks:
  smash = -1
else:
  for i in bricks:
    if i == pos:
      pos = pos+1
    else:
      smash = smash + 1
print smash


Measured memory_bytes: 21136
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
		int m,nmin,nmax; cin >> m >> nmin >> nmax;
		if (m+nmin+nmax==0) break;
		vector<int> P(m);
		rep(i,m) cin >> P[i];

		int gap = 0;
		int ans = 0;
		for (int i = nmax-1; i >= nmin-1; i--) {
			if (chmax(gap,P[i]-P[i+1])) ans = i; 
		}

		cout << ans+1 << endl;
	}
}


Measured memory_bytes: 3120
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

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

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


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {
    int n;
    vector<int> v;
    int sum = 0;
    cin >> n;
    REP(i,0,n){
        int tmp;
        cin >> tmp;
        sum += tmp;
        v.push_back(tmp);
    }

    int m;
    cin >> m;
    vector<int> p(m);
    vector<int> x(m);

    REP(i,0,m){
        cin >> p[i] >> x[i];
    }

    REP(i,0,m){
        int tmp = sum;
        tmp -= v[p[i] - 1];
        tmp += x[i];
        cout << tmp << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007

int main () {
	int N;
	char S[2][53];
	scanf ("%d", &N);
	scanf ("%s", S[0]);
	scanf ("%s", S[1]);
	long long sum;
	int hor, i;
	if (S[0][0] == S[1][0]) {
		sum = 3;
		hor = 1;
		i=1;
	} else {
		sum = 6;
		hor = 0;
		i=2;
	}
	for (; i<N; i++) {
		if (S[0][i]==S[1][i]) {
			if (hor) {
				sum *= 2;
				sum %= MOD;
			}
			hor = 1;
		} else {
			if (hor) {
				sum *= 2;
				sum %= MOD;
			} else {
				sum *= 3;
				sum %= MOD;
			}
			hor = 0;
			i += 1;
		}
	}
	printf ("%lld\n", sum);
	return 0;
}

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

using namespace std;

typedef long long ll;
const long long mod = 1000000007;



int main(){
  ll h, w, i, j;

  cin>>h>>w;

   char v[h][w];

   for(i = 0 ;i < h;i++){
       for(j = 0;j < w;j++)
        cin>>v[i][j];
   }
   ll dp[h+1][w+1];
   memset(dp, sizeof(dp), 0);
   for(i = 0;i < w;i++){
       if(v[0][i] == '#'){
           for(j = i;j < w;j++){
               dp[0][j] = 0;
           }
           break;
       }
       else{
           dp[0][i] = 1;
       }
   }
    for(i = 0;i < h;i++){
       if(v[i][0] == '#'){
           for(j = i;j < h;j++){
               dp[j][0] = 0;
           }
           break;
       }
       else{
           dp[i][0] = 1;
       }
   }

   for(i = 1;i < h;i++){
       for(j = 1;j < w;j++){
           if(v[i][j] == '#')
            dp[i][j] = 0;
            else{
                dp[i][j] = (dp[i-1][j]%mod+ dp[i][j-1]%mod)%mod;
            }
       }
   }
//    for(i = 0;i < h;i++){
//        for(j = 0;j < w;j++){
//            cout<<dp[i][j]<<" ";
//        }
//        cout<<"\n";
//    }
   cout<<dp[h-1][w-1];





} 


Measured memory_bytes: 9088
#include <stdio.h>
int main(void)
{
    int x[1000],y[1000],z[1000];
    int i;
    int n;

 

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d",&x[i],&y[i],&z[i]);

    x[i] *= x[i];
    y[i] *= y[i];
    z[i] *= z[i];

    
    if(x[i] == y[i] + z[i] || y[i] == x[i] + z[i] || z[i] == x[i] + y[i]){
        printf("YES\n");
    }else{
        printf("NO\n");
    }  
    }
    

 return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001
#define INF         INT_MAX

int32_t main(){

	int n,k;
	cin>>n>>k;
	
	int sum1=0,sum2=0;
	for(int i=0;i<k;i++){
		sum1+=i;
		sum2+=n-i;
	}

	// cout<<sum1<<"  "<<sum2<<endl;
	int ans=(sum2-sum1+1)%mod;
	for(int i=k;i<=n;i++){

		sum1+=i;
		sum2+=n-i;

		// cout<<sum1<<"  "<<sum2<<endl;
		ans+=(sum2-sum1+1)%mod;
		ans=ans%mod;

	}
	cout<<ans%mod<<endl;
	return 0;
}

Measured memory_bytes: 3556
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll N;
  cin>>N;
  ll a[N];
  for(int i=0; i<N; ++i){
      cin>>a[i];
    }
  sort(a,a+N);
  cout<<a[N-1]-a[0]<<endl;
}



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

using namespace std;
int n, k;
int x[100000];
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    int ans = 1000000000;
    for (int i = 0; i <= n - k; ++i) {
        int l = x[i];
        int r = x[i + k - 1];
        if ((long long)l * r >= 0) {
            ans = min(ans, max(abs(l), abs(r)));
        } else {
            ans = min(ans, abs(l) * 2 + abs(r));
            ans = min(ans, abs(l) + abs(r) * 2);
        }
    }
    cout << ans << endl;
}


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

int main(){

	int N, W;
	cin >> N >> W;

	int w[101];
	int* v = new int[1001];

	for (int i = 0; i < N; i++)
		cin >> v[i] >> w[i];
	

	int DP[102][10001];

	for (int j = 0; j <= W; j++)
		DP[0][j] = 0;

	for (int i = 1; i <= N; i++)
		for (int j = 0; j <= W; j++)
			if (j < w[i - 1])
				DP[i][j] = DP[i-1][j];
			else{
				if (DP[i-1][j]>DP[i-1][j - w[i - 1]] + v[i - 1])
					DP[i][j] = DP[i - 1][j];
				else
					DP[i][j] = DP[i-1][j - w[i - 1]] + v[i - 1];
			}


			cout << DP[N][W] << endl;

			delete[] v;

			return 0;
}

Measured memory_bytes: 5148
#include<stdio.h>
#include <time.h>
int main(void){
        float a,b,c,d,e,f,n,i,j,k,x,y;
	while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f)!=EOF){
		
		y=(d*c-a*f)/(d*b-a*e);
		x=(c-b*y)/a;
		printf("%4.3f %4.3f\n",x,y);
	}
	return 0;
}


Measured memory_bytes: 1924
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    def dfs(s):
        if len(s) == n:
            print(s)
            return
        for i in range(len(set(list(s))) + 1):
            dfs(s + chr(ord("a") + i))
    dfs("")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 59224
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define MAX 200009
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;

long long power(long long x, unsigned long long y, unsigned int m){
    if(y == 0) return 1;
    unsigned long long p = power(x, y/2, m) % m;
    p = (p * p) % m;
    
    if(y & 1)
        return  ((x % m)*p) % m;
    else 
        return p;
}


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		
		string s; cin >> s;
		if(s == "ABC") cout << "ARC";
		else cout << "ABC";
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 3588
using System;
using CompLib.Util;

public class Program
{
    private const int MaxA = 1000000;

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] a = sc.IntArray();
        int[] cnt = new int[MaxA + 1];
        foreach (int i in a)
        {
            cnt[i]++;
        }

        int ans = 0;
        for (int i = 1; i <= MaxA; i++)
        {
            if (cnt[i] > 0)
            {
                if (cnt[i] == 1) ans++;
                for (int j = i; j <= MaxA; j += i)
                {
                    cnt[j] = 0;
                }
            }
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 47188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll a, b;

int main(){
	cin >> a >> b;
	ll ans = abs(abs(a) - abs(b));
	if (a*b > 0){
		if (a < 0 && b < 0){
			if (a > b)ans += 2;
		}
		else{
			if (a > b)ans += 2;
		}
	}
	else if (a*b < 0){
		ans++;
	}
	else{
		if (a > b)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = input.nextInt();
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      if(array[i] != i + 1)
        count++;
    }
    if (count <= 2)
      System.out.println("YES");
    else
      System.out.println("NO");
  }
}


Measured memory_bytes: 21844
#include<iostream>
#include<queue>
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
int main(){
  int N;
  cin >> N;
  priority_queue<int> Q;
  rep(i,0,N){
    int temp;
    cin >> temp;
    Q.push(-temp);
    if(Q.size() > N/2+1) Q.pop();
  }
  int a = -Q.top(); Q.pop();
  int b = -Q.top(); Q.pop();

  cout << b-a<<endl;
}


Measured memory_bytes: 640
addNumCard :: Integer -> Integer -> Integer -> Integer -> Integer
addNumCard a b c d | d <= 0 = 0
                   | a > 0 = (min a d) + addNumCard 0 b c (d -a)
                   | b > 0 = 0 + addNumCard a 0 c (d -b)
                   | c > 0 = (-1 * (min c d)) + addNumCard a b (c-1) (d -c)
                   | otherwise = 0

main = do
    [a,b,c,d] <- map read <$> (words <$> getLine) :: IO [Integer]
    putStrLn $ show  $ addNumCard a b c d
    

Measured memory_bytes: 3952
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m, w;

int dp[100001][101];

main(){
	scanf("%d %d %d", &n, &m, &w);
	vector<vector<pii>> g(n);
	vi deg(n);
	REP(i, m){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		g[a].emplace_back(b, c);
		deg[b] ++;
	}
	queue<int> que;
	REP(i, n) if(deg[i] == 0) que.push(i);
	int ans = -1;
	while(!que.empty()){
		int u = que.front();
		que.pop();
		FOR(e, g[u]){
			int v = e->first;
			int c = e->second;
			REP(i, -w-c) dp[v][i+c] |= dp[u][i];
			dp[v][c] = 1;
			if(--deg[v] == 0) que.push(v);
		}
		REP(i, -w) if(dp[u][i]) ans = max(ans, i);
	}
	if(ans < 0) puts("NA");
	else printf("%d\n", ans+w);
	return 0;
}


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

// floor(X*0.08) = A and floor(X*0.1) = B なる整数Xを求めよ。 
// Xの最大値は1000 (1000*0.1= 100より)

int main(){
    int A, B; //1 ~ 100の整数
    cin >> A >> B; 
    int X = 1;
    while (X <= 1000){
        int a = (int) (X*0.08);
        int b = (int) (X*0.1);
        if( a == A && b == B){
            cout << X << endl;
            return 0;
        } 
        X++;
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g;}
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }
ll vsum(vi a)
{
	ll res = 0;
	rep(i, sz(a))res += a[i];
	return res;
}

int main()
{
	int n, a[3]; 
	cin >> n >> a[0] >> a[1] >> a[2];
	vi l(n);
	rep(i, n)cin >> l[i];
	int ans = 1e9;
	rep(mask, pow(4, n))
	{
		int tmp = mask;
		vvi a_tmp(3);
		rep(pos, n)
		{
			int r = tmp % 4;
			rep(i, 3)if (i == r) a_tmp[i].push_back(l[pos]);
			tmp /= 4;
		}
		bool invalid = false;
		rep(i, 3)if (a_tmp[i].empty())invalid=true;
		if (invalid)continue;
		int mp = 0;
		rep(i, 3)
		{
			int s = vsum(a_tmp[i]);
			int m = sz(a_tmp[i]);
			mp += 10 * (m - 1);
			mp += abs(s - a[i]);
		}
		chmin(ans, mp);
	}
	co(ans);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define INFll (1LL << 60)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
        
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int now = 1;
    int ans = 0;
    bool flag = false;
    rep(i, n) {
        if(a[i] == 1) flag = true;
        if(a[i] == now) {
            now++;
        } else {
            ans++;
        }
    }
    if(!flag) {
        cout << -1 << '\n';
        return 0;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	string s;
	cin>>s;
	cout<<s.substr(0,s.length()-8)<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()


if n % 7 == 0:
    n //= 7
    n *= 9
    if n % 2 and n % 5:
        co = 1
        i = 0
        while True:
            i += 1
            co *= 10
            co %= n
            if co == 1:
                break
        print(i)
    else:
        print(-1)
else:
    n *= 9
    if n % 2 and n % 5:
        co = 1
        i = 0
        while True:
            i += 1
            co *= 10
            co %= n
            if co == 1:
                break
        print(i)


    else:
        print(-1)

Measured memory_bytes: 66520
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  const int mod = 1e9 + 7;
  auto mod_pow = [&] (ll a, ll b) {
    ll ret = 1;
    while (b) {
      if (b & 1) ret = (a * ret) % mod;
      a = (a * a) % mod;
      b >>= 1;
    }
    return ret;
  };
  vi f(n + 1);
  vi invf(n + 1);
  f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = (1LL * i * f[i - 1]) % mod;
  invf[n] = mod_pow(f[n], mod - 2);
  for (int i = n - 1; i >= 0; i--) invf[i] = (1LL * invf[i + 1] * (i + 1)) % mod;
  auto comb = [&] (int a, int b) {
    ll ret = (1LL * f[a] * invf[b]) % mod;
    ret = (ret * invf[a - b]) % mod;
    return ret;
  };
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    int add = (1LL * comb(n, i) * mod_pow(8, n - i)) % mod;
    ans += add;
    if (ans >= mod) ans -= mod;
  }
  ans = (2 * ans) % mod;
  ans = (ans + mod_pow(8, n)) % mod;
  ans = -ans + mod;
  ans = (ans + mod_pow(10, n)) % mod;
  cout << ans << '\n';
  return (0);
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using P = std::tuple<int,int>;
using ll = long long;

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

// I want to delete this stupid solution ;(
#define sandwich(x) [](auto a, auto b){return (x)(a, b);}

template <typename T>
using F2 = std::function<T(T,T)>;

template <typename T, int N, typename F = std::plus<T>>
    struct SegmentTree{
        SegmentTree(T u, F f = F()){
            size = 1;
            while(size < N){
                size <<= 1;
            }

            unit = u;
            func = f;
            
            init();
        }
        void init(){
            for(int i=0;i<size;++i){
                data[i+size] = unit;
            }
            
            for(int i=size-1;i>0;--i){
                data[i] = func(data[i*2], data[i*2+1]);
            }
        }
        void update(int k, int v){
            k += size;
            data[k] = v;
            
            while(k > 1){
                k >>= 1;
                data[k] = func(data[k*2], data[k*2+1]);
            }
        }
        inline T query(int l, int r){
            return _query(l, r, 1, 0, size);
        }
        T _query(int a, int b, int k, int l, int r){
            if(b <= l || r <= a){return unit;}
            if(a <= l && r <= b){return data[k];}
            int mid = (l + r) >> 1;
            return func(_query(a, b,   2*k,   l, mid),
                        _query(a, b, 2*k+1, mid, r  ));
        }
        
        T unit, data[N*4];
        int size;
        F func;
    };

SegmentTree<ll, 100000> segtree(0);

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

    int N, K;
    while(true){
        std::cin >> N >> K;

        if(N == 0 && K == 0){break;}

        segtree.init();
        
        for(int i=0;i<N;++i){
            int a;
            std::cin >> a;

            segtree.update(i, a);
        }

        ll res = -1001001001001001001ll;
        for(int i=0;i+K<=N;i++){
            res = max(res, segtree.query(i, i+K));
        }

        std::cout << res << std::endl;
    }
}

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

int main() {
int S, a, b, c, d;
cin >> S;

a = S / 1000;
b = ( S - a*1000 ) /100;
c = ( S - a*1000 - b*100 ) /10;
d = S - a*1000 -b*100 -c*10;

if ( a == b || b ==c || c==d ){
cout << "Bad" << endl;
}
else{
cout << "Good" << endl;
}
}

Measured memory_bytes: 256