akhauriyash/Code-Regression huggingface dataset:
// Problem : D - Keep Distances
// Contest : AtCoder - ACL Contest 1
// URL : https://atcoder.jp/contests/acl1/tasks/acl1_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

constexpr int Maxn = 2e5 + 5;
constexpr int LOG = 20;

int n, K, q;
int a[Maxn];
int pre[Maxn][LOG];
int suf[Maxn][LOG];
int64_t pre_sum[Maxn][LOG];
int64_t suf_sum[Maxn][LOG];

int main() {

  scanf("%d %d", &n, &K);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n; ++i) {
    pre[i][0] = upper_bound(a + 1, a + n + 1, a[i] - K) - a - 1;
    suf[i][0] = lower_bound(a + 1, a + n + 1, a[i] + K) - a;
    pre_sum[i][0] = (pre[i][0] >= 1 ? pre[i][0] : 0);
    suf_sum[i][0] = (suf[i][0] <= n ? suf[i][0] : 0);
  }
  for (int j = 1; j < LOG; ++j) {
    for (int i = 1; i <= n; ++i) {
      pre_sum[i][j] = pre_sum[i][j - 1];
      suf_sum[i][j] = suf_sum[i][j - 1];
      if (pre[i][j - 1] >= 1) {
        pre[i][j] = pre[pre[i][j - 1]][j - 1];
        pre_sum[i][j] += pre_sum[pre[i][j - 1]][j - 1];
      }
      else {
        pre[i][j] = 0;
      }
      if (suf[i][j - 1] <= n) {
        suf[i][j] = suf[suf[i][j - 1]][j - 1];
        suf_sum[i][j] += suf_sum[suf[i][j - 1]][j - 1];
      }
      else {
        suf[i][j] = n + 1;
      }
    }
  }
  
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    int64_t left_sum = 0;
    int64_t right_sum = 0;
    int len = 1;
    {
      int lg = LOG - 1, pos = r;
      while (lg >= 0) {
        if (pre[pos][lg] >= l) {
          left_sum += pre_sum[pos][lg];
          pos = pre[pos][lg];
          len += (1 << lg);
        }
        --lg;
      }
    }
    {
      int lg = LOG - 1, pos = l;
      while (lg >= 0) {
        if (suf[pos][lg] <= r) {
          right_sum += suf_sum[pos][lg];
          pos = suf[pos][lg];
        }
        --lg;
      }
    }
    printf("%lld\n", left_sum - right_sum + len + r - l);
  }
  
  return 0;
  
}


Measured memory_bytes: 98292
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int  N = sc.nextInt();
		String S = sc.next();
		char[] c = S.toCharArray();
		int max = 0;
		int tmp = 0;
		for(int i = 0; i < N; i++) {
			if(c[i] == 'I') {
				tmp++;
				if(tmp > max) {
					max = tmp;
				}
			}else if(c[i] =='D') {
				tmp--;
			}
		}
		System.out.println(max);
		}
}

Measured memory_bytes: 21844
var
  n, i, j : longint;
  ans : qword;
  s : ansistring;
begin
  read(s);
  n:=length(s);
  for i:=1 to n do
    begin
      if s[i]='W' then
        begin
          inc(j);
          ans:=ans+(i-j)
        end
    end;
  write(ans)
end.

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,M,A,B;cin>>N>>M;
  int minimum=0; int maximum=INT_MAX;
  for(int i=0;i<M;i++)
  {
    cin>>A>>B;
    if(minimum<A){minimum=A;}
    if(maximum>B){maximum=B;}
  }
  if(minimum>maximum){cout<<0<<endl;}
  else{cout<<1+(maximum-minimum)<<endl;}
  return 0;
}


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

using ll = unsigned long long;

int main() {
  int N;
  cin >> N;
  vector<ll> as(N);
  for(int i = 0; i < N; ++i) {
    cin >> as[i];
  }
  sort(as.begin(), as.end());

  ll sum = 0;
  int ans = 0;
  for(int i = 0; i < N; ++i) {
    // cout << as[i] << " -> sum : " << sum << endl;
    if(sum * 2 < as[i]) {
      ans = 0;
    }
    sum += as[i];
    ans++;
  }
  cout << ans << endl;
  return 0;
  /*
  vector<ll> cusum(N);
  cusum[0] = as[0];
  for(int i = 1; i < N; i++) {
    cusum[i] = cusum[i - 1] + as[i];
  }

  int ans = 1;
  for(int i = N - 2; i >= 0; i--) {
    if(cusum[i] * 2 >= as[i + 1])
      ans++;
    else
      break;
  }
  cout << ans << endl;
  return 0;
  */
}


Measured memory_bytes: 1152
from itertools import accumulate
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
s = list(accumulate(a))

ans = float("inf")

for j in range(2,n-1):
    i_list = []
    i_left = bisect_left(s, s[j-1]//2)-1
    if i_left != -1:
        i_list.append([s[i_left], s[j-1]-s[i_left]])
    if i_left != j-2:
        i_list.append([s[i_left+1], s[j-1]-s[i_left+1]])

    k_list = []
    k_left = bisect_left(s, s[j-1]+(s[-1]-s[j-1])//2)-1
    if k_left != j-1:
        k_list.append([s[k_left] - s[j-1], s[-1]-s[k_left]])
    if k_left != n-2:
        k_list.append([s[k_left+1] - s[j-1], s[-1]-s[k_left+1]])
    for i in i_list:
        for k in k_list:
            tmp = max(i+k)-min(i+k)
            ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 25800
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INF 1<<29
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 



/*****************************************************************************/

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

	int n;
	cin >> n;
	vi a(n), b(n), c(n);
	f_vI(a, n); f_vI(b, n); f_vI(c, n);
	sort(all(a)); sort(all(b)); sort(all(c));
	int ans = 0;
	f(i, 0, n) {
		ans += (lower_bound(all(a), b[i]) - a.begin())*(c.end() - upper_bound(all(c), b[i]));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 2560
s = list(input())
t = list(input())
alph = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
s0, t0 = [], []
for i in range(26):
    for j in s:
        if alph[i] == j:
            s0.append(j)
    for j in t:
        if alph[25 - i] == j:
            t0.append(j)
s0 = "".join(s0)
t0 = "".join(t0)
print("Yes" if s0 < t0 else "No")

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

typedef long long ll;
using namespace std;
typedef pair<ll, ll> b_i;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll a[n], b[n];
  priority_queue<b_i> que;
  for(ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  for(ll i = 0; i < n; i++) {
    cin >> b[i];
    que.push(b_i(b[i], i));
  }
  ll count = 0;
  while(!que.empty()) {
    b_i bi = que.top();
    que.pop();
    ll left, right;
    ll bval = bi.first;
    ll i = bi.second;
    if(b[i] == a[i]) continue;
    if(i == 0) left = n - 1;
    else left = i - 1;
    if(i == n - 1) right = 0;
    else right = i + 1;
    ll diff = b[i] - a[i];
    ll count_diff = diff / (b[left] + b[right]);
    if(diff < 0 || count_diff == 0) {
      count = -1;
      break;
    }
    b[i] -= count_diff * (b[left] + b[right]);
    count += count_diff;
    que.push(b_i(b[i], i));
  }
  cout << count << "\n";
  return 0;
}



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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

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;
}

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll a, b, c;
    in(a);
    in(b);
    in(c);
    ll sum = a + c + b;
    if (sum >= 22)
    {
        out("bust");
    }
    else
    {
        out("win");
    }
}

Measured memory_bytes: 256
//      https://youtu.be/X_hMZYDMps4

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;    // 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nl                  "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define pf                  push_front
#define all(x)              x.begin(),x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"

int main()
{
    fast;
    ll t,i,j,k,l,m,n,o,p,q,temp,flag=0,mod=1000000007,W;
    cin>>n>>W;
    ll v[n+1],w[n+1],ans[n+1][W+1];
    memset(ans,0,sizeof(ans));
    for(i=1;i<=n;i++){
        cin>>w[i]>>v[i];
        for(j=1;j<=W;j++){
            if(j<w[i]){
                ans[i][j]=ans[i-1][j];
                continue;
            }
            ans[i][j]=max(ans[i-1][j],v[i]+ans[i-1][j-w[i]]);
        }
    }
    cout<<ans[n][W];
}


Measured memory_bytes: 82512
N = int(input())
h = [int(_n) for _n in input().split()]
dp = [0]*N
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
    dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]))
print(dp[N-1])


Measured memory_bytes: 13980
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextLong() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextDouble() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

func main() {
	io := NewIo()
	defer io.Flush()
	N := io.NextInt()
	M := io.NextInt()
	d := intMin(N, M/2)
	N -= d
	M -= 2 * d
	ans := d
	ans += M / 4
	io.PrintLn(ans)
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int lapLength = (h + w) * 2;
        int square = h * w;
        System.out.println(square + " " + lapLength);
    }
}


Measured memory_bytes: 26100
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        String[][] s = new String[h][w];
        for (int i = 0; i < h; i++) {
            String[] line = sc.next().split("");
            for (int j = 0; j < w; j++) {
                s[i][j] = line[j];
            }
        }

        // 主処理
        boolean isAdjacent = true;
        for (int i = 0; i < h; i++) {

            if (!isAdjacent) {
                break;
            }

            for (int j = 0; j < w; j++) {

                if ("#".equals(s[i][j])) {

                    // 左右隣接判定
                    boolean isLine = true;
                    if (j == 0) {
                        isLine = s[i][j].equals(s[i][j + 1]);
                    } else if (j == w - 1) {
                        isLine = s[i][j].equals(s[i][j - 1]);
                    } else {
                        isLine = s[i][j].equals(s[i][j + 1]) || s[i][j].equals(s[i][j - 1]);
                    }

                    // 上下隣接判定
                    boolean isColumn = true;
                    if (i == 0) {
                        isColumn = s[i][j].equals(s[i + 1][j]);
                    } else if (i == h - 1) {
                        isColumn = s[i][j].equals(s[i - 1][j]);
                    } else {
                        isColumn = s[i][j].equals(s[i + 1][j]) || s[i][j].equals(s[i - 1][j]);
                    }

                    isAdjacent = isLine || isColumn;
                }

                if (!isAdjacent) {
                    break;
                }
            }
        }

        String result = isAdjacent ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 22996
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const long long INF = 1LL << 60;
ll MOD = 1e9+7;

int main() {

    ll D,T,S; cin>>D>>T>>S;
    if(D <= S * T){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long int li;
typedef long long ll;

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

    int n; cin >> n;
    vector<int> a(n+1,0), b(n+1,0);

    for (int i=2; i<=n; i++) cin >> a[i];
    
    for (int i=1; i<=n; i++) {
        b[a[i]] += 1;
    }

    for (int i=1; i<=n; i++) cout << b[i] << "\n";

    return 0;
}

Measured memory_bytes: 4748
#include<bits/stdc++.h>
using namespace std;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,a,b,ans;
    cin>>n>>a>>b;
    ans=(b*n-b+a)-(a*n-a+b)+1;
    cout<<(ans>0?ans:0);
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//https://github.com/atcoder-live/library/blob/master/mint.cpp
struct mint {
	LL x; 
	mint(LL x=0):x((x%mod+mod)%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(LL t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};

struct combination {
	vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
	combination(LL n):fact(n+1),ifact(n+1) {
		assert(n < mod);
		fact[0] = 1;
		for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(LL n,LL k) {
		if (k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

LL H,W,A,B;

mint ans;

void solve(){
	combination c(H+W);
	for(LL x=B+1;x<=W;x++){
		LL y = H-A-(x-B)+1;
		if(y<=0) break;
		ans += c((x-1)+(y-1),x-1)*c((H-y)+(W-x),W-x);
	}
}

int main(){
    cin >> H >> W >> A >> B;

    solve();

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

Measured memory_bytes: 5900
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll w,h,ans=0; cin>>w>>h;
    vector<pair<ll,ll>> e(w+h,mk(0,0));
    rep(i,w){
        ll p; cin>>p;
        e[i]=mk(p,0);
    }
    rep(i,h){
        ll q; cin>>q;
        e[w+i]=mk(q,1);
    }
    sort(al(e));
    ll wcnt=w+1,hcnt=h+1;
    rep(i,w+h){
        if(e[i].second){
            ans+=wcnt*e[i].first;
            hcnt--;
        }
        else{
            ans+=hcnt*e[i].first;
            wcnt--;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6484
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

K = int(input())


def snuke_factor(n):
    """
    n / 各桁の和
    :param n:
    :return:
    """
    if n == 0:
        return INF
    return n / sum(list(map(int, str(n))))


# for i in range(9999, 1000000, 10000):
#     print(i, int(snuke_factor(i)))

# e ずつ増やす
d = 1
# 10 の倍数
e = 1
# 9999...
suffix = 0
for _ in range(K):
    print(d * e + suffix)
    if d % 10 == 9:
        if snuke_factor((d + 1) * e + suffix) > snuke_factor((d + 10) * e + suffix):
            # 増やす速度を 10 倍にする
            e *= 10
            d //= 10
            # 9 を 1 桁増やす
            suffix = (suffix + 1) * 10 - 1
    d += 1


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
vector<int> g[N];
int indeg[N], dp[N], vis[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m, mx = 0; cin>>n>>m;
    queue<int> q;
    for(int i = 1; i <= m; ++i) {
        int u,v; cin>>u>>v;
        g[u].push_back(v); indeg[v]++;
    }
    for(int i = 1; i <= n; ++i) {
        if(indeg[i] == 0)
            q.push(i);
    }
    while(q.size()) {
        int v = q.front(); q.pop();
        if(vis[v])
            continue;
        else {
            vis[v] = 1;
            for(int i = 0; i < g[v].size(); ++i) {
                --indeg[g[v][i]];
                dp[g[v][i]] = max(dp[g[v][i]], 1+dp[v]);
                if(indeg[g[v][i]] == 0)
                    q.push(g[v][i]);
            }
        }
    }
    for(int i = 1; i <= n; ++i) mx = max(mx, dp[i]);
    cout<<mx<<"\n";
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int n;
  cin >> n;
  double sum;
  rep(i, n) {
    double a;
    cin >> a;
    sum += 1.0/a;
  }
  cout << 1.0/sum << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
 
	int a, b, b2;
	
	cin >> a >> b;
	
	int ans = 0;
	b2 = b + b;
	if (a > b2) {
		cout << a - b2 << endl;
	} else {
		b2 = 0;
		cout << b2 << endl;
	}
      return 0;
}

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

#define ll long long

const ll M = 1e9 + 7;

ll Mod(ll a)
{
    return (a % M + M) % M;
}

ll MulMod(ll a, ll b)
{
    return Mod(Mod(a) * Mod(b));
}

ll AddMod(ll a, ll b)
{
    return Mod(Mod(a) + Mod(b));
}

ll SubMod(ll a, ll b)
{
    return Mod(Mod(a) - Mod(b));
}

void test()
{
    string s = "0";
    ll cnt = 0;

    while(s != "99999")
    {
        if(s.length() < 5)
        {
            for(ll i = 0; i < s.length(); i++)
            {
                if(s[i] == '9')
                {
                    cnt++;
                    break;
                }
            }
        }
        else
        {
            bool has9 = false;
            bool has0 = false;
            
            for(ll i = 0; i < s.length(); i++)
            {
                if(s[i] == '0')
                {
                    has0 = true;
                }

                if(s[i] == '9')
                {
                    has9 = true;
                }
            }

            if(has0 && has9)
            {
                cnt++;
            }
        }
        
        
        s = to_string(stoi(s) + 1);
    }

    cout << cnt << "\n";
}

int main()
{
    //test();
    //return 0;
    
    ll n;
    cin >> n;
    
    ll eight = 1;
    ll nine = 1;
    ll ten = 1;

    for(ll i = 0; i < n; i++)
    {
        eight = MulMod(eight, 8);
        nine = MulMod(nine, 9);
        ten = MulMod(ten, 10);
    }

    ll first = SubMod(ten, nine);
    ll second = SubMod(ten, nine);
    ll third = SubMod(ten, eight);

    ll ans = AddMod(first, second);
    ans = SubMod(ans, third);

    cout << ans;

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<math.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
const long MAX = 10000002;
const long MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];
long long P[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

void Pinit() {
	P[0] = 1;
	for (int i = 1; i < MAX; i++) {
		P[i] = P[i - 1] * 2 % MOD;
	}
}

int main() {
	long long N;
	long long L[18];
	long long ans;
	
	cin >> N;
	COMinit();
	Pinit();

	ans = 0;
	long long t = 0;
	for (int i = N / 2; i <= N; i += 1) {
		long long m = P[i] - t;
		if (m < 0) {
			m += MOD;
		}
		ans = (ans + COM(N, i) * m) % MOD;
		t = (t * 2 + COM(i, i - N / 2)) % MOD;
	}

	cout << ans << endl;
}

Measured memory_bytes: 313340
#include<set>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int x[3], counter=0;
  cin >> x[0] >> x[1] >> x[2];
  sort(x,x+3);
  if((x[1]-x[0])%2 == 0){
    counter +=(x[1]-x[0])/2 + x[2]-x[1];
  }
  else{
    counter +=(x[2]+1-x[0])/2 + (x[2]+1-x[1])/2 +1;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int henkann(int a) {
	if (a == 1) {
		return 9;
	}
	else {
		return 1;
	}
}

int main() {
	int a;
	cin >> a;
	int h, t, o;
	h = a / 100;//100の位

	t = a % 100;
	o = t % 10;
	t = t / 10;
	
	int out;
	out = henkann(h) * 100 + henkann(t) * 10 + henkann(o);
	cout << out;
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int countX(string str)
{
    int count = 0;
    for (int i = 0; i < str.size(); i++)
    {
        if (str[i] == 'x')
        {
            count++;
        }
    }
    
    return count;
}

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

    int num = countX(s);

    cout << ((num > 7) ? "NO" : "YES") << endl;
    return 0;
}

Measured memory_bytes: 256
X,Y =input().split()

count = 0

kame = 4
tsuru = 2

X = int(X)
Y = int(Y)

for i in range(0,X+1):
    if kame *i + tsuru*(X-i)==Y:
        count = 1
        
if count ==1:
    print("Yes")
else:
    print("No")

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

As = [int(a) for a in input().split()]


prod = 1
overflow_flag = False

if 0 in As:
    print(0)
else:
    for a in As:
        prod *= a

        if prod > 10**18:
            overflow_flag = True
            break

    if overflow_flag:
        print("-1")
    else:
        print(prod)


Measured memory_bytes: 21712
#include<stdio.h>
int main()
{
    int p,q,r;
    scanf("%d%d%d",&p,&q,&r);
    int a,b,c;
    a=p+q;
    b=r+p;
    c=r+q;
    int minn;
    if(a>b) minn=b;
    else minn=a;
    if(minn>c) minn=c;
    printf("%d\n",minn);
    return 0;
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  

const int MOD = M;

int ipow(int base, int exp)
{
    int ret = 1;
    base %= MOD;
    while(exp)
    {
        if(exp&1)
            ret = (ret*base)%MOD;
        exp >>= 1;
        base = (base*base)%MOD;
    }
    return ret%MOD;
}

int mod_inv(int base)
{
    return ipow(base, MOD-2);
}



int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n, a, b;
    cin >> n >> a >> b;
    int ans = ipow(2, n) - 1;
    int nca = 1, den = 1;
    for(int i=n-a+1;i<=n;i++) nca =(nca*i)%MOD;
    for(int i=1;i<=a;i++) den = (den*i)%MOD;
    ans = (ans-(nca*mod_inv(den))%MOD + MOD)%MOD;
    int ncb = 1;
    den = 1; 
    for(int i=n-b+1;i<=n;i++) ncb = (ncb*i)%MOD;
    for(int i=1;i<=b;i++) den = (den*i)%MOD;
    ans = (ans -(ncb*mod_inv(den))%MOD + MOD)%MOD;

    cout << (ans+MOD)%MOD << "\n";

    return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
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())
w, a, b = M()
x = abs(a-b)
print(max(0, x-w))

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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N, M;
    std::cin >> N >> M;

    vector<int> X(M);
    REP(i, M) {
        std::cin >> X[i];
    }

    SORT(X);

    vector<int> X_diff;
    for(int i = 1; i < M; i++) {
        X_diff.push_back(X[i] - X[i - 1]);
    }

    SORT(X_diff);

    int num_rm = (N - 1 < X_diff.size()) ? N - 1 : X_diff.size();
    std::cout << accumulate(X_diff.begin(), X_diff.begin() + X_diff.size() - num_rm, 0) << std::endl;

    return 0;
}


Measured memory_bytes: 1276
from itertools import permutations

N, M = map(int, input().split())
ab = [[int(_) for _ in input().split()] for _ in range(M)]
Graph = [[] for _ in range(N+1)]
cand = list(permutations(range(1, N+1), N))
ans = 0

for i in ab:
    Graph[i[0]].append(i[1])
    Graph[i[1]].append(i[0])

for i in cand:
    if i[0] != 1:
        break
    flag = True
    for j in range(len(i)-1):
        if not (i[j+1] in Graph[i[j]]):
            flag = False
            break
    
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll h,w;
  	ci(h>>w);
  vst A(h);
  FOR(i,0,h){
    ci(A[i]);
  }
  st s;
  FOR(i,0,w){
    s+='.';
  }

  FOR(i,0,h){
    if(A[i]==s) continue;
    
    else{
    FOR(j,0,w){
      bool b=false;
      FOR(k,0,h){
        if(A[k][j]!='.'){
          b=true;
            break;
        }
      }
        if(b) cout<<A[i][j];
    }
    }
    co(" ")
  }
}

Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-09 15:06:40
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=500010,mod=998244353;
i64 f[N],F[N],n,k,ans;
i64 power(i64 a,i64 b,i64 p)
{
	i64 r=1;
	for(;b;b>>=1,a=a*a%p) if(b&1) r=r*a%p;
	return r;
}
i64 inv(i64 a){ return power(a,mod-2,mod); }
i64 C(i64 a,i64 b){ return a<0||b<0||a<b?0:f[a]*F[a-b]%mod*F[b]%mod; }
int main()
{
	k=read(); n=read(); f[0]=1;
	fr(i,1,n) f[i]=f[i-1]*i%mod;
	F[n]=inv(f[n]);
	fd(i,n,1) F[i-1]=F[i]*i%mod;
	fr(i,1,n) if(i>=n-i&&i>=k)
	{
		if(i-(n-i)>=k) ans=(ans+C(n,i))%mod;
		else ans=(ans+C(n-(i+i==n),i)-C(n-(i+i==n),i+i-k+1)+mod)%mod;
//		printf("%d %d\n",i,int(ans));
		//(0,0)->(n,2i-n)
		//y > (k-i)-1
		//(0,0)->(n,4i-2k-n+2)
	}
	printf("%d\n",int(ans));
	return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
const int INF=1e9;
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  string s;cin>>s;
  for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(s[i]!=s[j])fin("Yes");
  fin("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  char c[3][3];
  rep(i,3) rep(j,3) cin >> c[i][j];
  cout << c[0][0] << c[1][1] << c[2][2] << "\n";
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  int w,h,x,y,r;
  cin>>w>>h>>x>>y>>r;
  if(0<=x-r&&x+r<=w&&0<=y-r&&y+r<=h)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3080
#include<stdio.h>
int main()
{
  char c;
  int x[26],i;
  for(i=0;i<26;i++) x[i]=0;
  while(scanf("%c",&c)!=EOF)
    {
      if((c>='A')&&(c<='Z')) c+='a'-'A';
      if((c>='a')&&(c<='z')) x[c-'a']++;
    }
  for(i=0;i<26;i++) printf("%c : %d\n",i+'a',x[i]);
  return 0;
}


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

using namespace std;

/*
int main() {
	long long int X, Y, Z;
	cin >> X >> Y >> Z;
	vector < long long int >XYZ( 3 );
	XYZ[0] = X;
	XYZ[1] = Y;
	XYZ[2] = Z;

	vector<vector<long long int>>D( X + Y + Z, vector<long long int>( 3 ) );

	priority_queue<pair<long long int, pair<long long int, pair<int, int>>>, vector<pair<long long int, pair<long long int, pair<int, int>>>>>que;
	for( size_t i = 0; i < X + Y + Z; i++ ) {
		for( size_t j = 0; j < 3; j++ ) {
			cin >> D[i][j];
		}

//		if( D[i][0] >= D[i][1] && D[i][0] >= D[i][2] ) {
		que.push( make_pair( D[i][0] - D[i][2], make_pair( i, make_pair( 0, 2 ) ) ) );
		que.push( make_pair( D[i][0] - D[i][1], make_pair( i, make_pair( 0, 1 ) ) ) );
		//		}
//		if( D[i][1] >= D[i][0] && D[i][1] >= D[i][2] ) {
		que.push( make_pair( D[i][1] - D[i][0], make_pair( i, make_pair( 1, 0 ) ) ) );
		que.push( make_pair( D[i][1] - D[i][2], make_pair( i, make_pair( 1, 2 ) ) ) );
		//		}
//		if( D[i][2] >= D[i][1] && D[i][2] >= D[i][0] ) {
		que.push( make_pair( D[i][2] - D[i][1], make_pair( i, make_pair( 2, 1 ) ) ) );
		que.push( make_pair( D[i][2] - D[i][0], make_pair( i, make_pair( 2, 0 ) ) ) );
		//		}
	}
	long long int ans = 0;
	vector<bool>used( X + Y + Z );
	while( que.size() ) {
		auto now = que.top(); que.pop();
		if( used[now.second.first] ) {
			continue;
		}

		if( !XYZ[now.second.second.first] && XYZ[now.second.second.second] ) {
			continue;
		}
		used[now.second.first] = true;

		ans += D[now.second.first][now.second.second.first];
		XYZ[now.second.second.first]--;
	}
	cout << ans << endl;
}

*/

int main() {
	long long int N, M;
	cin >> N >> M;
	vector<vector<long long int>>D( N, vector<long long int>( M ) );
	for( size_t i = 0; i < N; i++ ) {
		for( size_t j = 0; j < M; j++ ) {
			cin >> D[i][j];
			D[i][j]--;
		}
	}
	long long int ans = N;
	for( size_t idx = 0; idx < M; idx++ ) {
		vector<long long int>count( M );
		long long int maxv = 0, maxidx = -1;
		for( size_t i = 0; i < N; i++ ) {
			count[D[i][0]]++;
			if( maxv<count[D[i][0]] ) {
				maxv = count[D[i][0]];
				maxidx = D[i][0];
			}
		}

		ans = min( maxv, ans );

		for( size_t i = 0; i < N; i++ ) {
			auto now = D[i].begin();
			while( *now != maxidx ) {
				now++;
			}
			D[i].erase( now );
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int yoko = scan.nextInt();
        int tate = scan.nextInt();
        String c = scan.next();
        int i;
        int y;
        for (i = 1; i <= tate; i++) {
            for (y = 1; y <= yoko; y++) {
                if (i == 1 && y == 1 || i == tate && y == yoko || i == 1 && y == yoko || y == 1 && i == tate) {
                    System.out.print("+");
                } else if (y == 1 || y == yoko) {
                    System.out.print("|");
                } else if (i == 1 || i == tate) {
                    System.out.print("-");
                } else if (i == tate / 2 + 1 && y == yoko / 2 + 1) {
                    System.out.print(c);
                } else {
                    System.out.print(".");
                }
            }
            System.out.println("");
        }

    }

}



Measured memory_bytes: 26172
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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 ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  int n;
  cin>>n;
  int a[n];
  int cnt = 1;
  for(int i = 0; i < n; i++){
    cin>>a[i];
    if(a[i] == cnt) cnt++;
  }
  if((cnt-1)==0) cout<<-1<<endl;
  else cout<<n-(cnt-1)<<endl;
  return 0;
}



Measured memory_bytes: 1024
MOD=10**9+7
def pow(x,n,mod):
    ans = 1
    while n>0:
        if n&1==1:
            ans*=x
            ans%=mod
        x = x*x
        x%=mod
        n = n>>1
    return ans

N,a,b=map(int,input().split())
xa=1
for i in range(N,N-a,-1):
  xa*=i
  xa%=MOD
xb=xa
for i in range(N-a,N-b,-1):
  xb*=i
  xb%=MOD
ya=1
for i in range(2,a+1):
  ya*=i
  ya%=MOD
yb=ya
for i in range(a+1,b+1):
  yb*=i
  yb%=MOD
ans=(pow(2,N,MOD)-1
     -(xa*pow(ya,MOD-2,MOD)%MOD)
     -(xb*pow(yb,MOD-2,MOD)%MOD))%MOD
print(ans)

Measured memory_bytes: 65304
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX_N 100000

struct dfs_r {
  int counter;
  int prenum[MAX_N];
  int parent[MAX_N];
  int lowest[MAX_N];
  bool visited[MAX_N];
  bool cut[MAX_N];
  
  dfs_r() {
    counter = 1;
    fill(visited, visited+MAX_N, false);
    fill(cut, cut+MAX_N, false);
  }
};

void dfs(int u, int prev, int root, dfs_r &r, vector<int> *es) {
  int child_c = 0;
  r.prenum[u] = r.counter;
  r.lowest[u] = r.counter;
  r.counter++;
  r.visited[u] = true;
  for(vector<int>::iterator itr=es[u].begin(); itr!=es[u].end(); ++itr) {
    int v = *itr;
    if(!r.visited[v]) {
      child_c++;
      r.parent[v] = u;
      dfs(v, u, root, r, es);
      r.lowest[u] = min(r.lowest[u], r.lowest[v]);
    } else if(v != prev) {
      r.lowest[u] = min(r.lowest[u], r.prenum[v]);
    }
  }
  if(u==root) {
    r.parent[u] = -1;
    if(child_c>=2) {
      r.cut[u] = true;
    }
  } else if(r.parent[u] != root && r.prenum[r.parent[u]]<=r.lowest[u]) {
    r.cut[r.parent[u]] = true;
  }
}

bool solve() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> es[MAX_N];
  for(int i=0; i<m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    es[a].push_back(b);
    es[b].push_back(a);
  }
  dfs_r r;
  for(int i=0; i<n; i++) {
    if(!r.visited[i]) {
      dfs(i, -1, i, r, es);
    }
  }
  
  for(int i=0; i<n; i++) {
    if(r.cut[i]) {
      printf("%d\n", i);
    }
  }
  
  return true;
}

int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 6840
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<pair<double, double>> p(n);

	for (int i = 0; i < n; i++)
	{
		double x, y;
		cin >> x >> y;

		p[i].first = x;
		p[i].second = y;
	}

	double sum = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i != j)
			{
				sum += sqrt((p[i].first - p[j].first) * (p[i].first - p[j].first) + (p[i].second - p[j].second) * (p[i].second - p[j].second));
			}
		}
	}

	printd(sum / n, 10)
}


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

typedef long long int ll;
typedef pair<int,int> pii;
const int mod = 1e9+7;

const double pi = acos(-1);

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int a = 0;
    for(int i=0;i<m;i++){
        int num;
        scanf("%d",&num);
        a+=num;
    }
    if(a==n) printf("0\n");
    else if(a>n) printf("-1\n");
    else printf("%d\n",n-a);

	return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
int main(void){
    int i,j,n,num,a[10];
    
    while(1){
        scanf("%d",&n);
        if(n==0)break;
        
        for(i=0;i<10;i++){
            a[i]=0;
        }
        
        for(i=0;i<n;i++){
            scanf("%d",&num);
            a[num]++;
        }
        
        for(i=0;i<10;i++){
            if(a[i]==0){
                puts("-");
                continue;
            }
            for(j=0;j<a[i];j++){
                printf("*");
            }
            puts("");
        }
    }
    return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}
string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}
 
string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	double k,ans,cur;
	cin>>n;
	ans=0;
	while (n--)
	{
		cin>>k;
		cur=1;
		cur/=k;
		ans+=cur;
	}
	ans=1/ans;
	cout<<setprecision(10)<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Yes(X) puts ( (X) ? "Yes" : "No")
#define YES(X) puts ( (X) ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = (a); i < (b) ; i++)
#define rep(i, n) for ( int i = 0; i < (n) ; i++)
const int MOD = 1000000007;
typedef long long ll;
typedef unsigned  u;
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0) return Lgcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / Lgcd(a, b) * b;
}
/* main */
int main() {
  int n, x[100], y[100], h[100], k = 0;
  cin >> n;
  rep(i, n) cin >> x[i] >> y[i] >> h[i];
  rep(i, 101){
    rep(j, 101){
      bool f = true;
      for(k; k < n; k++) if(h[k])break;
      int H = h[k] + abs(i - x[k]) + abs(j - y[k]);
      rep(l, n) if(h[l] != max(H - abs(i - x[l]) - abs(j - y[l]), 0)) f = false;
      if(f) cout << i << " " << j << " " << H << endl;
    }
  }
}

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

int main() {
	string s;
	cin >> s;
	string k = "No";
	sort(s.begin(),s.end());
	if(s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(1) != s.at(2))
	{
		k = "Yes";
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i, n) for(int i = 2; 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++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	string a;
	REP(i, n) {
		cout <<  s.at(i) << t.at(i);
	}
	cout << a << endl;
}

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

int main(){

  while(1){

    int x,y;

    cin>>x>>y;

    if(x==0 && y==0 ) break;

    if(x>y) swap(x,y);

    cout<<x<<" "<<y<<endl;

  }


  return 0;

}



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


MAX = 10**9+7

def pow_k(x, n):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
        K %= MAX

    return K * x



if N == 1:
    print(0)
elif N == 2:
    print(2)
else:
    res = pow_k(10, N) - 2*pow_k(9, N) + pow_k(8, N) 
    print(res % MAX)

Measured memory_bytes: 10176