akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    Set<Integer> set = new HashSet<>();
    for (int i = 0; i < K; i++) {
      int d = sc.nextInt();
      for (int j = 0; j < d; j++)
        set.add(sc.nextInt());
    }
    sc.close();

    int ans = N - set.size();
    System.out.println(ans);
  }
}


Measured memory_bytes: 46196
/**
 * Title: D - Derangement
 * Url: https://atcoder.jp/contests/abc072/tasks/arc082_b
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int n; cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin >> p[i];
    int cnt = 0;
    bool flag = false;
    while(!flag) {
        flag = true;
        for(int i=0; i<n; i++) {
            if(p[i]==i+1) {
                if(i==n-1) {
                    int tmp = p[i];
                    p[i] = p[i-1];
                    p[i-1] = tmp;
                    cnt++;
                    flag = false;
                } else {
                    int tmp = p[i];
                    p[i] = p[i+1];
                    p[i+1] = tmp;
                    cnt++;
                    flag = false;
                }
            }
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}


signed main(){
	int N;
	cin >> N;
	vector<int> a(N); for(auto& e:a)cin >> e;
	int ans = 0,now = 0;
	RREP(i,N){
		now--;
		if(now == a[i])continue;
		else{
			if(now < a[i]){
				ans += a[i];
				now = a[i];
			}else{
				cout << -1 << endl;
				return 0;
			}
		}
	}
	if(now){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
 
typedef struct{
  int id;
  int parent;
  int sibling;
  int depth;
  int height;
  int degree;
  int left;
  int right;
} node;
 
node tree[25];
 
 
int main(){
 
  int n,i,j,count,k,m,l,r;
  scanf("%d",&n);
 
 for(i=0;i<n;i++){
   tree[i].parent = -1;
   tree[i].sibling = -1;
   tree[i].degree = 0;
   tree[i].depth = 0;
   tree[i].height = 0;
 
 }
  
 for(i=0;i<n;i++){
   scanf("%d",&m);
   tree[m].id = m;
   scanf("%d%d",&tree[m].left,&tree[m].right);
   tree[tree[m].left].parent = m;
   if( tree[m].left != -1) tree[m].degree++;
   tree[tree[m].left].sibling = tree[m].right ;
 
   tree[tree[m].right].parent = m;
   if( tree[m].right != -1) tree[m].degree++;
   tree[tree[m].right].sibling = tree[m].left;
   }
 
 for(i=0;i<n;i++){
   j = i;
   while(tree[j].parent != -1){
     j = tree[j].parent;
     tree[i].depth++; 
   }
 }
 
for(i=0;i<n;i++){
  tree[i].height= height(i);
 }
 
 
 
  
 for(i=0;i<n;i++){
   printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",tree[i].id,tree[i].parent,tree[i].sibling,tree[i].degree,tree[i].depth,tree[i].height);
   if(tree[i].parent == -1) printf("root\n");
   else if(tree[i].left == -1 && tree[i].right == -1) printf("leaf\n");
   else printf("internal node\n");
 }
  
 return 0;
}
     
     
int height(int x){
  int r,l;
  if(tree[x].left == -1 && tree[x].right == -1) return 0;
  if(tree[x].left == -1) l=1+0;
  else  l=1+height(tree[x].left);
  if(tree[x].right == -1) r=1+0;
  else r=1+height(tree[x].right);
  if(l<=r) return r;
  else return l;
}

Measured memory_bytes: 612
n=int(input())
bossN=list(map(int,input().split()))
boss={}
for emp in bossN:
    if emp in boss:
        boss[emp]+=1
    else:
        boss[emp]=1
for i in range(1,n+1):
    if i in boss:
        print(boss[i])
    else:
        print("0")

Measured memory_bytes: 33616
N, M, C = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
ans = 0
N.times do |i|
    sum = 0
    a = gets.split.map(&:to_i)
    M.times do |j|
        sum += a[j] * B[j]
    end
    ans += 1 if sum + C > 0
end
puts ans

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

ll a;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>a;
    a+=a*a+a*a*a;
    cout<<a;
    
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int N;
    cin >> N;
    vector<Vi> A(2, Vi(N));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    Vi csum1(N + 1), csum2(N + 1);
    for (int i = 0; i < N; i++) {
        csum1[i + 1] = csum1[i] + A[0][i];
    }
    for (int i = 0; i < N; i++) {
        csum2[i + 1] = csum2[i] + A[1][i];
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int tmp = csum1[i + 1] + (csum2[N] - csum2[i]);
        ans = max(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ps = [[i for i in input().split()] for j in range(m)]

p = [0] * (n+1)
p_wa = [0] * (n+1)

num_ac = 0
num_wa = 0

for i in range(m):
    mondai = int(ps[i][0])
    if p[mondai] == 0:
        if ps[i][1] == 'WA':
            p_wa[mondai] += 1
        else:
            num_ac += 1
            num_wa += p_wa[mondai]
            p[mondai] = 1

print(num_ac,num_wa)

Measured memory_bytes: 27496
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var dp = new int[n + 1, 4];
            for (int i = 0; i < n + 1; i++)
                for (int j = 0; j < 4; j++) dp[i, j] = int.MaxValue;
            dp[0, 0] = 0;
            var p = new int[n]; var t = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                p[i] = int.Parse(line[0]);
                t[i] = int.Parse(line[1]);
            }
            getAns(dp, p, t);
        }
    }
    public static void getAns(int[,] dp, int[] p, int[] t)
    {
        var n = p.Length;
        if (p[0] > t[0]) { Console.WriteLine("NG 1"); goto end; }
        else dp[1, 1] = p[0];
        var ok = false;
        for (int i = 1; i < n; i++)
            for (int j = 1; j <= 3; j++)
            {

                if (dp[i, j] != int.MaxValue)
                {
                    if (j <= 2 && checkGet(p, t, i - 1, j))
                    {
                        dp[i + 1, j + 1] = Math.Min(dp[i + 1, j + 1], dp[i, j] + Math.Abs(p[i] - p[i - 1]));
                        ok = true;
                    }
                    if (checkGoHome(p, t, i - 1, j))
                    {
                        dp[i + 1, 1] = Math.Min(dp[i + 1, 1], dp[i, j] + p[i] + p[i - 1]);
                        ok = true;
                    }
                    if (!ok) { Console.WriteLine("NG {0}", i + 1); goto end; }
                }
            }
        getAns2(dp, p);
        end:;
    }
    public static void getAns2(int[,] dp, int[] p)
    {
        var n = dp.GetLength(0);
        var ok = false;
        var ans = int.MaxValue;
        for (int i = 0; i < 4; i++)
            if (dp[n - 1, i] != int.MaxValue)
            {
                ans = Math.Min(ans, dp[n - 1, i]);
                ok = true;
            }
        if (ok) { Console.WriteLine("OK {0}", p[n - 2] + ans); return; }
        else
        {
            for (int i = 1; i < n; i++)
            {
                var flg = false;
                for (int j = 0; j < 4; j++)
                    if (dp[i, j] != int.MaxValue) flg = true;
                if (!flg) { Console.WriteLine("NG {0}", i ); return; }
            }
        }
    }
    public static bool checkGoHome(int[] p, int[] t, int i, int b)
    {
        var nt = p[i] * (b + 1) + p[i + 1];
        return nt <= t[i + 1] - t[i];
    }
    public static bool checkGet(int[] p, int[] t, int i, int b)
    {
        var L = Math.Abs(p[i + 1] - p[i]);
        var nt = L * (b + 1);
        return nt <= t[i + 1] - t[i];
    }
}


Measured memory_bytes: 8144
#include <iostream>
using namespace std;
int main() {
    int n, a;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a;
        if (a%2 == 0) {
            if ((a%5)*(a%3)!=0) {
                cout << "DENIED" << endl;
            return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n,m;
vector<pair<ll, ll> > py;

string to_num(ll phone){
    string res;
    res = to_string(phone);
    while(res.size()!=12)res = "0"+res;
    return res;
}

int main(void) {
    cin >> n >> m;
    rep(i,m){
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        py.push_back(make_pair(tmp1,tmp2));
    } 
    vector<priority_queue<pair<ll, ll> > > vecs(n+1, priority_queue<pair<ll, ll> >());
    rep(i,m){
        vecs[py[i].first].push(make_pair(-1*py[i].second, i));
    }
    vector<pair<ll, ll> > nums;
    ll phone,x;
    rep(i,n+1){
        x = 1;
        while(vecs[i].size()!=0){
            phone = i;
            phone = phone*1000000+x;
            nums.push_back(make_pair(vecs[i].top().second, phone));
            vecs[i].pop();
            x++;
        }
        DEBUG{cout << "nums : " << nums.size() << endl;}
    }
    sort(nums.begin(), nums.end());
    rep(i,m){
        cout << to_num(nums[i].second) << endl;
    }
    return 0;

}


Measured memory_bytes: 12144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,k;
int main()
{
	scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
	if(k<=a) printf("%lld\n",k);
	else if(k<=a+b) printf("%lld\n",a);
	else printf("%lld\n",a-(k-a-b));
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a * b) / 2 << endl;
  return 0;
}



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

int main()
{
	double D,d,a,b,x,y;
	while(scanf("%lf%lf%lf%lf%lf", &D,&a,&b,&x,&y), D)
	{		
		d=hypot(a,b);
		if(a*x+b*y>0)d=2-d;

		fabs(a*y-b*x)>1e-7||D<d?puts("impossible"):printf("%.8lf\n", d);
	}
}

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

int main() {
    int n;
    ll ans = 0;
    cin >> n;

    map<string, int> mp;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    
    for (auto hoge : mp)
    {
        string a = hoge.first;
        int b = hoge.second;
        ans += (ll)b * (b - 1) / 2;
    }
    
    cout << ans << endl;
    return 0;
}

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

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

  vector<int> b(m), c(n);
  vector<vector<int>> A(n, vector<int>(m));
  rep(i, n) rep(j, m) cin >> A[i][j];
  rep(i, m) cin >> b[i];

  rep(i, n) rep(j, m) c[i] += A[i][j] * b[j];

  rep(i, n) cout << c[i] << endl;
}


Measured memory_bytes: 3176
package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	S := io.NextLine()
	cnt := 0
	for _, s := range S {
		if s == '(' {
			cnt++
		} else if s == ')' {
			cnt--
		} else {
			io.Println(cnt)
			break
		}
	}
}

// I/O template
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 buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

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

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

func (io *Io) NextFloat() 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) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(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 ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 1100
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int A, B, C;

  std::cin >> A >> B >> C;

  std::cout << std::min(B / A, C) << std::endl;

  return 0;
}


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

using namespace std;
int checksort(int a[],int N)
{
    for(int i=0;i<N-1;i++)
    {
        if(a[i]>a[i+1])
            return 0; 
    }
    return 1; 
}

int main()
{
    int count =0;

    int N;
    cin >>N;
    int a[N];

    for(int i=0;i<N;i++)
    {
        cin>> a[i]; 
    }

    int l=0;
    int r = N-1; 
    while(l<=r)
    {
        //cout<<"l "<<l<<" r "<< r<<endl; 
        if(a[r] <a[l])
        {
            swap(a[r],a[l]);
            l++;
            r--;
            count++; 
        }
        else if(a[r] >a[r-1])
        {
            r--; 
        }
        else if(a[l] < a[l+1])
        {
            l++; 
        }
        else
        {
            l++;
            r--;
        }
    }
    if(count>1)
    {
        cout<<"NO"<<endl; 
    }
    else
    {
        if(checksort(a,N)==1)
            cout<<"YES"<<endl; 
        else
           cout <<"NO"<<endl; 
    }

    return 0; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define all(v)          v.begin(), v.end()
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mem(dp,x)       memset(dp,x,sizeof dp);
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
// 1, 1, 2, 5, 14, 42, 132, 429, 1430, CATALAN NUMBER
int32_t main()
{
	g_b();
	int c = 0;
	bool f = 0;
	w(tc) {
		int a , b; cin >> a >> b;
		if (a == b)
			c++;
		else c = 0;
		if (c == 3)
			f = 1;
	}
	if (f) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3644
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (x, a, b) = (v[0], v[1], v[2]);
    if (x - a).abs() <= (x - b).abs() {
        println!("A");
    } else {
        println!("B");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const ll N=1e7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<ll>prime(N+1,1),d(N+1,0);
    ll i,j,k,ans=0;
    for(i=2;i*i<=N;i++)
    { 
    
        for(j=i*i;j<=N;j+=i)
        {
        prime[j]++;
        if(j==i*i)
        d[j]=1;
        }
    
    }
   ans=1;
    for(i=2;i<=n;i++)
    {
       if(d[i]==1)
        {
        ans+=(i*(2*prime[i]-1));
       // cout<<(2*prime[i]-1)<<" ";
        }
        else
        {
        ans+=(i*2*(prime[i]));
       // cout<<(2*prime[i])<<" ";
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 159448
a, b, c, d = map(int, input().split())

if a <= c <= b <= d:
    print(b - c)
elif c <= a <= d <= b:
    print(d - a)

elif a <= c <= d <= b:
    print(d - c)
elif c <= a <= b <= d:
    print(b - a)

elif (a <= b < c <= d) or (c <= d < a <= b) :
    print(0)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
char ans = 'a';

int main()
{
char c ;
cin >> c ;
if(c-'A'>=0&&c-'A'<26)ans='A';
cout << ans << endl;
return 0;
}

Measured memory_bytes: 3596
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut v: Vec<i64> = buf.split_whitespace().into_iter().map(|elem| elem.parse().unwrap()).collect();
    assert!(v.len() == 3);
    v.sort();
    println!("{} {} {}", v[0], v[1], v[2]);
}


Measured memory_bytes: 5020
/**
 *    author:  FromDihPout
 *    created: 2020-05-30
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int curr = 1, ans = 0;
    for (int i = 0; i < n ; i++) {
        int x;
        cin >> x;
        if (x == curr) curr++;
        else ans++;
    }
    if (curr == 1) ans = -1;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,i,j,key;
  scanf("%d",&n);
  int array[n];
  for(i = 0; i < n; i++){
    scanf("%d",&array[i]);
  }
  for(j = 0; j <= n - 1; j++){
    key = array[j];
    i = j - 1;
    while(i >= 0 && array[i] > key){
      array[i + 1] = array[i];
      i--;
    }
    array[i + 1] = key;
    for(i = 0; i < n; i++){
      printf("%d",array[i]);
      if(i == n - 1){
        printf("\n");
        break;
      }
      printf(" ");
    }
  }
  return 0;
}



Measured memory_bytes: 2072
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define DEB 0

int field[1024][1024];
int dp[1024][1024];
int h,w,n;

int main(){
  
  while(scanf("%d%d%d",&h,&w,&n),h|w|n){
    memset(dp,0,sizeof(dp));
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i+1][j+1]);
      }
    }

    int x=1;
    int y=1;
    dp[1][1] = n-1;
    REP(i,1,h+1){
      REP(j,1,w+1){
	int k1,k2;
	if( dp[i-1][j]%2 && field[i-1][j]==0 ){
	  k1 = 1;
	}else{
	  k1 = 0;
	}
	if( dp[i][j-1]%2 && field[i][j-1]==1 ){
	  k2 = 1;
	}else{
	  k2 = 0;
	}

	dp[i][j] += (dp[i-1][j]+k1)/2  + (dp[i][j-1]+k2)/2;
	if( i==y && j==x ){
	  if( (field[i][j]+dp[i][j])%2==1 ){
	    x++;
	  }else{
	    y++;
	  }
	}
      }
    }
#if DEB
    REP(i,1,h+1){
      REP(j,1,w+1){
	printf("%2d ",dp[i][j]);
      }
      puts("");
    }
#endif
    
    // Nツ嘉アツ姪堋づ個湘ウツ妥板づーツ青カツ青ャ
    /*
    REP(i,1,h+1){
      REP(j,1,w+1){
	field[i][j] = (field[i][j]+dp[i][j])%2;
      }
    }
    */
#if DEB
    puts("field");
    REP(i,1,h+1){
      REP(j,1,w+1){
	printf("%2d ",field[i][j]);
      }
      puts("");
    }
#endif
    
    /*
    int x=1;
    int y=1;
    for(;;){
      if( x>w || y>h )break;
      if( (field[y][x]+dp[y][x])%2==1 ){
	x++;
      }else{
	y++;
      }
    }
    */

    printf("%d %d\n",y,x);
  }
  return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  for(int i=0;i < b + 2;i++){
    cout << "#" ; 
  }
  cout << endl;
  for(int i=0;i < a; i++){
    string A;
    cin >> A;
    cout << "#" << A << "#" << endl;
    }
  for(int i=0;i < b + 2;i++){
    cout << "#" ; 
  }  
}

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

int main(void){
    int a,b;
    cin >> a >> b;
    int x = a+b , y = a-b,z = a*b;
    int c= max(x,y),d =max(y,z),e= max(c,d);
    cout << e << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// N 商品数
	// M 選択数
	// Ai その商品の票数
	var N, M int
	fmt.Scan(&N, &M)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
	}
	sum := 0
	for _, aa := range a {
		sum += aa
	}
	//fmt.Println(sum)
	b := (4 * M)
	//fmt.Println(b)
	// 分数にしないと
	//w := sum / b
	w := float64(sum) / float64(b)
	//fmt.Println(w)
	var c int
	for _, aa := range a {
		if float64(aa) >= float64(w) {
			c++
		}
	}
	//fmt.Println(c)
	if c >= M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 512
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int P, Q, R;

    AtCoder(FastScanner sc) {
        P = sc.nextInt();
        Q = sc.nextInt();
        R = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(P + Q + R - Math.max(Math.max(P, Q), R));
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

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

  int tot = 1;
  for(int i=0; i<N; i++){
    if(tot*2<tot+K){
      tot *= 2;
    }else{
      tot += K;
    }
  }

  cout << tot << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
int main(){
    fastio;
    file();
    int n;
    cin>>n;
    vv v(n);
    fors(i,n){
      cin>>v[i];
    }
    // bool flag=true;
    int temp=0,cnt=0;
    for(int i=0;i<n;++i){
      if(v[i]%2==0){
        temp++;
      if(v[i]%3==0 || v[i]%5==0){
       cnt++;
        // flag=0;
        // break;
      }
    }
    }
    if(temp==cnt){
      test("APPROVED");
    }
    else{
      test("DENIED");
    }
    return 0;
}
// 5
// 6 7 9 10 31

Measured memory_bytes: 256
mod = 10**9+7
S = input()
A = 0
AB = 0
ABC = 0

N = 1
for i in range(len(S)):
    if S[i] == 'A':
        A += N
    elif S[i] == 'B':
        AB += A
    elif S[i] == 'C':
        ABC += AB
    else:
        ABC = 3*ABC + AB
        AB = 3*AB + A 
        A = 3*A + N
        N *= 3
    A %= mod
    AB %= mod
    ABC %= mod
    N %= mod

print(ABC)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1100000
using namespace std;
ll int inv[N],comb[N],fact[N],factinv[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
ll modpow(ll x,ll n){
    if(n==0) return 1;
    ll res=modpow(x*x%MOD,n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
ll inverse(int x){
    if(x<N&&inv[x]) return inv[x];
    if(x<N) return inv[x]=modpow(x,MOD-2);
    return modpow(x,MOD-2);
}
void calc_comb(ll int n){
    comb[0]=1;
    rep2(i,1,n){
        comb[i]=comb[i-1]*(n+1-i)*inv[i]%MOD;
    }
    return;
}
ll int combination(int a,int b){
    ll int ans=1;
    rep2(i,1,b){
        ans=ans*(a+1-i)*inv[i]%MOD;
    }
    return ans;
}
void calc_fact(int n){
    fact[0]=fact[1]=1;
    factinv[0]=factinv[1]=1;
    rep2(i,2,n){
        fact[i]=fact[i-1]*i%MOD;
        factinv[i]=factinv[i-1]*inv[i]%MOD;
    }
}
void add(ll* x,int y){
    *x=(*x+y)%MOD;
}
void product(ll *x,ll y){
    *x=(*x*y)%MOD;
}
void add2(ll *x,int y,int n,int i,int j){
    ll ans=fact[n];
    product(&ans,factinv[n-i*j]);
    product(&ans,modpow(factinv[i],j));
    product(&ans,factinv[j]);
    *x=(*x+ans*y)%MOD;
}
main(){
    ll dp[1100][1100]={};
    calc_inv();
    calc_fact(1000);
    int n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    dp[a-1][n]=1;
    rep2(i,a,b){
        dp[i][0]=dp[i-1][0];
        rep2(k,i,n){
            add(&dp[i][k],dp[i-1][k]);
            int j=c;
            while((k-j*i>=i||k-j*i==0)&&j<=d){
                add2(&dp[i][k-j*i],dp[i-1][k],k,i,j);
                j++;
            }
        }
    }
    cout<<dp[b][0];return 0;
}

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

int main(void){
	char s[110][10],t[110][10];
	int i,j,n, m;
	int max=0;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%s", s[i]);
	}
	scanf("%d", &m);
	for (i = 0; i < m; i++){
		scanf("%s", t[i]);
	}

	for (i = 0; i < n; i++){
		int count = 0;
		for (j = 0; j < n; j++){
			if ((strcmp(s[i], s[j]) == 0)) count++;
		}
		for (j = 0; j < m; j++){
			if ((strcmp(s[i], t[j]) == 0)) count--;
		}
		if (count>max) max = count;
	}
	printf("%d\n", max);

	return 0;
}



Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main {


    public Main(FastScanner in, PrintWriter out, int test) {
        int N = in.nextInt();
        Map<String, Integer> freq = new HashMap<>();
        for (int i = 0; i < N; i++) {
            String v = in.next();
            freq.merge(v, 1, Integer::sum);
        }
        for (String v : Arrays.asList("AC", "WA", "TLE", "RE")) {
            out.println(v + " x " + freq.getOrDefault(v, 0));
        }
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        // int T = in.nextInt();
        for (int t = 1; t <= 1; t++) {
            Main sol = new Main(in, out, t);
        }

        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream)
    {
        this.stream = stream;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}

Measured memory_bytes: 49496
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=a;i>=b;i--)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.14159265358979323
#define sz(a) (int)((a).size())
#define len(a) (int)(a.length())
#define FOR(i,j,k,l) for(ll i=j;i<k;i+=l)

void Fast_IO() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
   freopen("input.in","r",stdin);
   freopen("output.out","w",stdout); 
   #endif
} 

int main(){
   //Fast_IO();
   ll n;
   cin>>n;
   vector<ll>v;
   ll sum=0;
   f(i,0,n){
      ll x;
      cin>>x;
      v.pb(x);
      sum^=x;
   }
   f(i,0,n){
      ll k = v[i]^sum;
      cout<<k<<spc;
   }
}






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

typedef long long ll;

const ll MOD = 1e9 + 7;
ll n,a,b;

ll pow(ll a, ll b, ll m)
{
    ll ans = 1;
    a %= m;
    while(b)
    {
        if(b & 1)ans = (ans % m) * (a % m) % m;
        b /= 2;
        a = (a % m) * (a % m) % m;
    }
    ans %= m;
    return ans;
}

ll inv(ll x, ll p)//x关于p的逆元，p为素数
{
    return pow(x, p - 2, MOD);
}

ll C(ll n, ll m, ll p)//组合数C(n, m) % p
{
    if(m > n)return 0;
    ll up = 1, down = 1;//分子分母;
    for(int i = n - m + 1; i <= n; i++)up = up * i % p;
    for(int i = 1; i <= m; i++)down = down * i % p;
    return up * inv(down, p) % p;
}

ll Lucas(ll n, ll m, ll p)
{
    if(m == 0)return 1;
    return C(n % p, m % p, p) * Lucas(n / p, m / p, p) % p;
}

int main(){
	cin >> n >> a >> b;
	if( b >= n / 2 ) b = n - b;
	ll ca = Lucas(n , a, MOD);
	ll cb = Lucas(n , b, MOD);
	ll c = (ca + cb) % MOD;
	c = (pow(2,n,MOD) - c - 1 + MOD) % MOD;
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <climits>

using namespace std;
typedef long long ll;

int main() {
	ll N;
	cin >> N;
	vector<ll> h(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> h[i];
	}

	ll ans = 0, max = 0;
	for (ll i = 0; i < N; i++)
	{
		if (h[i] >= max)
		{
			ans++;
			max = h[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<long long>s(1001);
void sum()
{
  s[0]=0;
  for(int i=1;i<=1000;i++)s[i]+=s[i-1]+i;
}
int main()
{
  sum();
  int n,k;
  cin>>n>>k;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  double ans=0;
  double ex=0;
  for(int i=0;i<=(n-k);i++)
  {   
    if(i==0)
    {
    	for(int j=0;j<k;j++)
    	{
      		ex=ex+(double)s[a[i+j]]/a[i+j];
    	}
    }
    else 
    {
      ex=ex-((double)s[a[i-1]]/a[i-1])+((double)s[a[i+k-1]]/a[i+k-1]);
    }
    if(ans<ex)ans=ex;
  }
  printf("%.9f\n",ans);
  return 0;
}

Measured memory_bytes: 1024
function Main(input) {
    var input = input.split("\n");
    var str = input[0].split("");
    var ans="";
    for(;str.length!=0;){
    	ans+=str.pop();
    }
    console.log(ans);
}
//??°??????????????¢??°??¨(??????)
function ascendingOrder(val1,val2){
    return val1 - val2;
}
//??°??????????????¢??°??¨(??????)
function descendingOrder(val1,val2){
    return val2 - val1;
}
//??°??????
function Int(str){
    return parseInt(str, 10);
}
//????????????
function Str(num){
    return num.toString(10);
}


//???????????°??¨
function debug(){
	var input = document.getElementById("input").value;
	Main(input);
}

//?????????????????\??????????????????
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 15408
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    B = [tuple(SI()) for _ in range(n)]

    BT = list(zip(*B))
    res = 0
    for a in range(n):
        is_good = True
        for i in range(n):
            if B[i][n - a:] + B[i][:n - a] != BT[(i - a) % n]:
                is_good = False

        if is_good:
            res += n

    return res


print(main())


Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
string s;
void f() {
	double x1, x2, y1, y2, x3, y3, a, b, c, d;
	//input
	s += ',';
	int n = 1; bool b00l = 0; double pk = 1, pk1 = 1, p = 0;
	for (char ch : s) {
		if (ch == ',') {
			p *= pk1;
			if (n == 1)x1 = p;
			if (n == 2)y1 = p;
			if (n == 3)x2 = p;
			if (n == 4)y2 = p;
			if (n == 5)x3 = p;
			if (n == 6)y3 = p;
			n++; b00l = 0; pk = 1; p = 0; pk1 = 1;
		}
		else if (ch == '.') {
			b00l = 1; pk /= 10;
		}
		else if (ch == '-') {
			pk1 = -1;
		}
		else if (b00l) {
			p += (double)(ch - '0') * pk;
			pk /= 10;
		}
		else {
			p *= 10; p += (double)(ch - '0');
		}
	}

	a = x1 - x2; b = y1 - y2;
	c = b; d = a;
	if (d < 0)d *= -1;
	else c *= -1;
	double k1 = -100000, k2 = 100000;
	while (k2 - k1 >= 0.0000000000001) {
		double mid = (k1 + k2) / 2;
		if ((a * (y3 + k1 * d - y1) - b * (x3 + k1 * c - x1)) * ((a * (y3 + mid * d - y1) - b * (x3 + mid * c - x1))) > 0) {
			k1 = mid;
		}
		else k2 = mid;
	}
	double k = k1 + k2;
	printf("%.20f %.20f\n", x3 + k * c, y3 + k * d);
}
signed main() {
	while (cin >> s) f();
}


Measured memory_bytes: 3228
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 2505
#define maxe 10005
#define LL long long
using namespace std;
LL dis[maxn];
bool flg,vis[maxn],use[maxn];
int n,m,p,tim[maxn],que[maxn];
int tot,lnk[maxn],son[maxe],net[maxe],w[maxe];
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
inline void add(int x,int y,int z){net[++tot]=lnk[x];son[tot]=y;w[tot]=z;lnk[x]=tot;}
void DFS(int x){
	use[x]=1;
	for (int j=lnk[x];j;j=net[j])
	if (!use[son[j]]) DFS(son[j]);
}
void spfa(){
	memset(dis,192,sizeof(dis));
	int hed=0,tal=1;que[1]=1;dis[1]=0;
	while (hed!=tal){
		int x=que[hed=(hed+1)%maxn];vis[x]=0;
		if (++tim[x]>n){
			memset(use,0,sizeof(use));DFS(x);
			if (use[n]){flg=1;break;}
			vis[x]=1;continue;
		}
		for (int j=lnk[x];j;j=net[j])
		if (dis[son[j]]<dis[x]+w[j]){
			dis[son[j]]=dis[x]+w[j];
			if (!vis[son[j]]){
				que[tal=(tal+1)%maxn]=son[j];vis[son[j]]=1;
				if (dis[que[(hed+1)%maxn]]<dis[son[j]]) swap(que[(hed+1)%maxn],que[tal]);
			}
		}
	}
}
int main(){
	n=read();m=read();p=read();
	for (int i=1;i<=m;i++){
		int x=read(),y=read(),z=read()-p;
		add(x,y,z);
	}
	spfa();
	if (flg) printf("-1\n");
	else printf("%lld\n",max(dis[n],(LL)0));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  
  if((a+b)%2==1){
    cout << "IMPOSSIBLE";
  } else {
    cout << (a+b)/2;
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int N= saori.saori_hayami();
		int ans = 0;
		for(int i = 1;i <= N;i++){
			ans = ans + i;
		}
		System.out.println(ans);
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 20948
#include<iostream>
#include<cstring>
const int N=2e5+100;
using namespace std;
int main()
{
	string str;
	while(cin>>str)
	{
		int len=str.length();
		int f=0;
		for(int i=0;i<=len-1;i++)
		{
			if(str[i]==str[i+1]&&i+1<len)
			{
				f=1;
				cout<<i+1<<" "<<i+2<<endl;
				break;
			}
			else if(str[i]==str[i+2]&&i+2<len)
			{
				cout<<i+1<<" "<<i+3<<endl;
				f=1;
				break;
			}
		}
		if(f==0)cout<<-1<<" "<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
ll INF = pow(10,15);

vector<ll> a;
vector<vector<ll>> dp(410, vector<ll>(410,INF));
vector<vector<ll>> cumsum(410, vector<ll>(410));

ll solve(int i, int j){
	if(dp[i][j] != INF){
		return dp[i][j];
	}
	if(j - i == 0){
		dp[i][j] = 0;
	}else if(j - i == 1){
		dp[i][j] = a[i] + a[j];
	}else{
		ll mn(INF);
		for(int t(i);t<j;++t){
			ll cost = solve(i,t) + solve(t+1,j) + cumsum[i][t] + cumsum[t+1][j];
			if(mn > cost) mn = cost;
		}
		dp[i][j] = mn;
	}
	return dp[i][j];
}

int main(){
	int n;
	cin >> n;
	a.resize(n);
	rep(i,n) cin >> a[i];
	cumsum[0][0] = a[0];
	if(n >= 2){
		for(int i(1);i<n;++i) cumsum[0][i] = cumsum[0][i-1] + a[i];
		for(int i(1);i<n;++i){
			for(int j(i);j<n;++j){
				cumsum[i][j] = cumsum[0][j] - cumsum[0][i-1];
			}
		}
	}
	cout << solve(0,n-1) << endl;
	return 0;
}

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

fn main() {
	let l: f64 = read();
	let ans = (l/3.0).powi(3_i32);
	println!("{}", ans);
}

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



Measured memory_bytes: 4352
//package codeforces;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeMap;
import java.util.TreeSet;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Stack;
import java.util.Set;

public class Main {
	// Integer.bitCount(i); count no of 1 bit in a given number
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String[] args) {
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		// code
		int n = scn.nextInt(),k=scn.nextInt();
		long arr[] = new long[n];
		long memo[] = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong();
		if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		}
		

	}

	public static long mincost(long arr[],int n,int i,int k,long memo[])
	{	if(i==n-1)
		return 0;
		if(i>=n)
			return Integer.MAX_VALUE;
		if(memo[i]!=-1)
			return memo[i];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=a;
		}
		return a;
	}

	public static boolean[] sieveOfEratosthenes(int n) {

		boolean prime[] = new boolean[n + 1];
		for (int i = 0; i < n; i++)
			prime[i] = true;

		for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		}

		for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		}
		return prime;
	}

	public static class Pair implements Comparable {
		int x;
		int y;
		int z;

		Pair(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public int compareTo(Object o) {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		}

	}

}


Measured memory_bytes: 75572
package main

import (
	"fmt"
)

func main() {

	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	var result int
	if N >= 2 {
		result = result + N*(N-1)/2
	}
	if M >= 2 {
		result = result + M*(M-1)/2
	}

	fmt.Println(result)
}


Measured memory_bytes: 1832