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

 int n;
 long long int k;
 cin>>n>>k;
 int a[n+1];
 int i;
 for(i=0;i<n;i++)
 cin>>a[i+1];
 vector<int> v;
 int p=1;
 map<int,int> m;
 while(m[p]==0)
 {
 	m[p]=v.size()+1;
 	v.push_back(p);
 	p=a[p];
 }
 if(k<v.size())
 cout<<v[k]<<endl;
 else
 {
 	k-=m[p]-1;
 	//cout<<v.size()<<endl;
 	if(m[p]!=1)
 	v.erase(v.begin(),v.begin()+m[p]-1);
 	k%=v.size();
 	cout<<v[k]<<endl;
 }
 return 0;
}


Measured memory_bytes: 13916
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	         String s = sc.next();
      if(s.equals("SUN")){
            System.out.println(7);
        }else if(s.equals("MON")){
            System.out.println(6);
        }else if(s.equals("TUE")){
            System.out.println(5);
        }else if(s.equals("WED")){
            System.out.println(4);
        }else if(s.equals("THU")){
            System.out.println(3);
        }else if(s.equals("FRI")){
            System.out.println(2);
        }else if(s.equals("SAT")){
            System.out.println(1);
        }
      		
    }
}


Measured memory_bytes: 24020
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int A, B;
  cin >> A >> B;
  if(A % 2 == 0 || B % 2 == 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SIZE_N 10000
#define SIZE_P 10000
int  flag[SIZE_N+1];
int primes[SIZE_P+1];
int seive()
{
    int  i,j,total=0,val;

    for(i=2; i<=SIZE_N; i++) flag[i]=1;

    val=sqrt(SIZE_N)+1;

    for(i=2; i<val; i++)
        if(flag[i]==1)
            for(j=i; j*i<=SIZE_N; j++)
                flag[i*j]=0;

    for(i=2; i<=SIZE_N; i++)
        if(flag[i]==1)
            primes[total++]=i;

    return total;
}

int main()
{
    int total= seive();

    long  long i,n,res=1,p=1,exp,tmp;
    cin>>n;
    for(i=0; primes[i]<=n; i++)
    {

        exp=0;

        p=primes[i];
        tmp=n;

        while(tmp)
        {
            tmp/=p;
            exp+=tmp;


        }

        res=res*(exp+1);
        res=res%1000000007;
    }

    cout<<res<<endl;


    return 0;
}


Measured memory_bytes: 256
def nyu():
    H,W = map(int,input().split())
    S = [list(input()) for i in range(H)] 
    return S,H,W

def check(S,H,W):

    for h in range(H):
        for w in range(W):
            if S[h][w] != "#":
                if h !=0 :
                    if S[h-1][w] == "#":
                        S[h][w] +=1
                if h !=H-1 :
                    if S[h+1][w] == "#":
                        S[h][w] +=1
                if w !=0 :
                    if S[h][w-1] == "#":
                        S[h][w] +=1
                if w !=W-1 :
                    if S[h][w+1] == "#":
                        S[h][w] +=1
#右斜め
                if h !=H-1  and w !=W-1:                    
                    if S[h+1][w+1] == "#":
                        S[h][w] +=1
                if h != 0  and w !=W-1:                    
                    if S[h-1][w+1] == "#":
                        S[h][w] +=1
#左斜め下　左斜め上
                if h !=H-1  and w !=0:                    
                    if S[h+1][w-1] == "#":
                        S[h][w] +=1

                if h != 0  and w !=0:                    
                    if S[h-1][w-1] == "#":
                        S[h][w] +=1

    for a in S:
       print(*a,sep='')
 

def convert(S,H,W):
    
    for h in range(H):
        for w in range(W):
            if S[h][w]==".":
                S[h][w] = 0
    return S

S,H,W = nyu()
S =convert(S,H,W)
check(S,H,W)


Measured memory_bytes: 3572
S=list(input())

acgt=["A","C","G","T"]

max_length = 0
length = 0
for word in S:
    if word in acgt:
        length+=1
    else:
        if length!=0:
            if max_length<length:
                max_length=length
            length=0
if length!=0:
    if max_length<length:
        max_length=length
print(max_length)


Measured memory_bytes: 9076
#include <stdio.h>

int main(int argc, const char * argv[]){
    int sec,min,hour;
    scanf("%d", &sec);
    hour = sec / 3600;
    min = (sec - (hour * 3600)) / 60 ;
    sec = sec - ((hour * 3600) + (min * 60));
    printf("%d:%d:%d\n", hour,min,sec);
}


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

int main()
{
	int N;
	cin >> N;
	string s;
	rep(i,N)
	{
		cin >> s;
		P[s]++;
	}
	int M = 0;
	for (auto it = P.begin(); it != P.end(); ++it)
	{
		M = max(M,it->second);
	}
	for (auto it = P.begin(); it != P.end(); ++it)
	{
		if (it->second == M)
		{
			cout << it->first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 25216
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

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

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

def main():
  h,n=LI()
  w=[]
  v=[]
  max_w=0
  for _ in range(n):
    _w,_v=LI()
    w.append(_w)
    v.append(_v)
    max_w=max(max_w,_w)

  dp=[[inf]*(h+10**4+1) for _ in range(n+1)]
  dp[0][0]=0
  for i in range(n):
    for j in range(h+max_w):
      if j<w[i]:
        dp[i+1][j]=dp[i][j]
      else:
        dp[i+1][j]=min(dp[i][j],dp[i+1][j-w[i]]+v[i])
  ans=inf
  for i in range(n+1):
    for j in range(h,h+max_w):
      ans=min(ans,dp[i][j])

  return ans

# main()
print(main())


Measured memory_bytes: 349676
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  8 19:06:56 2019

@author: yuta
"""

N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A = [A1,A2]

def main(n,a):
    count = []
    for i in range(n):
        count.append(sum(a[0][0:(i+1)])+sum(a[1][i:n]))
    max_value = max(count)
    print(max_value)
main(N,A)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>

using namespace std;

 long long n, k, l, r, c = 0;
 // int q, n;
 int main() {

     int a, b;
     cin >> a >> b; 
     if (a < b) cout << 0;
     else cout << 10; 
    }
    

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

int main(){
  int K,S;
  cin >> K >> S;
  int counter =0;
  for(int i = 0; i <= K; i++){
    for(int j = 0; j <= K; j++){
        if(i + j <= S && (S - i - j) <= K)counter++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin>>t;
	while (t--)
	{
		int x, y, a, b, c;
		cin >> x >> y >> a >> b >> c;
		int red[a], green[b], cless[c];
		for (auto &i : red) cin >> i;
		for (auto &i : green) cin >> i;
		for (auto &i : cless) cin >> i;
		sort(red, red + a, greater<int>());
		sort(green, green + b, greater<int>());
		vector<int> fin;
		for (int i = 0; i < x; i++) fin.pb(red[i]);
		for (int i = 0; i < y; i++) fin.pb(green[i]);
		for (auto i : cless) fin.pb(i);
		sort(all(fin), greater<int>());
		ll sm = 0, req = x + y;
		for (auto i : fin) {
			sm += i;
			req--;
			if (!req) break;
		}
		cout << sm << "\n";
	}
	return 0;
}

Measured memory_bytes: 6432
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b;
  string s;
  long long ans = 0;
  
  cin >> s;

  s[5] = ' ';
  s[13] = ' ';
  
  cout << s << endl;

}

Measured memory_bytes: 256
def main():
    N = int(input())
    B = list(map(int, input().split()))
    #  [1,2,3]
    # P = range(1, 100)
    l = []

    for P in range(1, 100):
        l2 = []
        for t in B:
            x = (t - P) ** 2
            l2.append(x)

        l.append(sum(l2))
    print(min(l))


main()

Measured memory_bytes: 2940
n = int(input())

a = []
b = set()
for _ in range(n):
    tmp = int(input())
    a.append(tmp)
    b.add(tmp)

max_num = max(b)
c = b - {max_num}
if len(c) == 0 or a.count(max_num) >= 2:
    second_max_num = max_num
else:
    second_max_num = max(c)

for elem in a:
    if not elem == max_num:
        print(max_num)
    else:
        print(second_max_num)


Measured memory_bytes: 21088
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] p = new int[n];
    for (int i=0;i<n;i++){
      p[i] = sc.nextInt()-1;
    }
    sc.close();
    int ans = 0;
    for (int i=0;i<n;i++){
      if (p[i] ==i){
        ans++;
        i++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 48940
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
#define INF 1e9
int a[210][210];
int c[10][10];
int dis[10][10];
int main(){
    int h,w;
    cin>>h>>w;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin>>c[i][j];
        }
        
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin>>a[i][j];
        }
        
    }
    //ワーシャルフロイト
   /*  for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            if(i!=j){
                dis[i][j]=INF;
            }
        }
        
    }*/
    
    for (int k = 0; k < 10; k++)
    {
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
             c[i][j]=min(c[i][j],c[i][k]+c[k][j]);   
            }
            
        }
        
    }
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cerr<<c[i][j];
        }
        cerr<<endl;
        
    }

    int sum=0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(a[i][j]!= 1 || a[i][j]!=-1)
            sum+=c[a[i][j]][1];
        }
        
    }
    cout<<sum<<endl;
    

    
    

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if (!n) break;
    vector<pair<int,int>> b;
    REP(i,n) {
      int r,w;
      cin>>r>>w;
      b.emplace_back(r,w);
    }
    sort(b.rbegin(),b.rend());
    int sum = 0;
    REP(i,n) sum += b[i].first;
    int sumw = 0;
    REP(i,n) sumw += b[i].second;
    int b0r = b[0].first;
    if (b0r*2 > sum) {
      int rem = b0r*2 - sum;
      vector<vector<bool>> dp(n,vector<bool>(rem+1101,false));
      dp[0][0] = true;
      REP(i,n-1)
        REP(j,rem+1) {
          dp[i+1][j] = dp[i+1][j] || dp[i][j];
          dp[i+1][j+b[i+1].second] = dp[i+1][j+b[i+1].second] || dp[i][j];
        }
      int mxb = 0;
      REP(i,rem+1)
        if (dp[n-1][i])
          mxb = i;
      //int rbmt = max(2 * b0r, b0r + mxb);
      cout << b0r*2 + (sumw - mxb) << endl;
    } else {
      cout << (sum + sumw) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  int min = 0;
  cin >> N;
  vector<int> W;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    W.push_back(a);
  }
  for (int i = 1; i <= N; i++)
  {
    int r = 0, l = 0;
    for (int j = 0; j <= i - 1; j++)
    {
      r += W.at(j);
    }
    for (int k = i; k < N; k++)
    {
      l += W.at(k);
    }
    //cout << "r" << r << endl;
    //cout << "l" << l << endl;
    //cout << "abs" << abs(l - r) << endl;

    if (i == 1)
    {
      min = abs(l - r);
    }
    else if (abs(l - r) < min)
    {
      min = abs(l - r);
    }
  }

  cout << min << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
bool map[10][10000] = { 0 };
int M, N;
int res = 0;
void dfs(int x) {
	int sum = 0;
	int term = 0;
	if (x == M) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				if (map[j][i] == 1)
					term++;
			}
			sum += M - term > term ? M - term : term;
			term = 0;
		}
		res = max(res, sum);
		return;
	}
	dfs(x + 1);
	for (int i = 0; i < N; i++)
		map[x][i] = !map[x][i];
	dfs(x + 1);

}
int main() {
	while (1)
	{
		cin >> M >> N;
		if (M == 0 && N == 0)
			break;
		for (int i = 0; i < M; i++)
			for (int j = 0; j < N; j++)
				cin >> map[i][j];
		res = 0;
		dfs(1);
		cout << res<<endl;
	}
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

int arr[MAX], pref[MAX], suff[MAX];

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

    cin>>n;

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

    pref[0] = arr[0];
    for(int i = 1; i < n; i++){
        pref[i] = __gcd(pref[i-1], arr[i]);
    }
    suff[n-1] = arr[n-1];
    for(int i = n - 2; i >= 0; i--){
        suff[i] = __gcd(suff[i+1], arr[i]);
    }

    int Max = 0;
    Max = max(Max, suff[1]);
    Max = max(Max, pref[n-2]);

    for(int i = 1; i < n - 1; i++){
        Max = max(Max, __gcd(pref[i-1], suff[i+1]));
    }

    cout<<Max<<endl;

    return 0;
}

Measured memory_bytes: 1408
//clang 3.8.0

#include <iostream>
using namespace std;
#define		endl		"\n"
#define		ll			long long int
#define		mod			1000000007
#define		f(i,a,b)	for(ll i = (ll)(a); i < (ll)(b); i++)
#define		rf(i,a,b)   for(ll i = (ll)(a); i > (ll)(b); i--)
#define		ull			unsigned long long
#define		ld			long double


int main()
{
    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7')
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
}

Measured memory_bytes: 3160
import sys
from fractions import gcd
n,k = map(int,input().split())
A = list(map(int,input().split()))
if k in A:
    print("POSSIBLE")
    sys.exit()
A.sort()
if A[n-1] < k:
    print("IMPOSSIBLE")
    sys.exit()
mod = A[0]
for i in range(1,n):
    mod = gcd(mod,A[i])
    if mod == 1 or (k%mod==0):
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 16116
N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
AB.sort(key=lambda x: x[1])

ans = 1
removed = AB[0][1] - 1
for i in range(M):
    if AB[i][0] > removed:
        removed = AB[i][1] - 1
        ans += 1
print(ans)


Measured memory_bytes: 29076
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>

using namespace std;
const int64_t INF=1e10;

#include <cstdint>
#include <iostream>
#include <utility>
#include <map>

int64_t gcd(int64_t a,int64_t b){//calc gcd
	if(a==0){
		return b;
	}else if(b==0){
		return a;
	}else if(a>b){
		return gcd(a%b,b);
	}else{
		return gcd(b%a,a);
	}
}
std::pair<int64_t,int64_t> extgcd(int64_t a,int64_t b){//a*(pair->first) + b*(pair->second) = gcd(a,b)
	if(a==0){
		return std::make_pair(0,1);
	}else if(b==0){
		return std::make_pair(1,0);
	}else{
		if(a>b){
			std::pair<int64_t,int64_t> d=extgcd(a%b,b);
			return std::make_pair(d.first,d.second-(a/b)*d.first);
		}else{
			std::pair<int64_t,int64_t> d=extgcd(a,b%a);
			return std::make_pair(d.first-(b/a)*d.second,d.second);
		}
	}

}
int64_t inline normalize_mod(int64_t a,int64_t m){
	return (m+a%m)%m;
}
int64_t mod_inv(int64_t a,int64_t m){//a^-1(mod m),m is a prime number
	int64_t raw=extgcd(a,m).first;
	return normalize_mod(raw,m);;
}
std::map<int64_t,int64_t> factorization(int64_t n){
	std::map<int64_t,int64_t> retval;
	for(int64_t i=2;i*i<=n;i++){
		int64_t counter=0;
		while(n%i==0){
			n=n/i;
			counter++;
		}
		if(counter!=0){
			retval.emplace(i,counter);
		}
	}
	return retval;
}
std::pair<int64_t,int64_t> mod_fact(int64_t n,int64_t m){//n!=first*m^second
	if(n==0){
		return std::make_pair(1,0);
	}else{

		std::pair<int64_t,int64_t> d=mod_fact(n/m,m);
		int64_t second=d.second+n/m;
		int64_t first;
		if((n/m)%2==0){
			first=1;
		}else{
			first=m-1;
		}
		for(int64_t i1=1;i1<=(n%m);i1++){
			first=normalize_mod(first*i1,m);
		}
		return std::make_pair(first,second);
	}
}
int64_t calcg(int64_t r,int64_t c){
	int64_t ans=c+1;
	int64_t last_value=c+1;
	for(int64_t i1=1;i1<=r;i1++){
		last_value *= (c+i1+1);
		last_value = normalize_mod(last_value,1e9+7);
		last_value *= mod_inv(i1+1,1e9+7);
		last_value = normalize_mod(last_value,1e9+7);
		ans += last_value;
		ans = normalize_mod(ans,1e9+7);
	}
	return ans;
}
int main(){
	int64_t r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	cout<<normalize_mod(calcg(r2,c2)-calcg(r1-1,c2)-calcg(r2,c1-1)+calcg(r1-1,c1-1),1e9+7);
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

struct ModInt {
  static void setMod(int m) {
    mod = m;
  }

  ModInt(int val = 0) : val(val%mod) {}

  inline const ModInt operator + (const ModInt& rhs) const {
    return ModInt((this->val + rhs.val) % mod);
  }

  inline const ModInt operator - (const ModInt& rhs) const {
    return ModInt((this->val + mod - rhs.val) % mod);
  }

  inline const ModInt operator * (const ModInt& rhs) const {
    return ModInt((this->val * rhs.val) % mod);
  }

  inline ModInt& operator += (const ModInt& rhs) {
    this->val = (this->val + rhs.val) % mod;
    return *this;
  }

  inline ModInt& operator -= (const ModInt& rhs) {
    this->val = (this->val + mod - rhs.val) % mod;
    return *this;
  }

  inline ModInt& operator *= (const ModInt& rhs) {
    this->val = (this->val * rhs.val) % mod;
    return *this;
  }

  int val;
  static int mod;
};
int ModInt::mod = MOD;

constexpr int MAX_N = 51;
constexpr int MAX_K = MAX_N*MAX_N;
int N, K;

ModInt dp[MAX_N][MAX_N][MAX_K];

signed main()
{
  cin >> N >> K;
  if(K == 0) {
    cout << 1 << endl;
    return 0;
  }

  dp[0][0][0] = 1;

  FOR(i,1,N+1) {
    REP(j,N+1) {
      REP(k,MAX_K) {
        if(k-2*j>=0) {
          dp[i][j][k] = ModInt(2*j+1)*dp[i-1][j][k-2*j] 
          + ModInt((j+1)*(j+1))*dp[i-1][j+1][k-2*j];
          if(j-1>=0) {
            dp[i][j][k] += dp[i-1][j-1][k-2*j];
          }
        }
      }
    }
  }

  cout << dp[N][0][K].val << endl;

  return 0;
}


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 200005;

vector<ll> prime = {
  2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293
};

int main(){
  ll X,Y; cin >> X >> Y;
  if(X%Y==0LL){
    cout << "-1" << endl;
  }else{
    for(auto p:prime){
      if(Y%p!=0LL){
        cout << X*p << endl;
        return 0;
      }
    }
    cout << "-1" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

class Simple {
    int X, Y, Z;
    void Solve() {
        //input
        X = io.Int;
        Y = io.Int;
        Z = io.Int;
        //cal
        var ans = (X - Z) / (Y + Z);
        //ret
        Console.WriteLine(ans);
    }


    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() { Solve(); io.writeFlush(); }
}

class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
X, Y, Z, K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

sum12s = []
for A in As:
    for B in Bs:
        sum12s.append(A+B)
sum12s.sort(reverse=True)
sum12s = sum12s[:K] + [-1]

anss = [] + [-1]
for C in Cs:
    ans2s = []
    iAns = iSum12 = 0
    for _ in range(min(K, len(anss)+len(sum12s)-2)):
        if anss[iAns] >= C+sum12s[iSum12]:
            ans2s.append(anss[iAns])
            iAns += 1
        else:
            ans2s.append(C+sum12s[iSum12])
            iSum12 += 1
    anss = ans2s + [-1]

print('\n'.join(map(str, anss[:-1])))


Measured memory_bytes: 55244
n = int(input())
a = input()
b = input()
c = input()

ans = 0
for i in range(n):
  if a[i] == b[i] and b[i] == c[i]:
    # すべて同じなので操作しなくて良い
    continue

  if a[i] != b[i] and a[i] != c[i] and b[i] != c[i]:
    # すべて異なるので操作2回
    ans = ans + 2
    continue

  # 1つ異なる
  ans = ans + 1

print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> v;
  int n;

  cin >> n;
  for(int i=0; i<n; i++) {
    int temp;
    cin >> temp;
    v.push_back(temp);
  }

  for(int i=0; i<n; i++) {
    cout << v[n-(i+1)];
    if(i != n-1) {
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}



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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/


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

  vi a(n);
  rep(i, 0, n) cin >> a[i];

  vector<vector<pii>> dp(n, vector<pii>(n, {inf, 0}));
  rep(i, 0, n) dp[i][i] = {0, a[i]};
  rep(len, 2, n+1) rep(l, 0, n-len+1){
    int r = l+len-1;
    rep(m, l, r){
      int sf = dp[l][m].first + dp[m+1][r].first;
      int ss = dp[l][m].second + dp[m+1][r].second;
      chmin(dp[l][r], {sf+ss, ss});
    }
  }

  cout << dp[0][n-1].first << endl;

  return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  string S;
  cin>>A>>B>>S;
  int ans=1;
  for(int i=0;i<A;i++){
    if(S[i]<'0'||S[i]>'9'){
      ans=0;
      break;
    }
  }
  if(ans){
    if(S[A]!='-') ans=0;
  }
  if(ans){
    for(int i=A+1;i<A+B+1;i++){
      if(S[i]<'0'||S[i]>'9'){
        ans=0;
        break;
      }
    }
  }
  cout<<(ans?"Yes":"No")<<endl;
}

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

using namespace std;

const int size = 2e5+ 7;
long long int weight[size], value[size], dp[size];

int main(){
	int n, w;
	long long int totalValue = 0;
	cin>>n>>w;
	for(int x=0;x<n;x++){
		cin>>weight[x]>>value[x];
		totalValue += value[x];
	}

	for(int x=0;x<=totalValue;x++) dp[x] = 1e14;
	dp[0] = 0;
	
	for(int i=0;i<n;i++){
		for(int x=totalValue;x>=0;x--){
			if(x-value[i] >=0 ){
				dp[x] = min(dp[x], dp[x-value[i]] + weight[i]);
			}
		}
	}
	// for(int x=0;x<=totalValue;x++){
		
	// }

	for(int x=totalValue;x>=0;x--){
		if(dp[x] <= w){
			cout<<x;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 3072
N , K = map(int,input().split())
ans = 0
for i in range(K + 1, N + 1):
    before_range = max((N % i - K + 1) , 0)
    before_cnt = (N // i + 1)
    before = before_cnt * before_range
    after_range = min((i - 1) - (N % i) , (i - 1) - K + 1)
    after_cnt = (N // i)
    after = after_cnt * after_range
    now = before + after
    if K == 0:
        now -= 1
    #print(now)
    ans += now
print(ans)

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

using namespace std;

typedef long long ll;

const int N(2e5 + 9);

int T, n, m, ans;

bool equ(double x, double y)
{
    return abs(x - y) < 1e-8;
}
int main()
{   
    double w, h, x, y;
    cin>>w>>h>>x>>y;
    printf("%.9lf ", w * h / 2);
    if (equ(x, w / 2) && equ(h / 2, y)) cout<<1;
    else cout<<0;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;



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

    int ans = 0;
    while (N > 0) {
        N -= 1000;
    }

    ans = abs(N);
    cout << ans << endl;
}


Measured memory_bytes: 3684
object Main extends App {

  import scala.io.StdIn._
  val n = readInt
  implicit val memo = Array.tabulate(19){_ ⇒ None: Option[Int]}
  implicit val memo2 = Array.tabulate(19){len ⇒ Array.tabulate(len + 1){_ ⇒ None: Option[List[Int]]}}
  val numbers = Array.tabulate(n){_ ⇒
    val arg = readLine.trim.split(' ')
    g(arg.tail.headOption.getOrElse("").asBase(arg.head.toInt), 0)
  }
  if (numbers.foldLeft(0)(_^_) != 0)
    println("win")
  else println("lose")
  def g(number: Int, current: Int): Int = {
    if (number == 0) g(current)
    else if (number % 2 == 1) g(number / 2, current + 1)
    else if (current == 0) g(number / 2, 0)
    else g(current) ^ g(number / 2, 0)
  }
  def g(length: Int)(implicit memo: Array[Option[Int]]): Int = {
    if (length == 0) 0
    else memo(length) match {
      case Some(r) ⇒ r
      case None ⇒
        val nextState = (0 until length).flatMap(max ⇒ separation(length - max - 1, max)(memo2).map(_ ^ g(max))).distinct.sorted
        var find = false
        var prev = -1
        for (n ← nextState if !find) {
          if (prev + 1 != n) find = true
          prev = prev + 1
        }
        if (!find) prev += 1
        memo(length) = Some(prev)
        prev
    }
  }
  def separation(length: Int, max: Int)(implicit memo2: Array[Array[Option[List[Int]]]]): List[Int] = {
    if (length <= 0 || max == 0) List(0)
    else memo2(length)(math.min(length, max)) match {
      case Some(l) ⇒ l
      case None ⇒ (0 to math.min(length, max)).flatMap(nextMax ⇒ separation(length - nextMax - 1, nextMax).map(_ ^ g(nextMax))).toList.distinct.also(l ⇒ memo2(length)(math.min(length, max)) = Some(l))
    }
  }
  implicit class AsPrimeBase(val value: String) extends AnyVal{
    def asBase(base: Int): Int = {
      value.map{
        case c if c.isDigit ⇒ c.asDigit
        case c if c.isUpper ⇒ c - 'A' + 10
        case c ⇒ c - 'a' + 36
      }.foldLeft(0){(a, b) ⇒ a * base + b}
    }
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
    @inline
    def takeIf(@inline predicate: T ⇒ Boolean): Option[T] = Some(value).filter(predicate)
  }
}


Measured memory_bytes: 161264
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int p = sc.nextInt();
		int flagment = a * 3 + p;
		int applePie = flagment / 2;
		
		System.out.println(applePie);
	}	
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main(){
  int k, x;
  cin >> k >> x;

  if(500*k>=x) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
h,*s=open(0)
h,w,k,*m=map(int,h.split())
b=w
while b:
 b-=1;r=t=j=0;d=[0]*h
 while w-j:
  i=c=0;j+=1
  while h-i:
   d[c]+=s[i][~j]>'0';c+=b>>i&1;i+=1
   if max(d)>k:d=[0]*h;f=t<j;r+=1;t=j;j-=f;break
 m+=r+c,
print(min(m))

Measured memory_bytes: 43976
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int n, a;
	cin >> n >> a;
	int b = a + n - 1;
	
	cout << n * (a + b) / 2 - (inII(0, a, b) ? 0 : (0 < a ? a : b)) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x; i <= y; ++ i)
#define repd(i,x,y) for(register int i = x; i >= y; -- i)
typedef long long ll;
using namespace std;
template<typename T>inline bool chkmax(T&x,T y) { return x < y ? x = y,1 : 0; }
template<typename T>inline bool chkmin(T&x,T y) { return x > y ? x = y,1 : 0; }
template<typename T>inline void read(T&x)
{
	char c;int sign = 1;x = 0;
	do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
	do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
	x *= sign;
}
const int N = 2e5 + 50;
ll n,mx,l[N],r[N],ans;
ll a[N],b[N],s[N],cnt[N],top;

int main()
{
	read(n);
	rep(i,1,n) read(a[i]);
	rep(i,1,n) b[i] = a[i];
	l[1] = 1;
	rep(i,2,n)
	{
		while(a[i-1] < a[i])	
		{
			a[i-1] *= 4; ans += (i-s[top]-1)*2;
			-- cnt[top]; if(!cnt[top])--top;
		}
		if(a[i-1]/a[i]>=4)
		{
			s[++top] = i-1;
			while(a[i-1]/a[i] >= 4)
				a[i-1] /= 4,++ cnt[top];
		}
		l[i] = i + ans;
	}
	while(top) cnt[top--] = 0;
	ans = 0;
	r[n] = 0; s[0] = n + 1;
	rep(i,1,n) a[i] = b[i];
	repd(i,n-1,1)
	{
		while(a[i+1] < a[i])
		{
			a[i+1] *= 4; ans += (s[top]-i-1)*2;
			-- cnt[top]; if(!cnt[top]) -- top;
		}
		if(a[i+1]/a[i]>=4)
		{
			s[++top] = i + 1;
			while(a[i+1]/a[i] >= 4)
				a[i+1]/=4,++cnt[top];
		}
		r[i] = ans;
	}
	ans = l[n];
	rep(i,1,n) ans = min(ans,l[i-1] + r[i]);
	cout << ans << endl;
	
	return 0;
}

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

int main(){
    int N,M;
    cin >>N>>M;
    int A[N];
    for(int i=0;i<N;++i){
        cin >>A[i];
    }
    
    for(int k=1;k<M+1;++k){
        for(int a=0;a<N;++a){
    if(0<=a&&a<N-1){
        if(A[a]%k>A[a+1]%k){
            int temp = A[a];
            A[a]=A[a+1];
            A[a+1]=temp;
            
        }
        else{
        }
        }
    else{
        break;
    }
    }
    }
    
    for(int w=0;w<N;++w){
        cout <<A[w]<<endl;
    }
    return 0;
}

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

using namespace std;

int N;
int Q;
string s;
vector<string> t, d;

string L="L", R="R";

int check(int m){
    for(int i=0; i<Q; ++i){
        if(t[i][0] == s[m]){
            if(d[i] == L){
                m--;
            }else{
                m++;
            }
        }
    }
    return m;
}

int main(){
    cin>>N>>Q;
    cin>>s;

    t.resize(Q);
    d.resize(Q);
    for(int i=0; i<Q; ++i){
        cin>>t[i]>>d[i];
    }

    int ans=0;
    int l, r;
    l=-1;
    r=N;
    while(l+1!=r){
        int m=(l+r)/2;
        int result = check(m);
        if(result==-1){
            l=m;
        }else if(result==N){
            r=m;
        }else{
            r=m;
        }
    }
    ans+=l+1;

    l=-1;
    r=N;
    while(l+1!=r){
        int m=(l+r)/2;
        int result = check(m);
        if(result==-1){
            l=m;
        }else if(result==N){
            r=m;
        }else{
            l=m;
        }
    }
    ans+=N-r;

    cout<<N-ans<<endl;
}

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

using namespace std;

int main()
{
    string S;
    long long int black = 0, blnum = 0, hoge = 0;
    cin >> S;
    for(int i = 0; i < S.size(); ++i) {
        if(S[i] == 'B') {
            black += i; blnum++;
        }
    }
    for(int i = 0; i < blnum; ++i) {
        hoge += S.size() - 1 - i;
    }
    cout << hoge - black << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y,z;
    cin >> x >> y >> z;
    int i=0;
    int ky=0;
    while(1){
        if(i==0)ky+=z;
        ky+=(y+z);
        i++;
        if(ky>x){
            cout << i-1 << endl;
            return 0;
        }
        if(ky==x){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, z, W, a[2000];
	cin >> n >> z >> W;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int d[2000][2];
	for (int k = n; k--;) {
		for (int i = 0; i < 2; i++) {
			int w = k ? a[k - 1] : i ? z : W;
			int m = a[n - 1] < w ? w - a[n - 1] : a[n - 1] - w;
			for (int j = k + 1; j < n; j++)
				if (i ? m > d[j][0]:m < d[j][1])
					m = d[j][!i];
			d[k][i] = m;
		}
	}
	cout << d[0][0] << endl;
	return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
keta=[-1]*N
a=[]
for i in range(M):
    c1,c2=map(int,input().split())
    a.append([c1,c2])


for p in a:
    k=p[0]
    s=p[1]
    if keta[k-1] == -1:
        keta[k-1] = s
    elif keta[k-1] != s:
        print(-1)
        exit()


if N==1:
    for i in range(0,10**N):
        Q= str(i)
        flag=1
        for j in range(N):
            if keta[j]!= -1 and Q[j]==str(keta[j]):
                flag *= 1
            elif keta[j]!= -1 and Q[j] != str(keta[j]):
                flag *= 0

        if flag==1:
            print(i)
            exit()

    
    
for i in range(10**(N-1),10**N):
    Q= str(i)
    flag=1
    for j in range(N):
        if keta[j]!= -1 and Q[j]==str(keta[j]):
            flag *= 1
        elif keta[j]!= -1 and Q[j] != str(keta[j]):
            flag *= 0

    if flag==1:
        print(i)
        break
else:
    print(-1)

    


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

int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++) cin>>a[i];
  int x=0;
  int y=1;
  int ans=0;
  while (x<N){
    if(a[x]==y){
      ans++;
      y++;
      x++;
    }
    else{
      x++;
    }
  }
  int answer;
  answer=N-ans;
  if(answer==N) cout<<-1<<endl;
  else cout<<answer<<endl;
}

Measured memory_bytes: 1024
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}


//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var s = next();
	var t = nextCharArray();
	var output = s;
	var add = "";
	for(var i = 0; i < N; i++){
		if(s[i] == t[0]){
			var isOK = true;
			for(var j = 0; j < t.length; j++){
				if(s[i + j] != t[j]){
					isOK = false;
					break;
				}
			}
			if(isOK){
				break;
			}else{
				var tmp = t.pop();
				add = tmp + add;
			}
		}else{
			var tmp = t.pop();
			add = tmp + add;
		}
	}
	output = s + add;
	myout(output.length);
}


Measured memory_bytes: 30100
#include<iostream>
using namespace std

;

int main(){

int a, b;

cin>>a>>b;

if (a==b){

cout<<"a"<<" == "<<"b"<<"\n";

};

if (a>b){

cout<<"a"<<" > "<<"b"<<"\n";

};

if (a<b){

cout<<"a"<<" < "<<"b"<<"\n";


};

return 0;

}

Measured memory_bytes: 1124
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	string s1, s2, s3;

	cin >> s1 >> s2 >> s3;

	transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
	transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
	transform(s3.begin(), s3.end(), s3.begin(), ::toupper);

	cout << s1[0] << s2[0] << s3[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;

int main(){
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<ll> A(x), B(y), C(z);
	for (int i = 0; i < x; i++) cin >> A[i];
	for (int i = 0; i < y; i++) cin >> B[i];
	for (int i = 0; i < z; i++) cin >> C[i];
	// sort(A.begin(), A.end());
	// sort(B.begin(), B.end());
	// sort(C.begin(), C.end());
	vector<ll> AB;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			ll ab = A[i] + B[j];
			AB.push_back(ab);
		}
	}
	sort(AB.rbegin(), AB.rend());
	vector<ll> ans;
	for (int i = 0; i < min(k,x*y); i++) {
		for (int j = 0; j < z; j++) {
			ll abc = AB[i] + C[j];
			ans.push_back(abc);
		}
	}
	sort(ans.rbegin(), ans.rend());
	for (int i = 0; i < k; i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 43368
#include "bits/stdc++.h"
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i < n; i++)
    {
        int b = a[i], j;
        for (int i = 0; i < n - 1; i++)
        {
            printf("%d ", a[i]);
        }
        printf("%d\n", a[n - 1]);
        for (j = i - 1; j >= 0 && a[j] > b; j--)
        {
            a[j + 1] = a[j];
            
        }
        a[j + 1] = b;
    }
    for (int i = 0; i < n - 1; i++)
    {
        printf("%d ", a[i]);
    }
    printf("%d\n", a[n - 1]);
}


Measured memory_bytes: 3196
#include<stdio.h>

int main(void){
    int n,t,s1,s2,sa,i,min;

    scanf("%d",&n);
    int w[n+10];
    min = 100 * n;

    for(i=1; i<=n; i++){
        scanf("%d",&w[i]);
    }


    for(t=1; t<n; t++){
        s1 = 0;
        s2 = 0;

        for(i=1; i<=t; i++){
            s1 += w[i];
        }

        for(i=t+1; i<=n; i++){
            s2 += w[i];
        }

        if(s1 >= s2){
            sa = s1 - s2;
        }else{
            sa = s2 - s1;
        }

        if(min > sa)
        min = sa;


    }

    printf("%d\n",min);

    return 0;

}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
    int h,a;
    scanf("%d%d",&h,&a);
    if(h<=a)
        printf("1\n");
    else if(h%a==0)
        printf("%d\n",h/a);
    else
        printf("%d\n",h/a+1);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR(i,x,y) for(int i=(x);i<=(y);i++)
#define DOR(i,x,y) for(int i=(x);i>=(y);i--)
using namespace std;
int n,ans=0x7fffffff;
int sum1[300005],sum2[300005];
char s[300005];
char a[300005];
int main(){
	scanf("%d",&n);
	scanf("%s",a+1);
	FOR(i,1,n){
		s[i]=a[i];
		if(s[i]=='W'){
			sum1[i]=sum1[i-1]+1;
		}
		else sum1[i]=sum1[i-1];
	}
//	FOR(i,1,n) printf("%c  ",s[i]);
	DOR(i,n,1) 
		if(s[i]=='E') sum2[i]=sum2[i+1]+1;
		else sum2[i]=sum2[i+1];
	FOR(i,1,n){
		if(ans>sum1[i-1]+sum2[i+1]) ans=sum1[i-1]+sum2[i+1];//s读入 
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define cil(a, b) (((a) % (b) == 0) ? (a) / (b) : (a) / (b) + 1) 

using namespace std;

int main() {
    int n, k, a;
    cin >> n >> k;
    for (int i = 0 ; i < n ; ++i) cin >> a;
    cout << max(1, cil(n - k, k - 1) + 1) << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

typedef long long ll;

ll x,y;

int main(){
	cin >> x >> y;
	if(y == 1 || x == y){
		cout << "-1";
		return 0;
	}
	if((x*y+x) % y == 0) cout << "-1";
	else cout << x*y+x;
}

Measured memory_bytes: 256