akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define MAX 200005
#define forl(i, start, stop, step) for (int i = start; i < stop; i += step)
#define rforl(i, start, stop, step) for (int i = start; i > stop; i += step)
#define pii pair<int, int>
#define F first
#define S second
#define vi vector<int>
#define vpii vector< pii >
#define vll vector<ll>
#define pb push_back

vector<int> blocks[MAX];
int ans[MAX];
int main() {
	int n, q; scanf("%d%d", &n, &q);
	forl(i, 0, n, 1) {
	    int s, t, x; scanf("%d%d%d", &s, &t, &x);
	    blocks[i].pb(x); blocks[i].pb(s); blocks[i].pb(t);
	}
	set<pii> d;
	forl(i, 0, q, 1) {
	    int x; scanf("%d", &x);
	    d.insert(pii(x, i));
	}
	sort(blocks, blocks + n);
	
	memset(ans, -1, sizeof(ans));
	forl(i, 0, n, 1) {
	    int x = blocks[i][0], s = blocks[i][1], t = blocks[i][2];
	    int l = s - x, r = t - x - 1;
	     auto lit = d.lower_bound(pii(l, -1));
	     auto rit = d.upper_bound(pii(r, q + 1));
	     if (lit == rit) continue;
	     for (auto it = lit; it != rit; ++it) {
	         pii dd = *it;
	         int di = dd.F, idx = dd.S;
	         ans[idx] = x;
	     }
	     d.erase(lit, rit);
	}
	
	forl(i, 0, q, 1) printf("%d\n", ans[i]);
	
	return 0;
}

Measured memory_bytes: 23040
s = input()
a = s[0]
b = s[1]
c = s[2]
d = s[3]

cnt = 0

if a==b:
    cnt +=1
if a==c:
    cnt+=1
if a==d:
    cnt+=1

if b==c:
    cnt += 1
if b==d:
    cnt+=1
if c==d:
    cnt+=1

if cnt == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N;
}
int dp[MX + 20];
void solve() {
  rep(i, 1, 100000) { dp[i] = i; }

  int p6 = 1;
  rep(i, 0, 100000) {
    p6 = 1;
    rep(p, 1, 15) {
      p6 *= 6;
      if (i + p6 < MX) dp[i + p6] = min(dp[i + p6], dp[i] + 1);
    }
  }

  int p9 = 1;
  rep(i, 0, 100000) {
    p9 = 1;
    rep(p, 1, 13) {
      p9 *= 9;
      if (i + p9 < MX) dp[i + p9] = min(dp[i + p9], dp[i] + 1);
    }
  }

  cout << dp[N] << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> pi;


typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,m;
	cin>>n>>m;
	cout<<(n*m)/gcd(n,m)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    private static Scanner scanner = new Scanner(System.in);
    private static final int N = 100;
    private static final int INF = -1;
    private static int[][] Mat = new int[N][N];
    private static int[] Distance = new int[N];
    private static Queue<Integer> queue = new LinkedList<>();
    private static int n;

    public static void main(String[] args){

        graph_input();

        bfs(0);

        for (int i = 0; i < n; i++) {
            System.out.print((i+1) + " " + Distance[i] + "\n");
        }
    }

    private static void bfs(int s) {
        queue.add(s);

        for (int i = 0; i < n; i++) {
            Distance[i] = INF;
        }

        Distance[s] = 0;

        int u;
        while (!queue.isEmpty()){
            u = queue.peek();
            queue.remove();

            for (int v = 0; v < n; v++) {
                if (Mat[u][v] == 0) continue;
                if (Distance[v] != INF) continue;
                queue.add(v);
                Distance[v] = Distance[u] + 1;
            }
        }
    }


    private static void graph_input() {

        n = scanner.nextInt();

        int u, k, v;
        for (int i = 0; i < n; i++) {
            u = scanner.nextInt();
            k = scanner.nextInt();
            for (int j = 0; j < k; j++) {
                v = scanner.nextInt();
                Mat[u-1][v-1] = 1;
            }
        }
    }
}

Measured memory_bytes: 27936
import numpy as np

n = int(input())
h = list(map(int, input().split()))

cost = np.zeros(n)
for i in range(n-1, -1, -1):
    if i==n-1:
        cost[i] = 0
    elif i==n-2:
        cost[i] = abs(h[i+1]-h[i])
    else:
        cost[i] = min(cost[i+1]+abs(h[i+1]-h[i]),
                    cost[i+2]+abs(h[i+2]-h[i]))

print(int(cost[0]))

Measured memory_bytes: 22736
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		
		for (int i = 0; i < str.length(); i++){
			if (Character.isUpperCase(str.charAt(i))){
				System.out.print(Character.toLowerCase(str.charAt(i)));
			} else if (Character.isLowerCase(str.charAt(i))) {
				System.out.print(Character.toUpperCase(str.charAt(i)));
			} else {
				System.out.print(str.charAt(i));
			}
		}
		System.out.println("");
	}
}

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

int main() {
    string s;
    cin >> s;
    if(s[0] == 'A' && s[1] == 'A' && s[2] == 'A')
        cout << "No" << endl;
    else if(s[0] == 'B' && s[1] == 'B' && s[2] == 'B')
        cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}

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

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

  char c = s[0];
  bool flg = false;
  int cnt=0;
  for (int i = 1; i < n; i++)
  {
    if(s[i]!=c){
      if(!flg){
        flg=true;
        cnt++;
      }
      s[i]=c;
      flg = true;
    }
    else{
      flg = false;
      if(cnt==k) break;
    }
  }
  
  int ans=0;
  for (int i = 0; i < n-1; i++)
  {
    if(s[i]==s[i+1]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  X=I()

  sm1=sm2=0
  for i in range(1010):
    sm1+=100
    sm2+=105
    if sm1<=X and X<=sm2:
      return 1
  return 0

# main()
print(main())


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


/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
/*
int main(){
    string N;
    cin>>N;
    ll ans=0;
    ll sizee=N.size();
    reverse(N.begin(),N.end());
    for(ll i=0;i<sizee;i++){
        if(N.at(i)=='1' || N.at(i)=='2' || N.at(i)=='3' || N.at(i)=='4'){
            ans+=func(N.at(i));
        }
    }
}
*/
//失敗コードの残骸


//dp法なるもので求められるらしい。
//他の人のコードを見ながら書いたが、初期値の扱いがヘンテコになった。(dp.at(0)が無駄になっている。)
int main(){
    string S;//さすがにstringはS
    cin>>S;
    reverse(S.begin(),S.end());//1234なら4321になる
    int n=S.size();//長さ
    vector<vector<int>> dp(n+1,vector<int> (2,0));//最初はdp.at(0)=(0,0)から計算する腹つもりだったが、これだとdp.at(1).at(1)が1小さくなるのに気付いた。
    for(int i=0;i<n;i++){
        int p=S.at(i)-'0';
        if(i==0){//仕方なく初期値のみ例外処理
            dp.at(i+1).at(0)=p;
            dp.at(i+1).at(1)=10-p+1;
        }
        else{
            dp.at(i+1).at(0)=min(dp.at(i).at(0)+p,dp.at(i).at(1)+p);
            dp.at(i+1).at(1)=min(dp.at(i).at(0)+10-p+1,dp.at(i).at(1)+10-p-1);
        }
    }
    cout<<min(dp.at(n).at(0),dp.at(n).at(1))<<endl;
}

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


int main() {
  string s, t;
  int ans = 1000000;
  cin >> s >> t;

  vector<int>table(s.size()-t.size()+1);

  for (int i = 0; i < s.size()-t.size()+1; i++) {
    for(int j = 0; j < t.size(); j++) {
      if(t.at(j) != s.at(i+j)) table.at(i)++;
    }
  }
  for (int i = 0; i < table.size(); i++) {
    ans = min(ans, table.at(i));
  }
  cout << ans << endl;
}

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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(max(a,b)-min(a,b)>max(a,c)-min(a,c)){
		cout<<'B'<<endl;
    }else{
		cout<<'A'<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
sa=input()
sb=input()
sc=input()
pta=0
ptb=0
ptc=0
turn="a"
for i in range(300):
 if pta==len(sa) and turn=="a":
  print("A")
  break
 elif ptb==len(sb) and turn=="b":
  print("B")
  break
 elif ptc==len(sc) and turn=="c":
  print("C")
  break
 elif turn=="a":
  turn=sa[pta]
  pta+=1
 elif turn=="b":
  turn=sb[ptb]
  ptb+=1
 else:
  turn=sc[ptc]
  ptc+=1

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

int main() {
	int a, b; cin >> a >> b;
	if (a >= 13) {
		cout << b << endl;
	}
	else if (a >= 6) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int,int> pii;
const int mod = (int) 1000000007;
const int inf = (int) 2e18;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
  // code
  int d, s, t;
  cin >> d >> s >> t;
  if(s*t >= d) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}

Measured memory_bytes: 3648
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	as := make([][][]int, 4)

	for i := 0; i < n; i++ {
		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		y, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		switch sc.Text() {
		case "R":
			as[0] = append(as[0], []int{x, y})
		case "U":
			as[1] = append(as[1], []int{x, y})
		case "L":
			as[2] = append(as[2], []int{x, y})
		case "D":
			as[3] = append(as[3], []int{x, y})
		}
	}

	const inf = int(1e15)
	mt := inf

	for _, d := range []int{0, 1} {
		m := make(map[int][][]int)
		for _, i := range []int{d, d + 2} {
			for _, v := range as[i] {
				m[v[1-d]] = append(m[v[1-d]], []int{v[d], i})
			}
		}
		for _, v := range m {
			sort.Slice(v, func(i, j int) bool { return v[i][0] < v[j][0] })
			var md bool
			var pv int
			for _, p := range v {
				if p[1] == d {
					md = true
					pv = p[0]
				} else if md == true {
					mt = min(mt, (p[0]-pv)*5)
					md = false
				}
			}
		}
	}

	for _, d := range []int{0, 1, 2, 3} {
		m := make(map[int][][]int)
		for _, i := range []int{d, (d + 1) % 4} {
			for _, v := range as[i] {
				k := v[0] + v[1]
				if d%2 == 1 {
					k -= v[1] * 2
				}
				m[k] = append(m[k], []int{v[0], i})
			}
		}
		for _, v := range m {
			sort.Slice(v, func(i, j int) bool { return v[i][0] < v[j][0] })
			var md bool
			var pv int
			for _, p := range v {
				mi := d
				if d >= 2 {
					mi = (d + 1) % 4
				}
				if p[1] == mi {
					md = true
					pv = p[0]
				} else if md == true {
					mt = min(mt, (p[0]-pv)*10)
					md = false
				}
			}
		}
	}

	if mt == inf {
		fmt.Println("SAFE")
	} else {
		fmt.Println(mt)
	}
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 86104
#template
def inputlist(): return [int(j) for j in input().split()]
#template
dx = [1,1,0,-1,-1,-1,0,1]
dy = [0,1,1,1,0,-1,-1,-1]
from collections import deque
def dfs(x,y,w,h,lis,flag):
    if lis[x][y] == 1:
        flag = 1
        lis[x][y] = 0
        stack = deque([])
        l = [x,y]
        stack.appendleft(l)
        while len(stack) != 0:
            li = stack.popleft()
            xa = li[0]
            ya = li[1]
            for i in range(8):
                nx = xa + dx[i]
                ny = ya + dy[i]
                if nx < 0 or ny < 0 or nx > h-1 or ny > w-1:
                    continue
                if lis[nx][ny] == 0:
                    continue
                stack.appendleft([nx,ny])
                lis[nx][ny] = 0
    if flag:
        return 1
    else:
        return 0

while True:
    w,h = inputlist()
    if w == 0 and h == 0:
        break
    maze = [[0] for _ in range(h)]
    for i in range(h):
        maze[i] = inputlist()
    ans = 0
    for x in range(h):
        for y in range(w):
            ans += dfs(x,y,w,h,maze,0)
    print(ans)


Measured memory_bytes: 6044
#include <iostream>
#define ll long long
using namespace std;

int main(){
  string S,T; cin >> S >> T;
  int count=0;

  for(int i=0; i<3; i++){
    if(S[i]==T[i]){count++;}
  }
  
  cout << count;
  
  return 0;
}

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

void chmin (int &x, int a) {
    x = min(x, a);
}

const int inf = 1e9 + 13;

signed main () {
    int n, k;
    cin >> n >> k;
    vector < int > a(n);
    for (int &x: a)
        cin >> x;
    int ans = inf;
    for (int i = 0; i + k <= n; ++i) 
        chmin(ans, a[i + k - 1] - a[i] + abs(a[i]));
    for (int i = n - 1; i - k + 1 >= 0; --i)
        chmin(ans, a[i] - a[i - k + 1] + abs(a[i]));
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,t,a,i,h,c=1000000000,ans;
	cin>>n>>t>>a;
	for (i=0;i<n;i++){
		cin>>h;
		if (abs(500*(a-t)+3*h)<c){
			ans=i+1;
			c=abs(500*(a-t)+3*h);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int calc(int a, int b, char op){
	if(op=='+') return a+b;
	if(op=='-') return a-b;
	if(op=='*') return a*b;
}


signed main() {
	while (1) {
		int sum = 0;
		vi d;
		rep(i, 0, 4) {
			int num;
			cin >> num;
			d.push_back(num);
			sum += d[i];
		}
		if (sum == 0) break;
		bool f = false;
		char op[4] = { "+-*" };
		sort(all(d));
		do {
			/*rep(i, 0, 4) {
				cout << d[i] << " ";
			}
			cout << endl;*/
			rep(i, 0, 3) {
				rep(j, 0, 3) {
					rep(k, 0, 3) {
						int t1 = calc(d[0], d[1], op[i]);
						int t2 = calc(d[2], d[3], op[k]);
						int t3 = calc(t1, d[2], op[j]);
						int t4 = calc(d[1], d[2], op[j]);
						int t5 = calc(d[0], t4, op[i]);
						int t6 = calc(d[1], t2, op[j]);
						int t7 = calc(t4, d[3], op[k]);
						if (calc(t1, t2, op[j]) == 10) {
							printf("((%d %c %d) %c (%d %c %d))\n", d[0], op[i], d[1], op[j], d[2], op[k], d[3]);
							k = 3; j = 3; i = 3; f = true;
						}
						else if (calc(t3, d[3], op[k]) == 10) {
							printf("(((%d %c %d) %c %d) %c %d)\n", d[0], op[i], d[1], op[j], d[2], op[k], d[3]);
							k = 3; j = 3; i = 3; f = true;
						}
						/*else if (calc(t5, d[3], op[k]) == 10) {
							printf("((%d %c (%d %c %d)) %c %d)\n", d[0], op[i], d[1], op[j], d[2], op[k], d[3]);
							k = 3; j = 3; i = 3; f = true;
						}
						else if (calc(d[0], t6, op[i]) == 10) {
							printf("(%d %c (%d %c (%d %c %d)))\n", d[0], op[i], d[1], op[j], d[2], op[k], d[3]);
							k = 3; j = 3; i = 3; f = true;
						}
						else if (calc(d[0], t7, op[i]) == 10) {
							printf("(%d %c ((%d %c %d) %c %d))\n", d[0], op[i], d[1], op[j], d[2], op[k], d[3]);
							k = 3; j = 3; i = 3; f = true;
						}*/
						if(f) break;
					}
					if(f) break;
				}
				if(f) break;
			}
			if (f) break;
		} while (next_permutation(all(d)));
		if (f == false) cout << 0 << endl;
	}
}

Measured memory_bytes: 1244
n, m, q = gets.split.map(&:to_i)
set = q.times.map {gets.split.map(&:to_i)}

maximum = 0

[*1..m].repeated_combination(n) do |seq|
  score = 0
  set.each do |a, b, c, d|
    score += d if seq[b - 1] - seq[a - 1] == c
  end
  maximum = [maximum, score].max
end

puts maximum

Measured memory_bytes: 14620
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    println!("{}", read::<u64>() * read::<u64>());
}


Measured memory_bytes: 2132
import java.util.Scanner;

public class Main {

    private final static Scanner sc = new Scanner(System.in);

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int x = nextInt();
        int a = nextInt();
        int b = nextInt();

        int ax = Math.abs(x - a);
        int bx = Math.abs(x - b);

        if (ax < bx) {
            out("A");
        } else {
            out("B");
        }
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}

Measured memory_bytes: 23892
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
	public static void main(String [] args)throws Exception{
		BufferedReader Reader = new BufferedReader (new InputStreamReader(System.in));
		int j=0;
		int N = Integer.parseInt(Reader.readLine());
		String A[] = Reader.readLine().split(" ",0);
		for(int i=0;i<=N-1;i++){
			String v = A[i];
			j = i-1;
			while (j>=0 && Integer.parseInt(A[j])>Integer.parseInt(v)){
				A[j+1] = A[j];
				j--;
			}
			A[j+1] = v;
			System.out.println(String.join(" ",A));
		}
	}
}

Measured memory_bytes: 27816
#include<bits/stdc++.h>
using namespace std;
int find_max(int i,vector<vector<int>>&adj,vector<int>&maxpath)
{
    if(maxpath[i]!=-1)
        return maxpath[i];
    if(adj[i].size()==0)
    {
        maxpath[i]=0;
        return 0;
    }
    int ans=-1;
    for(int j=0;j<adj[i].size();j++)
    {
        ans=max(ans,find_max(adj[i][j],adj,maxpath)+1);
    }
    maxpath[i]=ans;
    return ans;

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

vector<vector<int>>adj(n+1);
int x,y;
vector<bool>source(n+1,true);
for(int i=0;i<m;i++)
{
    cin>>x>>y;
    adj[y].push_back(x);
    source[x]=false;
}
vector<int>maxpath(n+1,-1);
int ans=-1;
for(int i=1;i<=n;i++)
{
    if(source[i]==true)
    {
        ans=max(ans,find_max(i,adj,maxpath));
    }
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 12416
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

template<typename InputIterator> string join(InputIterator first, InputIterator last, const string &sep) {
  if (first == last) return "";
  stringstream ss;
  ss << *(first++);
  for_each(first, last, [&](auto &x) { ss << sep << x; });
  return ss.str();
}

main() {
  int n, q;
  cin >> n >> q;
  vector<list<int>> l(n);
  while (q--) {
    int c = in();
    if (c == 0) {
      int t, x;
      cin >> t >> x;
      l[t].emplace_back(x);
    }
    if (c == 1) {
      int t = in();
      cout << join(all(l[t]), " ") << endl;
    }
    if (c == 2) {
      int s, t;
      cin >> s >> t;
      l[t].splice(l[t].end(), l[s]);
    }
  }
}



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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,m,k;
	cin >> n >> m >> k;
	
	vector<int> a(n),b(m);
	for(int i=0;i<n;i++) cin >> a[i];
	for(int j=0;j<m;j++) cin >> b[j];
	
	int mb=1<<29;
	for(int i=0;i<m;i++){
		mb=min(mb,b[i]);
	}
	
	vector<vector<pair<int,int>>> ad(n);
	for(int i=0;i<k;i++){
		int x,y,w;
		cin >> x >> y >> w;
		x--,y--;
		ad[x].push_back(make_pair(y,w));
	}
	
	int res=1<<29;
	for(int i=0;i<n;i++){
		int mc=1<<29;
		for(pair<int,int> p:ad[i]){
			int ch=p.first;
			mc=min(mc,b[ch]-p.second);
		}
		mc=min(mc,mb);
		res=min(res,mc+a[i]);
	}
	cout << res << "\n";
	return 0;
}

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

using namespace std;

string answer(string x) {
  if (x[0] == 'Y' && x[1] == 'A' && x[2] == 'K' && x[3] == 'I') return "Yes";
  return "No";
}

int main() {
  string s;
  cin >> s;
  cout << answer(s);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=50,M=(1<<17)+10;

#define bit(x) (1ll<<(x))
#define pin(x,s) (((x)&(s))==(x))

int n,q,l[N],r[N],m,cnt;
ll pw[N],seg[N];
VI v;
ll ans,dp[M],pd[M],ins[M],pr[M];
int f[N];
int find(int x) {
	return f[x]==x?x:f[x]=find(f[x]);
}
/*
void dfs(int u,ll way) {
	if (u==m-1) {
		ans=(ans+way*pw[f[u].cnt-1])%mod;
	} else {
		rep(i,0,m) f[u+1].a[i]=f[u].a[i]; f[u+1].cnt=f[u].cnt;
		if (f[u+1].find(u)==f[u+1].find(u+1)) {
			dfs(u+1,way*(seg[u]+1)%mod);
		} else {
			dfs(u+1,way*seg[u]%mod);
			f[u+1].merge(u,u+1);
			dfs(u+1,way);
		}
	}
}
*/

int main() {
	scanf("%d",&n);
	scanf("%d",&q);
	rep(i,0,q) {
		scanf("%d%d",l+i,r+i);
		v.pb(l[i]-1);
		v.pb(r[i]);
	}
	sort(all(v));
	v.erase(unique(all(v)),v.end());
//.	bool f0=(v[0]==1);
	m=SZ(v);
	rep(i,0,m-1) {
		seg[i]=(powmod(10,v[i+1]-v[i])-1)*powmod(9,mod-2)%mod;
	}
	pw[0]=1;
	rep(i,1,m+1) pw[i]=pw[i-1]*9%mod;
	rep(i,0,q) {
		l[i]=lower_bound(all(v),l[i]-1)-v.begin();
		r[i]=lower_bound(all(v),r[i])-v.begin();
	}
	rep(i,0,m) f[i]=i;
	rep(i,0,q) {
		if (find(l[i])!=find(r[i])) f[find(l[i])]=find(r[i]);
	}
	cnt=0;
	rep(i,0,m) if (find(i)==i) {
		rep(j,0,m) if (find(j)==find(i)) pr[j]=bit(cnt);
		++cnt;
	}
//	printf("gg %d\n",cnt);
	rep(S,0,bit(cnt)) {
		// inside
		ins[S]=1;
		rep(i,0,m-1) {
			if (pin(pr[i],S)&&pin(pr[i+1],S)) ins[S]=ins[S]*(seg[i]+1)%mod;
		}
//		printf("%d %d\n",S,ins[S]);
	}
//	puts("faq");
	rep(S,0,bit(cnt)) {
		pd[S]=ins[S];
		int w=__builtin_ctz(S);
		int ps=S^bit(w),rs=ps;
		while (ps!=0) {
			ll ww=1;
			rep(i,0,m-1) if ((pin(pr[i],ps)&&pin(pr[i+1],S^ps))||
				(pin(pr[i+1],ps)&&pin(pr[i],S^ps))) ww=ww*seg[i]%mod;
			pd[S]=(pd[S]-ins[ps]*pd[S^ps]%mod*ww)%mod;
			ps=(ps-1)&rs;
		}
//		printf("%d %d\n",S,pd[S]);
	}
//	puts("faq");

	rep(S,0,bit(cnt)) {
		dp[S]=pd[S];
		int w=__builtin_ctz(S);
		int ps=S^bit(w),rs=ps;
		while (ps!=0) {
			ll ww=9;
			rep(i,0,m-1) if ((pin(pr[i],ps)&&pin(pr[i+1],S^ps))||
				(pin(pr[i+1],ps)&&pin(pr[i],S^ps))) ww=ww*seg[i]%mod;
			dp[S]=(dp[S]+dp[ps]*pd[S^ps]%mod*ww)%mod;
			ps=(ps-1)&rs;
		}
	}
	ll ans=dp[bit(cnt)-1];
	if (ans<0) ans+=mod;
	ans=ans*powmod(10,v[0]+n-v[m-1])%mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 2688
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

signed main(void)
{
	string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;

	return 0;
}

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

void iSortAscend( char *, int );
void iSortDescend( char *, int );

int main( void ) {
	char aStr[ 20 ][ 7 ], min[ 7 ], max[ 7 ];
	int i, j, a0, L;

	while ( scanf( "%d %d", &a0, &L ), L ) {
		sprintf( aStr[ 0 ], "%0*d", L, a0 );

		for ( i = 1; ; i++ ) {
			strcpy( min, aStr[ i - 1 ] );
			iSortAscend( min, L );

			strcpy( max, aStr[ i - 1 ] );
			iSortDescend( max, L );

			sprintf( aStr[ i ], "%0*d", L, atoi( max ) - atoi( min ) );

			for ( j = 0; j < i; j++ )
				if ( !strcmp( aStr[ j ], aStr[ i ] ) )
					break;
			if ( j != i )
				break;
		}

		printf( "%d %d %d\n", j, atoi( aStr[ i ] ), i - j );
	}

	return 0;
}


void iSortAscend( char *data, int n ) {
	char tmp;
	int i, j;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		if ( data[ i - 1 ] > tmp ) {
			j = i;
			do {
				data[ j ] = data[ j - 1 ];
				j--;
			} while ( j > 0 && data[ j - 1 ] > tmp );
			data[ j ] = tmp;
		}
	}
}

void iSortDescend( char *data, int n ) {
	char tmp;
	int i, j;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		if ( data[ i - 1 ] < tmp ) {
			j = i;
			do {
				data[ j ] = data[ j - 1 ];
				j--;
			} while ( j > 0 && data[ j - 1 ] < tmp );
			data[ j ] = tmp;
		}
	}
}

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

int main() {
	
	int N;
	cin >>N;
	
	vector<int> vec(N);
	
	for(int i=0; i<N; i++){
		
		cin >>vec.at(i);
		
	}
	

	
	int max;
	max=*max_element(vec.begin(),vec.end());
	
	int total=0;
	
	for(int i=0; i<N; i++){
		
		total+=vec.at(i);
		
	}
	
	if(max<(total-max)){
		
		cout <<"Yes" <<endl;
		
	}
	else{
		
		cout <<"No" <<endl;
		
	}
	
	return 0;
	
}


Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int,input().split())) for _ in range(N)]
ls=[]
d=C
for i in range(N):
  for j in range(M):
    d+=A[i][j]*B[j]
  if d>0:
    ls.append(d)
  d=C
print(len(ls))

Measured memory_bytes: 3064
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

last = [0] * 26
satisfied = 0
for i in range(1, D+1):
    t = int(input())
    satisfied += s[i-1][t-1]
    last[t-1] = i
    for j in range(26):
        satisfied -= c[j] * (i-last[j])
    print(satisfied)



Measured memory_bytes: 9268
N,M=map(int,input().split())
p = list(map(int,input().split()))
for i in range(N): p[i] -= 1

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

def uf_root(a):
  if par[a] == a: return a
  par[a] = uf_root( par[a] )
  return par[a]

def uf_same(a,b):
  if (uf_root(a) ==uf_root(b)): return True
  return False

def uf_union(a,b):
  if (uf_same(a,b)): return
  a = uf_root(a)
  b = uf_root(b)
  par[a] = b
  return

for i in range(M):
  x,y = map(int, input().split())
  x -= 1
  y -= 1
  uf_union(x,y)

ans = 0
for i in range(N):
  if ( uf_same(i,p[i]) ):
    ans += 1
print(ans)




Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	map<ll,ll>ch;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		ch[now]++;
		if(ch[now]==2){
			cout << "NO";
			return 0;
		}
	}
		cout << "YES";
	// your code goes here
	return 0;
}

Measured memory_bytes: 16056
s = input().split()
A = int(s[0])
B = int(s[1])
C = int(s[2])
K = int(input())

for i in range(K):
    if A >= B:
        B *= 2
    elif B >= C:
        C *= 2
    else:
        break

b = A < B < C

print('Yes' if b else 'No')


Measured memory_bytes: 9176
#!/usr/bin/env python3

ans = 0 
mod = 10**9 + 7 

lst = list(map(int,input().split()))
x = lst[0]
y = lst[1]

a = (2*y-x)/3
b = (2*x-y)/3
N = 10**6
g1 = [1, 1]  
g2 = [1, 1]  
inverse = [0, 1]  

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#a = cmb(6,3,mod)
#print(a)

if a.is_integer() and b.is_integer():
    a = int(a)
    b = int(b)
    ans = cmb(a+b,b,mod)
    print(ans)
else:
    print(0)


Measured memory_bytes: 121840
#include<iostream>
 using namespace std;
 
 int main() {
 
 int N,A;
 cin>>N>>A;
 int L=A;
 int R=A+N-1;
 
 int eat;
 if(R<=0)eat=R;
 else if(L>=0)eat=L;
 else eat=0;
int answer=(R+L)*(R-L+1)/2-eat;
 cout<<answer<<endl;
 
 return 0;
}

Measured memory_bytes: 256
n = gets.chomp

words = {}

n.to_i.times {
  word = gets.chomp
  if words.has_key?(word)
    words[word] += 1
  else
    words[word] = 1
  end
}

by_num = words.to_a.sort {|a,b| b[1] <=> a[1]}
num = by_num[0][1]
selected = by_num.select {|w| w[1] == num}

selected.map{|w| w[0]}.sort{|a,b| a <=> b}.each{|w|
  puts w
}



Measured memory_bytes: 45032
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<long long, long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, j, k)  for (register int i = (int)(j); i <= (int)(k); i++)
#define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}

const int maxn = 330;
int n, x, y, z;
int a[maxn];
double f[maxn][maxn][maxn];
double g[maxn][maxn][maxn];

inline bool ok(int A, int B, int C) {
  if (A < 0 || B < 0 || C < 0) return 0;
  if (A + B + C > n) return 0;
  if (C > z) return 0;
  if (B + C > y + z) return 0;
  return 1;
}
void dfs(int A, int B, int C) {
  if (A == x && B == y && C == z) return;
  if (f[A][B][C] != 0) return;
  if (ok(A + 1, B, C)) {
    dfs(A + 1, B, C);
    f[A][B][C] += f[A + 1][B][C] * (A + 1) / (A + B + C + 1);
    // g[A][B][C] += (g[A + 1][B][C] + n * 1.0 / (A + 1 + B + C) * (A + 1) / (A + B + C + 1)) * f[A + 1][B][C];
    g[A][B][C] += g[A + 1][B][C] * (A + 1) / (A + B + C + 1) + n * 1.0 / (A + B + C + 1) * (A + 1) / (A + B + C + 1) * f[A + 1][B][C];
  }
  if (ok(A - 1, B + 1, C)) {
    dfs(A - 1, B + 1, C);
    f[A][B][C] += f[A - 1][B + 1][C] * (B + 1) / (A + B + C);
    // g[A][B][C] += (g[A - 1][B + 1][C] + n * 1.0 / (A + B + C) * (B + 1) / (A + B + C)) * f[A - 1][B + 1][C];
    g[A][B][C] += g[A - 1][B + 1][C] * (B + 1) / (A + B + C) + n * 1.0 / (A + B + C) * (B + 1) / (A + B + C) * f[A - 1][B + 1][C];
  }
  if (ok(A, B - 1, C + 1)) {
    dfs(A, B - 1, C + 1);
    f[A][B][C] += f[A][B - 1][C + 1] * (C + 1) / (A + B + C);
    // g[A][B][C] += (g[A][B - 1][C + 1] + n * 1.0 / (A + B + C) * (C + 1) / (A + B + C)) * f[A][B - 1][C + 1];
    g[A][B][C] += g[A][B - 1][C + 1] * (C + 1) / (A + B + C) + n * 1.0 / (A + B + C) * (C + 1) / (A + B + C) * f[A][B - 1][C + 1];
  }
  // cout<<A<<' '<<B<<' '<<C<<' '<<f[A][B][C]<<' '<<g[A][B][C]<<endl;
}

void work() {
  n = read();
  rep(i, 1, n) {
    a[i] = read();
    if (a[i] == 1) x++;
    else if (a[i] == 2) y++;
    else z++;
  }
  f[x][y][z] = 1;
  dfs(0, 0, 0);
  printf("%.10f\n", g[0][0][0]);
}

int main() {
  #ifdef LZT
    freopen("in", "r", stdin);
  #endif

  work();

  #ifdef LZT
    Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  #endif
}


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

int main()
{
  int h,w;
  cin>>h>>w;
  vector<string> v(h);
  for(auto &i:v) cin>>i;
  for(int i=0;i<w+2;i++) cout<<"#";
  cout<<"\n";
  for(auto i:v) cout<<"#"<<i<<"#\n";
  for(int i=0;i<w+2;i++) cout<<"#";
  cout<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  int n, k, q;

  cin >> n >> k >> q;
  
  int point[n];
  for (int i = 0; i < n; i++) {
    point[i] = k - q;
  }

  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    point[a-1]++;
  }
  for (int i = 0; i < n; i++) {
    if (point[i] > 0) pr("Yes");
    else pr("No");
  }

  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<functional>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int>P;
using namespace std;

const int INF=1e5;

const int di[]={-1,0,1,0},dj[]={0,-1,0,1};

int main()
{
    int h,w;
    cin>>h>>w;
    vector<string> m(h);
    rep(i,h)
    {
        cin>>m[i];
    }
    P route[h][w];
    vector< vector<int> > d(h,vector<int>(w,INF));
    queue<P> que;
    que.push(P(0,0));
    bool reachable=false;
    vector<vector<bool>> reached(h,vector<bool>(w,false));
    reached[0][0]=true;
    while(!que.empty())
    {
        P now=que.front();
        que.pop();
        if(now.first==h-1 && now.second==w-1)
        {
            break;
        }
        rep(i,4)
        {
            int nh=now.first+di[i];
            int nw=now.second+dj[i];
            if((nh>=0 && nh<h && nw>=0 && nw<w && m[nh][nw]!='#' && !reached[nh][nw]))
            {
                que.push(P(nh,nw));
                route[nh][nw]=now;
                reached[nh][nw]=true;
            }
        }

    }

    if(!reached[h-1][w-1])
    {
        cout<<-1;
    }
    else
    {
        int bc=0;
        int rc=1;
        P router=P(h-1,w-1);
        while(router.first!=0 || router.second!=0)
        {
            rc++;
            int x=router.first;
            int y=router.second;
            router=route[x][y];

        }
        rep(i,h)rep(j,w)
        {
            if(m[i][j]=='#')bc++;
        }
        cout<<h*w-rc-bc;
    }
    




    
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    int b = 1;
    int s = 0;
    rep(i, n)
    {
        if (a[i] != b)
        {
            s++;
        }
        else
        {
            b++;
        }
    }

    if (s == n)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
typedef long long ll;
using namespace std; 

int main(){
	int w,a,b;
	cin>>w>>a>>b;
	int hasil;
	if(a>b){
		if(a-b+1<=w)hasil=0;
		else{
			hasil=a-b-w;
		}
	}
	else if(a<b){
		if(b-a+1<=w)hasil=0;
		else{
			hasil=b-a-w;
		}
	}
	cout<<hasil;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
ll dp[105][100005];
int main()
{
	ll i,n,W,w;
	cin>>n>>W;
	ll v[n],wt[n];
	for(i=0;i<n;i++)
		cin>>wt[i]>>v[i];
	for (i = 0; i <= n; i++) 
   	{ 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               dp[i][w] = 0; 
           else if (wt[i-1] <= w) 
               dp[i][w] = max(v[i-1] + dp[i-1][w-wt[i-1]],  dp[i-1][w]); 
           else
               dp[i][w] = dp[i-1][w]; 
       }
   	}
   	cout<<dp[n][W]<<endl;
	return 0;
}

Measured memory_bytes: 80128
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	cnt := 0
	var before rune
	for i, r := range s {
		if i == 0 {
			before = r
		} else {
			if before != r {
				cnt++
				before = r
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1280
#include <stdio.h>

int main(void) {
	int n, sum = 0, ave, max, min;
	long long total = 0;
	int a[100];
	int i, j;
	int mode, cnt, temp_cnt;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if (i == 0){
			min = a[i];
			max = a[i];
		}
		if (a[i] < min) min = a[i];
		if (a[i] > max) max = a[i];
		sum += a[i];
	}
	
	mode = 0;
	cnt = 0;
	
	for (i = 0; i < n; i++){
		temp_cnt = 1;
		for (j = i + 1; j < n; j++){
			if (a[i] == a[j]) temp_cnt++;
		}
		if (temp_cnt > cnt){
			cnt = temp_cnt;
			mode = a[i];
		}
	}
	
	if (sum % n == 0) ave = sum/n;
	else{
		if ((mode < ave) && (cnt > max)) ave = sum/n;
		else ave = (sum+(n/2))/n;
	}
	
	for (i = 0; i < n; i++){
		total += (a[i] - ave)*(a[i] - ave);
	}
	
	printf("%ld\n", total);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
typedef long long ll;
using namespace std;

int main(){
  ll x;
  cin >> x;
  bitset<32> b(x);
  cout << b << endl;
  cout << (~b)<<endl;
  cout << (b<<1)<<endl;
  cout << (b>>1) <<endl;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  vector<int> a(n);
  bool all_even = true;
  rep(i,n) {
    cin >> a[i];
    if(a[i] % 2 == 1) all_even = false;
  }

  if(all_even) cout << "second" << '\n';
  else cout << "first" << '\n';
}

Measured memory_bytes: 3756
N, Q = map(int, input().split())
S = input()

q = []

pref = [0] * (len(S))

c=0
for i in range(2, len(S)+1):
    if (S[i-2:i] == "AC"):
        c += 1
    pref[i-1] = c


for i in range(Q):
    l,r = map(int, input().split())
    print(pref[r-1] - pref[l-1])

Measured memory_bytes: 6060
#include <iostream>
#include<cstring>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	string c[100];
	for(int i=0;i<a;i++){
		cin>>c[i];
	}
	for(int i=0;i<b+2;i++){
		cout<<"#";
	}
	cout<<endl;
	for(int i=0;i<a;i++){
		cout<<"#";
		cout<<c[i];
		cout<<"#"<<endl;
	}
	for(int i=0;i<b+2;i++){
		cout<<"#";
	}
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n, i;
    int c[51] = {};
    int v[51] = {};
    int ans, max;
    scanf("%d\n", &n);
    for(i=0; i<n; i++){
        scanf("%d", &v[i]);
       /*printf("%d\n", v[i]);*/
    }
    for(i=0; i<n; i++){
        scanf("%d", &c[i]);
    }

    max = 0;
    for(i=0; i<50; i++){
        if(v[i]>c[i]){
            ans = v[i]-c[i];
            max += ans; 
        }
    }
    printf("%d\n", max);
    return 0;
}



Measured memory_bytes: 128
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if(n == 1){
	   cout <<"Hello World";
    } else{
	cout << a + b << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,i0,n) for(int i=i0;i<n;++i)

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    rep(i,n) s[i] = 'x';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : Test4.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b && b<c){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}



Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <climits>
#include <set>
#include <deque>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {

	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";

    return out;

}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin >> s;

	if (s == "Sunny")
		cout << "Cloudy\n";
	else if (s == "Cloudy")
		cout << "Rainy\n";
	else 
		cout << "Sunny\n";

	return 0;

}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 200005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

i64 a[100005] ;

int main()
{
    i64 i , j , k , l , m , n , fl=-1 ;

    scanf("%lld",&n) ;

    for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;

    sort(a+1,a+n+1) ;

    for( i=n ; i>1 ; i-- )
    {
        if(a[i]==a[i-1])
        {
            if(fl>0){
                printf("%lld\n",fl*a[i]) ;
                return 0 ;
            }
            else{
                fl = a[i] ;
                i-- ;
            }
        }
    }

    printf("0\n") ;

    return 0 ;
}


Measured memory_bytes: 1024
s = input()

if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)


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

#define PB push_back
#define SZ(c) ((int)(c).size())
#define REP(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
const int MAX = 1100100;

int N;
int A[MAX], pos[MAX];
vector<int> Q[MAX];
vector<int> E[MAX];

void quit(){
	cout << "Impossible" << endl;
	exit(0);
}

int DFS(int n, int p){
	int ret = 0;
	for(auto x: E[n]) if (x!=p) ret = max(ret, 1+DFS(x, n));
	return ret;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> N;
	REP(I, N){
		cin >> A[I];
	}
	sort(A, A+N);
	
	REP(I, N-1) if (A[I]+1 < A[I+1]) quit();
	
	Q[A[0]].PB(0); // center
	E[0].PB(1);
	E[1].PB(0);
	Q[A[1]].PB(1);
	
	if (N>2){
		if (A[2] == A[0]) quit();
	}
	
	
	for(int I=2; I<N; I++){
		int d = A[I]-1;
		int p = Q[d][pos[d]++];
		if (pos[d]==SZ(Q[d])) pos[d]--;
		
		Q[A[I]].PB(I);
		E[I].PB(p);
		E[p].PB(I);
	}
	
	bool ok = true;
	REP(I, N) ok &= DFS(I,-1)==A[I];
	
	if (ok) cout << "Possible" << endl;
	else    quit();
}





























Measured memory_bytes: 51968
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int sum = 0;

    for (int i = k; i > 0; i--)
    {
        if (a > 0)
        {
            sum++;
            a--;
        }
        else if (b > 0)
        {
            b--;
        }
        else if (c > 0)
        {
            sum--;
            c--;
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 3636