akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: u32 = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

fn solve() {
	let r = read!(f64);
	println!("{}", std::f64::consts::PI*r*2.0);
}


fn run() {
    solve();
}


Measured memory_bytes: 2248
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef pair<int, int> ii;

long long count_P_in_nfact(long long n , long long p) {
    long long res = 0;
    while (n) {
        n /= p;
        res += n;
    }
    return res;
}
long long count_5_in_nfact(long long n , long long p) {
    long long res = 0;
    while (n) {
        n /= p;
        res += n / 2;
    }
    return res;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; ++i) {
        cout << s[i] << t[i];
    }
    cout << '\n';

    return 0;
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> dp(n,1e18);
    ll i,j;
    dp[0]=0;
    ll h[n];
    for(i=0;i<n;i++){
        cin >> h[i];
    }
    for(i=0;i<n;i++){
        if((i+1) < n){
            dp[i+1] = min(dp[i+1] , abs(h[i]-h[i+1]) + dp[i] );
        }
        if((i+2) < n){
            dp[i+2] = min(dp[i+2] , abs(h[i]-h[i+2]) + dp[i] );
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    int N;
    cin >> N;
    vint A(N);
    bool ok = true;
    rep(i, N)
    {
        cin >> A[i];
        if (A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0))
        {
            ok = false;
        }
    }
    if (ok)
    {
        cout << "APPROVED ";
    }
    else
    {
        cout << "DENIED";
    }

    return 0;
}

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

int a, b, c, k;

int main(){
    scanf("%d%d%d%d", &a, &b, &c, &k);
    for (int i = 0; i <= k; ++i){
        for (int j = 0; j <= k - i; ++j){
            for (int l = 0; l <= k - i - j; ++l){
                int d = a * (1 << i);
                int e = b * (1 << j);
                int f = c * (1 << l);
                if (f > e && e > d){
                    printf("Yes");
                    return 0;
                }
            }
        }
    }
    printf("No");
}


Measured memory_bytes: 3820
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    boolean f = true;

    for (int i=0; i < N; i++) {
      int t = sc.nextInt();
      int x = sc.nextInt();
      int y = sc.nextInt();

      if (x+y <= t) {
        if (t%2 != (x+y)%2) {
          f = false;
        }
      } else {
        f = false;
      }
    }

    if (f == false) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 87524
const main = (input) => {
  const lines = input.trim().split("\n")
  const [N, M, C] = lines[0].split(" ").map(str => parseInt(str));
  const B = lines[1].split(" ").map(str => parseInt(str));
  let A = lines.slice(2).map(line => line.split(" "));

  // const answer = A.reduce((cnt, a) => cnt + (a.reduce((acc, cur, i) => acc += cur * B[i], C) > 0), 0)
  const answer = A.filter(a =>
    a.reduce((acc, cur, i) => acc + cur * B[i], C) > 0
  ).length;
  console.log(answer);
}

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


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

int main(){
    int n, i, mx = 0;
    cin >> n;
    while(mx*(mx+1)/2 < n){
        mx++;
    }
    for(i=1; i<=mx; i++){
        if(mx*(mx+1)/2 - n != i){
            printf("%d\n", i);
        }
    }
    return 0;
}

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

typedef long long ll;
static const int N = 1e5 + 10;
static const int inf = 0x3f3f3f3f;
ll n, k, a[N];

int main ()
{
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	ll ans = inf;
	for (ll i = k; i <= n; ++i)
	{
		ll l = i - k + 1;
		ll r = i;
		if (a[l] * a[r] < 0)
		ans = min(ans, min(abs(a[l]), abs(a[r])) * 2 + max(abs(a[l]), abs(a[r])));
		else
		ans = min (ans, max(abs(a[l]), abs(a[r])));
//		cout << ans << endl;
	}
	cout << ans;
}

Measured memory_bytes: 1024
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    string s,t;
    cin>>s;
    if(a+b+1==s.size()){
        if(s[a]=='-'){
            rep(i,s.size()){
                if(i!=a&&s[i]=='-')return no,0;
            }
            yes;
        }
        else no;
    }
    else{
        no;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>


int main(void){
  int a, b, c;
  std::cin >> a >> b >> c;

  int jin[3][3];
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      jin[i][j] = 0;
    }
  }
  jin[0][0] = a;
  jin[0][1] = b;
  jin[1][1] = c;

  for(int K=-1000; K<1000; K++){
    int n3 = K - a - b;
    int n8 = K - b - c;
    int n9 = K - a - c;
    int n6 = K - n3 - n9;
    int n4 = K - c - n6;
    int n7 = K - a - n4;

    if(n3 + c + n7 == K){
      std::cout << a << " " << b << " " << n3 << std::endl;
      std::cout << n4 << " " << c << " " << n6 << std::endl;
      std::cout << n7 << " " << n8 << " " << n9 << std::endl;
    }
  }

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// a^n mod を計算する
// O(logn)
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int n;
    cin>>n;
    int a[n];
    map<int,int> m;
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
    }

    if(n%2==0){
        bool ok=true;
        for(int i=1;i<n;i+=2){
            if(m[i]!=2) ok=false;
        }
        if(ok) cout<<modpow(2,n/2,MOD);
        else cout<<0<<endl;
    }
    else{
        bool ok=true;
        for(int i=0;i<n;i+=2){
            if(i==0){
                if(m[i]!=1) ok=false;
            }
            else{
                if(m[i]!=2) ok=false;
            }
        }
        if(ok) cout<<modpow(2,n/2,MOD);
        else cout<<0<<endl;
    }
}



Measured memory_bytes: 4480
#include<stdio.h>
#include<string.h>
int main(){
    int k;
    char s[110];
    scanf("%d\n",&k);
    scanf("%s",s);
  // for(int i=0;s[i]!='\0';i++)
   //scanf("%c",s[i]);
    if(strlen(s)<=k){
        printf("%s",s);
        return 0;
    }
  else if(strlen(s)>k){
    scanf("%d",&k);
    scanf("%s",s);
    s[k]='\0';
    printf("%s...",s);
    return 0;
  }
}


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


long long w,d;
vector<long long> vw,vd;

long long solve();

int main() {
    while(1){
        cin >> w >> d;
        if(w + d==0)break;
        vw.resize(w);
        vd.resize(d);
        for(int i = 0;i < w;++i)cin >> vw[i];
        for(int i = 0;i < d;++i)cin >> vd[i];
        cout << solve() << endl;
    }
    return 0;
}


long long solve(){
    long long ans = 0,idw =0,idd = 0;
    sort(vw.begin(),vw.end());
    sort(vd.begin(),vd.end());
    while(idw < w || idd < d){
        if(idw == w)ans += vd[idd++];
        else if(idd == d)ans += vw[idw++];
        else if(vw[idw] == vd[idd]) ans += vw[idw++],++idd;
        else if(vw[idw] > vd[idd])ans += vd[idd++];
        else ans += vw[idw++];
    }
    return ans;
}



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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

template <typename T> std::string tostr(const T& t)
{
    std::ostringstream os; os<<t; return os.str();
}

int main(){
    ll n,m;
    cin>>n>>m;
    if(n==1&&m==1){
        cout<<1<<endl;
    }else if(n==1){
        cout<<m-2<<endl;
    }else if(m==1){
        cout<<n-2<<endl;
    }else{
        cout<<(n-2)*(m-2)<<endl;
    }
    
    return 0;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#ifdef LOCAL
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl
#else
#define dmp(x) void(0)
#endif

template <class t, class u>
void chmax(t &a, u b)
{
  if (a < b)
    a = b;
}
template <class t, class u>
void chmin(t &a, u b)
{
  if (b < a)
    a = b;
}
const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;

using vi = vc<int>;
int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b)
{
  return (a * b) / gcd(a, b);
}
int fact(int n)
{
  if (n == 0)
    return 1;
  return n * fact(n - 1);
}

int main()
{
 long n;cin>>n;
  if(n>=1&&n<=6){
   cout << 1 <<endl;
  }else if(n>=7&&n<=11){
  	cout << 2 <<endl;
  }else if(n%11==0){
  cout <<n/11*2<<endl;
  }else if(n%11 >=1&&n%11<=6){
   cout<<(n/11)*2+1<<endl;
  }else{
  cout <<(n/11)*2+2<<endl;
  }
}

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

using namespace std;

using ll=long long ;
void solve() {
    string s; cin >> s;
    ll k; cin >> k;
    int i = 0;
    while (s[i]=='1') {
        i++;
    }
    char res = k <= i? '1' : s[i];
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
int main() {
  int N; cin >> N;
  vector<double> a(N);
  rep(i, N){double s;cin >> s; a[i]=1/s;}
  
  double sum = 0;
  rep(i, N) sum+=a[i];
  double ans = 1/sum;
  cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;
    bool ans = false;
    for(int i=0; i<3; i++){
        if(s.at(i) == '7') ans = true;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3600
package main

import "fmt"

func main() {

	var (
		str, cmd, replace       string
		num, cmd_num1, cmd_num2 int
	)

	fmt.Scanln(&str)
	fmt.Scanln(&num)

	for i := 0; i < num; i++ {

		fmt.Scanf("%s %d %d", &cmd, &cmd_num1, &cmd_num2)

		if cmd == "print" {
			fmt.Println(str[cmd_num1 : cmd_num2+1])

		} else if cmd == "replace" {
			fmt.Scanf("%s", &replace)
			str = str[:cmd_num1] + replace[:] + str[cmd_num2+1:]

		} else if cmd == "reverse" {
			str1 := str[:cmd_num1]
			str2 := ""
			for j := cmd_num2; j >= cmd_num1; j-- {
				str2 += str[j : j+1]
			}
			str3 := str[cmd_num2+1:]
			str = str1 + str2 + str3

		}
	}

}



Measured memory_bytes: 3432
n=int(input())
l=[i for i in range(1,n+1)]
lst=[]
for i in range(n):
  a=0
  p=l[i]
  q=p
  while q%2==0:
    a+=1
    q=q//2
  lst.append((a,p))
lst.sort(reverse=True)
print(lst[0][1])
    
    
    

Measured memory_bytes: 3188
#include <iostream>

#define SIZE 100

using namespace std;

int *insertion(int, int[]);
void trace(int, int[]);

int main(void) {
	int n, seq[SIZE];

	cin >> n;

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

	trace(n, seq);

	insertion(n, seq);

	cin >> n;

	return 0;
}

int *insertion(int n, int seq[]) {
	for (int i = 1; i < n; i++) {
		int key = seq[i];
		int j = i - 1;
		while (j >= 0 && seq[j] > key) {
			seq[j + 1] = seq[j];
			j--;
		}
		seq[j + 1] = key;
		trace(n, seq);
	}
	return seq;
}

void trace(int n, int seq[]) {
	for (int k = 0; k < n; k++) {
		if (k > 0) {
			cout << " ";
		}
		cout << seq[k];
	}
	cout << "\n";
}

Measured memory_bytes: 3104
N = int(input())
grid = [[i for i in map(int,input().split())] for j in range(2)]

ans = 0
for i in range(1,N+1):
  temp = 0
  temp += sum(grid[0][:i])
  temp += sum(grid[1][i-1:])
  if temp > ans:ans=temp

print(ans)

Measured memory_bytes: 3060
n = input()
l = map(int, raw_input().split())
max = l[0]
min = l[0]
s = 0
for i in range(n):
 if max < l[i]:
  max = l[i]
 if min > l[i]:
  min = l[i]
 s = s + l[i]
print min, max, s

Measured memory_bytes: 7024
N = int(raw_input())
X = map(int, raw_input().split())

sortedX = sorted(X)
medSmall = sortedX[N/2-1]
medLarge = sortedX[N/2]

#print medSmall, medLarge

for i in range(N):
    if(X[i] <= medSmall):
        print(medLarge)
    else:
        print(medSmall)


Measured memory_bytes: 19932
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 3624
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int count = 0;
		for (int i=0; i<S.length()/2; i++) {
			if (S.charAt(i) != S.charAt(S.length()-i-1)) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22996
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    int X = sc.nextInt();
    int L[] = new int[N];
    for(int i=0; i<N; i++) L[i] = sc.nextInt();
    int ans = 1;
    int number = 0;
    for(int i=0; i<N; i++){
      number += L[i];
      if(number > X) break;
      ans++;
    }
    out.println(ans);
      
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

int main()
{
	int n,a;
	cin >> n;
	int num = 1;
	for(int i=0; i<n; i++){
		cin >> a;
		if(a==num)num++;
	}	
	if(num==1)cout <<"-1\n";
	else cout <<(n-(num-1))<<endl;
}	


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i=0; i<n; i++)
		cin >> s[i];
	sort(s.begin(), s.end());
	vector<int> cnt(n);
	vector<int> ans;
	int max_cnt = 0;
	for (int i=0; i<n; i++) {
		if (!i || s[i] != s[i-1])
			cnt[i] = 1;
		else cnt[i] = cnt[i-1] + 1;
		if(cnt[i]>max_cnt) {
			max_cnt = cnt[i];
			ans.resize(0);
		}
		if(cnt[i]==max_cnt)
			ans.push_back(i);
	}
	for (int i : ans)
		cout << s[i] << "\n";
	return 0;
}

Measured memory_bytes: 14580
N,K=map(int,input().split())
if K>(N-1)*(N-2)/2:
  print("-1")
else:
  print(int(N*(N-1)/2-K))
  for i in range(N-1):
    print("1",i+2)
  a=(N-2)*(N-1)/2-K
  if a!=0:    
    b=2
    for j in range(N-1):
      for k in range(N-j-2):
      	print(2+j,3+j+k)
      	a=a-1
      	if a==0:
      		break
      if a==0:
        break
 

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		long[] a = new long[n];
		long[] asum = new long[n];
		asum[0] = a[0];

		for (int i = 0; i < n; i++) {
			a[i] = nl();
			if (i > 0) {
				asum[i] = asum[i - 1] + a[i];
			}
		}

		long sum = 0;

		for (int i = 0; i < n; i++) {
			sum += (a[i] % MOD) * ((asum[n - 1] - asum[i]) % MOD);
			sum %= MOD;
		}
		out(sum);

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int w;
	int d;

	XY(int h, int w, int d) {
		this.h = h;
		this.w = w;
		this.d = d;
	}
}


Measured memory_bytes: 64324
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

class SegTree:
  def segfunc(self, x, y):
    if x[0] >= y[0]: return x
    return y
  def __init__(self, n, ide_ele, init_val):
    #####単位元######
    self.ide_ele = ide_ele
    #num:n以上の最小の2のべき乗
    self.num = 2 ** (n - 1).bit_length()
    self.seg = [self.ide_ele] * 2 * self.num
    #set_val
    for i in range(n):
      self.seg[i + self.num - 1] = init_val[i]    
    #built
    for i in range(self.num - 2, -1, -1) :
      self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) 
  def update(self, k, x):
    k += self.num - 1
    self.seg[k] = x
    while k + 1:
      k = (k - 1) // 2
      self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) 
  def query(self, p, q):
    if q <= p:
      return self.ide_ele
    p += self.num - 1
    q += self.num - 2
    res = self.ide_ele
    while q - p > 1:
      if p & 1 == 0:
        res = self.segfunc(res, self.seg[p])
      if q & 1 == 1:
        res = self.segfunc(res, self.seg[q])
        q -= 1
      p = p // 2
      q = (q - 1) // 2
    if p == q:
      res = self.segfunc(res, self.seg[p])
    else:
      res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
    return res

x = pow(2, N)
table = [0] * pow(2, N)
for i in range(pow(2, N)):
  ng = 0
  ok = x
  while ok - ng > 1:
    m = (ok + ng) // 2
    if a[i] > a[m]: ok = m
    else: ng = m
  table[i] = ok

#print(table)
seg = SegTree(x, (0, N), [(a[i], i) for i in range(x)])
tt = [0]
for i in range(N):
  t = pow(2, i)
  tt.sort(reverse = True)
  ttt = []
  for j in tt:
    #print(tt)
    if table[j] >= x:
      print("No")
      exit(0)
    y, k = seg.query(table[j], x)
    if a[j] <= y or (y == 0):
      print("No")
      exit(0)
    seg.update(k, (0, N))
    ttt.append(k)
  tt += ttt
print("Yes")

Measured memory_bytes: 123864
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n,k;
	cin>>n>>k;
	if(n>=2*k-1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String s =  in.next();

        int length= s.length();
        while (length > 0) {
            out.print("x");
            length--;
        }
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define irep(i,n) for(int i = n-1; i>=0; i--)
int GCD(int a,int b){
  int A,B;
  if(a<b){
    A=b;
    B=a;
  }
  else{
    A=a;
    B=b;
  }
  int R=A%B;
  while(R!=0){
    A=B;
    B=R;
    R=A%B;
  }
  return B;
}
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  vector<int> v(n);
  rep(i,n){
    cin >> v[i];
  }
  int ans=abs(x-v[0]);
  rep(i,n-1){
    ans = GCD(ans,abs(x-v[i+1]));
  }
  cout << ans << endl;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string S;
  cin >> S;
  bool f=false;
  bool g=false;
  ll d1 = stoi(S.substr(0, 2));
  ll d2 = stoi(S.substr(2, 2));
  f = (d1<=12 and d1>=1);
  g = (d2>=1  and d2<=12);
  if(f and g){
    cout << "AMBIGUOUS";
  }else if(f){
    cout << "MMYY";
  }else if(g){
    cout << "YYMM";
  }else{
    cout << "NA";
  }
  return 0;
}


Measured memory_bytes: 256
bool debug=false;
#include <stdio.h>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define PB push_back
#define F first
#define S second
const int N=6e3+10;
const int INF=1e9+10;
vector<pair<int,int>> graph[N];
int in[N],from[N],a[N],p[N],s[N],went[N];
int run(int root,int v){
	if(root+1==v)return 0;
	if(debug){
		printf("run(%d,%d)\n",root,v);
		for(int i=root;i<v;i++)for(pair<int,int> j:graph[i])printf("%d to %d cost=%d\n",i,j.F,j.S);
		printf("done debug\n");
	}
	int now,ans=0,tt,nv=v+1;
	for(int i=root;i<v;i++)from[i]=-1,in[i]=INF,went[i]=0;
	for(int i=root;i<v;i++)for(pair<int,int> j:graph[i])if(in[j.F]>j.S){
		from[j.F]=i;
		in[j.F]=j.S;
	}
	for(int i=root+1;i<v;i++)if(from[i]==-1)return -INF;
	else ans+=in[i];
	graph[v].clear();
	for(int i=root;i<v;i++)p[i]=v;
	went[root]=-2;
	for(int i=root+1;i<v;i++)if(went[i]==0){
		if(debug)printf("i=%d::\n",i);
		now=i;
		while(went[now]==0){
			if(debug)printf("dfs %d\n",now);
			went[now]=-1;
			now=from[now];
		}
		if(went[now]==-1){
			tt=now;
			now=i;
			while(now!=tt){
				went[now]=-4;
				now=from[now];
			}
			if(debug)printf("find ring\nnow=%d\n",now);
			p[now]=nv;
			graph[nv].clear();
			went[now]=-3;
			now=from[now];
			while(now!=tt){
				p[now]=nv;
				went[now]=-3;
				if(debug)printf("p[now=%d]=%d\n",now,p[now]);
				now=from[now];
			}
			nv++;
		}
		if(went[now]==-2){
			now=i;
			while(went[now]==-1){
				went[now]=-2;
				now=from[now];
			}
		}
		else {
			now=i;
			while(went[now]==-1){
				went[now]=-4;
				now=from[now];
			}
		}
	}
	for(int i=root;i<v;i++)if(went[i]!=-2&&p[i]==v)p[i]=nv++;
	if(debug)for(int i=root;i<v;i++)printf("p[%d]=%d\n",i,p[i]);
	if(debug)for(int i=root;i<v;i++)printf("went[%d]=%d\n",i,went[i]);
	for(int i=root;i<v;i++)for(pair<int,int> j:graph[i])if(p[j.F]!=p[i]&&went[j.F]!=-2)graph[p[i]].PB({p[j.F],j.S-in[j.F]});
	ans+=run(v,nv);
	return ans;
}
void solve(int n,int m,int root){
	int ans,l,r,x,y,c;
	for(int i=0;i<n;i++)graph[i].clear();
	while(m--){
	    scanf("%d%d%d",&l,&r,&c);
	    if(r==root)continue;
	    else if(l==root)graph[0].PB({r==0?root:r,c});
	    else graph[l==0?root:l].PB({r==0?root:r,c});
	}
	ans=run(0,n);
	if(ans<0)printf("-1\n");
	else printf("%d\n",ans);
}
int main(){
    int n,m,r;
    scanf("%d%d%d",&n,&m,&r);
	solve(n,m,r);
}



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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20

typedef long long ll;
using namespace std;

int n,t;
int s[10000],q[500];
int ans = 0;
int main() {
    scanf("%d",&n);
    rep(i,0,n){
        cin >> s[i];
    }
    scanf("%d",&t);
    rep(i,0,t){
        cin >> q[i];
    }
    rep(i,0,t){
        rep(j,0,n){
            if(q[i] == s[j]){
                ans++;
                break;
            }
        }
    }
    pout(ans);
    return 0;
}


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

using namespace std;

const int MAXN = 105, MAXA = 1e5 + 5;

int dp[MAXA], N, X, m[MAXN];

int main(){
	scanf("%d %d", &N, &X);
	for(int i=1; i<=N; ++i){
		scanf("%d", &m[i]);
		X -= m[i];
	}
	for(int j=1; j<=X; ++j)
		for(int i=1; i<=N; ++i) if(m[i] <= j) dp[j] = max(dp[j], dp[j - m[i]] + 1);
	printf("%d\n", N + dp[X]);
	return 0;
}

Measured memory_bytes: 640
a=[] #appendのために宣言が必要
while True:
    try:
        a.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

b=a[0][1]
cnt = 0
kadai = []
s=0

while  cnt != b:
    kadai.append(a[1][cnt])
    cnt = cnt + 1

for i in kadai:
    s = s + i
    
if a[0][0]-s>=0:
    print(a[0][0]-s)
else:
    print('-1')

Measured memory_bytes: 9888
#include <bits/stdc++.h>
#include <random>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define ld double
#define pld pair<ld,ld>
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define all(v) v.begin(),v.end()

using namespace std;
//using namespace __gnu_pbds;

ll MOD = 998244353;
const ll INF = 1e18;
const ld E = 1e-18;
const ld PI=acos(-1);
mt19937_64 rnd(time(0));
ll p1 = 31, p2 = 37, p3 = 7, p4 = rnd() % 100 + 1, md1 = MOD, md2 = 998244353, md3 = 998244357, md4 = rnd() % 1000000000;

//using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll n, m, k;


ll binpow(ll h, ll r, ll md = MOD)
{
    ll l = 1;
    while (r)
    {
        if (r & 1) l *= h, l%=md;
        h *= h;
        h %= md;
        r /= 2;
    }
    return l;
}

ll gcd(ll x, ll y)
{
    if (x < y) swap(x, y);
    while (x && y)
    {
        x %= y;
        swap(x, y);
    }
    return x + y;
}

void solve()
{
    cin >> n >> m;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("capitals.in","r",stdin);
    //freopen("capitals.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    if (n%2==0 || n%5==0)
    {
        cout << "-1\n";
        return 0;
    }
    ll p=7%n, j=1;
    while (j<=n && p!=0)
    {
        p=(p*10+7)%n;
        j++;
    }
    if (p==0)
    cout << j << "\n"; else cout << "-1\n";
    return 0;
}

/*
a-b=k
a+b=m
a=(m+k)/2;
b=(m-k)/2;
*/


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

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

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

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


//


////////////////////////////////////////////////////////////////////




int main() {
ll n,t;
cin>>n>>t;

ll dp[1000*n+1][n+1];
for(int i=0;i<=1000*n;i++){
    for(int j=0;j<=n;j++){
        dp[i][j]=10000000000000;
    }
}

ll w[n+1];
ll v[n+1];
rep(i, n){
    cin>>w[i]>>v[i];
}

ll sum=0;
dp[0][0]=0;
for(ll j=1;j<=n;j++){
for(ll i=0;i<=sum;i++){
    dp[i][j]=min(dp[i][j-1],dp[i][j]);
    dp[i+v[j]][j]=dp[i][j-1]+w[j];
}
sum+=v[j];

}

ll ans=0;
for(ll i=0;i<=1000*n;i++){
    for(ll j=0;j<=n;j++){
if(dp[i][j]<=t) ans=max(ans,i);
    }
}


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



Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n';

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s, t;cin>>s>>t;
    int m = s.size(), n = t.size();
    int ans = n;
    for(int i = 0; i < m - n +1; ++i){
        int cnt = 0;
        for(int j = i; j < n + i; ++j){
            cnt += (s[j]!=t[j-i]);
        }
        ans = min(ans, cnt);
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <time.h>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    vs s(3); rep(i,3) cin >> s[i];
	vector<vb> match(3,vb(8020,true));
	rep(i,3){
		ll n = s[i].size();
		ll j = (i+1) % 3;
		ll m = s[j].size();
		rep(k,6010){
			REP(l,k,k+s[j].size()){
				if(l < 4000 || l >= 4000 + n) continue;
				if(s[i][l-4000] != s[j][l-k] && s[i][l-4000] != '?' && s[j][l-k] != '?'){
					match[i][k] = false;
					break;
				}
			}
		}
	}
	ll ans = inf;
	rep(i,8010){
		if(!match[0][i]) continue;
		rep(j,8010){
			bool f = j-i>4000 || j-i<-4000 || match[1][4000+j-i];
			bool g = j>8000 || j<0 || match[2][4000-(j-4000)];
			if(f && g){
				int mx = max({4000+s[0].size(), i+s[1].size(), j+s[2].size()});
				int mn = min({4000, i, j});
				chmin(ans, mx-mn);
			}
		}
	}
	cout << ans << "\n";
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N+1);
  for (int i = 0; i < N+1; i++) cin >> A.at(i);
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    int def1 = min(A.at(i), B.at(i));
    ans += def1;
    A.at(i) -= def1;
    B.at(i) -= def1;
    int def2 = min(A.at(i+1), B.at(i));
    ans += def2;
    A.at(i+1) -= def2;
    B.at(i) -= def2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    long long int n,i,min,x,max,sum;
    scanf("%lld",&n);
    long long int ai[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld",&ai[i]);
    }
    min=ai[0];
    for(x=1;x<n;x++)
    {
        min=(min<ai[x])?min:ai[x];
    }
    max=ai[0];
    for(x=1;x<n;x++)
    {
        max=(max>ai[x])?max:ai[x];
    }
    sum=ai[0];
    for(x=1;x<n;x++)
    {
        sum=sum+ai[x];
    }
    printf("%lld %lld %lld\n",min , max, sum);
return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N);
	int ans = 0;
	
	for(int i=0;i<N;i++)cin>>A[i];
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			ans = max(ans,abs(A[i]-A[j]));
		}
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N,K;
    cin >> N >> K ;
    vector<ll> A(N),b(N+1);
    rep(i,N)cin >> A[i];
    rep(i,N)b[i+1] += b[i] + A[i];
    map<ll,ll> mp;
    ll ans = 0;
    for(int i = 0 ;i <= N;i++){
        // b[i] - i == b[j] - j になると嬉しい
        if(i>=K)mp[(b[i-K]-i+K)%K]--;
        ans += mp[(b[i]-i)%K];
        mp[(b[i]-i)%K]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        pw.println(Array(2) { sc.next() }.reversed().joinToString(""))
    }
}


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

int main() {
  int n, m;
  string s;
  cin >> n >> m >> s;
  int dp[n + 1], current = n;
  for (int i = m; i >= 0; --i) {
    if (s.rbegin()[i] == '0') {
      dp[n] = n - i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (i - m >= 0 && s[i - m] == '0') {
      dp[i] = i - m;
    } else {
      dp[i] = min(dp[i + 1], i);
    }
  }
  vector<int> result;
  do {
    auto next = dp[current];
    if (next == current) {
      result = {-1};
      break;
    }
    result.emplace_back(current - next);
    current = next;
  } while (current != 0);
  for (auto it = result.rbegin(); it != result.rend(); ++it) {
    cout << *it << ' ';
  }
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  cin >> N;
  vector<int> a(3 * N);
  REP(i, 3 * N) cin >> a[i];
  sort(ALL(a));

  ll res = 0;
  for(int i = N; i <= 3 * N - 2; i += 2) {
    res += a[i];
  }
  cout << res << endl;
  return 0;
}



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

int main(){
    double r;
    const double pi = acos(-1);
    
    cin >> r ;
    cout<<fixed<<setprecision(10);
    cout << r*r*pi<<" "<<2*pi*r<<endl;
}


Measured memory_bytes: 3268
#include<stdio.h>
#include<iostream>

using namespace std;

int main(){
  int n,k;
  
  cin >> n>>k;
  
  int ans=1;
  while(n>0){
    if(k>ans){
      ans*=2;
      n--;
    }else{
      ans+=k;
      n--;
    }
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>

int main(){
	int r, d, x_;
	std::cin>>r>>d>>x_;

	long long x= x_;

	for(int i=0; i<10; i++){
		x= r*x - d;
		std::cout<<x<<std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
using ll = long long;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll S) {
  string str = to_string(S);
  bool pred = true;
  for (auto i = 0; i != 3; ++i) {
    if (str[i] == str[i + 1]) pred = false;
  }
  cout << (pred ? "Good" : "Bad") << endl;
}

int main() {
  ll S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256