akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	cnt = 0
	fst = True

	ansans = []
	pgt = queue.Queue()
	for i,val in enumerate(A):
		if i == 0:
			pgt.put(val)
		else:
			tmp = pgt.get()
			ansans.append(tmp)

			pgt.put(val)

			if tmp == val:
				pgt.put(val)
			else:
				pgt.put(val)

	#print(ansans)
	print(sum(ansans))


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 )
	   a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
			return false;
	return true;
}

const int MAXN = 2e5 + 10;

int n;
int A[ MAXN ];

int main()
{
	cin >> n;
	FOR( i, 0, n )
		cin >> A[ i ];
	
	int x = 1, sol = 0, pl = 0;
	bool ok = false;
	FOR( i, 0, n )
	{
		if ( A[ i ] == x )
		{
			pl = i;
			x++;
			ok = true;
		}
		else
			sol++;
	}
	
	if ( !ok )
	{
		cout << "-1\n";return 0;
	}
	
	int ans = 0;
	ans = pl - x + 1;
	
	cout << sol << "\n";
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long lucas[101];
int main(){
	int n;
	cin>>n;
	lucas[0]=2;
	lucas[1]=1;
	for(int i=2;i<=n;i++){
		lucas[i]=lucas[i-1]+lucas[i-2];
	}
	cout<<lucas[n];
	return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  
  if(a%2==0){
  	int p=a*12+a/2;
  	int q=b*10;
  	int r=p+12;
    int s=q+9;
    
    if( p<=q && q<=r ) cout << q << endl;
    else if ( q<=p && p<=s ) cout << p << endl;
    else cout << "-1" << endl;
  }
  
  else{
    int p=a*12+a/2+1;
  	int q=b*10;
  	int r=p+11;
    int s=q+9;
    
    if( p<=q && q<=r ) cout << q << endl;
    else if ( q<=p && p<=s ) cout << p << endl;
    else cout << "-1" << endl;
  }
}

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

using namespace std;

bool search(int n,int k,vector<vector<int> >&list,vector<int>&a){
    bool flag;
    for(int i=0;i<k;i++){
        flag=false;
        for(int j=1;j<=list[n][0];j++){
            if(list[n][j]==a[i]){
                flag=true;
                break;
            }
        }
        if(!flag)return false;
    }
    return true;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        vector<vector<int> >list(n,vector<int>(n+1,0));
        for(int i=0;i<n;i++){
            cin >> list[i][0];
            for(int j=1;j<=list[i][0];j++){
                cin >> list[i][j];
            }
        }
        int k;
        cin >>k;
        vector<int> a(k,0);
        for(int i=0;i<k;i++){
            cin >> a[i];
            }
        bool flag=false;
        int ans=-1;
        for(int i=0;i<n;i++){
            if(search(i,k,list,a)){
                if(ans!=-1){
                    ans=-1;
                    break;
                }
                else ans=i+1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3160
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int, int>> xys(N);
    REP(n, N) cin >> xys[n].first >> xys[n].second;

    int cnt = 0;
    double dist_sum = 0.0;
    vector<int> shff(N);
    REP(n, N) shff[n] = n;
    do {
        double dist = 0.0;
        FOR(i, 1, N) {
            auto prev = shff[i - 1];
            auto curr = shff[i];
            auto xy1 = xys[prev];
            auto xy2 = xys[curr];
            dist += hypot(xy1.first - xy2.first,
                          xy1.second - xy2.second);
        }
        dist_sum += dist;
        ++cnt;
    }while(next_permutation(ALL(shff)));
    
    printf("%.12f\n", dist_sum / cnt);
    return 0;
}


Measured memory_bytes: 256
# デバッグ用
GBN_DEBUG = False
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

S = input()
#N = int(input())
#S, T = input().split()
#N, M = map(int, input().split())
#W = [input() for _ in range(N)]
#A = list(map(int, input().split()))

#GBN_DEBUG = True

if (S[2] == S[3]) and (S[4] == S[5]):
    print('Yes')
else:
    print('No')


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

#define ll long long int

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    if((n - 1) % 2 == 0) {
        ans += (n - 1) / 2;
        ans *= n;
    } else {
        ans += n / 2;
        ans *= (n - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(x,y)
	while (r=x%y)!=0
		x=y
		y=r
	end
	return y
end

def lcm(x,y)
	x*y/gcd(x,y)
end

while v=gets
	m,n=v.split.map(&:to_i)
	printf("%d %d\n",gcd(m,n),lcm(m,n))
end

Measured memory_bytes: 6112
#include <iostream>

int main() {
    int N;
    std::string c;
    std::cin >> N >> c;
    int ans = 0;
    int right = N - 1;
    for (int left = 0; left < N; left++) {
        if (c[left] == 'W') {
            while (c[right] == 'W') {
                right--;
            }
            if (right <= left) {
                std::cout << ans << std::endl;
                exit(0);
            }
            else {
                ans++;
                right--;
            }
        }
        else if (left >= right) {
            std::cout << ans << std::endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,k;
    cin>>n>>k;
    std::vector<int> v(n);
    for (auto &it:v)
        cin>>it;
    for (int i=0;i<=n-1-k;++i)
    {
        if (v[i]<v[i+k])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;
 
 
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> plist(N);
  for (int i = 0; i<N; i++) {
    int p;
    cin >> p;
    plist.at(i) = p;
  }
  sort(plist.begin(), plist.end());
  
  int ans=0;
  for (int i = 0; i<K; i++) {
    ans += plist.at(i);
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 3596
import math

n, d = [int(x) for x in input().split(' ')]
total = 0
for i in range(n):
    x, y = [abs(int(x)) for x in input().split(' ')]
    dis = math.sqrt((x**2)+(y**2))
    if(d >= dis):
        total += 1

print(total)

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

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

    int mx = max(h, w);
    int mn = min(h, w);

    int ans = 0;
    int p = 0;
    while (p < n) {
        int m = mx;
        if (ans > mx) {
            m = mn;
        }
        p += m;
        ans++;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
n = int(input())
sample = [i+1 for i in range(n)][::-1]

hoge = [1, 2 ,4, 8, 16, 32, 64][::-1]
add = []

flag = False
for h in hoge:
    for s in sample:
        if s % h == 0:
            print(s)
            flag = True
            break
    if flag:
        break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
// (int)size_t 0 =s.length();
#define size_t size_t
int k[10000000];
int main(){
  string s;
  int n,ans=0;
  cin>>s;
  size_t a = s.length();
  for(int i=0;i<a;i++){
    if(i%2==1){
      if(s[i]=='L' || s[i]=='U' || s[i]=='D') ans++;
    }
    if(i%2==0){
      if(s[i]=='R' || s[i]=='U' || s[i]=='D') ans++;
    }
  }
  if(a==ans) cout<<"Yes\n";
  else cout<<"No\n";
  return(0);
}


Measured memory_bytes: 256
n=int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))

fl=[];fnex=[]
total=0

fl.append(min(al[0],bl[0]))
total+=fl[0]

fnex.append(min(al[1],bl[0]-fl[0]))
total+=fnex[0]
#print(fl)

#print(min(al[1],bl[0]-fl[0]))

for i in range(2,n+1):
  #i がi番目のmonsterを倒す
  fii=min(al[i-1]-fnex[i-2],bl[i-1])
  fl.append(fii)
  total+=fii
  #print(i)
  #print(fii)
  #i が(i+1)番目のmonsterを倒す
  fnex.append(min(al[i],bl[i-1]-fii))
  total+=fnex[i-1]
  #print(min(al[i],bl[i-1]-fii))
  
print(total)
  

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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int N;
	cin >> N;
	int count = 0;
	bool F = true;
	
	if (N%2==0) {
		for (int i = 0; i < N && F; i++) {
			std::string aun;
			cin >> aun;
			if (aun == "A") {
				count++;
			} else {
				count--;
				if(count < 0) {
					F = false;
				}
			}
		}
	} else {
		F = false;
	}
	if (count != 0) {
		F = false;
	}

	if (F) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 3156
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigInteger a = sc.nextBigInteger();
        BigInteger b = sc.nextBigInteger();
        if(a.compareTo(b) > 0) System.out.println("GREATER");
        else if(a.compareTo(b) < 0) System.out.println("LESS");
        else System.out.println("EQUAL");
    }
}

Measured memory_bytes: 35860
N = int(input())
list_A = list(map(int, input().split()))
a = 1

mul_A = 1

for i in range(N):
    a = list_A[i]
    mul_A = mul_A * a
    
sum_A = 0

for i in range(N):
    a = mul_A // list_A[i]
    sum_A = sum_A + a
    
print(mul_A/sum_A)
    

Measured memory_bytes: 3060
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=rd())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int rd(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=x*10+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define P (998244353)
#define N (200010)
int n,m,k,pw[N]{1},fc[N]{1},ans;
int fpw(int a,int b){int r(1);while(b)b&1?r=r*a%P:0,a=a*a%P,b>>=1;return r;}
int inv(int a){return fpw(a,P-2);}
signed main(){
	Rd(n),Rd(m),Rd(k),pw[1]=m-1;
	Frn1(i,1,n)pw[i]=pw[i-1]*pw[1]%P,fc[i]=i*fc[i-1]%P;
	Frn1(i,0,k)ans=(ans+fc[n-1]*inv(fc[i])%P*inv(fc[n-i-1])%P*m%P*pw[n-i-1]%P)%P;
	wr(ans),exit(0);
}


Measured memory_bytes: 6764
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1};
vector<int> y4 = {1, 0, -1, 0};
vector<int> x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


template<class T> struct edge { int from, to; T cost;};

int N,M; // 各々頂点数、辺数
const int MAX_N = 1000;
const int MAX_M = 2000;
vector<ll> d(MAX_N);   // 最短距離             // llにするときは(ry
vector<edge<ll>> es(MAX_M); // 辺              // llにするときはここもllにしてくれ
vector<bool> negative(MAX_N);

// s番目の頂点から各頂点への最短距離を求める。但しtrueならアカン負の閉路が存在する
bool bellman_ford(int s){
  rep(i, N) d[i] = INF;
  d[s] = 0;
  rep(vv, N-1){
    rep(i, M){
      auto e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) d[e.to] = d[e.from] + e.cost;
    }
  }
  bool nclose = false;
  rep(vv, N-1){ // 離島、負の閉路について
    rep(i, M){
      auto e = es[i];
      if (d[e.from] == INF) continue;
      if (d[e.from] + e.cost < d[e.to]) negative[e.from] = true, nclose = true;
      if (negative[e.from]) negative[e.to] = true;
    }
  }
  return nclose;
}


int main() {
  cin >>N >>M;
  rep(i, M){
    int a,b; ll c; cin >>a >>b >>c; a--; b--; c = -c;
    es[i] = {a,b,c};
  }
  bellman_ford(0);
  if (negative[N-1]) cout <<"inf" <<endl;
  else{
    cout <<-d[N-1] <<endl;
  }
}


Measured memory_bytes: 256
# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007

result = 0
a = 1
b = 1

for i in range(K + 1):
    # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
    result += pow(26, K - i, m) * (a * pow(b, m - 2, m)) * pow(25, i, m)
    result %= m
    a *= len(S) - 1 + (i + 1)
    a %= m
    b *= i + 1
    b %= m
print(result)


Measured memory_bytes: 75460
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long num;
string S;

int main(){
	cin >> S;
	for(int i = 0; i < S.size() - 1; i++){
		if(S[i] != S[i+1]){
			num++;
		}
	}
	cout << num << endl;

}


Measured memory_bytes: 512
import numpy as np
a,b,c,d=map(int,input().split())
n=np.array([c-a,d-b])
p=np.array([-n[1],n[0]])
print(*([c,d]+p), end=" ") #print(*([c,d]+p),*([a,b]+p))がPython3.4.3には対応してない？
print(*([a,b]+p))

Measured memory_bytes: 12504
object Main extends App {
  val n = io.StdIn.readLine().toInt
  val m = (1e9+7).toInt
  val an = io.StdIn.readLine().split(' ').map(_.toLong)
  var sum: Long = 0
  var b: BigInt = 1
  val max = an.max
  while (b <= max) {
    var (z, o) = (0, 0)
    an.indices foreach {i =>
      if ((an(i) & 1) == 0) z += 1 else o += 1
      an(i) = an(i) >> 1
    }
    sum += ((b*z*o) % m).toLong
    sum %= m
    b = b << 1
  }
  println(sum)
}

Measured memory_bytes: 90960
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9+1;
int main(){ 
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 256
def subset_sum(n,a,s):
	cnt=0
	for i in range(n):
		r=s-a[i]
		j=i+1
		k=n-1
		while j<k:
			t=a[j]+a[k]
			if t<r:
				j+=1
			elif t>r:
				k-=1
			else:
				cnt+=1
				j+=1
				k-=1
	return cnt

while True:
	n,s=map(int,input().split())
	if n==0 and s==0:
		break
	a=[0]*n
	for i in range(n):
		a[i]=i+1
	print(subset_sum(n,a,s))



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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;
}

int c[10][10];

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

  rep(i, 10) rep(j, 10)
  {
    cin >> c[i][j];
  }

  rep(k, 10) rep(i, 10) rep(j, 10)
  {
    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  }

  ll ans = 0;
  rep(i, h) rep(i, w)
  {
    int a;
    cin >> a;
    if (a == -1)
      continue;
    ans += c[a][1];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();		//n項目
		long c=0;
		
		for(int i=1;i<=n;i++) {
			
			// 3の倍数かつ、5の倍数の場合
		    if (i%3==0&&i%5==0) {
		    	
		    }
		     
		    // 3の倍数の場合
		    else if (i%3==0) {
		    	
		    }
		     
		    // 5の倍数の場合
		    else if (i%5==0) {
		    	
		    }
		     
		    // いずれでもない場合
		    else {
		    	c=c+i;
		     }
		   }
		 System.out.println(c);
		sc.close();
	}

}


Measured memory_bytes: 27204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
using Graph = vector<vector<ll>>;


int main(void){
    // Your code here!
    ll n,x,y;cin >> n >> x >> y;
    Graph G(n);
    x--;y--;
    rep(i,n){
        if(i !=0) G[i].push_back(i-1);
        if(i !=n-1) G[i].push_back(i+1);
    }
    G[x].push_back(y);
    vector<int> d(n,0);
    rep(i,n){
        queue<int> q;
        vector<int> D(n,-1);
        q.push(i);
        D[i] = 0;
        while( !q.empty()){
            int v = q.front();
            q.pop();
            for(auto nv:G[v]){
                if(D[nv] != -1)continue;
                D[nv] = D[v] +1;
                if(nv > i) d[D[nv]] += 1;
                q.push(nv);
            }
        }
    }
    FOR(i,1,n-1){
        cout << d[i] << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    if(n%2 == 0){
        cout << n/2 -1 <<endl;
    }else{
        cout << n/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
string s;
int main(){
	int n;
	int m;
	int f,count,ans;
	while(cin>>n,n){
		cin>>m;
		cin>>s;
		f=0;
		count=0;
		ans=0;
		for(int i=0;i<s.size();i++){
			if(f==0){
				if(s[i]=='I')f=1;
			}
			else if(f==1){
				if(s[i]=='O')f=2;
				else count=0,f=1;
			}
			else if(f==2){
				if(s[i]=='I'){
					f=1;
					count++;
					if(count>=n)ans++;
				}
				else count=f=0;
			}
		}
		
		cout<<ans<<endl;
	}
	
}


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

int main()
{
  int n, ans = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      ans++;
  }
  cout << ans << endl;
}

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

struct flow{
    int t,s,d;
    flow(int t,int s,int d):t(t),s(s),d(d){}
    bool operator<(const flow &rhs) const{
        return t<rhs.t;
    }
};

const int MAX_N=2e4+10;

int N,M,t,s,d,ans;
vector<flow> fs;
vector<int> infected(MAX_N);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M,N){
        fs.clear();
        for (int i=0;i<M;++i){
            cin >> t >> s >> d;
            fs.emplace_back(t,--s,--d);
        }
        sort(fs.begin(),fs.end());
        fill(infected.begin(),infected.end(),0);
        infected[0]=1;
        for (int i=0;i<M;++i){
            if (infected[fs[i].s]) infected[fs[i].d]=1;
        }
        ans=0;
        for (int i=0;i<N;++i) ans+=infected[i];
        cout << ans << '\n';
    }
}


Measured memory_bytes: 3608
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    ll y = x/d;
    if(y>=k){
        cout << x - k*d << endl;
    }else{
        x -= d*y;
        k-=y;
        if(k%2==0){
            cout << x << endl;
        }else{
            cout << abs(x-d) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3648
NN = int(input())
AA1 = list(map(int,input().split()))
AA2 = list(map(int,input().split()))

SS = [0]*NN

SS[0] = AA1[0] + sum(AA2)
for ii in range(1, NN-1):
    SS[ii] = SS[ii-1] - AA2[ii-1] + AA1[ii]
SS[NN-1] = sum(AA1) + AA2[NN-1]

print(max(SS))


Measured memory_bytes: 61940
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;

  vector<int> v;
  int last = 0;
  if (S[0] == '0') v.push_back(0); 
  for (int i = 0; i < N; i++) {
    if (last != S[i]) {
      v.push_back(1);
      last = S[i];
    } else {
      v.back()++;
    }
  }
  if (S[N-1] == '0') v.push_back(0);
   
  vector<int> sum(v.size()+1, 0);
  for (int i = 0; i < v.size(); i++) {
    sum[i+1] = sum[i] + v[i];
  }
  
  int ans = 0;
  for (int l = 0; l < sum.size(); l+=2) {
    int r = l + (K*2+1);
    if (r >= sum.size()) {
      r = sum.size() - 1;
    }
    ans = max(ans, sum[r]-sum[l]);
  }

  cout << ans << endl;
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n, m;
  cin >> n >> m;
  vector<int> A(m);
  for (auto &a : A) {
    cin >> a;
  }
  LL sum = accumulate(all(A), 0);
  if (sum > n) {
    cout << -1 << "\n";
  } else {
    cout << n - sum << endl;
  }

  return 0;
}

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

int main(){
  int N,x,fx;
  cin >> N;
  x = N;
  while(N != 0){
    fx += N % 10;
    N /= 10;
  }
  if(x%fx == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(int argc, const char * argv[]) {
    double r, a, l;
    
    cin >> r;
    
    a = r * r * M_PI;
    l = 2 * r * M_PI;
    
    cout << fixed;
    cout << setprecision(6);
    
    cout << a << " " << l << endl;
    
    return 0;
}



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

int main(void){
  int h,w;
  cin >> h >> w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      string s;
      cin >> s;
      if(s == "snuke"){
        cout << char('A'+j) << i+1 << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int n, ans;
int coin[6] = {500,100,50,10,5,1};

int main(){
	while(scanf("%d", &n),n){
		ans = 0;
		n = 1000-n;
		for(int i = 0; i < 6; i++){ 
			ans += n/coin[i]; 
			n %= coin[i]; 
		}
		printf("%d\n", ans);
	}
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    int n; cin >> n;
    vl a(n);
    rep(i,n)cin>>a[i];
    sort(rall(a));
    ll res = 0;
    ll pre = 0;
    queue<int> que;
    rep(i,n){
        if(i == 0){
            que.push(a[i]);
        }
        else if(i == 1){
            int num = que.front();
            que.pop();
            res += num;
            que.push(a[i]);
            que.push(a[i]);
        }
        else{
            int num = que.front();
            que.pop();
            res += num;
            que.push(a[i]);
            que.push(a[i]);
        }
    }
    out(res);
}

Measured memory_bytes: 5568
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s);
    let mut m = s.split(" ");
    let a: i32 = m.next().unwrap().trim().parse().unwrap();
    let b: i32 = m.next().unwrap().trim().parse().unwrap();

    let ans: i32 = a + b / 2;
    println!("{}", ans);
}

Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int A = s.nextInt();
        int B = s.nextInt();
        int T = s.nextInt();
        
        int output = B * (T / A);
        System.out.print(output);
    }
}

Measured memory_bytes: 21844
import java.math.BigDecimal;
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		String str;//???????????\??????
		
		double r;
		r = scan.nextDouble();
		
		//double r;
		//r = Double.parseDouble(Integer.toString(scan.nextInt()) + ".0");//??°??????????????????/0????????????
		//?????¨?????3.14
		
		//????????¢???????±???????
		//BigDecimal x = new BigDecimal(?¨???????????????\??????);
		BigDecimal x = new BigDecimal(r * r * Math.PI);
		str = String.valueOf(x.setScale(5, BigDecimal.ROUND_UP)) + " ";
		
		
		
		//?????¨????????????????±???????
		BigDecimal y = new BigDecimal(2 * r * Math.PI);
		str = str + String.valueOf(y.setScale(5, BigDecimal.ROUND_HALF_UP));
		
		
		System.out.println(str);
		
		
	}
}

Measured memory_bytes: 28232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		
		InputStreamReader isr= new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		
		String strNum = br.readLine();
		String[] strNumList = strNum.split(" ");
		
		int intNumW = Integer.parseInt(strNumList[0]);
		int intNumH = Integer.parseInt(strNumList[1]);
		int intNumX = Integer.parseInt(strNumList[2]);
		int intNumY = Integer.parseInt(strNumList[3]);
		int intNumR = Integer.parseInt(strNumList[4]);
		
		int intDifferenceXR = intNumX - intNumR;
		int intSumXR = intNumX + intNumR;
		
		int intDifferenceYR = intNumY - intNumR;
		int intSumYR = intNumY + intNumR;
		
		String strMessage = "";
		
		if(intDifferenceXR >= 0 && intSumXR <= intNumW) {
			if(intDifferenceYR >= 0 && intSumYR <= intNumH) {
				strMessage = "Yes";
			}else {
				strMessage = "No";
			}
		}else {
			strMessage = "No";
		}
		System.out.println(strMessage);
	}
}


Measured memory_bytes: 24452
#include<iostream>
using namespace std;
int main(){
    int n,min,max;
    long sum;
    sum = 0;
    min = 1000000;
    max = -1000000;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]<min){
            min = a[i];
        }
        if(a[i]>max){
            max = a[i];
        }
        sum = sum + a[i];
    }
    cout << min << " " << max << " " << sum <<endl;
    
}


Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {

    ll N, A, B, C, D;

    cin >> N >> A >> B >> C >> D;

    string S;
    cin >> S;

    S = '#' + S + '#';

    bool ans = true;

    repl(i, A, C){
        if (S[i] == '#' && S[i + 1] == '#') {
            ans = false;
        }
    }
    repl(i, B, D) {
        if (S[i] == '#' && S[i + 1] == '#') {
            ans = false;
        }
    }

    if (A < B && C > D) {
        ans = false;
        repl(i, B - 1, D) {
            if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
                ans = true;
            }
        }

    }
    if (ans) {
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3876
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
 * メインクラス
 *
 */
public class Main {

	/**
	 * メインメソッド
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		// 標準入力を取得
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());

		List<String> items = new ArrayList<>();

		String line = null;
		List<Integer> as = new ArrayList<Integer>();
		while ((line = br.readLine()) != null) {
			items.add(line);
		}

		char[][] chars = new char[items.size()][N];

		for (int i = 0; i < items.size(); i++) {
			for (int j = 0; j < N; j++) {
				chars[i][j] = items.get(i).toCharArray()[j];
			}
		}

		int answer = 0;

		for (int i = 0; i < N; i++) {

			Map<Character, Integer> count = new HashMap<>();

			for (int j = 0; j < items.size(); j++) {

				if (count.containsKey(chars[j][i])) {
					count.put(chars[j][i], count.get(chars[j][i]) + 1);
				}else {
					count.put(chars[j][i], 1);
				}
			}
			int max = 0;
			for (Entry<Character, Integer> e : count.entrySet()) {
				if (max < e.getValue()) {
					max = e.getValue();
				}
			}

			answer += (items.size() - max);

		}

		System.out.println(answer);
		;

	}
}


Measured memory_bytes: 22228
#include <stdio.h>

int a[8][8] = { {1, 2, 1, 2, 1, 4, 1, 4},
		{1, 2, 1, 4, 1, 4, 1, 2},
		{1, 4, 1, 2, 1, 2, 1, 4},
		{1, 4, 1, 4, 1, 2, 1, 2},
		{2, 1, 2, 1, 4, 1, 4, 1},
		{2, 1, 4, 1, 4, 1, 2 ,1},
		{4, 1, 2, 1, 2, 1, 4, 1},
		{4, 1, 4, 1, 2, 1, 2, 1} };
int main(){
  int p[8], c[8], v,i , j, f, s, res, odd;

  while(scanf("%d%d%d%d%d%d%d%d", &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &p[6], &p[7]) != EOF){
    s = 9999999;
    for(i = 0; i < 8; ++i){
      odd = 0;
      for(j = 0; j < 8; ++j) odd += a[i][j] < p[j] ? p[j] - a[i][j] : 0;
      if(s > odd){ s = odd; res = i;}
    }

    for(i = 0; i < 8; ++i) printf(i ? " %d" : "%d", a[res][i]);
    puts("");
  }
  return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <complex>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

long long gcd(long long x, long long y){
    if (x > y)
        return gcd(y, x);
    long long m = 1;
    while(m != 0){
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}
long long lcm(long long x, long long y){
    return x * y / gcd(x, y);
}

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    sort(v.rbegin(),v.rend());
    vector<ll> a(n);
    a[0]=v[0];
    int ki=1;
    rep(i,n-1){
        if(v[i]!=v[i+1]){
            a[ki]=v[i+1];
            ki++;
        }
    }
    ll g,l;
    rep(i,ki){
        if(i==0){
            g=a[i];
            l=a[i]/2;
        }
        else{
            g=gcd(g,a[i]);
            l=lcm(l,a[i]/2);
        }
        if(l>m){
            cout <<0<<endl;
            return 0;
        }
    }

    rep(i,ki){
        if((a[i]/g)%2==0){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (m+l)/(2*l) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=1000500;
#define int long long
ll ans[max_n]={1};//??
ll ans1[max_n]={1};//?????
ll end1[max_n];
ll n,p=1e9+7;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b)
{
	int x=gcd(a,b);
	return a*b%p*end1[x]%p;
}
void fun(int n,int p)
{
    ans[1]=1;
    for(int i=2;i<=n;i++)
    {
        ans[i]=(ans[i-1]*i)%p;
    }
}

ll pow(ll x,ll n,ll mod)//???
{
    if(n==0)return 1%mod;
    ll ans=1;
    while(n>0)
    {
        if(n&1)ans=ans*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ans;
}

void fu(int n,int p)
{
    ans1[n]=pow(ans[n],p-2,p);//??n!mod p???
    //??????1!~(n-1)!???
    //(n-1)!=n!???*n
    for(int i=n-1;i>=1;i--)
    {
        ans1[i]=ans1[i+1]*(i+1)%p;
    }
}

void f(int n,int p)
{
    for(int i=n;i>=1;i--)
    {
        end1[i]=(ans1[i]*ans[i-1])%p;
    }
}
ll a[1000006];
ll LCM=1;
ll GCD;
int x;
ll endd;
ll cheng=1;
int mx[1000005];
signed main()
{
	n=1000005;
    fun(n,p);
    fu(n,p);
    f(n,p);
	int t;cin>>t;
	for(int i=1;i<=t;i++)
	{
		cin>>a[i];
		int x=a[i];
		for(int v=2;v*v<=x;v++)
		{
			if(x%v)continue;
			int cur=0;
			while(x%v==0)
			{
				cur++;
				x/=v;
			}
			mx[v]=max(mx[v],cur);
		}
		if(x!=1)mx[x]=max(mx[x],1LL);
	}
	for(int i=2;i<=n;i++)
	{
		if(mx[i])
		{
			LCM=LCM*pow(i,mx[i],p)%p;
		}
	}
	//cout<<LCM%p<<endl;
	//return 0;
	for(int i=1;i<=t;i++)
	{
		endd=(endd+LCM*end1[a[i]]%p)%p;
	}
	cout<<endd%p;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());

    vector<int64_t> L(n), R(n);
    for (int i = 0; i < n; i++){
        if (A[i] + i < n)
            L[A[i] + i]++;
        if (0 <= i - A[i])
            R[i - A[i]]++;
    }

    int64_t ans = 0;
    for (int i = 0; i < n; i++)
        ans += L[i] * R[i];
    cout << ans << endl;
}

Measured memory_bytes: 7224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	map<ll, ll> m;
	for (ll i = 0; i < N; ++i)
	{
		ll a; cin >> a;
		if (a == 0 && i != 0)
		{
			std::cout << 0 << std::endl;
			return 0;
		}
		++m[a];
	}

	if (m[0] != 1)
	{
		std::cout << 0 << std::endl;
	}
	else
	{
		ll res{1};
		for (auto &p : m)
		{
			if (p.first == 0) continue;
			for (ll i = 0; i < p.second; ++i)
				(res *= m[p.first-1]) %= MOD;
		}

		std::cout << res << std::endl;
	}
}


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

int main() {
    int n;
    cin>>n;
    vector<int> vec(n);
    rep(i,n){
        cin>>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    int suma=0;
    int sumb=0;
    rep(i,n){
        if(i%2==1){
            suma+=vec.at(i);
            //cout<<"A"<<suma<<endl;
        }
        else{
            sumb+=vec.at(i);
            //cout<<"A"<<sumb<<endl;
        }
    }
    cout<<abs(sumb-suma)<<endl;
   
}



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

int main(){
  string s;
  cin >> s;
  int a,b;
  size_t size = s.length();
  a=0;
  b=0;
  for (int j=0;j<size;j++){
    if(j%2==0){
      if(s[j]=='0'){
	a++;}}
    if(j%2==1){
      if(s[j]=='1'){
	a++;
      }
    }}
  for(int k=0;k<size;k++){
    if(k%2==0){
      if(s[k]=='1'){
	b++;}}
    if(k%2==1){
      if(s[k]=='0'){
	b++;}}}
  if (a>b){
    cout <<b<< endl;
  }
  if (b>=a){
    cout <<a<< endl;
  }
}


Measured memory_bytes: 512
#include <stdio.h>

int main()
{
  unsigned int a, b, n, m, o, x;
  fscanf(stdin, "%u %u", &n, &m);
  char buf[100];
  buf[32]=buf[65]=buf[98]='\n';
  buf[99]='\0';
  a = n & m;
  o = n | m;
  x = n ^ m;
  int i=0;
  for (b = 2147483648U; b>0; b>>=1) {
    buf[i] = '0'+ a/b;
    buf[i+33] = '0'+ o/b;
    buf[i+66] = '0'+ x/b;
    a%=b;
    o%=b;
    x%=b;
    i++;
  }
  fputs(buf, stdout);
  return 0;
}



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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

string s;
vll b;
vll c;
vector<stack<lli>> idx;
lli ans;

class bit {
private:
	vll* v;
	lli n;
public:
	bit (lli n) {
		this->v = new vll(n+1);
		this->n = n;
	}
	void add(lli i,lli val){
		for(;i <= n;i += i&-i) this->v->at(i) += val;
	}
	lli sum(lli i){
		lli ret = 0;
		for(;i > 0;i -= i&-i) ret += this->v->at(i);
		return ret;
	}
};

bit* cnt;

void error(){
  cout << -1 << endl;
  exit(0);
}

int main(){
  cin >> s;
  if(s.size() == 1){
    cout << 0 << endl;
    return 0;
  }
  idx = vector<stack<lli>>(128);
  c = vll(128);
  b = vll(s.size());
  for(lli i = 0;i < s.size();i++){
    c[s[i]]++;
    b[i] = c[s[i]];
  }
  for(lli i = 0,j = 0;i < s.size();i++){
    if(c[s[i]] % 2 == 1 && b[i] == c[s[i]]/2+1) b[i] = s.size()-1;
    else if(b[i] > c[s[i]]/2) b[i] = idx[s[i]].top(),idx[s[i]].pop();
    else idx[s[i]].push(++j),b[i] = s.size();
  }
  if(count(b.begin(),b.end(),s.size()-1) > 1) error();
  reverse(b.begin(),b.end());
  cnt = new bit(s.size()+1);
  for(lli i = 0;i < s.size();i++){
    ans += cnt->sum(s.size())-cnt->sum(b[i]);
    cnt->add(b[i],1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4484
n,x=map(int,input().split())
a=list(map(int,input().split()))
if sum(a)<x:
    a.sort(reverse=True)
else:
    a.sort()
c=0
for t in a:
    x-=t
    if x<0:break
    c+=1
if x>0:
    print(c-1)
else:
    print(c)

Measured memory_bytes: 38716
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;

int n, m; 
int k[10], s[10][10];

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
		}
	}
	int p[10];
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	int ans = 0, answer = 0;
	int cnt[10];
	for (int i = 0; i < pow(2, n); i++) {
		fill(cnt, cnt + m, 0);
		int num = i;	
		for (int j = 0; j < n; j++) {
			if (num % 2 == 1) {
				for (int l = 0; l < m; l++) {
					for (int t = 0; t < k[l]; t++) {
						if (s[l][t] == j+1) {
							cnt[l]++;
						}
					}
				}
			}
			num /= 2;
		}
		for (int j = 0; j < m; j++) {
			if (cnt[j] % 2 == p[j]) {
				ans++;
			}
		}
		if (ans == m) {
			answer++;
		}
		ans = 0;
	}
	cout << answer << endl;
	return 0;
}

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

int main(void) {
  int N, cnt=0;
  string S;
  cin >> N >> S;
  
  for(int i=2; i<N; i++){
    if(S[i-2]=='A' && S[i-1]=='B' && S[i]=='C')
      cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define fl(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rfl(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        forloop(n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define section(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define m 1000000007
const long long INF64 = 1e18;




void solve()
 { 
   int h,w;
   cin>>h>>w;
   char grid[h+2][w+2];
   for(int i=1;i<=h;i++)
   	  {
   	  	for(int j=1;j<=w;j++)
   	  		  {
   	  		  	cin>>grid[i][j];

   	  		  }
   	  }


 

 int dp[h+2][w+2];
 memset(dp,0,sizeof(dp));
for(int i=1;i<=h;i++)
	  {
	  	if(grid[i][1]=='.')
	  		dp[i][1]=1%m;
	  	else
	  		break;
	  }
for(int i=1;i<=w;i++)
	  {
	  	if(grid[1][i]=='.')
	  		 dp[1][i]=1%m;
	  		else 
	  			break;
	  }
 for(int i=2;i<=h;i++)
 	  {
 	  	for(int j=2;j<=w;j++)
 	  		 { 
 	  		 	if(grid[i][j]=='#')
 	  		 		continue;

 	  		 		else
 	  		 		{
 	  		 			 dp[i][j]=(dp[i-1][j]%m+dp[i][j-1]%m)%m;

 	  		 		}






 	  		 }
 	  }

 	  cout<<dp[h][w]%m;
}



  








 



signed main()
{fast
	int t;
   //cin>>t;
	t=1;

	while(t--)
		 {
		 	solve();
		 }
}












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

using Values = std::vector<int>;
using Costs = std::vector<int>;

int solve(const Values& values, const Costs& costs)
{
  const int n = values.size();
  int x = 0;
  int y = 0;
  for (int i = 0; i < n; ++i) {
    if (costs[i] < values[i]) {
      x += values[i];
      y += costs[i];
    }
  }
  return x - y;
}

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

  Values values(n);
  Costs costs(n);
  for (auto& v : values) {
    std::cin >> v;
  }
  for (auto& c : costs) {
    std::cin >> c;
  }

  std::cout << solve(values, costs) << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  int a[1000],count=0,count1=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
      if(a[i]%2==0)
      {
          count1++;
          if((a[i]%3!=0)&&(a[i]%5!=0))
          {
               cout<<"DENIED"<<endl;
          break;
          }
           else
            count++;
      }

    }
    if(count1==count)
    cout<<"APPROVED"<<endl;
  return 0;

}

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

using namespace std;

int main(){
	vector<string> button;
	button.push_back(".,!? ");
	button.push_back("abc");
	button.push_back("def");
	button.push_back("ghi");
	button.push_back("jkl");
	button.push_back("mno");
	button.push_back("pqrs");
	button.push_back("tuv");
	button.push_back("wxyz");

	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		string s;
		string ret;
		cin >> s;
		char current = s[0];
		int count = 0;
		for (int unsigned i = 0; i < s.size(); i++){
			if (s[i] == '0'){
				if (count == 0) continue;
 				int it = (int)(current - '0') - 1;
				cout << button[it][(count -1) % button[it].size()];
				count = 0;
			}
			else {
				current = s[i];
				count++;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1216