akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n int

	fmt.Sscan(getNextLine(scanner), &n)
	aaa := getIntList(scanner)
	sums := make([]int, n+1)
	size := 1
	for size < 4*n {
		size <<= 1
	}

	left := 1
	right := 1000000000
	sums[0] = size>>1 + n - 1
	for left < right {
		sum := 0
		wholesum := 0
		m := (left + right) >> 1
		seg := make([]int, size)
		for i := 0; i < n; i++ {
			wholesum += n - i
			if aaa[i] >= m {
				sums[i+1] = sums[i] + 1
			} else {
				sums[i+1] = sums[i] - 1
			}
			seg[sums[i]]++
			for j := sums[i]; j > 0; {
				j = (j - 1) >> 1
				seg[j]++
			}
			sum += count(0, sums[i+1]-size/2+2, 0, 0, size/2, seg)
		}

		if sum*2 >= wholesum {
			left = m + 1
			continue
		}
		right = m
	}
	sort.Sort(sort.IntSlice(aaa))
	ans := aaa[0]
	for i := len(aaa) - 1; i >= 0; i-- {
		if left > aaa[i] {
			ans = aaa[i]
			break
		}
	}
	fmt.Println(ans)
}

func count(a int, b int, i int, li int, ri int, seg []int) int {
	if ri <= a || li >= b {
		return 0
	}
	if a <= li && ri <= b {
		return seg[i]
	}
	return count(a, b, i*2+1, li, (li+ri)/2, seg) + count(a, b, i*2+2, (li+ri)/2, ri, seg)
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	int cnt = 0;
	if (s[0] == '1') {
		cnt++;
	}
	if (s[1] == '1') {
		cnt++;
	}
	if (s[2] == '1') {
		cnt++;
	}
	cout << cnt << '\n';
	
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,h;
	while(cin>>n>>h)
	{
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			int b;
			cin>>b;
			if(b>=h)
			{
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int main(){
	int a = 0, b = 0, c = 0,d=0,e=0,f=0,g=0, counto = 0;
	cin >> a >> b >> c;
	d = max(a, max(b, c));
	if (a  != d) {
		counto+=d-a;
	}
	if (b  != d) {
		counto+=d-b;
	}
	if (c != d) {
		counto+=d-c;
	}
	
	if (counto%2==0) {
		cout << (d * 3 - a - b - c) / 2 << endl;
	}
	else { cout << (d * 3 + 3 - a - b - c) / 2 << endl;}

	/*while (a < d - 1) {
		a += 2;
		counto++;
	}
	if (a == d) {
		e++;
	}
	while (b < d - 1) {
		b += 2;
		counto++;
	}
	if (b == d) {
		e++;
	}
	while (c < d - 1) {
		c += 2;
		counto++;
	}
	if (c == d) {
		e++;
	}
	cout << counto << endl;
	if (e < 2) {
		cout << counto + 1 << endl;
	}
	else { cout << counto << endl; }*/
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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







int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    
    vector<ll> p(n + 1);
    REP(i, n){
        p[i + 1] = p[i] + a[i];
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INF));
    REP(i, n){
        dp[i][i] = 0;
    }
    for(ll len = 1; len <= n - 1; len++){
        for(ll l = 0; l < n; l++){
            ll r = l + len;
            if(r >= n) break;
            for(ll k = l; k < r; k++){
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r]);
            }
            dp[l][r] += p[r + 1] - p[l];
        }
    }
    cout << dp[0][n - 1] << endl;
}

Measured memory_bytes: 1536
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
}

macro_rules! get_v {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse::<$t>().unwrap())
            .collect::<Vec<_>>()
    }};
}

fn main() {
    let (mut n, k) = get!(i32, i32);
    let v = get_v!(i32);
    let mut ans = 1;
    n -= k;
    if n <= 0 {
        println!("{}", ans);
        return;
    } else {
        while 0 < n {
            n -= k - 1;
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#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())

#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
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

int main() {
    // 時分より下の合計の2倍より次が小さいか
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) {
        cin >> a[i];
    }
    sort(all(a));
    LL sum = 0;
    int pos = 0;
    REP(i,0,n-1) {
        sum += a[i];
        if (sum * 2 < a[i+1]) pos = i + 1;
    }
    cout << n - pos << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

int div(int n)
{
   int div=0;
   for(int i=1;i<=sqrt(n+1);i++)
   {
      if(n%i==0)
      {
         if(i*i==n)
            div++;
         else
            div+=2;
      }
   }
   return div;
}

void f()
{
  int n;
  cin>>n;
  if(n<105)
    cout<<0<<nl;
  else
  {
    int cnt=0;
    for(int i=105;i<=n;i+=2)
    {
      if(div(i)==8)
        cnt++;
    }
    cout<<cnt<<nl;
  }
}

int main()
{
    su;
    f();
    return 0;
}


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

using int64 = long long;
using uint64 = unsigned long long;

#define repeat(i, x) for (int64 i = 0; (i) < (x); (i)++)
#define rev_repeat(i, x) for (int64 i = (x) - 1; (i) >= 0; (i)--)
#define countup(i, n) for (int64 i = 0; (i) <= (n); (i)++)
#define countdown(i, n) for (int64 i = (n); (i) >= 0; (i)--)
#define range(i, a, b) for (int64 i = (a); (i) < (b); (i)++)
#define traverse(it, ctn) for (auto it = begin(ctn); (it) != end(ctn); (it)++)
#define rev_traverse(it, ctn) for (auto it = rbegin(ctn); (it) != rend(ctn); (it)++)

template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec)
{
    os << "[";
    repeat (i, vec.size())
    {
        os << (i == 0 ? "" : ", ") << vec[i];
    }
    os << "]";
    return os;
}

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

template<typename T>
ostream& operator<<(ostream& os, set<T>& s)
{
    os << "{";
    traverse (it, s)
    {
        if (it != s.begin()) os << ", ";
        os << *it;
    }
    os << "}";
    return os;
}

template<typename K, typename V>
ostream& operator<<(ostream& os, map<K, V>& m) 
{
    os << "{";
    traverse (it, m)
    {
        if (it != m.begin()) os << ", ";
        os << it->first << ": " << it->second;
    }
    os << "}";
    return os;
}

//
// _______  _____  _______  _____  _______ _______ _____ _______ _____ _    _ _______ 
// |       |     | |  |  | |_____] |______    |      |      |      |    \  /  |______ 
// |_____  |_____| |  |  | |       |______    |    __|__    |    __|__   \/   |______ 
//
//  _____   ______  _____   ______  ______ _______ _______ _______ _____ __   _  ______   /
// |_____] |_____/ |     | |  ____ |_____/ |_____| |  |  | |  |  |   |   | \  | |  ____  / 
// |       |    \_ |_____| |_____| |    \_ |     | |  |  | |  |  | __|__ |  \_| |_____| .  
//

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

    int n;
    cin >> n;

    vector<int64> b(n);
    repeat (i, n)
    {
        cin >> b[i];
        b[i] = b[i] - (i + 1);
    }

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

    int64 c1 = b[n / 2], c2 = b[n - n / 2 - 1],
          c1sum = 0, c2sum = 0;

    repeat (i, n)
    {
        c1sum += abs(b[i] - c1);
        c2sum += abs(b[i] - c2);
    }

    cout << min(c1sum, c2sum) << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    double now = min(n, b-1);
    cout << floor(a * (now/b)-floor(now/b));
}


Measured memory_bytes: 3784
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe


bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

solve :: Int -> [Int] -> [Int]
solve valK as =
  case foldr op (Just (2, 2)) as of
    Just (x, y) -> [x, y]
    Nothing     -> [-1]
  where
    op _ Nothing = Nothing
    op a (Just (minX, maxX)) | a1 <= a2 = Just (a1, a2 + a - 1)
                             | otherwise = Nothing
      where a1 = a * ((minX + a - 1) `div` a)
            a2 = a * (maxX `div` a)
      

main :: IO ()
main = do
  conts <- B.getContents
  let valK : as = bsReadInts conts
      answer = solve valK as
  putStrLn $ unwords $ map show answer


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

using namespace std;
typedef long long ll;

const int N = 1e5 + 7;
int t, res, n, m;

main()
{
#define file "r"
//    freopen(file".inp", "r", stdin);
//  freopen(file".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    int T; cin >> T;
    while(T --)
    {
        set<int> a, b;
        for(int i = 1; i <= 6; i ++) {cin >> t; a.insert(t); }
        for(int i = 1; i <= 13; i ++) if(!a.count(i) && i != 7) b.insert(i);
        int l = 6, r = 8, ans = 1;
//        cout << a.size() << "  " << b.size() << "\n";
        while(1)
        {
            if(a.count(l) && a.count(r))
                if(a.count(1)) a.erase(l), l --;
                else a.erase(r), r ++;
            else
                if(a.count(l)) a.erase(l), l --;
            else
                if(a.count(r)) a.erase(r), r ++;
            if(a.empty()) break;
            swap(a, b); ans ++;
        }
        cout << (ans&1 ? "yes\n" : "no\n");
//        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int i;
    rep(i, s.length()) cout << "x";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
	
	int n,m;

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

	std::vector<vector<pair<int,int>>> g(n+1);
	std::vector<vector<int>> dist(n+1,vector<int>(n+1,1e9));
	for(int i=1;i<=n;i++)dist[i][i]=0;
	while(m--){
		int x,y,c;
		scanf("%d %d %d",&x,&y,&c);
		g[x].pb({y,c});
		g[y].pb({x,c});
		dist[x][y]=min(dist[x][y],c);
		dist[y][x]=min(dist[y][x],c);
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				dist[i][j]=min(dist[i][j],
				dist[i][k]+dist[k][j]);
			}		
		}	
	}
	int ans = 0;
	std::vector<vector<bool>> vis(n+1,vector<bool>(n+1));
	for(int i=1;i<=n;i++){
		for(auto p : g[i]){
			int u = p.first;
			if(vis[i][u] || vis[u][i])continue;
			int c = p.second;
			vis[i][u]=1;
			vis[u][i]=1;
			if(dist[i][u]!=c && dist[u][i]!=c)ans++;
		}
	}

	printf("%d\n",ans );
	
}		


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 m,d;
    cin >> m >> d;
    int32 ans = 0;
    for(int32 month = 4; month <= m; ++month){
        for(int32 day = 22; day <= d; ++day){
            if(day % 10 < 2)continue;
            if(month == (day / 10) * (day % 10))ans++;
        }
    }
    ANS(ans);
    return 0;
}

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

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define mp make_pair
#define pb push_back
//////////

int const N = 1e5 + 41;

vector<int> a;
int n;
vector<pair<int, int> > b;

void fir(){
	printf("First\n");
	exit(0);
}

void sec(){
	printf("Second\n");
	exit(0);
}

void buildB(){
	a.pb(1e9 + 41);
	sort(a.begin(), a.end());
	int cnt = 0;
	fi(0, sz(a)-1){
		++cnt;
		if(a[i] != a[i+1]){
			b.pb(mp(a[i], cnt));
			cnt = 0;
		}
	}
	reverse(b.begin(), b.end());
}

void solveSpecial(){
	if(sz(b) == 1){
		int p1 = b[0].first % 2;
		int p2 = b[0].second % 2;
		if(p1 ^ p2){
			fir();
		}else{
			sec();
		}
	}
}

void check(int pos, int val){
	if(val == pos){
		fir();
	}
}

void solve(){
	buildB();
	solveSpecial();
	
	int rightZero = n + 1;
	int curCnt = b[0].second;
	int rightValue = (b[0].first - b[1].first) % 2;
	b.pb(mp(0, 0));
	fi(1, sz(b)-1){
		if(rightValue == 0){
			if(b[i].second % 2 == 1){
				check(curCnt, b[i].first);
				check(curCnt-1, b[i].first);
				int p = curCnt;
				if(p - (b[i].first - 1) >= 0){
					rightZero = min(rightZero, p - (b[i].first - 1));
				}
				p = curCnt - 1;
				if(p - (b[i].first - 1) >= 0){
					rightZero = min(rightZero, p - (b[i].first - 1));
				}
			}
		}else{
			if(b[i].second % 2 == 0){
				check(curCnt, b[i].first);
				check(curCnt+1, b[i].first);
				int p = curCnt;
				if(p - (b[i].first - 1) >= 0){
					rightZero = min(rightZero, p - (b[i].first - 1));
				}
				p = curCnt + 1;
				if(p - (b[i].first - 1) >= 0){
					rightZero = min(rightZero, p - (b[i].first - 1));
				}
			}
		}

		curCnt += b[i].second;
		rightValue = (b[i].first - b[i+1].first) % 2;
	}

	if(rightValue == 0){
		rightZero = min(rightZero, n);
	}else{
		rightZero = min(rightZero, n - 1);
	}
	if(rightZero % 2 == 1){
		fir();
	}else{
		sec();
	}

}

void read(){
	scanf("%d",&n);
	fi(0, n){
		int v;
		scanf("%d",&v);
		a.pb(v);
	}
}

void prepare(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}

int main(){
	prepare();
	read();
	solve();


	return 0;
}

Measured memory_bytes: 1784
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;
int main(void){
	string s;
	cin >> s;
	int i,check[3]={0};	

	for(i = 0; i < 3; i++)
		check[s[i]-'a'] = 1;
	i = 0;
	while(i < 3 && check[i] == 1)
		i++;
	if(i == 3)
		printf("Yes\n");
	else
		printf("No\n");
}


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


void solve(long long N, std::vector<long long> A){
  long long max_num = 1'000'000'000'000'000'000;
  sort(A.begin(), A.end());

  if (A.size() < 1 || A[0] == 0) {
    cout << 0 << endl;
    return;
  }

  unsigned long long ret = 1;
  for (int i=0; i<N; i++) {
    long long div = max_num / ret;
    if (div + 1 < A[i]) {
      cout << -1 << endl;
      return;
    }
    ret *= A[i];
    if (ret > max_num) {
      cout << -1 << endl;
      return;
    };
  }
  cout << ret << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4032
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る 
        ////console.log("***input = " + input);
        ////console.log("type = " + typeof(input));
        ////console.log("size=" + input.length);
	input = input.split("\n");
        ////console.log("***input.split = " + input);
        ////console.log("type = " + typeof(input));
        ////console.log("size=" + input.length);
	//文字列から10進数に変換するときはparseIntを使います

	var S = input[0];
	var T = input[1];
	//console.log("S=%s", S);
	//console.log("T=%s", T);
	
	//S'のある連続した|T|文字のX'を求める
	if(S.length < T.length){
		console.log("UNRESTORABLE");
		return;
	}
	for(var i=S.length-T.length;i>=0;i--) {
		var flag_UNRESTORABLE = 0;
		var answer = S;
		var X = S.substr(i,T.length);
		//console.log("X=" + X);
		for(var j=0;j<X.length;j++){
		        //console.log("X(%d)=%s",j,X.substr(j,1));
			if(X.substr(j,1) === T.substr(j,1)){
				//console.log(">correct");
				//console.log("answer=%s", answer);
			}else if (X.substr(j,1)==="?"){
				//console.log(">?");
				i//console.log("answer=%s,%s,%s,%s", answer.substr(0,i+j), T.substr(j,1), X.substr(j+1), answer.substr(i+X.length));
				answer = answer.substr(0,i+j) + T.substr(j,1) + X.substr(j+1) + answer.substr(i+X.length);
			}else{
				//console.log(">incorrect");
				flag_UNRESTORABLE = 1;
			}
			//console.log("ANSWER=%s", answer)
		}
		if(flag_UNRESTORABLE === 0){
			//console.log("OK!!");
			answer = answer.replace(/\?/g, "a");
			console.log("%s", answer)
			return;
		}
	}
	console.log("UNRESTORABLE");


	//X'とTを一文字ずつ比較する
	//X'とTを一致させることができれば、OK
	//X'とTを一致させることができなければ、NG

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8264
#include <iostream>

using namespace std;

int main()
{
    int k, s;
    cin >> k >> s;

    int count = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            if (0 <= s-x-y && s-x-y <= k) count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    a = [i for i in range(N+1)]
    s = [0] * (N+2)
    for i in range(N+1):
        s[i+1] = s[i] + a[i]
    ans = 0
    MOD = 10**9+7
    for i in range(K, N+2):
        ans += (s[-1]-s[-i-1]-s[i]+1) % MOD
    print(ans % MOD)
if __name__ == "__main__":
    main()

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

int main(){
    
    int n,k;cin>>k>>n;
    int arr[2*k-1]={};
    int temp=n;
    for(int i=0;i<2*k-1;i++){
        arr[i]=temp - (k-1);
        temp++;
    }
    for(int i=0;i<2*k-1;i++)cout<<arr[i]<<" ";
    
    
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	private Stack<Integer> stack = new Stack<Integer>();

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			int num = scan.nextInt();
			if (num != 0) {
				stack.push(num);
			}else {
				System.out.println(stack.pop());
			}
		}
	}
	
	private void debug() {
		System.out.println();
	}

}

Measured memory_bytes: 17212
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;
typedef pair<int,int> P;
int n,m;
int dp[201];
int ans=0;
vector<P> v;
int main(void){
	while(1){
		ans=0;
		v.clear();
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			int a,b;
			cin >> a >> b;
			v.push_back(P(a,b));
		}
		cin >> m;
		for(int i=0;i<m;i++){
			int a,b;
			cin >> a >> b;
			v.push_back(P(a,b));
		}
		sort(v.begin(),v.end());
		for(int i=0;i<v.size();i++)dp[i]=1;
		for(int i=0;i<v.size();i++){
			for(int j=0;j<v.size();j++){
				if(v[j].first<v[i].first && v[j].second<v[i].second){
					dp[i]=max(dp[i],dp[j]+1);
				}
			}
			ans=max(ans,dp[i]);
		}
		cout << ans << endl;
	}
    return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, d;
  std::cin >> n >> d;
  const auto c = 2 * d + 1;

  std::cout << (n - 1) / c + 1 << std::endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string n; cin >> n;
    if(n=="111") cout << 999 << ln;
    else if(n=="119") cout << 991 << ln;
    else if(n=="191") cout << 919 << ln;
    else if(n=="199") cout << 911 << ln;
    else if(n=="911") cout << 199 << ln;
    else if(n=="919") cout << 191 << ln;
    else if(n=="991") cout << 119 << ln;
    else cout << 111 << ln;    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int dfs(int now, vector<vector<int>> &f, vector<bool> &visited)
{
  int count = 1;
  for (const auto next : f[now])
  {
    if (!visited[next])
    {
      visited[next] = true;
      count += dfs(next, f, visited);
    }
  }

  return count;
}

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

  vector<vector<int>> f(N);

  rep(i, M)
  {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    f[A].push_back(B);
    f[B].push_back(A);
  }

  int mx = 0;
  vector<bool> visited(N, false);
  rep(i, N)
  {
    if (visited[i])
      continue;

    visited[i] = true;
    int tmp = dfs(i, f, visited);
    mx = std::max(tmp, mx);
  }

  cout << mx << endl;

  return 0;
}


Measured memory_bytes: 26760
N = int(input())
A = list(map(int,input().split()))

S = sum(A)
i = 0
S1 = 0
while(S1 < S/2):
  S1 += A[i]
  i += 1
if i == N:
  ans = abs(sum(A[:i-1])-sum(A[i-1:]))
else:
  ans = min(abs(sum(A[:i-1])-sum(A[i-1:])),abs(sum(A[:i])-sum(A[i:])))
print(ans)

Measured memory_bytes: 89804
N =  int(input())
a = list(map(int,input().split( )))

#if N % 2 == 0:
a_1 = a[0::2]
a_2 = a[1::2]
if N % 2 == 0:
	ans_list = a_2[::-1] + a_1
else:
	ans_list = a_1[::-1] + a_2

ans = ''
for i in range(N):
	if i == N-1:
		ans += str(ans_list[i])
	else:
		ans += str(ans_list[i]) + ' '
print(ans)

Measured memory_bytes: 26180
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var (
	N int
	A int
	B int
)

func main() {
	sc.Split(bufio.ScanWords)
	N, A, B = nextInt(), nextInt(), nextInt()

	fmt.Println(min(N*A, B))
}

func min(a, b int) int {
	if a < b {
		return a
	}

	return b
}


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

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;

int n;
long long ar[N];
long long prf[N];

int main(){
    scanf("%d " , &n);
    for(int i = 1; i <= n; i++){
        scanf("%lld" , &ar[i]);
        prf[i] = prf[i - 1] + ar[i];
    }
    long long ans = 0;
    for(int j = 1; j <= n; j++){
        long long cur = (prf[n] - prf[j]) % mod;
        ans += (ar[j] * cur) % mod;
        ans %= mod;
    }
    printf("%lld\n" , ans);
}


Measured memory_bytes: 6912
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}


int main()
{

    int n;
    long long A[200001];

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

    qsort(A, n, sizeof(long long), compare_int);

    long long sum=0;
    sum = A[0];
    //printf("\n+%lld", A[0]);
    int j = 1;
    for (int i = 1; i < n - 1; i++)
    {  
        sum +=A[j];
        //printf("\n+%lld", A[j]);

        if(i<n-2){
            sum += A[j];
            //printf("\n+%lld", A[j]);
            i++;
        }
        j++;
    }

    for (int i = 0; i < n; i++)
    {
        //printf("\n%lld",A[i]);
    }

    printf("%lld", sum);
    printf("\n");
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    UnionFind(int N) : par(N),siz(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
             par[i] = i;
             siz[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        // merge technique（小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

signed main()
{
    gearup;
    ll n,m; cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        uf.unite(--a,--b);
    }
    ll res = n - 1;
    rep(i,n)if(uf.root(i) != i)res--;
    out(res);
}


Measured memory_bytes: 4760
import sys
from heapq import heappush, heappop

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    AB = [[] for _ in range(m)]
    for _ in range(n):
        a, b = map(int, input().split())
        if a <= m:
            AB[m - a].append(b)

    que = []
    res = 0
    for i in reversed(range(m)):
        for b in AB[i]:
            heappush(que, -b)
        if que:
            res += heappop(que) * -1
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 24376
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    string N;
    cin >> N;
    Yes(N[0] == '7' || N[1] == '7' || N[2] == '7');
}


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

int main(int argc, const char * argv[]) {
    string S, T;
    cin >> S;
    cin >> T;
    
    int count = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == T[i]) {
            count++;
        }
    }
    
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: Ivan
 *
 * Created on July 9, 2018, 5:20 PM
 */

#include <stdio.h>
#include <stdlib.h>
#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right; }Node;

Node Tree[MAX];
int size, Depth[MAX], Height[MAX];

int getDepth(int u);
int getSibling(int u);
void print(int u);

int main(int argc, char** argv) {
  int i, index, left, right;
  scanf("%d", &size);

  for ( i = 0; i < size; i++ ) {
    Tree[i].parent = NIL;
  }

  for ( i = 0; i < size; i++ ){
    scanf("%d %d %d", &index, &left, &right);
    Tree[index].left = left;
    Tree[index].right = right;
    if ( left != NIL ) Tree[left].parent = index;
    if ( right != NIL ) Tree[right].parent = index;
  }

  for ( i = 0; i < size; i++ ){
    Depth[i] = getDepth(i);
    Height[i] = 0;
  }

  for ( i = 0; i < size; i++ ){
        if ( Tree[i].left == NIL && Tree[i].right == NIL )
        {
            Height[i] = 0;
            int p = Tree[i].parent;
            int c = 1;
            while(1)
            {
                if ( p == NIL ) break;
                if ( Height[p] < c ) Height[p] = c;
                c++;
                p = Tree[p].parent;
            }
        }
  }

  for ( i = 0; i < size; i++ ) print(i);
  return (EXIT_SUCCESS);
}

int getDepth(int u)
{
    int depth = 0;
    while(1){
        u = Tree[u].parent;
        if ( u == NIL ) break;
        depth++;
    }
    return depth;
}

int getSibling(int u)
{
    if ( Tree[u].parent == NIL ) return NIL;
    if ( Tree[Tree[u].parent].left != u && Tree[Tree[u].parent].left != NIL ) return Tree[Tree[u].parent].left;
    if ( Tree[Tree[u].parent].right != u && Tree[Tree[u].parent].right != NIL ) return Tree[Tree[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ", u);

    printf("parent = %d, ", Tree[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int degree = 0;
    if ( Tree[u].left != NIL ) degree++;
    if ( Tree[u].right != NIL ) degree++;
    printf("degree = %d, ", degree);
    printf("depth = %d, ", Depth[u]);
    printf("height = %d, ", Height[u]);

    if ( Tree[u].parent == NIL ) printf("root\n");
    else if ( Tree[u].left == NIL && Tree[u].right == NIL ) printf("leaf\n");
    else printf("internal node\n");
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    if(x < 1200)
        cout << "ABC" << endl;
    else
        cout << "ARC" << endl;

    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    int sum=0;
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        sum += a;
    }
    cout << max(-1,n-sum) << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;cin>>a>>b>>c;
  set<int>se;
  se.insert({a,b,c});
  int s=(a+b+c)/2;
  if(s%2==0&&se.count(s)){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 100002;

int n, k;
long long ans;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> k;
	vector<vector<int> > data(n);

	for (int i = 0; i < n; ++i) {
		int t, d;
		cin >> t >> d;
		data[t-1].push_back(d);
	}

	vector<int> maxv(n, -1);
	vector<int> others;

	for (int i = 0; i < n; ++i) {
		if (data[i].size() == 0)
			continue;

		sort(data[i].begin(), data[i].end(), greater<int>());

	 	maxv[i] = data[i][0];
	 	for (int j = 1; j < data[i].size(); ++j)
	 		others.push_back(data[i][j]);
	}
	
	sort(maxv.begin(), maxv.end(), greater<int>());
	sort(others.begin(), others.end(), greater<int>());

	long long cur = 0;
	for (int i = 0; i < k && i < others.size(); ++i)
		cur += others[i];

	for (int i = 1; i <= k; ++i) {
		if (maxv[i-1] == -1)
			break;

		cur += maxv[i-1];
		if (k-i < others.size())
			cur -= others[k-i];

		ans = max(ans, cur + (long long)i * i);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
using namespace std;
int main() {
    int num=0;
    cin >> num ;
    for(int i=9;i>0;i--){
        if(num%i==0){
            num=num/i;
            break;
        }
    }
    for(int i=9;i>0;i--){
        if(num%i==0){
            num=num/i;
            break;
        }
    }
    if(num==1){
        cout << "Yes";
    }
    else{
        cout << "No" ;
    }
    
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>L(N);
	for (int i = 0;i < N;++i) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	int sum = 0;
	for (int i = 0;i < N - 1;++i) {
		sum += L[i];
	}
	if (L[N - 1] < sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class DBrickBreak {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n;in>>n;
        ll a = 1;
        rep(i,n){
            ll tmp;in>>tmp;
            if(tmp==a){
                ++a;
            }
        }
        if(a==1){
            out<<-1<<endl;
        } else {
            out<<n-a+1<<endl;
        }

	}
};


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


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a, b;
  cin >> a >> b;
  if (a * b % 2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
c = a.copy()
b = list(map(int, input().split()))
for i in range(n):
    for j in range(2):
        if a[i+j] <= b[i]:
            b[i] -= a[i+j]
            a[i+j] = 0
        else:
            a[i+j] -= b[i]
            b[i] = 0
print(sum(c-a))

Measured memory_bytes: 24932
#include<cstdio>
#include<iostream>
#include<cstring>

using namespace std;
int key;

int dist(char s1,char s2){
 
  if(s1==s2){
    return 0;
  }else if(s1<s2){
    return s2-s1;
  }else{
    return 'z'-s1+s2-'a'+1;
  }
}

bool checkThe(char s[]){
  if(strlen(s)!=3){
    return false;
  }else{
    if(dist('t',s[0])==dist('h',s[1]) && dist('h',s[1])==dist('e',s[2])){
      key=dist('t',s[0]);
      return true;
    }
  }
  return false;
}
bool checkThis(char s[]){
  if(strlen(s)!=4){
    return false;
  }else{
    if(dist('t',s[0])==dist('h',s[1]) && dist('h',s[1])==dist('i',s[2]) && dist('i',s[2])==dist('s',s[3])){
      key=dist('t',s[0]);
      return true;
    }
  }
  return false;
}
bool checkThat(char s[]){
  if(strlen(s)!=4){
    return false;
  }else{
    if(dist('t',s[0])==dist('h',s[1]) && dist('h',s[1])==dist('a',s[2]) && dist('a',s[2])==dist('t',s[3])){
      key=dist('t',s[0]);
      return true;
    }
  }
  return false;

}
int main(){
 
  char str[100];
  char temp[100];
 
  char *tok;
  bool f;
  while(fgets(str,sizeof(str),stdin)!=NULL){
    key=0;
    f=false;
    for(int i=0;i<strlen(str);i++)
      temp[i]=str[i];
    temp[strlen(str)]='\0';

    str[strlen(str)]='\0';
    str[strlen(str)-1]='\0';
    tok=strtok(str," ");
 
    if(strlen(tok)==3){
      if(checkThe(tok)==true){
	f=true;
      }
    }else if(strlen(tok)==4){
      if(checkThat(tok)==true){
	f=true;
      }else if(checkThis(tok)==true){
	f=true;
      }
    }
    while(f==false && tok!=NULL){
      tok=strtok(NULL," ");
      if(tok!=NULL){
	if(strlen(tok)==3){
	  if(checkThe(tok)==true){
	    f=true;
	  }
	}else if(strlen(tok)==4){
	  if(checkThat(tok)==true){
	    f=true;
	  }else if(checkThis(tok)==true){
	    f=true;
	  }
	}
      }
    }
 
   
    for(int i=0;i<strlen(temp);i++){
      if('a'<=temp[i] && temp[i]<='z'){
	if(temp[i]-key>'z'){
	  printf("%c",(temp[i]-key));
	}else if(temp[i]-key<'a'){
	  printf("%c",(temp[i]-key)+26);
	}else{
	  printf("%c",(temp[i]-key));
	}
      }else{
	printf("%c",temp[i]);
      }
    }

  }

  return 0;
}

Measured memory_bytes: 1084
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e6+5;
const int M = (int)8e3+5;
const int Q = 102;
const int logN = 19;

int c[12],a[12][12];
void solve() {
    int ans = INT_MAX;
    int n,m,x;
    cin>>n>>m>>x;
    REP(i,0,n-1) {
        cin>>c[i];
        REP(j,0,m-1) {
            cin>>a[i][j];
        }
    }
    REP(i,0,(1<<n)) {
        vector<int> b(m);
        int cost = 0;
        REP(k,0,n-1) {
            if((1<<k)&i) {
                cost += c[k];
                REP(j,0,m-1) {
                    b[j] += a[k][j];
                }
                bool ch = true;
                REP(j,0,m-1) {
                    if(b[j]<x) {
                        ch = false;
                        break;
                    }
                }
                if(ch) ans = min(ans,cost);
            }
        }
    }
    if(ans==INT_MAX) ans = -1;
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 3660
#include <stdio.h>

int main(){
	int x,y;

	while(1){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0)
			break;
		if(x>=y)
			printf("%d %d\n",y,x);
		else if(x<y)
			printf("%d %d\n",x,y);
	}
	return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

const ll MAXN = 51;
ll a[MAXN];
ll p[MAXN];

ll dfs(ll n, ll x) {
	if (n == 0){
		return 1;
	}

	ll len = a[n-1];
	if (x == 1){
		return 0;
	} else if (x <= len + 1) {
		return dfs(n-1, x-1);
	} else if (x == len + 2) {
		return p[n-1] + 1;
	} else if (x <= 2*(len+1)) {
		return dfs(n-1, x-(len+2)) + p[n-1] + 1;
	} else {
		return 2*p[n-1] + 1;
	}
}

int main() {
	ll N, X;
	cin >> N >> X;

	//レベルLバーガーの厚さとパティの枚数を求める
	a[0] = 1;
	p[0] = 1;
	for (int ii = 1; ii <= N; ++ii){
		a[ii] = 2 * a[ii-1] + 3;
		p[ii] = 2 * p[ii-1] + 1;
	}

	ll ans = dfs(N, X);

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
from math import ceil, floor
N, K = map(int, input().split())
r = floor((2 * N) / K)
ans = floor(N / K)**3 if K % 2 == 1 \
    else ceil(r / 2) * (floor((2 * N - K) / (2 * K)) + 1)**2 + floor(r / 2) * floor(N / K)**2
print(ans)

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

int main(){
  
  double n;
  cin>>n;
  
  int nuki = n/1.08;
  int komi = nuki*1.08;
  int komi_1 = (nuki+1)*1.08;
  
  if(n==komi)
    cout<<nuki<<endl;
  else if(n==komi_1)
    cout<<nuki+1<<endl;
  else
    cout<<":("<<endl;
  
  return 0;
}

Measured memory_bytes: 256