akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define rep(i,x) for(int i = 0;i<x;i++)
#define REP(i,x) for(int i = 1;i<=x;i++)
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
//const ll mod = 1000000007LL;
const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; 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 nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}
//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
 
//    cout << fixed << setprecision(15);


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N >> M;
    swap(N,M);
    vector<ll> vec(N);
    ll up = 0,wa = 0;
    rep(i,N){
        cin >> vec[i];
        wa += vec[i];
        chmax(up,vec[i]);
    }
    if(N == 1){
        cout << vec[0] - 1 << "\n";
        return 0;
    }
    wa -= up;
    if(up + 1 <= wa){
        cout << "0\n";
        return 0;
    }
    else{
        cout << up - wa - 1 << endl;
    }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int A,B;
  A=a.size()-1;
  B=b.size()-1;
  
  if(a.at(A)==b.at(0)&&b.at(B)==c.at(0)){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
a = [0] + list(map(int,input().split()))
b = [0]*(n+1)
c = [0]*(n+1)

for i in range(1,n+1):
    b[i] = a[i] + i
    c[i] = i - a[i]
'''
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if b[i] == c[j]:
            ans += 1
print(ans)
これだと(多分)無理。
'''
bdic = {}
cdic = {}
'''
print(b)
print(c)
'''
for i in range(1,n+1):
    if b[i] not in bdic:
        bdic[b[i]] = 0
    bdic[b[i]] += 1

    if c[i] not in cdic:
        cdic[c[i]] = 0
    cdic[c[i]] += 1
bb = list(bdic.items())
cc = list(cdic.items())
bb.sort()
cc.sort()

bval = [bb[i][1]for i in range(len(bb))]
bkey = [bb[i][0]for i in range(len(bb))]

cval = [cc[i][1]for i in range(len(cc))]
ckey = [cc[i][0]for i in range(len(cc))]
'''
print(bval)
print(bkey)
print(cval)
print(ckey)
'''
#二分探索
def bisearch(data,value):#data:ソート済みリスト  value:調べる値
    left = 0
    right = len(data) - 1
    while left <= right:
        mid = (left + right)//2
        if data[mid] == value:
            return mid
        elif data[mid] < value:
            left = mid + 1
        else:
            right = mid - 1
    return -1
 
ans = 0
for i in range(len(bb)):
    if bisearch(ckey,bkey[i]) > -1:
        ans += bval[i]*cval[bisearch(ckey,bkey[i])]
print(ans)

Measured memory_bytes: 167880
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
int R, C, t, ans;
bitset<10005>b[15];

/*首先，翻?行列的次序不影??果，因?行的范??小，可以枚?所有行状?，即把行先翻?完?，
?于??行状?，在?列中??最?解，?行列翻?，即判断0多?是1多,1多?相当于不翻??列，
0多相当于翻??列，因此用bitset容器方便?理。*/
void dfs(int k)
{
    if(k == R)
    {
        int tmp = 0;
        for(int i=0; i<C; i++)
        {
            int num = 0;
            for(int j=0; j<R; j++)
                if(b[j][i]) num++;
            tmp += max(num, R-num);
        }
        ans = max(ans, tmp);
        return;
    }
    dfs(k+1);
    b[k].flip();
    dfs(k+1);
    //b[k].flip();
}

int main()
{
    while(~scanf("%d%d",&R,&C),R+C)
    {
        ans = -1;
        for(int i=0; i<R; i++)
            for(int j=0; j<C; j++)
            {
                scanf("%d",&t);
                b[i][j] = t;
            }
        dfs(0);
        printf("%d\n",ans);
    }
    return 0;
}

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

using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 100;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int a[maxn];

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

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    int f1 = 0, f = 0, p = 0;
    scanf("%d", &a[1]);
    if (n == 1) {
        if (a[1] == k)puts("POSSIBLE");
        else puts("IMPOSSIBLE");
        return 0;
    }
    p = a[1];
    if (a[1] > k) f1 = 1;
    for (int i = 2; i <= n; i++) {
        scanf("%d", &a[i]);
        p = gcd(p, a[i]);
        if (a[i] > k) f1 = 1;
        if (a[i] == k) f = 1;
    }
    //cout << f1 << endl;
    //cout << p << endl;
    if (f || (f1 && k % p == 0)) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
    return 0;
}


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

int main(){
  int H,W;
  string board[50];

  cin >> H >> W;
  for(int i = 0; i < H; i++){
    cin >> board[i];
  }

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

  for(int i = 0; i<H; i++){
    for(int j = 0; j<W; j++){
      if(board[i][j] == '#') continue;

      int cnt = 0;
      for(int d = 0; d < 8; d++){
        const int ni = i + dy[d];
        const int nj = j + dx[d];

        if(ni < 0 or H <= ni) continue;
        if(nj < 0 or W <= nj) continue;
        if(board[ni][nj] == '#') cnt++;
      }
      board[i][j] = (char)cnt+'0';
    }
  }

  for(int i = 0; i < H; i++){
    cout << board[i] << endl;
  }
  return 0;
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    scanf("%lld", &N);
    printf("%lld\n", N * N);
    return 0;
}

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

a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    a_sum = sum(a[:i + 1])
    b_sum = sum(b[i:])
    if ans < a_sum + b_sum:
        ans = a_sum + b_sum

print(ans)

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

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b; 
}

ll divnum(ll n,ll m,ll l){
    return n/m + n/l - n/(lcm(m,l)) ; 
}


int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    cout << (b-divnum(b,c,d))-((a-1)-divnum(a-1,c,d)) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = int.Parse(s);

            int max = int.MinValue;
            int min = int.MaxValue;
            long total = 0;

            string [] ss =Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++) 
            {
                int value =int.Parse(ss[i]);
                if (max < value) 
                    max = value;
         
                if (min > value)
                    min = value;
                    total = total + value;
                
            }
            Console.WriteLine(min+" " + max+" " + total);




        
          
        }
    }
}

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

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

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

int main(){
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    ll Bc = B/C; //Cで割り切れる
    ll Bd = B/D;
    ll Bcd = B/lcm(C,D);
    ll Ac = (A-1)/C; //Cで割り切れる
    ll Ad = (A-1)/D;
    ll Acd = (A-1)/lcm(C,D);
    ll Bwarikire = Bc + Bd - Bcd;
    ll Awarikire = Ac + Ad - Acd;
    cout << B-A+1-(Bwarikire-Awarikire);
}


Measured memory_bytes: 256
#include <stdio.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  unsigned long long int res = 1;
  int n;

  scanf ( "%d", &n );
  while ( n )
  {
    res *= n--;
  }
  printf ( "%lld\n", res );

  return ( 0 );
}

Measured memory_bytes: 0
def main():
    R = int(input())

    print(2 * 3.141592 * R)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


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

int main() {
    int N, A[200002];
    int num_sup[200002] = {0};
    cin >> N;
    for (int i = 2; i <= N; i++){
        cin >> A[i];
        num_sup[A[i]]++;
    }
    for(int i = 1; i <= N; i++) {
        cout << num_sup[i] << "\n";
        // printf("%d\n",num_sup[i]);
    }
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
#include<vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i; i < N; i++){
    cin >> H[i];
  }
  int ans = 0;
  int Heighest_Mt = 0;
  
  for (int i = 0; i < N; i++)
    if (H[i] >= Heighest_Mt){
      ans++;
      Heighest_Mt = H[i];
    }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

s=input().strip()
t=input().strip()
n=len(s)
m=len(t)
M=[]
for i in range(n-m+1):
    count=0
    for j in range(m):
        if s[i+j]==t[j]:
            count+=1
    M.append(m-count)
print(min(M))






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

void swap(int &a,int &b){
    a = a-b ;
    b += a ;
    a = b-a ;
}

int main(){
    int n ; cin >> n ;
    for(int i=0;i<n;i++){
        int a,b,c ;
        cin >> a >> b >> c ;
        if(a>b) swap(a,b) ;
        if(b>c) swap(b,c) ;
        if(a*a+b*b==c*c) cout << "YES" << endl ;
        else  cout << "NO" << endl ;
    }
}


Measured memory_bytes: 3056
#include <iostream>
using namespace std;
int main()
{
  int n,k,d[101],a[101][101],ans=0;
  bool b[100]={false};
  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>d[i];
    for(int j=0;j<d[i];j++){
      cin>>a[i][j];
      b[a[i][j]-1]=true;
    }
  }
  
  for(int i=0;i<n;i++){
    if(b[i]==false)ans++;
  }
  
  cout<<ans<<endl;
  return 0;
  
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(void)
{
  
  int n,i;
  
  while(scanf("%d",&n)!=EOF)
    {
      if(n>39)n=n%39;
      if(n==0)
	{
	  printf("3C39\n");
	}
      for(i=1;i<40;i++)
	{
	  if(i==n)
	    {
	      if(i>9)printf("3C%d\n",i);
	      else printf("3C0%d\n",i);
	      break;
	    }
	}
    }
  
  return 0;
}

Measured memory_bytes: 0
INF = 1000000007

input = open(0).read

N, K, *h = map(int, input().split())


def main():

    h.sort()

    ans = INF

    for i in range(N - K + 1):
        ans = min(ans, h[i + K - 1] - h[i])

    print(ans)
    return


main()


Measured memory_bytes: 14092
#include"iostream"
using namespace std;
template<class elem>
class dlinklist
{struct node
{
	elem data;
	node* prev;
	node* next;
	node() { prev = NULL; next = NULL; }
	node(const elem& x, node* p = NULL, node* n = NULL) :data(x), prev(p), next(n) {}
};
node* head;
node* tail;
public:dlinklist()
{
	head = new node;
	tail = new node;
	head->next = tail;
	tail->prev = head;
}
~dlinklist()
{
	node* p;
	while(head!=NULL)
	{
		p = head;
		head = head->next;
		delete p;
	}
}
void insert(const elem&x)
{
	node* p = new node(x, head, head->next);
	p->next->prev = p;
	head->next = p;
}
void Delete(const elem&x)
{
	node* p, * q;
	p = head;
	while(p->next!=tail&&p->next->data!=x)
		p = p->next;
	if (p->next == tail)return;
	q = p->next;
	p->next = q->next;
	q->next->prev = p;
	delete q;
}
void deletefirst()
{
	node* p = head->next,*q;
	q = p->next;
	head->next = q;
	q->prev = head;
	delete p;
}
void deletelast()
{
	node* p = tail->prev,*q;
	q = p->prev;
	tail->prev = q;
	q->next = tail;
	delete p;
}
void display()const
{
	node* p = head->next;
	if (p != tail)
	{
		cout << p->data;
		p = p->next;
	}
	while(p!=tail)
	{
		cout << ' ' << p->data;
		p = p->next;
	}
	cout << endl;
}
};
int main()
{
	dlinklist<int>a;
	char command[20];
	int n;
	int k;
	int j;
	cin >> n;
	cin.get();
	for(int i=0;i<n;++i)
	{
		k = 0;
		cin.getline(command,20);
		if (command[6] == ' ')
			if (command[0] == 'i')
			{
				j = 7;
				while (command[j] != '\0')
				{
					k = k * 10 + command[j] - '0';
					++j;
				}
				a.insert(k);
			}
			else
			{
				j = 7;
				while (command[j] != '\0')
				{
					k = k * 10 + command[j] - '0';
					++j;
				}
				a.Delete(k);
			}
		else
			if (command[6] == 'F')a.deletefirst();
			else a.deletelast();
	}
	a.display();
	return 0;
}



Measured memory_bytes: 34356
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  bool ap = true;
  while (n--) {
    int a; cin >> a;
    if (a % 2 == 0) ap &= a % 3 == 0 || a % 5 == 0;
  }
  cout << (ap ? "APPROVED\n" : "DENIED\n");
  return 0;
}


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

int sum(int x)
{
	int ans=0;
	while (x)
	{
		ans+=x%10;
		x/=10;
	}
	return ans;
}

int main()
{
	int n;
	cin>>n;
	int ans=1e9;
	for (int i=1;i<n;i++)
	{
		int a=i;
		int b=n-i;
		int tot=sum(a)+sum(b);
		ans=min(ans,tot);
	}
	cout<<ans<<"\n";
}

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

int main() {
	long long n,num[100001][3],dp[100001][3];
	cin>>n;
	for(int i=0;i<n;i++){
	    cin>>num[i][0]>>num[i][1]>>num[i][2];
	}
	for(int i=0;i<3;i++)dp[0][i]=num[0][i];
	
	for(int i=0;i<n-1;i++){
	   	dp[i+1][0]=num[i+1][0]+max(dp[i][1],dp[i][2]);
		dp[i+1][1]=num[i+1][1]+max(dp[i][0],dp[i][2]);
		dp[i+1][2]=num[i+1][2]+max(dp[i][0],dp[i][1]);
	    
	}
	long long hoge=max(dp[n-1][0],dp[n-1][1]);
	hoge=max(hoge,dp[n-1][2]);
	cout<<hoge<<endl;
	return 0;
}

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

const int N = 2e5 + 5;

int n, k;
long long a[N], s;

int main(){


    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort (a + 1, a + n + 1);
    for (int i = 1; i <= n - k; ++i) s += a[i];
    cout << s;


}


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

int F[13]={
		0,	//0
		1,	//1
		2,	//2
		1,	//3
		4,	//4
		1,	//5
		4,	//6
		1,	//7
		1,	//8
		4,	//9
		1,	//10
		4,	//11
		1,	//12
};

int main(int argc , char **argv)
{
	(void)argc;
	(void)argv;

	int x,y;
	cin >> x >> y;
	if (F[x]==F[y]){printf("Yes\n");}else{printf("No\n");}

	return 0;
}

Measured memory_bytes: 256
function Main(input){
  input = input.split(' ').map(x=>BigInt(x));
  var a = input[0];
  var b = input[1];
  var n = input[2];
  if (b==1){
    var max = 0n;
  }else if (n<b){
    var max = a*n/b - a*(n/b);
  }else{
    var border = (n+1n)/b;
    var t = 1n;
    var max = 0n;
    for (let t = 1n;t<=border;t++){
      var now = a*(b*t-1n)/b - a*((b*t-1n)/b);
      if (now > max){
        max = now;
      }
    }
  }
  console.log(max.toString())
}
  

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

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

#define ll long long

using namespace std;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n, 0), b(m, 0);
  vector<ll> pa(n+1, 0), pb(m+1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i - 1];
    pa[i] = pa[i - 1] + a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i - 1];
    pb[i] = pb[i - 1] + b[i - 1];
  }
  int result = 0;
  for (int i = 0; i <= n; i++) {
    ll diff = k - pa[i];
    int res = 0;
    if (diff < 0)
      break;
    int l = 1, r = m;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (pb[mid] <= diff) {
        res = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    result = max(result, i + res);
  }
  cout << result;
}


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

int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)if(s[i]=='?'){
		if(s[i+1]=='D'||s[i+1]=='?')s[i]='P';
		else s[i]='D';
		if(s[i-1]=='P')s[i]='D';
	}
	cout<<s<<endl;
	return 0;
}

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

const long long mod=998244353LL;

long long modpow(int a,int b)
{
	if (b==0)
	{
		return 1LL;
	}
	long long ans=modpow(a,b/2);
	ans*=ans;
	ans%=mod;
	if (b%2==1)
	{
		ans*=(long long)a;
		ans%=mod;
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int d[n],mx=0LL,memo[100005]={};
	for (int i = 0; i < n; ++i)
	{
		cin>>d[i];
		++memo[d[i]];
		mx=max(mx,d[i]);
	}
	if (d[0]!=0LL||memo[0]>1)
	{
		cout<<"0\n";
		return 0;
	}
	for (int i = 0; i <= mx; ++i)
	{
		if (memo[i]<=0LL)
		{
			cout<<"0\n";
			return 0;
		}
	}
	long long ans=1LL;
	for (int i = 0; i < mx; ++i)
	{
		ans*=modpow(memo[i],memo[i+1]);
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int L;
  cin >> L;
  using P = pair<int, int>;
  auto dfs = [&](auto dfs, int x) -> vector<vector<P>> {
    if (x == 1) {
      return vector<vector<P>>(1);
    }
    if (x % 2 == 1) {
      auto g = dfs(dfs, x - 1);
      g[0].emplace_back(sz(g) - 1, x - 1);
      return g;
    } else {
      auto g = dfs(dfs, x / 2);
      rep(i, sz(g)) rep(j, sz(g[i])) {
        g[i][j].second *= 2;
      }
      g.emplace_back(vector<P>());
      g[sz(g) - 2].emplace_back(sz(g) - 1, 0);
      g[sz(g) - 2].emplace_back(sz(g) - 1, 1);
      return g;
    }
  };
  auto ans = dfs(dfs, L);
  int m = 0;
  rep(i, sz(ans)) m += sz(ans[i]);
  cout << sz(ans) << " " << m << endl;
  rep(i, sz(ans)) rep(j, sz(ans[i])) {
    cout << i + 1 << " " << ans[i][j].first + 1 << " " << ans[i][j].second << endl;
  }
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    long long n, m;
    cin >> n >> m;
    
    cout << abs(n - 2) * abs(m - 2) << '\n';
    
    return 0;
}

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

#define ll long long
#define INF 1e9
#define fi first
#define se second

typedef vector <int> vi;
typedef pair <int, int> ii;

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

    ii v[n+1];
    for (int i = 1; i <= n; i++) {
		scanf("%d%d", &v[i].fi, &v[i].se);
	}
	// for (ii p : v) cout << p.fi << " " << p.se << endl;

    ll dp[n+1][w+1];
	memset(dp, 0, sizeof(dp));

    for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= w; j++) {
			dp[i][j] = max(dp[i][j], dp[i-1][j]);
			if (j >= v[i].fi) {
				dp[i][j] = max(dp[i][j], dp[i-1][j-v[i].fi] + v[i].se);
			}
		}
    }

	// for (int i = 0; i <= n; i++) {
	// 	for (int j = 0; j <= w; j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

    cout << dp[n][w] << endl;
}


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

#define ll long long int
#define db double
#define fl float
#define endl '\n'

#define mod (ll)(1000000007)
#define mod1 (ll)998242353
#define mod2 (ll)998244353
#define PI 3.1415926535897932384626433832795

#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pob pop_back

#define Sort(v) sort(v.begin(),v.end())
#define Sortd(v) sort(v.begin(),v.end(),greater<>())

#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;--i)
#define rf1(i,n) for(int i=n-1;i>=1;--i)
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repn(i,a,b) for(int i=a;i<=b;++i)

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;

//nC2
ll C2(ll n){
    ll ans= max(((n*(n-1))/2),(ll)0);
    return ans;
}
//square
ll sq(ll n){
    return n*n;
}

//GCD
ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    if(b==0){
        return a;
    }    
    else{
        return gcd(b,a%b);
    }
}

//sort pair by second values
bool sortsec(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.second < b.second); 
}


//Binary Exponentiation
ll BinExp(ll a, ll b, ll m){
    a%=m;
    ll res =1;
    while(b>0){
        if(b&1){
            res = (res * a)%m;
        }
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
vi min_pf(1000001);
vi min_prime_factor(int n){
    
    rep(i,2,n+1){
        min_pf[i]=0;
    }
    min_pf[0]=2;
    min_pf[1]=-1;//Doesn't exist :(
    rep(i,2,n+1){
        if(min_pf[i]==0){
            for(int j=i;j<=n;j+=i){
                if(min_pf[j]==0)min_pf[j]=i;
            }
        }
    }
    return min_pf;
}

//factorise function will return a vector consisting of all the prime factors and number of times they occur
ll factorise(int n){
    
    int cnt=0,fac=1;
    ll ans=1;
    while(n!=1){
        cnt=0;
        fac=min_pf[n];
        while(n%fac==0){
            cnt++;
            n/=fac;
        }
        ans*=(ll)(cnt+1);
    }
    return ans;
}


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    
    int n;
    cin>>n;

    min_prime_factor(n+1);
    ll fin=0;

    for(int c=1;c<=n-1;++c){
        int x=n-c;
        fin+=factorise(x);

    }

    cout<<fin<<endl;


    return 0;
}



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

int main() {
  int a,b;
  cin >> a >> b;
  vector<string> s(a);
  for(int i = 0; i < a; i++) {
    cin >> s[i];
  }

  sort(s.begin(), s.end());

  for(string ans: s) {
    cout << ans;
  }
  cout << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
   long long int a,b,c,d;
   cin>>a>>b>>c>>d;
   long long int u=a*c;
    long long int v=a*d;
     long long int w=b*c;
      long long int x=b*d;
     
      cout<<max({u,v,w,x});

}

 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    ll left = 0, right = LONG_LONG_MAX / 2 - 1;
    while((left + 1) < right) {
        ll middle = (left + right) / 2;
        ll total = 0;
        rep(i, n) {
            total += n - (lower_bound(all(a), middle - a[i]) - a.begin());
        }
        if (total >= m) left = middle;
        else right = middle;
    }
    vector<ll> dp(n + 2, 0);
    rep(i, n) dp[i + 1] = dp[i] + a[i];
    dp[n + 1] = dp[n];
    ll ans = 0, sum = 0;
    rrep(i, n) {
        ll idx = upper_bound(all(a), left - a[i]) - a.begin();
        ans += dp[n] - dp[idx];
        ll cnt = max(0LL, n - idx);
        ans += a[i] * cnt;
        sum += cnt;
    }
    ans += (m - sum) * left;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,st,ed) for(int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(int i=st,i##end=ed;i>=i##end;--i)
const int maxn=200005;
int n;
char s[maxn];
int cnt[26];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	REP(i,1,n)
		cnt[s[i]-'a']++;
	int sum=0;
	long long ans=0;
	REP(i,0,25)
		ans+=1ll*cnt[i]*sum,sum+=cnt[i];
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 384
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                A[j][k] = 0
if A[0][0] == 0 and A[0][1] == 0 and A[0][2] == 0:
    print('Yes')
elif A[1][0] == 0 and A[1][1] == 0 and A[1][2] == 0:
    print('Yes')
elif A[2][0] == 0 and A[2][1] == 0 and A[2][2] == 0:
    print('Yes')
elif A[0][0] == 0 and A[1][0] == 0 and A[2][0] == 0:
    print('Yes')
elif A[0][1] == 0 and A[1][1] == 0 and A[2][1] == 0:
    print('Yes')
elif A[0][2] == 0 and A[1][2] == 0 and A[2][2] == 0:
    print('Yes')
elif A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    print('Yes')
elif A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
    print('Yes')
else:
    print('No')

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

int main(){
    int N;
    std::cin >> N;
    long long ans = 0;
    for(int i=1; i<=N; i++){
        long long n_tmp = N / i;
        ans += n_tmp * (2 * i + (n_tmp - 1) * i) / 2; 
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, k;
	cin>>n>>k;
	int x;
	vector<bool> av(10, true);
	for(int i = 0; i < k; i++) {
		cin>>x;
		av[x] = false;
	}

	cout<<endl;
	while(1) {
		int x = n;
		bool flag = true;
		while(x > 0) {
			int r = x%10;
			if(!av[r]) flag = false;
			x = x/10;
		}
		if(flag) break;
		n++;
	}
	cout<<n;
}


Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int a,b,c;
		cin >> a >> b >> c;
		int d = max(max(a,b),c);
		int e = min(min(a,b),c);
		int f = a+b+c-d-e;
		if(d*d==e*e+f*f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
 
using namespace std;
 
typedef pair<int, int> P;

int main(){
	int n, w;
	while(cin >> n >> w, n|w){
		vector<int> v(200);
		int rm = 0;
		rep(i, n){
			int x;
			cin >> x;
			v[x/w]++;
			rm = max(rm, x/w);
		}
		int div = *max_element(v.begin(), v.end());
		double ans = 0.01;
		rep(i, rm){
			ans += (1-(i*1./rm))*(1.*v[i]/div);
		}
		cout << ans << endl;
	}
	

	return 0;
}

Measured memory_bytes: 1264
#include<cstdio>
#include<algorithm>
using namespace std;
typedef pair<int,int>P;
int main(void){
	int n;
	P pp[100001];
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&pp[i].first,&pp[i].second);
	}
	sort(pp,pp+n);
	for(i=0;i<n;i++){
		printf("%d %d\n",pp[i].first,pp[i].second);
	}
	return 0;
}


Measured memory_bytes: 3520
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}

ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  ll x;
  cin>>x;
  ll sum=0;
  ll y=x/500;
  sum+=y*1000;
  x-=y*500;
  sum+=x/5*5;
  cout<<sum;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n>>m>>k>>j;

	if(n+m>k+j) cout<<"Left"<<endl;
	else if(n+m<k+j) cout<<"Right"<<endl;
	else cout<<"Balanced"<<endl;



}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if (n == 2) {
    cout << 2 << endl;
    cout << 0 << endl;
    cout << 11 << endl;
  } else if (n == 1) {
    cout << 1 << endl;
    cout << 1 << endl;
  } else {
    cout << n - 1 << endl;
    for (int i = 0; i < n - 1; i++) {
      cout << 0;
      for (int j = 0; j < i; j++) cout << 1;
      cout << 0 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3216
#include <iostream>

using namespace std;

int counts[5];
#define MAX_L 11
char name[MAX_L];
int n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    while(n-- > 0){
        cin >> name;
        switch(name[0]){
        case 'M':
            ++counts[0];
            break;
        case 'A':
            ++counts[1];
            break;
        case 'R':
            ++counts[2];
            break;
        case 'C':
            ++counts[3];
            break;
        case 'H':
            ++counts[4];
        }
    }
    long long num = 0;
    int i, j, k;
    for(i = 0; i < 5; ++i){
        for(j = 0; j < i; ++j){
            for(k = 0; k < j; ++k){
                num += (long long)counts[i] * counts[j] * counts[k];
            }
        }
    }
    cout << num << '\n';
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;


ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//const string k = "enterstringtobechecked";



int main()
{
    SYNC
    //clock_t tStart = clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n; in(n);
    vl v(n);
    l(i,0,n)
    {
        in(v[i]);
    }
    ll ans=0;
    sort(all(v));
    reverse(all(v));
    ll j=0;
    l(i,0,n-1)
    {
        if(i==0)
            ans+=v[i];
        else
        {
            if(i%2)
                ans+=v[i-j];
            else
            {
                ans+=v[i-1-j];
                j++;
            }
        }
    }
    o(ans)<<endl;








    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);   
}


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

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

    vector< vector<int> > G(n+5, vector<int>(n+5, 0));

    for(int i=0; i<n; ++i){
        int u, k; cin >> u >> k;
        for(int j=0; j<k; ++j){
            int v; cin >> v;
            G[u][v] = 1;
        }
    }

    for(int i=1; i<=n; ++i){
        for(int j=1; j<=n; ++j){
            if(j != 1) cout << ' ';
            cout << G[i][j];
        }
        cout << endl;
    }
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    string s; cin >> s;
    if (s == "RRR") cout << 3 << endl;
    else if (s == "SRR" or s == "RRS") cout << 2 << endl;
    else if (s == "SSS") cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3660
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
#import math

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
A = list(map(int, input().split()))

count = 1

for a in A:
    #print(a, count)
    if a == count:
        count += 1

if count == 1:
    print(-1)
else:
    print(N-(count-1))


Measured memory_bytes: 72220
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define int ll

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(all(A), greater<int>());

  int temp = -1;
  int a = 0;
  int b = 0;
  bool found = false;
  rep(i, N) {
    if (temp == A[i]) {
      if (a > 0) {
        b = temp;
        found = true;
        break;
      } else {
        a = temp;
        temp = -1;
      }
    } else {
      temp = A[i];
    }
    if (found)
      break;
  }
  cout << a * b << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    sort(A.begin(), A.end());

    ll res = 0;
    ll m = (N-2)/2;
    if(N%2==0){
    	REP(i, m) res += -2 * A[i];
    	REP(i, m) res += 2 * A[N-1-i];
    	res -= A[m];
    	res += A[m+1];
    }else{
    	ll cand1 = 0;
    	REP(i, m+1) cand1 += -2*A[i];
    	REP(i, m) cand1 += 2*A[N-1-i];
    	cand1 += A[m+1];
    	cand1 += A[m+2];

    	ll cand2 = 0;
    	REP(i, m) cand2 += -2*A[i];
    	REP(i, m+1) cand2 += 2*A[N-1-i];
    	cand2 -= A[m];
    	cand2 -= A[m+1];

    	res = max(cand1, cand2);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m;
vector<int> G[100005];
bool used[100005];
vector<int> path;

void dfs(int idx){
	for(int i = 0;i < G[idx].size();i++){
		if(used[G[idx][i]])continue;
		path.push_back(G[idx][i]+1);
		used[G[idx][i]] = true;
		dfs(G[idx][i]);
		return;
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	used[0] = true;
	
	path.push_back(1);

	dfs(0);
	reverse(path.begin(),path.end());
	dfs(0);

	cout << path.size() << endl << path[0];	
	for(int i = 1;i < path.size();i++)
		cout << " " << path[i];

	cout << endl;
}



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

bool used[555][555];
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
ll bl,wh;
ll h,w;
string s[555];
void dfs(ll x,ll y,bool black){
    used[x][y]=1;
    if(black) bl++;
    else wh++;
    for(ll i=0;i<4;i++){
        ll nx=x+dx[i],ny=y+dy[i];
        if(nx<h && nx>=0 && ny>=0 && ny<w && !used[nx][ny]){
            if(black && s[nx][ny]=='.') dfs(nx,ny,0);
            if(!black && s[nx][ny]=='#') dfs(nx,ny,1);
        }
    }
}

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


    cin>>h>>w;
    for(ll i=0;i<h;i++){
        cin>>s[i];
    }

    ll ans=0;
    
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            bl=0,wh=0;
            if(!used[i][j] && s[i][j]=='.') dfs(i,j,0);
            if(!used[i][j] && s[i][j]=='#') dfs(i,j,1);
            ans += bl*wh; 
            //cerr<<bl<<" "<<wh<<endl;
        }
    }
    cout<<ans<<endl;


    
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if (abs(a - b) % 2 == 1) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    cout << max(a,b) - abs(a - b) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i,n) for( ll i=0 ; i<n ; i++ )
#define f(i, a, b) for( ll i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define MOD 1000000007

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}
ll SieveOfEratosthenes(ll n)
{
    vector<bool>prime(n+1);
    int ans = 0;
    for(int i =0; i<=n; i++)
        prime[i] = true;
    prime[1] = false;
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for(int i = 2; i<=n; i++)
    {
        if(prime[i])
        {
            ans++;
        }
    }
    return ans;
}
void permute(string a, int l, int r)
{
    if (l == r)
    {
        cout<<a<<endl;
    }
    else
    {
        for (int i = l; i <= r; i++)
        {
            swap(a[l], a[i]);
            permute(a, l+1, r);
        }
    }
}

ll maxpower(ll n,ll k)
{
    ll count = 0;
    while(n>0)
    {
        n = n/k;
        if(n>0)
            count++;
    }
    return count;
}
vector<int>adj[100001];
vector<bool>vis(100001,false);
void dfs(ll x)
{
    if(!vis[x])
    {
        vis[x] = true;
        for(auto v : adj[x])
        {
            dfs(v);
        }
    }
}
int32_t main()
{
    faster();
    ll n,m;
    cin>>n>>m;
    fi(i,m)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    ll ans = 0;
    for(int i =1;i<=n;i++)
    {
        if(!vis[i])
        {
            ans++;
            dfs(i);
        }
    }
    cout<<ans - 1;


}



Measured memory_bytes: 9608
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	if(n==1||n%2==1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	rep(i,n/2)
	{
		if(s[i]!=s[n/2+i])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}

	cout<<"Yes"<<endl;
	

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,i,min;
  cin >> n >> k;
  k--;
  vector<int> h(n);
  for(i=0;i<n;++i)
  {
  cin >> h[i];
  }
  sort(begin(h),end(h));
  min=h[n-1]-h[0];
 
  
  
  for(i=0;i<n-k;i++)
  {
  if(h[i+k]-h[i]<min) min=h[i+k]-h[i];  
  }
  cout << min << endl;
return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int main(){
    int N,M,X,Y;
    string S,T; 
    bool flag = true;
    map<char,char>pair1,pair2;
    
    //input
    cin >> S >> T;

    for(char s = 'a'; s <= 'z'; ++s){
        pair1[s] = '0';
        pair2[s] = '0'; 
    }


    for(int i = 0; i < S.size(); i++){
        //初見の文字なら更新
        if(pair1[S[i]] == '0' && pair2[T[i]] == '0'){
            pair1[S[i]] = T[i];
            pair2[T[i]] = S[i];
        }else if (pair1[S[i]] == T[i] && pair2[T[i]] == S[i]){
            continue;
        }else{
            flag = false;
        }

    }

    //     char mozi_S = S[i];
    //     char mozi_T = T[i];
    //     for(int j = i; j < S.size(); j++){
    //         if(mozi_S == S[j]){
    //             if(mozi_T != T[j]){
    //                 flag = false;
    //             }
    //         }
    //         if(mozi_T == T[j]){
    //             if(mozi_S != S[j]){
    //                 flag = false;
    //             }
    //         }
    //     } 
    // }
    // cout << "S:" << S << endl;
    // cout << "T:" << T << endl;
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 776