akhauriyash/Code-Regression huggingface dataset:
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element : vec) {
        is >> element;
    }
    return is;
}
template <class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int K, N;
    cin >> K >> N;
    vi a(N);
    cin >> a;

    int diff = 0;
    a.push_back(a[0] + K);
    REP(i, N) {
        chmax(diff, a[i + 1] - a[i]);
    }
    cout << K - diff;
}

#pragma region main
signed main() {
    std::ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    cin.tie(nullptr);
    //out << std::fixed;
    // out.precision(20);
    Main();
    //cout << flush;
}
#pragma endregion


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

#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)

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

  size_t h, w;
  cin >> h >> w;


  vector <vector <char>> s (h, vector <char> (w));
  for (auto && si : s)
  {
    for (auto && c : si)
    {
      cin >> c;
    }
  }

  vector <vector <int>> column_light (h, vector <int> (w, 0));
  vector <vector <int>> row_light (h, vector <int> (w, 0));

  rep (y, h)
  {
    auto light = 0;
    size_t start_x = w;
    rep (x, w)
    {
      if (s [y] [x] == '.')
      {
        ++ light;
        if (start_x == w)
        {
          start_x = x;
        }
      }
      else if (s [y] [x] == '#')
      {
        FOR (i, start_x, x)
        {
          row_light [y] [i] = light;
        }
        light = 0;
        start_x = w;
      }
    }
    if (light != 0)
    {
      FOR (i, start_x, w)
      {
        row_light [y] [i] = light;
      }
    }
  }

  rep (x, w)
  {
    auto light = 0;
    size_t start_y = h;
    rep (y, h)
    {
      if (s [y] [x] == '.')
      {
        ++ light;
        if (start_y == h)
        {
          start_y = y;
        }
      }
      else if (s [y] [x] == '#')
      {
        FOR (i, start_y, y)
        {
          column_light [i] [x] = light;
        }
        light = 0;
        start_y = h;
      }
    }
    if (light != 0)
    {
      FOR (i, start_y, h)
      {
        column_light [i] [x] = light;
      }
    }
  }

  auto ans = 0;
  rep (i, h)
  {
    rep (j, w)
    {
      ans = max (ans, row_light [i] [j] + column_light [i] [j] - 1);
      //cerr << "(" << row_light [i] [j] << "," << column_light [i] [j] << ") ";
    }
    //cerr << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 35712
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
    static int N;
    static int A[];
    static int L[];
    static int R[];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        sc.close();

        L = new int[N];
        R = new int[N];
        for (int i = 0; i < N; i++) {
            L[i] = L_calc(i);
            R[N - i - 1] = R_calc(N - i - 1);
        }
        
        int temp_max_gcd = 0;
        for (int i = 0; i < N; i++) {
            if (temp_max_gcd < gcd(L[i], R[i])) {
                temp_max_gcd = gcd(L[i], R[i]);
            }
        }
        System.out.println(temp_max_gcd);
    }

    public static int L_calc(int i) {
        if (i == 0) {
            return 0;
        }
        return gcd(L[i - 1], A[i - 1]);
    }

    public static int R_calc(int i) {
        if(i == N - 1) {
            return 0;
        }
        return gcd(R[i + 1], A[i + 1]);
    }

    public static int gcd(int x, int y) {
        if (x == 0){
            return y;
        } else if (y == 0) {
            return x;
        }
        int a = Math.max(x, y);
        int b = Math.min(x, y);
        while (a % b != 0) {
            int extra = a % b;
            a = b;
            b = extra;
        }
        return b;
    }
}


Measured memory_bytes: 50196
// ABC150-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    ll n,m;
    cin>>n>>m;
    int ans=0;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        a[i]/=2;
    } 
    bool flag=true;
    while(a[0]%2==0){
        rep(i,n){
            if(a[i]%2!=0){
                flag=false;
                break;
            }
            a[i]/=2;
        }
        m/=2;
    }
    rep(i,n) if(a[i]%2==0) flag=false;
    if(flag){
        ll lcm=a[0];
        for(int i=1;i<n;i++){
            lcm=lcm*a[i]/__gcd(lcm,a[i]);
            if(m<lcm){
                flag=false;
                break;
            }
        }
        if(flag){
            lcm=m/lcm;
            if(lcm%2==0) lcm--;
            ans=(lcm-1)/2+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
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 int INF = 2e9;
const ll LINF = (1LL<<60);

template <class T>
struct Edge {
  int rev, from, to;  // rev:逆向きの辺の番号
  T cap, original_cap;
  Edge(int r, int f, int t, T c) : rev(r), from(f), to(t), cap(c), original_cap(c) {}
};

template <class T>
struct Graph {
  vector<vector<Edge<T>>> G;
  Graph(int n = 0) : G(n) {}
  vector<Edge<T>>& operator[](int i) { return G[i]; }
  const size_t size() const { return G.size(); }
  Edge<T>& redge(Edge<T> e) {  // 逆向きの辺を返す
    return G[e.to][e.rev];   // 自己ループはないと仮定（あれば G[e.to][e.rev + 1] とする必要がある）
  }
  void add_edge(int from, int to, T cap) {  // 有向辺を加える
    G[from].push_back(Edge<T>((int)G[to].size(), from, to, cap));
    G[to].push_back(Edge<T>((int)G[from].size() - 1, to, from, 0));
  }
};

template <class T>
struct FordFulkerson { 
  //const T INF = 1e9;
  vector<int> used;
  FordFulkerson(){};
  T dfs(Graph<T>& G, int v, int t, T f) {  // 増加可能経路を見つけて増加分のフローを返す
    if (v == t) return f;
    used[v] = true;
    for (auto& e : G[v]) {
      if (!used[e.to] && e.cap > 0) {
        T d = dfs(G, e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G.redge(e).cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  T max_flow(Graph<T>& G, int s, int t) {
    T flow = 0;
    while (true) {
      used.assign(G.size(), 0);
      T f = dfs(G, s, t, INF);  // f が増加分のフロー
      if (f == 0) return flow;
      else flow += f;
    }
    return 0;
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n), b(n), c(n), d(n);
  REP(i,n) cin >> a[i] >> b[i];
  REP(i,n) cin >> c[i] >> d[i];

  Graph<int> G(n*2+2);
  REP(i,n){
    G.add_edge(n*2, i, 1);
    G.add_edge(n+i, n*2+1, 1);
  }
  REP(i,n) REP(j,n){
    if(a[i]<c[j] && b[i]<d[j]){
      G.add_edge(i, n+j, 1);
    }
  }

  FordFulkerson<int> ff;
  cout << ff.max_flow(G, n*2, n*2+1) << '\n';
  return 0;
}


Measured memory_bytes: 3812
unittest
{
	assert( [ "aca", "accc", "ca" ].parse.expand.solve == "A" );
	assert( [ "abcb", "aacb", "bccc" ].parse.expand.solve == "C" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto a = input.front;
	input.popFront;
	auto b = input.front;
	input.popFront;
	auto c = input.front;
	return tuple( a, b, c );
}

auto solve( string a, string b, string c )
{
	auto ss = [ a, b, c ];
	auto t = 0L;
	while( 0 < ss[ t ].length )
	{
		auto n = ss[ t ][ 0 ] - 'a';
		ss[ t ].popFront;
		t = n;
	}
	
	auto ans = "A".dup;
	ans[ 0 ] += t;
	
	return ans;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[][] sushi = new int[N][2];
		for(int i = 0; i < N; i++) {
			sushi[i][0] = sc.nextInt();
			sushi[i][1] = sc.nextInt();
		}
		Arrays.sort(sushi, (x,y) -> y[1]-x[1]);
		Set<Integer> used = new HashSet<>();
		Map<Integer, Integer> n = new HashMap<>();
		long sat = 0;
		for(int i = 0; i < K; i++) {
			sat += sushi[i][1];
			used.add(sushi[i][0]);
			if(n.containsKey(sushi[i][0]))
				n.put(sushi[i][0], n.get(sushi[i][0])+1);
			else
				n.put(sushi[i][0], 1);
		}
		sat += (long)used.size()*used.size();
		long newsat = sat;
		int x = K;
		LOOP:for(int i = K-1; i > 0; i--) {
			int t = n.get(sushi[i][0]);
			if(t > 1) {
				n.put(sushi[i][0], t-1);
				for(int j = x; j < N; j++) {
					if(!used.contains(sushi[j][0])) {
						used.add(sushi[j][0]);
						n.put(sushi[j][0], 1);
						newsat += -sushi[i][1]+sushi[j][1]+2*used.size()-1;
						sat = Math.max(sat, newsat);
						x = j+1;
						break;
					}
					if(j == N-1)
						break LOOP;
				}
			}
		}
		System.out.println(sat);
	}

}

Measured memory_bytes: 99616
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long

using namespace std;

int main()
{
int n;
cin>>n;
int val;
vector<int> a(n+1);
for(int i=1; i<n; i++){
	cin>>val;
	a[val]++;
}
for(int i=0; i<n; i++){
	cout<<a[i+1]<<endl;
}
}

Measured memory_bytes: 4056
import sys

def L(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())

import collections

def solver(N,A,Q,BC):
    T = sum(map(int,A))
    #print(T)

    Nums = collections.Counter(A)
    #print(Nums)
    for b,c in BC:
        diff = c - b

        T += Nums[b] * diff
        print(T)

        Nums[c] += Nums[b]
        Nums[b] = 0


def main():
    N = I()
    A = LI()
    Q = I()
    BC = []*Q
    BC = [LI() for _ in range(Q)]

    solver(N,A,Q,BC)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40440
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	if n == 1 && m == 1 {
		fmt.Println(1)
	} else if n == 1 {
		fmt.Println(m - 2)
	} else if m == 1 {
		fmt.Println(n - 2)
	} else {
		fmt.Println((n - 2) * (m - 2))
	}
}

Measured memory_bytes: 512
#include <iostream>
#include<stdio.h>
using namespace std;


int main()
{
    char a,b,c ;int x;
    while(cin>>a>>b>>c)
    {   x=0;
        if(a=='o')
            x++;
        if(b=='o')
            x++;
        if(c=='o')
            x++;
        printf("%d\n",700+x*100);
    }




return 0;}


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

#ifdef _DEBUG
#define ASSERT(x) assert(x)
#define DLOG(x) cout << __LINE__ << ": " << x << endl;
#else
#define ASSERT(x)
#define DLOG(x)
#endif
#define DLOG_V(x) DLOG(#x << ": " << x)

using namespace std;

constexpr static auto none{numeric_limits<int>::min()};

struct Tree {
  void print(ostream& os) const {
    doInOrder(rootIdx, [&os](auto&& i) { os << " " << i; });
    os << endl;
    doPreOrder(rootIdx, [&os](auto&& i) { os << " " << i; });
    os << endl;
  }

  void insert(int val) {
    size_t idx = rootIdx;
    while (true) {
      auto cur = tryGet(idx);
      if (cur == none) {
        vals_[idx] = val;
        return;
      } else {
        idx = val < cur ? leftIdx(idx) : rightIdx(idx);
      }
    }
  }

  bool find(int val) {
    size_t cur = rootIdx;
    for (;;) {
      auto it = vals_.find(cur);
      if (it == vals_.end()) {
        return false;
      }
      auto v0 = it->second;
      if (v0 == val) {
        return true;
      } else if (val < v0) {
        cur = leftIdx(cur);
      } else {
        cur = rightIdx(cur);
      }
    }
    return false;
  }

 private:
  constexpr static size_t rootIdx = 1;

  static size_t leftIdx(size_t idx) { return idx * 2; }
  static size_t rightIdx(size_t idx) { return idx * 2 + 1; }

  int tryGet(size_t idx) const {
    auto it = vals_.find(idx);
    if (it == vals_.end()) {
      return none;
    } else {
      return it->second;
    }
  }

  void doInOrder(size_t idx, const function<void(int)>& f) const {
    if (tryGet(idx) == none) {
      return;
    }
    doInOrder(leftIdx(idx), f);
    f(tryGet(idx));
    doInOrder(rightIdx(idx), f);
  }

  void doPreOrder(size_t idx, const function<void(int)>& f) const {
    if (tryGet(idx) == none) {
      return;
    }
    f(tryGet(idx));
    doPreOrder(leftIdx(idx), f);
    doPreOrder(rightIdx(idx), f);
  }

  unordered_map<size_t, int> vals_;
};

int main() {
  int num;
  cin >> num;
  Tree tree;
  ostringstream ss;
  for (int i = 0; i < num; ++i) {
    string cmd;
    cin >> cmd;
    if (cmd == "insert") {
      int val;
      cin >> val;
      tree.insert(val);
    } else if (cmd == "find") {
      int val;
      cin >> val;
      ss << (tree.find(val) ? "yes" : "no") << endl;
    } else if (cmd == "print") {
      tree.print(ss);
    }
  }
  cout << ss.str();
}



Measured memory_bytes: 35212
function Main(input: string) {
  const lines: string[] = input.split("\n");
  const params1 = lines[0].split(' ');

  const n: number = parseInt(params1[0]);
  const x: number = parseInt(params1[1]);
  const y: number = parseInt(params1[2]);

  let ds: { [n: number]: number } = (new Array(n)).fill(0);
  for (let i = 1; i <= n - 1; i++) {
    for (let j = i + 1; j <= n; j++) {
      // const d = (i <= x && y <= j) ? (j - y) + 1 + (x - i) : j - i;
      const d = Math.min(Math.abs(j - y) + 1 + Math.abs(x - i), j - i);
      ds[d]++;
    }
  }

  for (let i = 1; i <= n - 1; i++) console.log(ds[i]);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;


int main(){
  int i,j;
  ll n,k;
  cin>>n>>k;
  VI v(n);
  for(i=0;i<n;i++) cin>>v[i];
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  ll a=0;
  for(i=0;i<n;i++){
    if(i>=k) a+=v[i];
  }
  cout<<a<<endl;
    
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int MAXN=1e6+5;
int n,m,fa[MAXN];
struct EDGE {
	int u,v;
}e[MAXN];
ll ans[MAXN],sz[MAXN];
int get_fa(int x) {
	if(x==fa[x]) return x;
	return fa[x]=get_fa(fa[x]);
}
int main() {
	n=read();m=read();
	for(int i=1;i<=m;++i)e[i].u=read(),e[i].v=read();
	for(int i=1;i<=n;++i)fa[i]=i,sz[i]=1;
	ans[m]=(ll)n*(n-1)/2;
	for(int i=m;i>=1;--i){
		int u=get_fa(e[i].u),v=get_fa(e[i].v);
		if(u==v) ans[i-1]=ans[i];
		else {
			ans[i-1]=ans[i]-sz[v]*sz[u];
			sz[v]+=sz[u]; fa[u]=v;
		}
	}
	for(int i=1;i<=m;++i) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
//#include "atcoder/all"
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  map<char, ll> m;
  for (int i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    m[temp[0]]++;
  }

  vector<ll> num{m['M'], m['A'], m['R'], m['C'], m['H']};
  ll ans = 0;

  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += num[i] * num[j] * num[k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9+3;
const ll INF = 1e18+3;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<int> ids[10];
    rep(i, N){
        ids[S[i]-'0'].pb(i);
    }
    int ans = 0;
    rep(i, 10){
        rep(j, 10){
            rep(k, 10){
                if(ids[i].empty() || ids[k].empty()) continue;
                vector<int>::iterator it = ids[i].begin();
                int l = *it;
                it = ids[k].end(), it--;
                int r = *it;
                if(lower_bound(all(ids[j]), r) - lower_bound(all(ids[j]), l+1) > 0) ans++;
            }
        }
    }
    cout << ans << endl;
}

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

char a[0xff][0xff];

char check(string s) {
	char c = '0';
	for (char& d : s) {
		c = a[c][d];
	}
	return c;
}

int main() {
	for (char i = '0'; i <= '9'; i++) {
		for (char j = '0'; j <= '9'; j++) {
			int k;
			cin >> k;
			a[i][j] = '0' + k;
		}
	}
	int m = 10000;
	for (int n = 0; n < 10000; n++) {
		string s = to_string(10000 + n).substr(1);
		s.push_back(check(s));
		bool ok = true;
		for (int i = 0; i < s.size() && ok; i++) {
			for (char j = '0'; j <= '9' && ok; j++) {
				if (s[i] != j) {
					string t = s;
					t[i] = j;
					if (check(t) == '0') {
						ok = false;
					}
				}
			}
		}
		for (int i = 0; i < s.size() - 1 && ok; i++) {
			if (s[i] != s[i + 1]) {
				string t = s;
				char c = t[i];
				t[i] = t[i + 1];
				t[i + 1] = c;
				if (check(t) == '0') {
					ok = false;
				}
			}
		}
		if (ok) {
			m--;
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 3288
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int bal[] = new int[n];
        for(int i=0;i<n;i++){
            bal[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(bal);
        int cal[][] = new int[m][2];
        for(int i=0;i<m;i++){
            cal[i][0] = Integer.parseInt(sc.next());
            cal[i][1] = Integer.parseInt(sc.next());
        }
        Arrays.sort(cal, new Comparator<int[]>() {
            @Override
            public int compare(int[] a1, int[] a2){
                return Integer.compare(a2[1], a1[1]);
            }
        });

        int j=0; boolean f=true;
        for(int i=0;i<m;i++){
            while(cal[i][0]>0){
                if(j == n || cal[i][1] <= bal[j]){
                    f = false;
                    break;
                }
                bal[j] = cal[i][1];
                j++;
                cal[i][0] -= 1;
            }
            if(!f){
                break;
            }
        }
        Long sum = new Long(0);
        for(int i=0;i<n;i++){
            sum += bal[i];
        }
        System.out.println(sum);
        sc.close();
    }
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	for_(i,1,10) {
		for_(j,1,10) {
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

string s;
int k, len = 1;
LL ans;

int main() {
	cin >> s;
	read(k);
	if (k == 1 || s[0] != s[(int) s.size() - 1]) {
		for (int i = 1; i < (int) s.size(); ++i)
			if (s[i] == s[i - 1]) ++len;
			else {
				ans += len / 2;
				len = 1;
			}
		ans += len / 2;
		write(ans * k);
		putchar('\n');
	} else {
		LL l, r;
		for (l = 1; s[l] == s[l - 1] && l < (int) s.size(); ++l);
		for (r = s.size() - 1; s[r] == s[r - 1] && r; --r);
		if (l >= r) {
			write(1ll * (int) s.size() * k / 2);
			putchar('\n');
		} else {
			for (int i = l + 1; i < r; ++i)
				if (s[i] == s[i - 1]) ++len;
				else {
					ans += len / 2;
					len = 1;
				}
			ans += len / 2;
			write(ans * k + l / 2 + ((int) s.size() - r) / 2 + 1ll * 
			((int) s.size() - r + l) / 2 * (k - 1));
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string a;
    cin>>a;
    int b=0;
    for(int i=0;i<3;i++){
        if(a.at(i)==a.at(i+1)){
            b=b+1;
        }
    }
    if(b>=1){
        cout<<"Bad"<<endl;
    }
    else{
        cout<<"Good"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,H,A,D,S;
vl h,a;

int main(){
	cin>>n>>H>>A>>D>>S;
	ll res=H,as=0;
	h=a=vl(n);
	vector<pair<double,int> > b;
	for(int i=0;i<n;i++){
		ll d,s;
		cin>>h[i]>>a[i]>>d>>s;
		a[i]=max(a[i]-D,0ll);
		as+=a[i];
		if(A<=d&&a[i]){
			cout<<-1<<endl;
			return 0;
		}
		if(A-d>0){
			ll da=A-d;
			h[i]=(h[i]+da-1)/da;
			if(s>S) res-=a[i];
			if(a[i]){
				b.push_back({(double)h[i]/a[i],i});
			}
		}
	}
	sort(b.begin(),b.end());
	int B=b.size();
	for(int i=0;i<B;i++){
		int I=b[i].second;
		if(res<as-a[I]){
			cout<<-1<<endl;
			return 0;
		}
		res-=as*h[I]-a[I];
		as-=a[I];
		if(res<=0){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<H-res<<endl;
}

Measured memory_bytes: 4340
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	double t, x;
	cin >> t >> x;

	printf("%0.12lf\n", t / x);
	
}


 

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int prime_count(int[], int);
int main(void){
    int n, i, x[10000];
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    printf("%d\n", prime_count(x, n));
    return 0;
}
int prime_count(int a[], int n){
    int i, W = 0, j ,root, flag;
    for(i = 0;i <n; i++){
        //printf("%d ", a[i]);
        if(a[i] == 2){
            W++;
        }else if(a[i] % 2 == 0 || a[i] == 1){
            continue;
        }else{
            root = sqrt(a[i]);
            //printf("%d\n", root);
            flag = 1;
            for(j = 3; j < root + 1; j++){
                if(a[i] % j == 0){
                    flag = 0;
                }
            }
            if(flag){
                W++;
            }
        }
    }
    return W;
}



Measured memory_bytes: 2032
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}

int main(void) {
  int A, B;
  cin >> A >> B;
  int min = A - 2*B;
  if (min > 0) {
    pr(min);
  } else {
    pr(0);
  }
  return 0;
}



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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int poor = 0;
    if (A == B && B != C) poor = 1;
    if (B == C && C != A) poor = 1;
    if (C == A && A != B) poor = 1;
    if (poor == 1){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3576
import sys
input = sys.stdin.readline
 
class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        p = x
        
        while not self.par[p]<0:
            p = self.par[p]
        
        while x!=p:
            tmp = x
            x = self.par[x]
            self.par[tmp] = p
        
        return p
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx==ry: return False
        
        if self.rank[rx]<self.rank[ry]:
            rx, ry = ry, rx
        
        self.par[rx] += self.par[ry]
        self.par[ry] = rx
    
        if self.rank[rx]==self.rank[ry]:
            self.rank[rx] += 1
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, M = map(int, input().split())
p = list(map(lambda x: x-1, map(int, input().split())))
uf = Unionfind(N)

for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(p[x-1], p[y-1])

ans = 0

for i in range(N):
    if uf.is_same(p[i], i):
        ans += 1

print(ans)

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

#define INF (INT32_MAX/2)

int H, W;
vector<vector<char>> A;

int main() {
	cin >> H >> W;
	A = vector<vector<char>>( H, vector<char>( W ) );
	for( int i = 0; i < H; i++ ) {
		for( int j = 0; j < W; j++ ) {
			cin >> A[i][j];
		}
	}

	queue<pair<int, pair<int, int>>> que;
	for( int i = 0; i < H; i++ ) {
		for( int j = 0; j < W; j++ ) {
			if( A[i][j] == '#' ) {
				que.push( make_pair( 0, make_pair( i, j ) ) );
			}
		}
	}
	int ans = 0;
	while( !que.empty() ) {
		pair<int, pair<int, int>> p = que.front();
		que.pop();
		ans = p.first;
		int i = p.second.first;
		int j = p.second.second;
		int dirh[4] = { 0, 0, -1, 1 };
		int dirw[4] = { -1, 1, 0, 0 };
		for( int ii = 0; ii < 4; ii++ ) {
			int ny = i + dirh[ii];
			int nx = j + dirw[ii];
			if( ny < 0 || H <= ny || nx < 0 || W <= nx ) {
				continue;
			}
			if( A[ny][nx] == '.' ) {
				que.push( make_pair( ans + 1, make_pair( ny, nx ) ) );
				A[ny][nx] = '#';
			}
		}
	}


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

Measured memory_bytes: 13328
#include <stdio.h>
#include <string.h>

int main(void){
    char s[11];
    char ans[11]="";
    scanf("%s",s);

    int aidx = 0;
    for(int i=0; i<strlen(s); i++) {
        char c = s[i];
        if(c=='B' && strlen(ans)>0){
            if(aidx!=0) aidx--;
        }else if (c!='B'){
            ans[aidx] = c;
            aidx++;
        }
    }

    ans[aidx]='\0';

    printf("%s",ans);

    return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k;

int main(){
    int n;cin>>n;
    string s;cin>>s;
    ll ans=0;
    ll red=0,blue=0,green=0;

    for(i=0;i<n;i++){
        if(s[i]=='R'){red++;}
        if(s[i]=='G'){green++;}
        if(s[i]=='B'){blue++;}
    }

    ans=red*green*blue;

    for(i=0;i<n-2;i++){
        for(k=i+2;k<n;k++){
            if(((i+k)%2==0)&&(s[i]!=s[k] && s[k]!=s[(i+k)/2] && s[(i+k)/2]!=s[i])){ans--;}
        }
    }

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

Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>

typedef struct{
  double x, y;
}Point;

void koch(int n, Point a, Point b){
  if(n == 0) return;
  Point s, t, u;
  double th = M_PI * 60.0 / 180.0; //度からラジアンへ単位を変換

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n-1, a, s);
  printf("%.8f %.8f\n",s.x, s.y);
  koch(n-1, s, u);
  printf("%.8f %.8f\n",u.x, u.y);
  koch(n-1, u, t);
  printf("%.8f %.8f\n",t.x, t.y);
  koch(n-1, t, b);
}

int main(){
  Point a, b;
  int n;

  scanf("%d",&n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n",b.x, b.y);
 
  return 0;
}



Measured memory_bytes: 2048
import numpy as np

n = int(input())

a = list(map(int, input().split()))
l = [0 for i in range(100010)]

q = int(input())

s = np.sum(a)

for ae in a:
    l[ae] += 1

ans = []

for i in range(q):
    b, c = map(int, input().split())

    m_num = l[b]
    l[b] = 0
    m_s = m_num*b

    p_s = m_num*c
    l[c] += m_num

    s = s - m_s + p_s

    ans.append(s)

for i in range(q):
    print(ans[i])


Measured memory_bytes: 38788
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int  b1,b2,b3;
    cin>>b1>>b2>>b3;
    if(b1==1&&b2==1&&b3==0){
                   cout<<"Open"<<endl;
                  }
   else if(b1==0&&b2==0&&b3==1){
                   cout<<"Open"<<endl;
                  }
   else if (b1==0&&b2==0&&b3==0){
                   cout<<"Close"<<endl;
                  }
    else{
                   cout<<"Close"<<endl;
    }
                         
}


Measured memory_bytes: 3096
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

#define MOD 1000000007
#define INF INT_MAX
#define ll long long

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

	cin >> x >> a >> b;

	if (abs(x - a) > abs(x - b)) {
		cout << "B" << endl;
	}
	else {
		cout << "A" << endl;
	}

	return (0);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }
    vi b;
    for (int i = n - 1; i >= 0; i -= 2) {
        b.push_back(a[i]);
    }
    for (int i = n % 2; i < n; i += 2) {
        b.push_back(a[i]);
    }
    rep(i, n) {
        printf("%d ", b[i]);
    }
    printf("\n");
}

Measured memory_bytes: 5076
K,X=map(int,input().split())
list_x=[0]*(((K-1)*2)+1)
k=K-1
p=0
for i in range(K-1):
  list_x[p]=X-k
  k=k-1
  p=p+1
list_x[p]=X
k=1
p=p+1
for i in range(K-1):
  list_x[p]=X+k
  k=k+1
  p=p+1
for i in range(((K-1)*2)+1):
  print(str(list_x[i])+' ',end='')


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

typedef long long int ll;

int main()
{
	ll num; cin >> num;
	string ans;
	while(num > 0)
	{
		int rem = num % 26;
		bool flag = false;
		if(rem == 0) 
			{
				rem = 26;
				flag = true;
			}
		rem -= 1;
		ans += string(1, static_cast<char>('a' + rem ));
		num = num / 26;
		if(flag) num -= 1;
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
	return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>

double p1(int n,int *datax,int *datay){
	int i;
    double ans=0;
     for(i=0;i<n;++i){
	   ans+=fabs(datax[i]-datay[i]);
	 }
    return(ans);
}

double p2(int n,int *datax,int *datay){
	int i;
    double ans=0;
     for(i=0;i<n;++i){
	   ans+=(fabs(datax[i]-datay[i]))*(fabs(datax[i]-datay[i]));
	 }
    return(sqrt(ans));
}

double p3(int n,int *datax,int *datay){
	int i;
    double ans=0,k;
    
     for(i=0;i<n;++i){
	  ans+=(fabs(datax[i]-datay[i]))*(fabs(datax[i]-datay[i]))*(fabs(datax[i]-datay[i]));
	 }
	 
	 k=0.3333333333333333;
    return(pow(ans,k));
}

double pn(int n,int *datax,int *datay){
	int i;
    double max=0;
    
     for(i=0;i<n;++i){
	   if (fabs(datax[i]-datay[i])>max) max=fabs(datax[i]-datay[i]);
	 }
	 
    return(max);
}

int main(){

    int i,n;
    int datax[1001],datay[1001];
    
    scanf("%d",&n);
    for(i=0;i<n;++i){
     scanf("%d",&datax[i]);
     }
     
    for(i=0;i<n;++i){
     scanf("%d",&datay[i]);
     }
     
    printf("%.6lf\n",p1(n,datax,datay));
    printf("%.6lf\n",p2(n,datax,datay)); 
    printf("%.6lf\n",p3(n,datax,datay));
    printf("%.6lf\n",pn(n,datax,datay));
    
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int czero = 0, cone = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] == '0') czero++;
    else cone++;
  }
  cout << S.size() - abs(czero - cone) << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vi A(N);
	rp(i,0,N)cin>>A[i];
	bool active = true;
	int count = 0;
	while(active){
		rp(i,0,N){
			if(A[i]&1){
				active = false;
				break;
			}
			A[i]>>=1;
		}
		if(active){
			count++;
		}
	}
	ote(count);
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N, M;
vector<int> a, b;

int main(){
  cin >> N >> M;
  a.resize(M), b.resize(M);
  REP(i, M){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  vector<int> in(N+1, 0), out(N+1, 0), sum(N+1, 0);
  REP(i, M){
    in[a[i]]++, out[b[i]]++;
  }
  REP(i, N){
    sum[i+1] = sum[i] + in[i]-out[i];
  }
  bool ans = true;
  FOR(i, 1, N+1){
    if(sum[i] % 2 != 0){
      ans = false;
    }
  }

  cout << (ans ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 2176
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//Union-Find??¨

int main(void){
	int S,h,m,s;
	cin>>S;
	h = S/3600;
	S %= 3600;
	m = S/60;
	S %= 60;
	s = S;
	cout<<h<<":"<<m<<":"<<s<<endl;
	return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 200000+5;
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long
int a[N]={0};
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int cnt=1,js=0;
	for(int i=0;i<n;i++){
		if(a[i]==cnt){
			cnt++;
			js++;
		}
	}
	if(js==0) cout<<-1<<endl;
	else cout<<n-js<<endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader; 
import java.io.*;
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
import java.math.*;
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader()
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next()
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine();
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
   public static void main(String args[]) throws Exception
    {
        FastReader sc=new FastReader();
         PrintWriter pw=new PrintWriter(System.out);
        int t=1;//sc.nextInt();
        while(t-->0)
        {
           int n=sc.nextInt(),x=sc.nextInt(),tt=sc.nextInt(),d=tt,p=x,min=Integer.MAX_VALUE,f=0,a=0,t1=0;
           while(a<n)
           {
               a+=p;
               t1+=d;//pw.println(tt);
           }
           //String s=sc.next();

           pw.println(t1);
        }
           pw.close();
    }
}
  

Measured memory_bytes: 32880
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main (){
	int N;cin>>N;
	if (N==3||N==5||N==7)
	{
		cout<<"YES"<<endl;
	}else
	{
		cout<<"NO"<<endl;
	}
	
	
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;
long x, y;
long ans = 0;
int solve() {
    cin >> x >> y;
    for(long i = x; i <= y; i *= 2) {
        ans++;
    }
    cout << ans << endl;
}
int main(void) {
    solve();
    return 0;
}


Measured memory_bytes: 256
//ABC096C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<char>> s(h, vector<char>(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> s.at(i).at(j);
		}
	}
	
	//隅の４点をチェック
	if(s.at(0).at(0) == '#'){
		if(s.at(0).at(1) == '.' && s.at(1).at(0) == '.'){
			cout << "No" << endl;
			return 0;
		}
	}
	if(s.at(0).at(w-1) == '#'){
		if(s.at(0).at(w-2) == '.' && s.at(1).at(w-1) == '.'){
			cout << "No" << endl;
			return 0;
		}
	}
	if(s.at(h-1).at(0) == '#'){
		if(s.at(h-2).at(0) == '.' && s.at(h-1).at(1) == '.'){
			cout << "No" << endl;
			return 0;
		}
	}
	if(s.at(h-1).at(w-1) == '#'){
		if(s.at(h-1).at(w-2) == '.' && s.at(h-2).at(w-1) == '.'){
			cout << "No" << endl;
			return 0;
		}
	}
	
	//外側の辺をチェック
	for(int i=1;i<w-1;i++){
		if(s.at(0).at(i) == '#'){
			if(s.at(0).at(i-1) == '.' && s.at(0).at(i+1) == '.' && s.at(1).at(i) == '.'){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	for(int i=1;i<w-1;i++){
		if(s.at(h-1).at(i) == '#'){
			if(s.at(h-1).at(i-1) == '.' && s.at(h-1).at(i+1) == '.' && s.at(h-2).at(i) == '.'){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	for(int i=1;i<h-1;i++){
		if(s.at(i).at(0) == '#'){
			if(s.at(i-1).at(0) == '.' && s.at(i+1).at(0) == '.' && s.at(i).at(1) == '.'){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	for(int i=1;i<h-1;i++){
		if(s.at(i).at(w-1) == '#'){
			if(s.at(i-1).at(w-1) == '.' && s.at(i+1).at(w-1) == '.' && s.at(i).at(w-2) == '.'){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	
	//内側をチェック
	for(int i=1;i<h-1;i++){
		for(int j=1;j<w-1;j++){
			if(s.at(i).at(j) == '#'){
				if(s.at(i).at(j-1) == '.' && s.at(i-1).at(j) == '.' && s.at(i+1).at(j) == '.' && s.at(i).at(j+1) == '.'){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(){
  char a;
  cin>>a;
  if (a=='A') cout << 'T';
  if (a=='T') cout << 'A';
  if (a=='C') cout << 'G';
  if (a=='G') cout << 'C';
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll a[200001];
ll p[200001];
set<ll> s;
int main() {
	ll n; cin >> n;
	rep(i, 0, n) {
		cin >> a[i];
		p[a[i] - 1] = i;
	}
	ll ans = 0;
	s.insert(-1);
	s.insert(n);

	rep(i, 0, n) {
		set<ll>::iterator it = s.lower_bound(p[i]);
		ll r = *it - p[i];
		it--;
		ll l = p[i] - *it;
		ans += a[p[i]] * l*r;
		s.insert(p[i]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12800
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define INF 100000

int main(){
  string s;
  cin >> s;
  long long n = s.length();
  long long p[n+1];
  p[0] = 1;
  for(long long i=1;i<n+1;i++){
    p[i] = 3*p[i-1];
    p[i] %= 1000000007;
  }
  vector<long long> count;
  for(long long i=n;i>0;i--){
    if(s[n-i] == '1') count.push_back(i);
  }

  long long ans = 0;
  long long bai = 1;
  for(long long i=0;i<count.size()-1;i++){
    //cout << count[i] << endl;
    ans += p[count[i]-1]*bai;
    ans %= 1000000007;
    bai *= 2;
    bai %= 1000000007;
  }
  if(count[count.size()-1] == 1){
    ans += bai*3;
    ans %= 1000000007;
  }
  else{
    ans += p[count[count.size()-1]-1]*bai;
    ans %= 1000000007;
    bai *= 2;
    bai %= 1000000007;
    ans += bai;
    ans %= 1000000007;
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 2296
#include <stdio.h>
#include <string.h>

int main (){

    int n;
    scanf("%d", &n);
    char str[10000];
    scanf("%s", str);
    for(int i = 0; i < strlen(str); i++){
        str[i] = str[i] + n;
        if(str[i] >= 91) str[i] -= 26;
    }

    printf("%s", str);


}

Measured memory_bytes: 1712