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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MOD = 998244353;

map<VI, LL> M;

LL get(VI a)
{
	if (M.count(a)) return M[a];
	if (a.empty()) return M[a] = 1;

	int x = a.back();
	a.pop_back();
	LL res = get(a);
	if (x == 1) res *= 2;
	res %= MOD;

	a.PB(x);

	FOR (len, 1, SZ(a))
	{
		FOR (k, 2, SZ(a) + 1)
		{
			if (k * len > SZ(a)) break;
			VI b = a;
			VI c(len, 1);
			FOR (i, 0, len * k)
			{
				c[i%len] &= b.back();
				b.pop_back();
			}

			reverse(ALL(c));

			LL cur = get(c) * get(b);
			res = (res + cur) % MOD;
		}
	}

	return M[a] = res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	string s;
	cin>>s;
	VI a;
	FOR (i, 0, SZ(s))
	{
		a.PB(s[i] - '0');
	}

	LL res = get(a);
	cout<<res<<endl;
}



Measured memory_bytes: 7552
#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];
	}

vector<int> ans(n);

for(int i = 0;i < n;i++){
	ans[a[i]-1] = i+1;
}
for(int i = 0;i < n;i++){
	cout << ans[i] <<" ";
}
cout << endl;
return 0;
}

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

int N, M;
const long long inf = (long long)(-1e18);
vector<vector<long long>> vadd;
long long memo[1001][1001][8];
long long dfs(int n, int m, const int& j) {
  if (memo[n][m][j] != inf) return memo[n][m][j];
  if (n == N && m < M) return memo[n][m][j] = 2*inf;
  if (m == M) return memo[n][m][j] = 0;
  if (m > M || n > N) return memo[n][m][j] = 2*inf;
  return memo[n][m][j] = max(dfs(n + 1, m + 1, j) + vadd[j][n], dfs(n + 1, m, j));
}

int main(void) {
  cin >> N >> M;
  vadd = vector<vector<long long>>(8, vector<long long>(N));
  vector<vector<long long>> v(3, vector<long long>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> v[j][i];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 8; j++) {
      for (int k = 0; k < 3; k++) {
        if ((j >> k) & 1) {
          vadd[j][i] += v[k][i];
        } else {
          vadd[j][i] -= v[k][i];
        }
      }
    }
  }

  for (int i = 0; i < 1001; i++) for (int j = 0; j < 1001; j++) {
    for (int k = 0; k < 8; k++) {
      memo[i][j][k] = inf;
    }
  }

  long long ret = 0;
  for (int j = 0; j < 8; j++) {
    ret = max(ret, dfs(0, 0, j));
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 62976
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    m = min(A)
    mi = A.index(m)
    c = (N - 1) // (K - 1)
    if (N - 1) % (K - 1) > 0: c += 1
    print(c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13880
// timusg
#include <iostream>
#include <bits/stdc++.h>

int main(){
	using namespace std;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int mod = 1e9 + 7;
	int cas = 1;
	//cin >> cas;
	while(cas--){
		int64_t d, t ,s;

		cin >> d >> t >> s;

		if(t*s >= d){
			cout << "Yes\n";
		}

		else cout << "No\n";
	}
	
	return 0;
}  



Measured memory_bytes: 3672
#include <iostream>
#include<math.h>
using namespace std;

int main(){
  int k,a,b;
  cin >> k >> a >> b;
    int i;
    for( i=a;i<=b;i++){
      if(i%k==0){
        cout << "OK";
        break;
      }
    }
    if(i==b+1){
      cout << "NG";
    }
  return 0;
}


Measured memory_bytes: 3620
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;


typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int N;
vector<vector<int>> abc(100010, vector<int>(3));
vector<vector<int>> dp(100010, vector<int>(3));


int main(void){
	cin >> N;
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < 3; j++){
			cin >> abc[i][j];
		}
	}
	dp[1][0] = abc[1][0];
	dp[1][1] = abc[1][1];
	dp[1][2] = abc[1][2];

	for(int i = 2; i <= N; i++){
		for(int j = 0; j < 3; j++){
			dp[i][j] = max(dp[i-1][(j+1)%3] + abc[i][j], dp[i-1][(j+2)%3] + abc[i][j]);
		}
	}
	cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;




}


Measured memory_bytes: 11136
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        k: usize,
        p: [Usize1; n],
        c: [i64; n],
    }
    let mut res = *c.iter().max().unwrap();
    for i in 0..n {
        let mut f = vec![false; n];
        let mut j = i;
        let mut s = vec![0];
        while !f[j] {
            f[j] = true;
            let x = s.last().unwrap() + c[p[j]];
            s.push(x);
            if s.len() - 1 <= k {
                res = std::cmp::max(res, x);
            }
            j = p[j];
        }
        if *s.last().unwrap() > 0 {
            if k / (s.len() - 1) >= 2 {
                let r = *s.last().unwrap() * (k / (s.len() - 1) - 1) as i64;
                for j in 0..s.len() {
                    res = std::cmp::max(res, r + s[j]);
                }
            }
            let r = *s.last().unwrap() * (k / (s.len() - 1)) as i64;
            let d = k % (s.len() - 1);
            for j in 0..std::cmp::min(d + 1, s.len()) {
                res = std::cmp::max(res, r + s[j]);
            }
        }
    }

    println!("{}", res);
}


Measured memory_bytes: 2392
#include<bits/stdc++.h>
#include<functional>
#define ll long long
#define xxx map<int, pair<string, int>::reverse_iterator
using namespace std;

auto find(map<int, pair<string, int>> v, string s)
{
    for (auto it=v.rbegin(); it!=v.rend(); ++it)
        if ((it->second).first == s)
            return it->first;
}

int main() 
{
    int n;
    cin >> n;
    map<string, int> mp; // order directly fel map mtaa strings
    map<int, pair<string, int>> v;
    for (int i=0; i<n; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
        int p;
        cin >> p;
        v[p] = make_pair(s, i);
    }
    vector<int> ord;
    for (auto it=mp.begin(); it!=mp.end(); it++)
    {
        for (int j=0; j<it->second; j++)
        {
            auto index = find(v, it->first);
            ord.push_back(v[index].second);
            v.erase(index);
        }
    }
    for (int i=0; i<n; i++)
        cout << ord[i]+1 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if (a<=0 && b>=0) return cout<<"Zero",0;
	b=min(b,-1);
	if (a>b || (b-a+1)%2==0) return cout<<"Positive",0;
	cout<<"Negative";
}


Measured memory_bytes: 3636
from scipy.optimize import newton
from scipy.optimize import bisect
import numpy as np

def acinput():
    return list(map(int, input().split(" ")))


def func(s):
    global a,b,x
    #tmp1=(b**2)*np.sin(s)*np.cos(s)*0.5
    #tmp2=(a**2)*0.5/(np.tan(s))
    L=a*np.tan(s)
    tmp2=L*a/2
    tmp1=(b-L)*a
    
    return a*(tmp1+tmp2) -x

def func2(s):
    global a,b,x
    L=b/np.tan(s)
    
    return a*(b*L/2) -x


a,b,x=acinput()

if x<=0.5*(a**2)*b:
    res=newton(func2,1)
else:
    res=newton(func,0.5)

print(180*res/np.pi)



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t n,k; cin>>n>>k;
	int64_t ans=0;
	for(int64_t i=k+1;i<=n;++i){
		int64_t pr=n/i,rem=n%i;
		ans+=pr*(i-k);
		int64_t tmp=rem-k;
		if(k>0)++tmp;
		if(tmp>0)ans+=tmp;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N int
  var A []int
  NextInt(&N)
  NextIntSlice(&A)
  ans := 0
  prev := A[0]
  for _, a := range A[1:] {
    if a < prev {
      ans += prev - a
    } else {
      prev = a
    }
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]int, 0)
    return
  }
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]float64, 0)
    return
  }
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  fmt.Fprintln(writer, B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

Measured memory_bytes: 13212
S = input()
N = len(S)

def num(k, s, ans):
    # 長さk
    if k == N:
        for a in s:
            ans += int(a)
        return ans
    ss = s[:]
    sss = s[:]
    l = ss.pop()
    ss.append(l+S[k])
    sss.append(S[k])
    ans1 = num(k+1, ss, ans)
    ans2 = num(k+1, sss, ans1)
    return ans2

print(num(1, [S[0]], 0))

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        res = defaultdict(lambda : 0)
        if n < 4:
            res[n] = 1
        i = 2
        m = n
        while i*i <= n:
            while m%i == 0:
                res[i] += 1
                m //= i
            i += 1
        res[m] += 1
        return res

    n,p = LI()
    f = f(p)
    ans = 1
    for i,j in f.items():
        ans *= pow(i,j//n)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38512
implicit none
integer(8) :: i,j,k,n
read(5,*) n
do i = 1,int(3*n/4)
  do j = int(3*n/4), 3500
       if (4*i*j-N*i-N*j<=0) then
            continue
       else if (mod(N*i*j,4*i*j-N*i-N*j)==0) then
            goto 100
             endif
enddo
enddo
100 write(6,*) i,j,(N*i*j)/(4*i*j-N*i-N*j)
end


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

int main(int argc, char const *argv[]) {
  std::vector<int> v(100);
  int n,i,k,temp_cost,min;
  min=100*100*200;

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

  for (i=-100; i <= 100; i++) {
    temp_cost=0;
    for (k = 0; k < n; k++) {
      temp_cost+=(i-v[k])*(i-v[k]);
    }
    if (temp_cost<min) {
      min=temp_cost;
    }
  }

  cout<<min;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	int n;
	int a[101][2];
	cin >> n;
	for(int i = 0;i < 2;i++){
		for(int j = 0;j < n;j++){
			cin >> a[j][i];
		}
	}

	int sum[101][2] = {};
	for(int i = 0;i < n;i++){
		if(i != 0) sum[i][0] = a[i][0] + sum[i-1][0];
		else sum[i][0] = a[i][0];
	}

	for(int i = n-1;i >= 0;i--){
		sum[i][1] = a[i][1] + sum[i+1][1];
	}

	int ans = 0;
	for(int i = 0;i < n;i++){
		ans = max(ans, sum[i][0] + sum[i][1]);
	}

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

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

using namespace std;
int32_t  main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    int dp[n]={0};
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    dp[2]= min( dp[1]+abs(a[1] - a[2]),abs(a[0]-a[2]));
    for(int i=3;i<n;++i){
        dp[i] = min(  dp[i-1] + abs(a[i-1]-a[i]),  dp[i-2]+abs(a[i-2]-a[i])  );     
    }
    cout<<dp[n-1];
   return 0;
}

Measured memory_bytes: 4308
import sys

sys.setrecursionlimit(2 ** 20)  # 再帰回数上限の向上 かなり多くしないとREになる


class Node:
    def __init__(self,
                 left,
                 right):
        self.left = left
        self.right = right


def insert(t: dict, i: int, r: int):
    if r > i:
        if t[r].left is not None:
            insert(t, i, t[r].left)
        else:
            t[r].left = i
    if r < i:
        if t[r].right is not None:
            insert(t, i, t[r].right)
        else:
            t[r].right = i


def inorder(t: dict, p: int, in_ls: list):
    if t[p].left is not None:
        inorder(t, t[p].left, in_ls)
    in_ls.append(p)
    if t[p].right is not None:
        inorder(t, t[p].right, in_ls)


def preorder(t: dict, p: int, pre_ls: list):
    pre_ls.append(p)
    if t[p].left is not None:
        preorder(t, t[p].left, pre_ls)
    if t[p].right is not None:
        preorder(t, t[p].right, pre_ls)


N = int(input())
T = {}
in_list = []
pre_list = []

order = list(map(str, input().split()))
root = int(order[1])
T[root] = Node(None, None)

for _ in range(N-1):
    order = str(input())
    if order[0] == 'i':
        order = list(order.split())
        T[int(order[1])] = Node(None, None)
        insert(T, int(order[1]), root)
    else:
        inorder(T, root, in_list)
        print('', *in_list)
        preorder(T, root, pre_list)
        print('', *pre_list)
        in_list = []
        pre_list = []



Measured memory_bytes: 157108
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

const int DIM = 1e5 + 7;

#define int long long

int xL[DIM];
int xR[DIM];

int preL[DIM];
int preR[DIM];

int mxL[DIM];
int mxR[DIM];


int vL[DIM];
int vR[DIM];
 
main()
{
	IOS
	
	int n, c;
	cin >> n >> c;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> xL[i] >> vL[i];
		xR[n - i + 1] = c - xL[i];
		vR[n - i + 1] = vL[i];
	}
	
	for(int i = 1; i <= n; i++) 
		preL[i] = preL[i - 1] - xL[i] + xL[i - 1] + vL[i];
	
	for(int i = 1; i <= n; i++) 
		preR[i] = preR[i - 1] - xR[i] + xR[i - 1] + vR[i];
	
	for(int i = 1; i <= n; i++) 
		mxR[i] = max(mxR[i - 1], preR[i]);
	
	for(int i = 1; i <= n; i++) 
		mxL[i] = max(mxL[i - 1], preL[i]);
	
	int nutrition = 0;
	
	for(int i = 0; i <= n; i++)
	{
		int e = preL[i];
		
		amax(nutrition, e);
		e = e - xL[i] + mxR[n - i];
		amax(nutrition, e);
	}
	
	for(int i = 0; i <= n; i++)
	{
		int e = preR[i];
		
		amax(nutrition, e);
		e = e - xR[i] + mxL[n - i];
		amax(nutrition, e);
	}
	
	cout << nutrition;
}

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

int main()
{
	int n,v[20],c[20],sum=0;
	
	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	for(int j=0;j<n;j++){
		cin>>c[j];
	}
	
	for(int k=0;k<n;k++){
		if(v[k]>c[k]){
			sum+=(v[k]-c[k]);
		}
	}
	
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)


n = int(input())

GRAPH = [[] for _ in range(n + 1)]
EDGE = {}
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    a, b = min(a, b), max(a, b)
    GRAPH[a].append(b); GRAPH[b].append(a)
    EDGE[(a, b)] = c

def dfs(now, prev):
    for v in GRAPH[now]:
        if v == prev:
            continue
        next = v
        a, b = min(now, next), max(now, next)
        LENGTH[next] = LENGTH[now] + EDGE[(a, b)]
        dfs(next, now)

q, k = map(int, input().split())

LENGTH = [0] * (n + 1)
dfs(k, 0)

for _ in range(q):
    x, y = map(int, input().split())
    print(LENGTH[x] + LENGTH[y])


Measured memory_bytes: 132524
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int divisor=0;
		for (int i = a; i <=b; i++) {
			if(c%i==0) {
				divisor++;
			}
		}
		System.out.println(divisor);
	}
}


Measured memory_bytes: 26328
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        int maxL = 0;
        int[] dp = new int[n+1];
        for(int i = 0; i < n; i++){
            int t = a[i];
            dp[t] = dp[t-1]+1;
            maxL = Math.max(maxL,dp[t]);
        }
        pw.println(n-maxL);
        pw.flush();
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 46188
for roop in range(int(raw_input())):
    h,m = map(int,raw_input().split(":"))
    s = 120*h + 2*m
    l = 24*m
    if l < s: l,s = s,l
    arg = l - s if l - s < 180*4 else 360*4-(l-s)
    if   arg < 30*4: print "alert"
    elif arg < 90*4: print "warning"
    else           : print "safe"

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

using namespace std;

int main()
{
	int n, x;
	int roop = 0;
	vector<int> count(10001, -1);
	while (cin >> n >> x, n != 0)
	{
		count[roop]++;
		for (int i = 1; i <= n - 2; i++)
		{
			for (int j = i + 1; j <= n - 1; j++)
			{
				for (int k = j + 1; k <= n; k++)
				{
					if (i + j + k == x)
					{
						count[roop]++;
					}
				}
			}
		}
		roop++;
	}
	roop = 0;
	while(count[roop] != -1)
	{
		cout << count[roop++] << endl;
	}
    return 0;
}



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

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

int dp[1111][1111],h,w,ans;

string s[1111];
signed main(){
  memset(dp,-1,sizeof(dp));
  cin>>h>>w;
  r(i,h)cin>>s[i];
  queue<P>q;
  r(i,h)r(j,w){
    if(s[i][j]=='#'){
      q.push(P(i,j));
      dp[i][j]=0;
    }
  }
  while(!q.empty()){
    P p=q.front();q.pop();
    int y=p.first;
    int x=p.second;
    ans=max(ans,dp[y][x]);
    r(i,4){
      int Y=y+dy[i];
      int X=x+dx[i];
      if(Y<0||X<0||h<=Y||w<=X)continue;
      if(dp[Y][X]!=-1)continue;
      dp[Y][X]=dp[y][x]+1;
      q.push(P(Y,X));
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 27316
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main() {
	string s1, s2;
	cin >> s1 >> s2;
	reverse(s2.begin(), s2.end());
	if (s1 == s2)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
dishes = []
n.times do |i|
  s, p =  gets.chomp.split
  p = p.to_i * -1
  dishes << [i+1, s, p]
end
dishes.map { |i,s,p| s }.uniq.sort.each do |d|
  dishes.select {|i,s,p| s == d }.sort { |(i1,s1,p1), (i2,s2,p2)| p1<=>p2 }.each do |dish|
    puts dish[0]
  end
end


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

#define 	pie				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(int i = a ; i < b ; i++)
#define 	mod1 			1000003
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define     pi              pair<int, int>
#define 	vs 				vector<string>
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define     print2(a)       for(auto i : a)cout<<i;cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)
//greater<int>()
//__builtin_popcount();


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

void solve()
{
    ll n; cin>>n;
    ll ans = 0;
    ans = (n/500)*1000 + ((n -((n/500)*500))/5)*5;
    cout<<ans<<nl;

    

}

int main()
{
    int  t;
    //cin>>t;
    t = 1;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# 標準入力の取得
N = int(input())
A = list(map(int, input().split()))

# 求解処理
# 数列A内に負の数が奇数/偶数で場合分け
sign_count = len([a for a in A if a < 0])
result = int()
B = [abs(a) for a in A]
if sign_count % 2 == 1:
    B[B.index(min(B))] *= -1
result = sum(B)

# 結果出力
print(result)


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

const int N = 1e7 + 5;

ll a[N];

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "1\n";
    return 0;
  }
  memset(a, 0, sizeof a);
  for (ll i = 1; i < N; i++)
    for (ll j = i; j < N; j += i)
      a[j]++;
  ll ans = 0;
  for (ll i = 1; i <= n; i++)
    ans += i * a[i];
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 81736
#include <bits/stdc++.h>
#define openfile(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
#define mpr std::make_pair
#define lg(x) (31-__builtin_clz(x))
#define lgll(x) (63-__builtin_clzll(x))
#define __count __builtin_popcount
#define __countll __builtin_popcountll
#define X first
#define Y second
#define mst(x) memset(x,0,sizeof(x))
#define mst1(x) memset(x,-1,sizeof(x))
#define ALL(c) (c).begin(),(c).end()
#define FOR(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(int i=1;i<=n;i++)
#define FORit(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();++it)
#define pb push_back
#define RI(x) scanf("%d",&x)
#define RID(x) int x;RI(x)
using namespace std;
typedef long long LL;
typedef double LD;
typedef vector<int> VI;
typedef std::pair<int,int> PII;
template<class T>inline void maz(T &a,T b){if(a<b)a=b;}
template<class T>inline void miz(T &a,T b){if(a>b)a=b;}
template<class T>inline T abs(T a){return a>0?a:-a;}
const int N=100100, INF=1e9;
const LD EPS=1e-7;

vector<int> Edge[N];
int n;
void readEdge(){
  RID(a); RID(b);
  Edge[a].push_back(b);
  Edge[b].push_back(a);
}
int v[N];
int V;
bool visit(int x){ return v[x]==V;}
int final_level;
int c[N];

int dfs(int x, int level){
  if(c[x] == 2){ 
    final_level = level;
    return 1;
  }
  int res = 0;
  for(auto nxt: Edge[x]){
    if(visit(nxt)) continue;
    v[nxt] = V;
    res += dfs(nxt, level+1);
  }
  if(res == 1){
    c[x] = (level>(final_level/2))?2:1;
  }
  return res;
}

void color(int x, int xc){
  if(c[x] == 0) c[x] = xc;
  for(auto nxt: Edge[x]){
    if(visit(nxt)) continue;
    v[nxt] = V;
    color(nxt, c[x]);
  }
}

int main(){
  RI(n);
  FOR(i,n-1) readEdge();
  c[1] = 1;
  c[n] = 2;
  V++;
  dfs(1, 0);
  V++;
  color(1,1);
  int res[3] = {};
  FOR1(i,n){
    assert(1<=c[i] && c[i] <= 2);
    res[c[i]] += 1;
  }
  if(res[1] > res[2]) puts("Fennec");
  else puts("Snuke");
}


Measured memory_bytes: 12800
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;


int main(int argc, char *argv[]) {
	long long int n, a, b;
	cin >> n >> a >> b;
	if ((a - b) % 2 == 0) {
		cout << (a > b ? (a - b) / 2 : (b - a) / 2) << endl;
	}
	else {
		long long int res = 0;
		long long int aa = a, bb = b;
		aa = min(a, b), bb = max(a, b);
		long long int r = 0;
		r = aa;
		bb -= aa;
		aa = 1;
		r += (bb - aa) / 2;
		res = r;

		aa = min(a, b), bb = max(a, b);
		r = n - bb + 1;
		aa += n - bb + 1;
		bb = n;
		r += (bb - aa) / 2;
		res = min(res, r);
		cout << res << endl;
		// cout << min(max(a, b) - 1, n - min(a, b)) << endl;
	}


}









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

class Program
{
    static int[] ReadInts()
        => Console.ReadLine()
            .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
            .Select(s => int.Parse(s))
            .ToArray();

    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        Console.WriteLine(s.Contains('7') ? "Yes" : "No");
    }
}


Measured memory_bytes: 25884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
ll n;
ll a[200005];
ll s;
ll b[200005];
ll ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i+1]=(b[i]+a[i])%MOD;
        s=(s+a[i])%MOD;
    }
    for(int i=0;i<n;i++){
        ans=(ans+(a[i]*(s-b[i+1]))%MOD)%MOD;
    }
    if(ans<0){
        ans+=MOD;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 6716
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

A, V = nn()
B, W = nn()
T = n1()

if V <= W:
    print("NO")
else:
    if (V - W) * T >= abs(A - B):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 72776
N, K, Q = map(int, input().split())
A = [0] * Q
for i in range(Q):
    A[i] = int(input())

B = [0] * (N+1)
for i in range(Q):
    B[A[i]] += 1


for i in range(1, N+1):
    tmp = Q - B[i]
    if tmp < K :
        print('Yes')
    else:
        print('No')

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,c;
	cin >> a >>b >>c;
	
	
	cout << a*b /2<< endl;
	return 0;
}




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

using namespace std;

bool match(int k, string &s, string &t){
     for(int i=0; i<t.size(); i++){
         if(t[i] != s[i+k] && s[i+k] != '?')
            return false;
     }
     return true;
}


int main(){
    string s, t;
    cin >> s >> t;
    if(t.size() > s.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    int t_max = -1;
    for(int i=0; i<=s.size()-t.size(); i++){
        if(match(i, s, t))
           t_max = i;
    }
    if(t_max == -1){
       cout << "UNRESTORABLE" << endl;
       return 0;
    }
    for(int i=0; i<t.size(); i++){
        s[i+t_max] = t[i];
    }
    for(int i=0; i<s.size(); i++){
        if(s[i] == '?') s[i] = 'a';
    }

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int N, K;
vector<int> W(100010);

bool check(int P){
    int sum = 0, item = 0, truck = 0;
    while(1){
        if(item == N) return true;
        if(truck == K) return false;
        if(sum + W[item] <= P){
            sum += W[item];
            item++;
        } else {
            sum = 0;
            truck++;
        }
    }
}

int main(){
    cin >> N >> K;
    rep(i, N) cin >> W[i];
    int ng = 0, ok = INF;
    while(ok - ng > 1){
        int m = (ok + ng)/2;
        if(check(m)) ok = m;
        else ng = m;
    }
    cout << ok << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < ( int )( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll; 

void vdeb(vector<long long> &da) {
	int size = da.size();
	rip(i, size - 1, 0) {
		printf("%lld ", da[i]);
	}
	printf("%lld\n", da[size - 1]);
}

struct BIT{
    vector<ll> li;
    int size;
    BIT (int n){
        li=vector<ll>(n+1,0);
        size=n;
    }
    ll sum (int i){
        ll s=0;
        while(i>0){
            s=max(s,li[i]);
            i-=i & -i;
        }
        return s;
    }
    void add(int i,ll x){
        while(i<=size){
            li[i]=max(li[i],x);
            i+=i & -i;
        }
    }
};

int main(){
	int n;
	cin >> n;
	vector<int> a(n),h(n);
	rip(i,n,0){
		cin >> h[i];
	}
	rip(i,n,0){
		cin >> a[i];
	}
	BIT bt(n);
	vector<pair<int,int>> gg(n);
	rip(i,n,0){
		gg[i].first=h[i];
		gg[i].second=i;
	}
	sort(all(gg));
	rip(i,n,0){
		h[gg[i].second]=i+1;
	}
	rip(i,n,0){
		ll now=bt.sum(h[i])+a[i];
		bt.add(h[i],now);
	}
	ll ans=0;
	rip(i,n,0){
		ans=max(bt.li[i+1],ans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> a(N + 1);
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
  }
  set<int> s;
  int x = 1;
  s.insert(x);
  int cnt = 0;
  while (true) {
    ++cnt;
    x = a[x];
    if (x == 2) {
      cout << cnt << endl;
      break;
    }
    else if (s.count(x) > 0) {
      cout << -1 << endl;
      break;
    }
    else {
      s.insert(x);
    }
  }
  
  return 0;
}


Measured memory_bytes: 5376
#include <cstdio>
#include<algorithm>
using namespace std;
#define ll long long

const int N = 5e5 + 15;
const int mod = 1e9 + 7;
const int M = (1 << 22);
int A[N];

int add(int x, int y) {
	return (x + y) % mod;
}
int mul(int x, int y) {
	return (ll)x*y%mod;
}

int dp[M];
int sum[M], X[M];

void solve() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	int c = 0;
	int ret = 0;
	++dp[0];
	int k = 0;
	for (int i = 0; i < n; ++i) {
		c ^= A[i];
		if (i == n - 1 && c == 0)continue;
		if (c == 0) {
			ret = add(ret, dp[0]);
			dp[0] = add(dp[0], dp[0]);
			++k;
		}
		else {
			int x = k - sum[c];
			sum[c] = k;
			int v = mul(x, X[c]);
			dp[c] = add(dp[c], v);
			X[c] = add(1, add(X[c], dp[c]));
			ret = add(1, add(ret, dp[c]));
		}
	}
	ret = add(1, ret);
	if (c)
		printf("%d\n", (dp[c]+1)%mod);
	else
		printf("%d\n", ret);
}

int main() {
	//freopen("input.txt","r",stdin);
	solve();
}


Measured memory_bytes: 20608
def solve(n):
    Mrepeat = 10
    seedlist = [[str(i+j-1) for i in range(3)] for j in range(10)]
    seedlist[0] = ['0', '1']
    seedlist[9] = ['8', '9']
    numbers = [[] for i in range(Mrepeat + 1)]
    numbers[0] = [i for i in range(1,10)]
    for i in range(Mrepeat):
        for num in numbers[i]:
            for tmp in seedlist[num % 10]:
                numbers[i+1].append(int(str(num) + tmp))
    ans = []
    for i in numbers:
        ans += i
    return ans[n-1]

def main():
    n = int(input())
    print(solve(n))

if __name__ == '__main__':
    main()

Measured memory_bytes: 80224
#include <iostream>

using namespace std;
  
int n, q, A[25];
  
bool check(int i, int m) {
    if (m == 0) return true;
    if (i >= n) return false;
    bool res = check(i + 1, m) || check(i + 1, m - A[i]);
    return res;
}
  
int main()
{
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
  
    cin >> q;
    for(int i=0;i<q;i++) {
        int m;
        cin >> m;
        if (check(0, m)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
  
    
    return 0;
}



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

#define forn(i,n) for(ll i = 0;i<n;i++)
#define forne(i,j,n) for(ll i = j;i<n;i++)
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ll INF = 1000000001;
const ll N = 100001;
const lld PI = 3.141593;
#define F first
#define pb(a) push_back(a)
#define S second
#define pii pair<int,int>
typedef pair<ll,ll> pll;

ll powm(ll base,ll exp) {
	ll ans=1;
	while(exp){
		if(exp&1) ans=(ans*base)%mod;
		exp>>=1,base=(base*base)%mod;
	}
	return ans;
}

// ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
// bool valid(ll i, ll j) {
// 	return i >= 1 && i <= n && j >= 1 && j <= m; 
// }
// int maxdepth = INT_MAX;
// vector<int> edgeVector[100000];
// ll minans = 1;
// printf("1 %d D\n",abs(r));
// priority_queue<ll,vector<ll>,greater<ll>> pq;
// ll a[N],b[N];
// vector<vector<ll>> adj(N);
// vector<set<ll>> adjs(N);
// ll adj[1001][1001];
// vector<vector<ll>> ans(1001);
// bool visited[N];
// ll cnt[1001];
// ll h,c,t;
// vector<pair<int, pair<int, int> > > g[300043];



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

ll n;
cin>>n;
ll k = ceil((lld)n/1000);
ll fa = (k*1000 - n);
cout<<fa<<endl;
}

Measured memory_bytes: 3612
mod = 10 ** 9 + 7
n = int(input())
a_i = list(map(int, input().split()))
a_i.sort()
ans = 1
if max(a_i) >= n: ans = 0
else:
    for x in range(n //2):
        if n % 2 == 0:
            if a_i[2 * x] != 2 * x + 1 or a_i[2 * x + 1] != 2 * x + 1: ans = 0
            else: 
                ans *= 2
                ans = ans % mod
        elif a_i[0] == 0 and n % 2 != 0:
            if a_i[2 * (x + 1) - 1] != 2 * (x + 1) or a_i[2 * (x + 1)] != 2 * (x + 1): ans = 0
            else: 
                ans *= 2
                ans = ans % mod
        else: ans = 0
print(ans % mod)

Measured memory_bytes: 14008
#include<stdio.h>

int main(void)
{
	for (;;){
		int x, y;
		scanf("%d %d", &x, &y);
		if (x < y)
		{
			printf("%d %d\n", x, y);
		}
		else if (x > y)
		{
			printf("%d %d\n", y, x);
		}
		else if (x == y && x != 0)
		{
			printf("%d %d\n", x, y);
		}
		else
		{
			break;
		}
	}
	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<LL> a(n),b(n);
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  LL ans=0,tmp=0;
  if(n%2){
    if(n/2<n-1) ans=a[n/2+1]-a[n/2];
    for(int i=0;i<n/2;i++){
      ans+=2*(a[n/2]-a[i]);
    }
    for(int i=n/2+2;i<n;i++){
      ans+=2*(a[i]-a[n/2]);
    }
    tmp=2*a[n/2+1]-a[n/2]-a[n/2-1];
    for(int i=0;i<n/2-1;i++){
      tmp+=2*(a[n/2+1]-a[i]);
    }
    for(int i=n/2+1;i<n;i++){
      tmp+=2*(a[i]-a[n/2+1]);
    }
    ans=max(ans,tmp);
  }else{
    ans=a[n/2]-a[n/2-1];
    for(int i=0;i<n/2-1;i++){
      ans+=2*(a[n/2]-a[i]);
    }
    for(int i=n/2+1;i<n;i++){
      ans+=2*(a[i]-a[n/2]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

vector<bool> aclist(100010, false);

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

  int p;
  string s;
  vector<int> penalty(100010, 0);
  int psum = 0;
  int acpointa=0;
  
  for(int i=0; i<M; i++)
    {
      cin >> p >> s;

      if(aclist[p] == false)
	{
	  if(s=="AC")
	    {
	      aclist.push_back(p);
	      acpointa++;
	      aclist[p]=true;
	      psum += penalty[p]; 
	    }
	  else
	    {
	      penalty[p]++;
	    }
	}
    }
  
  cout << acpointa << " " << psum << endl;

  return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var n, m, p int
	var s string
	fmt.Scanf("%d %d", &n, &m)

	acflag := map[int]bool{}
	var ac, wa int
	wabuf := map[int]int{}

	for i := 0; i < m; i++ {
		fmt.Scan(&p)
		fmt.Scan(&s)
		if !acflag[p] {
			switch s {
			case "AC":
				ac++
				acflag[p] = true
				wa += wabuf[p]
			case "WA":
				wabuf[p]++
			}
		}
	}

	fmt.Print(ac)
	fmt.Print(" ")
	fmt.Println(wa)
}


Measured memory_bytes: 7936
#include <stdio.h>
int main() {
  int R;
  scanf("%d",&R );
  if(0<=R && R<1200)
  printf("ABC\n" );
  else if(1200<=R && R<2800)
  printf("ARC\n");
  else if(2800<=R && R<4209)
  printf("AGC\n");
  else
  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            boolean foundFirst = false;
            int firstMax = 0;
            int secodeMax = 0;
            for (int i = n - 2; i >= 0; i--) {
                if (a[i] == a[i + 1]) {
                    if (foundFirst) {
                        secodeMax = a[i];
                        break;
                    } else {
                        foundFirst = true;
                        firstMax = a[i];
                        a[i] = 0;
                    }
                }
            }
            long x = firstMax;
            x*=secodeMax;
            out.println(x );
        }

    }

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

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

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

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

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

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

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

    }
}


Measured memory_bytes: 36352
#include<bits/stdc++.h>
#define pb       push_back
#define mp       make_pair
//#define mod      10000007
#define pi       acos(-1.0)
#define test     int t; cin>>t ;while(t--)
typedef long long ll;
using namespace std;
vector<int>node[1000002];
int a[1000002];
int n,m;
void dfs(int p)
{
    a[p]=1; 
    for(int i=0;i<node[p].size();i++)
     {
         int temp=node[p][i];
         if(!a[temp])
         {
             dfs(temp);
         }
     }
}
int main()
{      


     ios::sync_with_stdio(false);
     cin.tie(NULL);
     
      int n,m;
      cin>>n>>m;
      int x,y;
      while(m--)
      {
         cin>>x>>y;
         node[x].push_back(y);
         node[y].push_back(x);
      }
       
       int cnt=0;
      for(int i=1;i<=n;i++)
       {
          if(!a[i])
          {
             cnt++;
             dfs(i);
          }
       }
       
       cout<<cnt-1<<endl;
      return 0;
    
 } 


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

vector<l_l> r[100005];

ll color[100005];

void calc(ll node, ll dist) {
  if (color[node] >= 0) {
    return;
  }

  color[node] = (dist % 2 == 0) ? 0 : 1;

  auto l = r[node];

  for (ll i = 0; i < l.size(); i++) {
    ll next_node = l[i].first;
    ll next_dist = l[i].second;
    calc(next_node, dist + next_dist);
  }
}

int main() {
  fill_n(color, 100002, -1);

  ll N;
  scanf("%lld", &N);

  for (ll i = 0; i < N; i++) {
    ll u, v, w;
    scanf("%lld %lld %lld", &u, &v, &w);

    r[u].emplace_back(make_pair(v, w));
    r[v].emplace_back(make_pair(u, w));
  }

  calc(1, 0);

  for (ll i = 1; i <= N; i++) {
    cout << (color[i]) << endl;
  }
}


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

using Lint=long long;
const Lint INF=1e18;

int main()
{
   int N,W; cin>>N>>W;
   vector<int> w(N),v(N);
   for(int i=0;i<N;i++) cin>>w[i]>>v[i];

   const int sumV=accumulate(v.begin(),v.end(),0LL);
   vector<vector<Lint>> dp(N+1,vector<Lint>(sumV+1,INF));
   dp[0][0]=0;
   for(int i=0;i<N;i++) for(int j=0;j<=sumV;j++) if(dp[i][j]!=INF){
      assert(j+v[i]<=sumV);
      dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
   }
   int ans=0;
   for(int j=0;j<=sumV;j++) if(dp[N][j]<=W) ans=j;
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 80256