akhauriyash/Code-Regression huggingface dataset:
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    String[] s= br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    long a = Long.parseLong(s[1]);
    long b = Long.parseLong(s[2]);
    long c = Long.parseLong(s[3]);
    long d = Long.parseLong(s[4]);
    b -= a;
    a = 0;
    if (b<0)
      b*=-1;
    long diff = d-c;
    long span = diff+1;
    long miss = 2*c-1;
    long fspan = span + (n-2)*diff;
    long fmiss = miss - (n-2)*diff;
    //System.out.printf("fspan: %d, fmiss: %d\n",fspan, fmiss);
    if (fmiss<=0) {
      if (b<(n-1)*d) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    } else {
      long period = fspan+fmiss;
      long max = (n-1)*d;
      if (b>max) {
        System.out.println("NO");
      } else {
        long bDiff = max-b;
        long moddedbDiff = bDiff % period;
        //System.out.printf("fspan: %d, fmiss: %d, period: %d, bDiff: %d, moddedbDiff: %d\n",fspan, fmiss, period, bDiff, moddedbDiff);
        if (moddedbDiff>=fspan) {
          System.out.println("NO");
        } else {
          System.out.println("YES");
        }
      }
    }
  }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<bitset<60>> a(n);
    bitset<60> tot = 0;
    for (int i = 0; i < n; ++i) {
        lint aa;
        cin >> aa;
        a[i] = aa;
        tot ^= a[i];
    }
    for (int i = 0; i < n; ++i) {
        a[i] &= (~tot);
    }
    bitset<60> used = 0;
    for (int i = 59; i >= 0; --i) {
        int idx = -1;
        for (int j = 0; j < n; ++j) {
            if (a[j][i] == 1 && used[j] == 0) {
                idx     = j;
                used[j] = 1;
                break;
            }
        }
        if (idx == -1)
            continue;
        for (int j = 0; j < n; ++j) {
            if (j == idx)
                continue;
            if (a[j][i] == 1)
                a[j] ^= a[idx];
        }
    }
    bitset<60> add = 0;
    for (int i = 0; i < n; ++i) {
        add ^= a[i];
    }
    lint ret = tot.to_ullong() + add.to_ullong() * 2;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main() {
  int num;
  while(cin >> num && num) {
    string res = "";
    for(int b = 1; num != 0; num /= 10, b *= -1) {
      int t = abs(num % 10);
      if(t == 0) {
        res += '0';
      } else if(num*b > 0) {
        res += '0' + t;
      } else {
        res += '0' + (10-t);
        num -= 10*b;
      }
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include<iostream>
using namespace std;
int main(){
  int n;cin >> n;int x=n;
  cout << n << ":";
  for(int i=2;i*i<=x;i++){
    while(n%i==0) {
      cout << " " << i;
      n/=i;
    }
  }
  if(n!=1)
    cout << " " << n;
  cout << endl;
  return 0;
}

Measured memory_bytes: 3076
X,N=map(int,input().split())
if N != 0:
  p=list(map(int,input().split()))
else:
  p=[]
d=0
while True:
  if not (X-d in p):
    print(X-d)
    break
  elif not (X+d in p):
    print(X+d)
    break
  d+=1

Measured memory_bytes: 9180
X = input().split()

K = int(X[0])
N = int(X[1])

A = input().split()

i = 0
j = 1
max_distance = 0

while j < N:
    a = int(A[j-1])
    b = int(A[j])
    distance = b - a
    if distance > max_distance:
        max_distance = distance
    j += 1

last_distance = (K + int(A[0])) - int(A[N-1])

if last_distance > max_distance:
    max_distance = last_distance

shortest_distance = K - max_distance
print(shortest_distance)

Measured memory_bytes: 18036
import Control.Monad
import Data.List

input :: IO (Maybe ([Integer] , [Integer]))
input = do
    abc <- getLine >>= return . map read . words
    if any (== 0) abc then
        return Nothing
    else do
        n <- readLn
        xs <- replicateM n readLn
        return $ Just (abc , xs)

isOK :: [Integer] -> Integer -> Bool
isOK abc r = w ^ 2 + h ^ 2 < r2 ^ 2
    where
        w:h:_ = sort abc
        r2 = r * 2

solve :: [Integer] -> [Integer] -> IO ()
solve abc = mapM_ putStrLn . map (toStr . isOK abc)
    where
        toStr x = if x then "OK" else "NA"

main :: IO ()
main  = input
    >>= maybe (return ()) (\ s -> uncurry solve s >> main)

Measured memory_bytes: 4128
N = int(input())

zls = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

res = [['a']]

def calc(prev_list):
    new_list = []
    for i in prev_list:
        for j in range(len(set(i))+1):
            new_list.append(i+[zls[j]])
    return new_list

for i in range(N-1):
    res = calc(res)

for i in res:
    print(''.join(i))


Measured memory_bytes: 25292
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int n;
	cin >> n;
	cout << n / 3 << endl;
	return 0;
}

Measured memory_bytes: 256
"""
Writer: SPD_9X2
https://atcoder.jp/contests/agc040/tasks/agc040_c

奇数文字目と偶数文字目がセットで消える
奇数文字目のABを反転すると、AB or BA or AC or BC or CC で消えていいことになる

すなわち、異なる文字の切れ目では必ず消せる
異なる切れ目は必ず存在するので、Cを適当にABに割り振った時に全て消せるかどうかが問題になる

A,Bのみの時に全て消せる条件は 両者の数が等しい事
Cを適切に割り振った時に両者の数を等しくできる必要十分条件は max(a,b) <= N//2
あとはこれを数えればよい→どうやって？

全ての並び方は 3**N　ここから補集合を引く？
Aが半数を超える(k個)の時のおき方は、 NCk * (2**(N-k))で求まる
Bの時も同様に。

"""

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv):
    return fac[n] * inv[n-r] * inv[r] % mod


N = int(input())
mod = 998244353

fac,inv = modfac(N+10,mod)
ans = pow(3,N,mod)

tpow = [1]
for i in range(N//2+10):
    tpow.append(tpow[-1]*2%mod)

for k in range(N//2+1,N+1):

    now = 2 * modnCr(N,k,mod,fac,inv) * tpow[N-k]
    ans -= now
    ans %= mod

print (ans)


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

int main(){
    ll N;
    cin >> N;
    // 商がA、余りもA
    // → N = A*m + Aの形(A<m)
    ll ans = 0;
    for(ll i=1;i*i<=N;i++){
        if(N%i==0&&i<(N/i-1)){
            ans += N/i-1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef pair< int, vector<int> > P;
#define DEPTH first
#define ARRAY second

int main(){
  int ans;
  int N;
  cin>>N;
  vector<int> A(N), sorted(N);
  for(int i=0; i<N; i++){
    cin>>A[i];
    sorted[i]=i+1;
  }

  map< vector<int>, int > num;
  queue<P> q;
  q.push( P(0,sorted) );
  while(!q.empty()){
    P now=q.front();
    q.pop();
    if(now.DEPTH>=4)break;
    if(num.count(now.ARRAY))continue;
    num[now.ARRAY] = now.DEPTH;
    for(int i=0; i<N; i++){
      for(int j=i+1; j<N; j++){
        P next=now;
        next.DEPTH++;
        reverse(next.ARRAY.begin()+i,next.ARRAY.begin()+j+1);
        q.push(next);
      }
    }
  }

  map< vector<int>, int > num2;
  queue<P> q2;
  q2.push( P(0,A) );
  while(!q2.empty()){
    P now=q2.front();
    q2.pop();
    if(now.DEPTH>=4)break;
    if(num2.count(now.ARRAY))continue;
    num2[now.ARRAY] = now.DEPTH;
    for(int i=0; i<N; i++){
      for(int j=i+1; j<N; j++){
        P next=now;
        next.DEPTH++;
        reverse(next.ARRAY.begin()+i,next.ARRAY.begin()+j+1);
        q2.push(next);
      }
    }
  }

  ans=9;
  map< vector<int>, int >::iterator it;;
  for(it=num.begin(); it!=num.end(); it++){
    if(!num2.count(it->first))continue;
    ans = min(ans, it->second + num2[it->first]);
  }

  cout<<ans<<endl;
}

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

int H, W;
vector<string> S(50);

int CheckBomb(int i, int j){
    int sum = 0;
    for(int y = -1; y <= 1; ++y){
        for(int x = -1; x <= 1; ++x){
            if(y != 0 || x != 0){
                if(i + y >= 0 && j + x >= 0 && i + y < H && j + x < W && S[i + y][j + x] == '#') ++sum;
            }
        }
    }
    return sum;
}

int main(void){
    
    cin >> H >> W;
    for(int i = 0; i < H; ++i) cin >> S[i];
    
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            if(S[i][j] != '#') S[i][j] = '0' + CheckBomb(i, j);
        }
    }
    
    for(int i = 0; i < H; ++i) cout << S[i] << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s = sc.next();
String t = sc.next();
char[] a = s.toCharArray();
char[] b = t.toCharArray();
boolean ok = true;
int n = s.length();
for(int i = 0;i < n;i++) {
	ok = true;
	for(int j = 0;j < n-i;j++) {
		if(a[j] != b[j+i]) {
			ok = false;
			break;
		}
	}
	for(int j = n-i;j < n;j++) {
		if(a[j] != b[j-n+i]) {
			ok = false;
			break;
		}
	}
	if(ok)break;
}
System.out.println(ok? "Yes":"No");
}}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MAXN 100009
int dp[MAXN], h[MAXN];

int solve(int i){
    if (dp[i] != -1)
        return  dp[i];
    if (i == 1)
        return dp[i] = 0;
    if (i == 2)
        return dp[i] = abs(h[1] - h[2]);
    return dp[i] = min(abs(h[i] - h[i-1]) + solve(i -1 ), abs(h[i] - h[i-2]) + solve(i - 2));
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int n;
    cin >> n;
    //memset(dp, -1, sizeof dp);
    
    
    rep(i, 1, n + 1)
        cin >> h[i];
    dp[1] = 0;
    dp[2] = abs(h[1] - h[2]);
    rep(i, 3, n + 1){
        dp[i] =  min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i - 2]);
    }
    cout << dp[n] << '\n';
    return 0;   
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
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;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  const int n = 5;
  vector<int> xs(n);
  for(int i=0;i<n;i++) cin>>xs[i];

  cout<<15-accumulate(xs.begin(),xs.end(),0)<<newl;
  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main()
{
	int K = 38;
	int N = 1 + K * (K - 1);

	printf("%d %d\n", N, K);
	vector<vector<int> > sol(N, vector<int>());

	int ni = 0;

	for (int i = 0; i < K; ++i) {
		for (int j = 0; j < K - 1; ++j) {
			sol[i * (K - 1) + j].push_back(ni);
		}
		sol[N - 1].push_back(ni);
		++ni;
	}
	for (int i = 0; i < K - 1; ++i) {
		for (int j = 0; j < K - 1; ++j) {
			sol[i].push_back(ni);
			for (int k = 0; k < K - 1; ++k) {
				int row = k + 1;
				int col = (j + i * k) % (K - 1);
				sol[row * (K - 1) + col].push_back(ni);
			}
			++ni;
		}
	}
	for (int i = 0; i < sol.size(); ++i) {
		for (int j = 0; j < K; ++j) printf("%d%c", sol[i][j] + 1, j == K - 1 ? '\n' : ' ');
	}

	return 0;
}


Measured memory_bytes: 896
def main():
  n, k = input().split(" ")
  enemies = list(map(int, input().split(" ")))
  n, k = int(n), int(k)
  count = 0

  if n > k:
    enemies.sort()
    count = sum(enemies[:n-k])
  print(count)

if __name__ == "__main__":
   main()


Measured memory_bytes: 26180
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int a, b, h; std::cin >> a >> b >> h;
  std::cout << (a+b)*h/2 << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ss string
#define ll long long int
#define Endl endl
#define u_b upper_bound
#define rep(i,n)         for(int i=0;i<n;i++)
#define ld long double
#define tc long long t;cin>>t;while(t--)
#define fr(i,a,b)        for(long long int i=a;i<=b;i++)
#define E endl
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define V deque<ll>v;
#define aaste long long int n;cin>>n;long long int a[n];for(long long int i=0;i<n;i++)cin>>a[i];
const ll   mod=            1000000007;
const ll   MOD1=           (int)1e9 + 9;
const ll   MOD2=           998244353;
const ld    pi=             atan2(0, -1);
const ld    eps=            1e-9;
const int   N=                   2e5+5;
 
const int MAXR = 1000005;
ll         tests=          1;
 
using namespace std;
ll binarySearch(ll l, ll r,ll k)
{
  if (r >= l) {
    ll mid = l + (r - l) / 2;
    if (mid*(mid+1)==k)
      return 1;
    if (mid*(mid+1)>k)
      return binarySearch( l, mid - 1,k);
    return binarySearch(mid + 1, r, k);
  }
  return 0;
}
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
void swap(ll *p1, ll *p2)
{
   ll temp=*p1;
   *p1=*p2;
   *p2=temp;
}
ll cbratt(ll x)
{
    ll l = 0, r = MAXR;
    while (l != r) {
        ll m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
int MaxSubArraySumReturn(int a[], int  n) //negative thakle o kaaj korbe in O(n)
{
 
    int sum = 0, best = 0;
   for(ll i=0;i<n;i++)
    {
        sum = max(a[i], a[i] + sum);
        best = max(best, sum);
    }
    return best;
 
}
ll totalDigits(ll n) 
{ 
 
    ll number_of_digits = 0; 
    for (ll i = 1; i <= n; i *= 10) 
        number_of_digits += (n - i + 1); 
  
    return number_of_digits; 
}
//Functions
ll a[10000001];
void findDivisors(ll n) 
{ 
  
    // Array to store the count 
    // of divisors 
    ll divi[n+1];
    memset(divi, 0, sizeof divi); 
    // For every number from 1 to n 
    for (ll i = 1; i <= n; i++) { 
  
        // Increase divisors count for 
        // every number divisible by i 
        for (ll j = 1; j * i <= n; j++) 
            divi[i * j]++; 
    }
    for(ll i=1;i<=n;i++)
    a[i]=divi[i];
}
int main()
{
  #ifndef ONLINE_JUDGE
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt", "w", stderr);
    }
#endif
    ll n;
    cin>>n;
    findDivisors(n);
    ll sum=0;
  for(ll i=1;i<=n;i++)
  {
    sum+=(i*a[i]);
  }
  cout<<sum<<Endl;
 }


Measured memory_bytes: 159840
#include<iostream> 
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	char s[105],t[105];
	scanf("%s%s",s,t);
	int len = strlen(s) ;
	for(int i=0;i<len;i++)
	{
		if(s[0]==t[i])
		{
			int j=i;
			int k;
			for( k=1;k<len;k++)
			{
				j++;
				if(s[k]!=t[j%len])
				break;
			}
			if(k==len)
			{
					cout<<"Yes"<<endl;
					exit(0);
			}
		
			
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
q = int(input())
for i in range(q):
    n,k = map(int,input().split())
    s = list(map(int,input().split()))
    sa = [0]
    for j in range(1,n):
      sa.append(s[j]-s[j-1]) 

    sa.sort(reverse = True)
    print(sum(sa[k-1:]))


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    vector<ll> A;
    cin >> N;
    for (int i = 0; i < 3*N; i++) {
        ll a; cin >> a;
        A.pb(a);
    }
    dsort(A,ll);
    ll ans = 0;
    for (int i = 1; i < 2*N; i+=2) {
        ans += A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 7352
<?php
  fscanf(STDIN, "%i", $n);
  for ($i = 1; $i < $n; $i++)
  {
      fscanf(STDIN, "%i %i", $a, $b);
      $tree[$a][] = $b;
      $tree[$b][] = $a;
  }

  for ($i = 1; $i <= $n; $i++)
  {
      $uni[$i]   = 0;
      $multi[$i] = 0;
  }
  
  $v = 1;
  $crumbs = [];
  while (!is_null($v))
  {
      $c = array_pop($tree[$v]);
      if (!is_null($c))
      {
          array_remove($tree[$c], $v);
          array_push($crumbs, $v);
          $v = $c;
      }
      else
      {
          $c = $v;
          $v = array_pop($crumbs);

          $bits = 1 << msb($multi[$c]);
          $uni[$c] &= ~($bits - 1);
          $uni[$c] += $bits;
          $multi[$v] |= $uni[$v] & $uni[$c];
          $uni[$v]   |= $uni[$c];
      }
  }
  echo (msb($uni[1]) - 1).PHP_EOL;

  function array_remove(&$array, $elem)
  {
      foreach ($array as $key => $value)
      {
          if ($value === $elem)
          {
              unset($array[$key]);
              break;
          }
      }
      $array = array_values($array);
  }

  function msb($x)
  {
      $p = 0;
      while ($x !== 0)
      {
          $x >>= 1;
          $p++;
      }
      return $p;
  }
?>


Measured memory_bytes: 63516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
vector<bool> seen;

class union_find {
public:
vector<int> par,rank;
union_find(int n): par(n),rank(n){
   for (int i=0;i < n;i++){
      par[i]=i;
      rank[i]=0;
   }
}

int find(int x){
   if (par[x]==x){
      return x;
   }
   else{
      return par[x] = find(par[x]); 
   }
}

void unite(int x ,int y){
   x=find(x);
   y=find(y);
   if (x==y) return;
   if (rank[x] < rank[y]){
      par[x] = y;
   }else{
      par[y]=x;
      if (rank[x]==rank[y]) rank[x]++;
   }
}

bool same(int x, int y){
   return find(x) == find(y);
}
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> w(m);    
    for (int i=0;i < m;i++){
        int x,y;
        cin >> x >> y;
        x--;y--;
        pair<int,int> p=make_pair(x,y);
        w[i]=p;
    }
    int count=0;
    int ans=0;
    for (int j=0;j <m;j++){
        union_find g(n);
        for (int k=0;k < m;k++){
            if (j==k) continue;
            pair<int,int> p=w[k];
            g.unite(p.first,p.second);
        }
        count=0;
        for (int i=0;i < n;i++){
            if (g.par[i]==i) count++;
        }
        if (count!=1) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static bool IsOdd(long n)
		{
			bool isOdd = n % 2 == 1;
			return isOdd;
		}

		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long n = array[0];
			long x = array[1];
			var a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

			long count = 0;
			if (a[0] > x) {
				long diff = a[0] - x;
				count += diff;
				a[0] -= diff;
			}

			for (int i = 0; i < n - 1; ++i) {
				if (a[i] + a[i + 1] > x) {
					long diff = (a[i] + a[i + 1]) - x;
					count += diff;
					a[i + 1] -= diff;
				}
			}

			Console.WriteLine($"{count}");
			Console.ReadKey();
		}
	}
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define M 1046572
#define L 14

char H[M][L];

int getChar(char ch) {
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
}

int getKey(char str[]) {
    long long total = 0, w = 1;
    rep(i, strlen(str)) {
        total += getChar(str[i]) * w;
        w *= 5;
    }
    return total;
}

int h1(int key) {
    return key % M;
}

int h2(int key) {
    return 1 + (key % (M - 1));
}

int getHash(int key, int i) {
    return (h1(key) + i * h2(key)) % M;
}

int insert(char str[]) {
    long long key = getKey(str), i = 0, index = 0;
    while (true) {
        index = getHash(key, i++);
        if (strcmp(H[index], str) == 0) return 1;
        else if (strlen(H[index]) == 0) {
            strcpy(H[index], str);
            return 0;
        }
    }
    return 0;
}

int find(char str[]) {
    long long key = getKey(str), i = 0, index = 0;
    while (true) {
        index = getHash(key, i++);
        if (strlen(H[index]) == 0) return 0; 
        else if (strcmp(H[index], str) == 0) return 1;
    }
    return 0;
}

int main() {
    int n;
    char command[9], str[L];
    rep(i, M) H[i][0] = '\0';
    scanf("%d", &n);
    rep(i, n) {
        scanf("%s %s", command, str);
        if (command[0] == 'i') insert(str);
        else {
            if (find(str)) printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}



Measured memory_bytes: 17436
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=3e5+10,inf=1e9+10,mod=1e9+7;
int a,n,b;
int ans[M];
main()
{
	int n,m;
	cin>>n>>m;
	if(n==1 && m==2)return cout<<0,0;
	if(n==1 && m==1)return cout<<1,0;
	if(n==2 && m==1)return cout<<0,0;
	if(n==1)
	{
		return cout<<m-2,0;
	}
	if(m==1)return cout<<n-2,0;
	if(n==2 && m==2)return cout<<0,0;
	cout<<(n-2)*(m-2);
}

Measured memory_bytes: 256
H,W=map(int,input().split())

bom=[]
for i in range(H):
    bom.append(list(input()))
#print(bom)

for h in range(H):
    for w in range(W):
        if bom[h][w]=="#":
            #continue ループ内の内容をスキップ
            continue

        cnt=0
        for x in range(-1,2):
            for y in range(-1,2):
                if h+x>=0 and w+y>=0 and h+x<H and w+y<W:
                    if bom[h+x][w+y]=="#":
                        cnt+=1
        bom[h][w]=str(cnt)

for i in bom:
    print("".join(i))


Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>

int main(void)
{
  int n;
  char taro[101];
  char hanako[101];
  int point_taro = 0;
  int point_hanako = 0;
  int i, j, k;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s %s", taro, hanako);

    if(strcmp(taro, hanako) > 0)
      point_taro += 3;
    else if(strcmp(taro, hanako) < 0)
      point_hanako += 3;
    else{
      point_taro++;
      point_hanako++;
    }
  }

    printf("%d %d\n", point_taro, point_hanako);
    
  return 0;
}

Measured memory_bytes: 604
from collections import deque
from sys import stdin

A = input()
d = deque([])
e = deque([])
area = 0
areas = deque([])

for a,b in enumerate(A):
    if b == "\\":
        d.append(a)
    elif b == "/" and d != deque([]):
        x = d.pop()
        area += a - x
        areas.append([x,a,a-x])

menseki = 0
kaitou = []
prev_start,prev_end = 20000,0
while len(areas) > 0:
    temp = areas.pop()
    if temp[0] > prev_start and temp[1] < prev_end:
        menseki += temp[2]
    else:
        if menseki != 0:
            kaitou.append(menseki)
        menseki = temp[2]
        prev_start, prev_end = temp[0],temp[1]
    if len(areas) == 0:
        kaitou.append(menseki)

print(sum(kaitou))
kaitou.append(len(kaitou))
print(*kaitou[::-1])



Measured memory_bytes: 7356
A, B, C = map(int,input().split())
K = int(input())

#赤＜緑＜青
kB = 0
kC = 0

while A >= B:
    B *= 2
    kB += 1

while B >= C:
    C *= 2
    kC += 1

if kB + kC <= K:
    print("Yes")
else:
    print("No")

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

int main(){
	string angou;
	
	while (getline(cin, angou)){
		int a = angou.size();

		for (int i = 0; i < 26; i++)
		{
			for (int q = 0; q < a; q++){
				if (angou[q] == ' ' || angou[q] == '.') continue;

				if (angou[q] == 'z') angou[q] = 'a';
				else angou[q]++;
			}

			bool theExists = angou.find("the") != string::npos;
			bool thisExists = angou.find("this") != string::npos;
			bool thatExists = angou.find("that") != string::npos;
			if (theExists || thisExists || thatExists)
			{
				cout << angou << endl;
				continue;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
using namespace std;
int main(){
  bool E[100000];
  vector<long long int> P;
  for(long long int i = 0; i < 100000LL; ++i) E[i] = true;
  E[0] = false;
  E[1] = false;
  for(long long int i = 2; i < 100000LL; ++i){
    if(E[i]){
      P.push_back(i);
      for(long long int j = i; i*j < 100000LL; ++j){
	E[i*j] = false;
      }
    }
  }
  long long int m, a, b, n = P.size();
  while(cin >> m >> a >> b, m){
    int p = 0, q = 0;
    for(int i = 0; i < n; ++i){
      for(int j = i; j < n; ++j){
	if(P[i]*P[j] > m || a*P[j] > b*P[i]) break;
	if(P[i]*P[j] > p*q){
	  q = P[j];
	  p = P[i];
	}
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}

Measured memory_bytes: 3244
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define p 998244353
using namespace std;
namespace ywy{
	inline ll mi(int a,int b){
		ll ans=1,tmp=a;while(b){
			if(b&1)ans=(ans*tmp)%p;tmp=(tmp*tmp)%p;b>>=1;
		}return(ans);
	}ll jc[1555555],jcny[1555555];
	inline void pre(int n){
		jc[0]=1;for(register int i=1;i<=n;i++)jc[i]=(jc[i-1]*i)%p;jcny[n]=mi(jc[n],p-2);
		for(register int i=n-1;i>=0;i--)jcny[i]=(jcny[i+1]*(i+1))%p;
	}
	inline ll cnm(int n,int m){
		if(n<m||m<0)return(0);ll cjr=jc[n];cjr*=jcny[m];cjr%=p;cjr*=jcny[n-m];return(cjr%p);
	}
	void ywymain(){
		int n,m;cin>>n>>m;pre(n+m);ll ans=0;for(register int i=1;i<=min(n,m);i++){
			ans=(ans+cnm(i*2,i)*cnm(n-i+m-i,n-i))%p;
		}ans*=mi(2,p-2);ans%=p;ans*=mi(cnm(n+m,m),p-2);ans%=p;ans+=max(n,m);ans%=p;cout<<ans<<endl;
	}
}
int main(){
	ywy::ywymain();return(0);
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	long long n, k;
	cin >> n >> k;
	long long cnt = 0;
	for(long long i = 1; i <= n; i++) {
		long long p = n / i;
		long long r = n % i;
		cnt += p * max(0LL, i - k) + max(0LL, r - k + 1);
		cnt -= k == 0;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:tuple(map(int,stdin.readline().split()))

n=int(input())

l=set(tuple([lnii() for i in range(n)]))

if len(l)==1:
  print(0)
  exit()

x_max=0
x_min=10**10
y_max=0
y_min=10**10

for x,y in l:
#  s=abs(x-y)
  s=x-y
  x_max=max(x_max,s)
  x_min=min(x_min,s)

#  t=abs(x+y)
  t=x+y
  y_max=max(y_max,t)
  y_min=min(y_min,t)

x_ans=x_max-x_min
y_ans=y_max-y_min
print(max(x_ans,y_ans))

Measured memory_bytes: 48888
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n,m;
    cin>>n>>m;
    vi64 a(n+1,-1);
    //forn(i,n+1)   cout<<i<<" "<<a[i]<<endl;
    a[0] = 0;
    a[1] = 1, a[2] = 2;
    //forn(i,n)   cout<<i<<" "<<a[i]<<endl;
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        a[x] = 0;
    }
    if(a[1]==0 && a[2]==2)  a[2]--;
    //forn(i,n+1)   cout<<i<<" "<<a[i]<<endl;
    for(int i=3;i<=n;i++){
        if(a[i]==-1){
            a[i] = (a[i-1] + a[i-2])%1000000007;
        }
    }
    //forn(i,n+1)   cout<<i<<" "<<a[i]<<endl;
    cout<<a[n]<<endl;
    return 0;
}



Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    //          int N =  int.Parse(Console.ReadLine());
    public static void Main()
    {
        int[] NKQ = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = NKQ[0], K = NKQ[1], Q = NKQ[2];
        int[] A = new int[Q];
        int[] B = new int[N+1];
        for (int i = 0; i < Q; i++)
        {
            A[i] = int.Parse(Console.ReadLine());
            B[A[i]]++;
        }
        for (int i = 1; i < N + 1; i++)
        {
            string output = "";
            int damage = Q - B[i];
            if (K - damage > 0)
            {
                output = "Yes";
            }
            else
            {
                output = "No";
            }
            Console.WriteLine(output);
        }

    }

}




Measured memory_bytes: 18268
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll t[800005],hell=998244353;
ll add(ll x,ll y){
	x+=y;
	if(x>=hell)
		x-=hell;
	return x;
}
void change(ll v,ll tl,ll tr,ll pos,ll val){
	if(tl==tr){
		t[v]=val;
		return;
	}
	ll tm=(tl+tr)/2;
	if(pos<=tm)
		change(2*v,tl,tm,pos,val);
	else
		change(2*v+1,tm+1,tr,pos,val);
	t[v]=add(t[2*v],t[2*v+1]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r){
	if(l>r)
		return 0;
	if(l==tl&&r==tr)
		return t[v];
	ll tm=(tl+tr)/2;
	return add(get(2*v,tl,tm,l,min(r,tm)),get(2*v+1,tm+1,tr,max(l,tm+1),r));
}
void solve(){
	ll n,k;
	cin>>n>>k;
	vector<p2> v(k);
	for(ll i=0;i<k;i++)
		cin>>v[i].first>>v[i].second;
	change(1,1,n,n,1);
	for(ll i=n-1;i>=1;i--){
		ll res=0;
		for(ll j=0;j<k;j++){
			ll l=i+v[j].first,r=min(i+v[j].second,n);
			if(l>r)
				continue;
			res=add(res,get(1,1,n,l,r));
		}
		change(1,1,n,i,res);
	}
	cout<<get(1,1,n,1,1);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 7880
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int main(){
	int a, b, c, t;
    c = 1;
  	while(c){
      cin >> a >> b;
      if (a == 0 && b == 0) c = 0;
      else{
        if ( a > b ){
        	t = a, a = b, b = t;
        } 
      	cout << a << " " << b << endl;
      }
    }
    return 0;
}



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

using namespace std;

struct node
{
    int x,y;
} ac[110],bc[110];

int vis[210][210];
int flag[210];
int pri[210];
int n;

bool find(int i)
{
    int j;
    for(j=1; j<=n; j++)
    {
        if(vis[ac[i].x][bc[j].x]&&!flag[j])
        {
            flag[j]=1;
            if(pri[j]==-1||find(pri[j]))
            {
                pri[j]=i;
                return true;
            }
        }
    }
    return false;
}

int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    memset(pri,-1,sizeof(pri));
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&ac[i].x,&ac[i].y);
    }
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&bc[i].x,&bc[i].y);
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(ac[i].x<bc[j].x&&ac[i].y<bc[j].y)
            {
                vis[ac[i].x][bc[j].x]=1;
            }
        }
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        memset(flag,0,sizeof(flag));
        if(find(i))
            ans+=1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A[3];
	rep(i, 0, 3)cin >> A[i];

	sort(A, A + 3);
	cout << A[2] - A[1] + A[1] - A[0] << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools

D,G = map(int, input().split())
PC = [list(map(int, input().split())) for _ in range(D)]

P_list = list(range(D))
cnt = float('inf')

for i in range(D):
	for bonus in itertools.combinations(P_list, i):

		tmp_cnt = 0
		score = 0

		for j in bonus:
			score += PC[j][0] * 100 * (j+1) + PC[j][1]
			tmp_cnt += PC[j][0]

		res_max_p = max([k for k in range(D) if k not in bonus])
		res_score = G - score
		if res_score > 0:
			t = (-res_score//((res_max_p+1)*100)) * (-1) 
			if t < PC[res_max_p][0]:
				tmp_cnt += t
			else:
				continue

		cnt = min(cnt, tmp_cnt)

if cnt == float('inf'):
	cnt = sum([PC[j][0] for j in range(D)])

print(cnt)




Measured memory_bytes: 3188
S = int(input())
# S = 10 ** 18 - 2
if S == 10 ** 18:
    x1 = 10 ** 9
    x2 = 0
else:
    x1 = (S // 10 ** 9) + 1
    x2 = 10 ** 9 - (S % 10 ** 9)
print(x1, 1, x2, 10 ** 9, 0, 0)

Measured memory_bytes: 9176
#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<fstream>

#define rep(i,a,N) for(int i=0+a;i<N;i++)
#define lint long long int
#define SIZE 100005
#define pb push_back
#define MP make_pair

using namespace std;

int main(){
	int n;
	int e[SIZE]={},o[SIZE]={};
	cin>>n;
	int t=0,me=0,mo=0,et=0,ot=0,cme=0,cmo=0,M=0;
	for(int i=1;i<n+1;i++){

	cin>>t;
		if(i%2==0){
			e[t]++;
			if(me<e[t]){me=e[t];et=t;}
		}
		else{
			o[t]++;
			if(mo<o[t]){mo=o[t];ot=t;}
		}
	}
	if(et==ot){
		for(int i=1;i<SIZE;i++){
		if(i!=et){
			if(cme<e[i])cme=e[i];
			if(cmo<o[i])cmo=o[i];
		}
		}
		if(cme>cmo)M=cme;
		else M=cmo;

		cout<<n-me-M<<endl;
	}
	else cout<<n-me-mo<<endl;
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;
 
int parent[N];
 
int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 
 
ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}
 
int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}
 
void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}
 
ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
        // is different from
        // res *= (n -r + i) / i;
    }
    return res;
}
 
int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

void solve() {
    int d, t, s;
    cin >> d >> t >> s;
    cout << ((d <= t * s) ? "Yes" : "No") << endl;
    return;
} 

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


Measured memory_bytes: 3644
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    static readonly int Mod = (int)1e9 + 7;

    public void Solve()
    {
        int N = Reader.Int();
        var A = Reader.IntArray(N);
        Console.WriteLine(Calc(N, A));
    }

    private long Calc(int N, int[] A)
    {
        long ans = 1;
        var count = new int[N];
        foreach (int a in A) count[a]++;
        if (N % 2 == 0 && count[0] > 0) return 0;
        if (N % 2 == 1 && count[0] != 1) return 0;
        for (int i = 1; i < N; i++)
        {
            if (i % 2 == N % 2 && count[i] > 0) return 0;
            if (i % 2 != N % 2 && count[i] != 2) return 0;
            if (i % 2 != N % 2 && count[i] == 2) ans = ans * 2 % Mod;
        }
        return ans;
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 13272
N = int(input())
H = list(map(int, input().split()))
ZTH = [0 for i in range(N+1)]

s = 0
H.append(0)

while H != ZTH:
  i = 0
  while i <= N - 1:
    if H[i] == 0:
      i += 1
    else:
      s += 1
      j = i
      while H[j] != 0 and j < N:
        j += 1
      i = j
  if i == N:
    for k in range(N):
      if H[k] != 0:
        H[k] -= 1
    i = 0
      
print(s)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int a(int a,int b){return a+b;}
int b(int a,int b){return a-b;}
int c(int a,int b){return a*b;}
int d(int a,int b){return a/b;}
int main(){
  int n,m;
  char op;
  while(cin >> n >> op >> m&& op!='?'){
    if(op=='+')cout << a(n,m) << endl;
    else if(op=='-')cout << b(n,m) << endl;
    else if(op=='*')cout << c(n,m) << endl;
    else if(op=='/')cout << d(n,m) << endl;
  }
}


Measured memory_bytes: 3072
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        System.out.println(Math.min(b / a, c));
    }

}

Measured memory_bytes: 23892
#include <stdio.h>

int main(void)
{
  int M,T,P,R,tID,pID,time,i,j,tmp,jud,rank[50];

  for(;;){
    scanf("%d %d %d %d", &M, &T, &P, &R);
    if(!(M|T|P|R)) break;

    int cor[50][10]={0}; int wro[50][10]={0};
    int sum[50]={0}; int pen[50]={0};
    for(i=0;i<R;i++){
      scanf("%d %d %d %d", &time, &tID, &pID, &jud);
      if(!jud){
	cor[tID-1][pID-1]=1; pen[tID-1]+=wro[tID-1][pID-1]*20+time;
      } else {
	wro[tID-1][pID-1]++;
      }
    }
    for(i=0;i<T;i++){
      for(j=0;j<P;j++){
	sum[i]+=cor[i][j];
      }
      rank[i]=T-1-i;
    }
    for(i=1;i<T;i++){
      for(j=1;j<T;j++){
	if(sum[rank[j-1]]<sum[rank[j]]){
	  tmp=rank[j-1]; rank[j-1]=rank[j]; rank[j]=tmp;
	} else if(sum[rank[j-1]]==sum[rank[j]]&&pen[rank[j-1]]>pen[rank[j]]){
	  tmp=rank[j-1]; rank[j-1]=rank[j]; rank[j]=tmp;
	}
      }
    }
    for(i=0;i<T-1;i++){
      if(sum[rank[i]]>sum[rank[i+1]])
	printf("%d,", rank[i]+1);
      else if(sum[rank[i]]==sum[rank[i+1]]&&pen[rank[i]]<pen[rank[i+1]])
	printf("%d,", rank[i]+1);
      else if(sum[rank[i]]==sum[rank[i+1]]&&pen[rank[i]]==pen[rank[i+1]])
	printf("%d=", rank[i]+1);
    }
    printf("%d\n", rank[T-1]+1);
  }
  
  return 0;
}


Measured memory_bytes: 604
#include <stdio.h>

int
main(void)
{
	char line[80];
	long a;
	long b;
	long c;
	int k = 1;

	while (gets(line)) {
		if (sscanf(line, "%ld %ld", &a, &b) == 2) {
			c = a + b;
			k = 1;
			while (c / 10 > 0) {
				k ++;
				c /= 10;
			}
			printf("%d\n", k);
		}
	}

	return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<int mod> class modint
{   
private:
    int val;
public:
    int value(){ return val; }
    modint(int x=0){ val=x%mod; }
    modint pow(int n){
        modint res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    modint inv(){ return pow(mod-2); }
    modint& operator+=(modint rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    modint& operator-=(modint rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    modint& operator*=(modint rhs){ val=val*rhs.val%mod; return *this; }
    modint& operator/=(modint rhs){ *this*=rhs.inv(); return *this; }
    modint operator+(modint rhs){ return modint(val)+=rhs; }
    modint operator-(modint rhs){ return modint(val)-=rhs; }
    modint operator*(modint rhs){ return modint(val)*=rhs; }
    modint operator/(modint rhs){ return modint(val)/=rhs; }
};

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

    int N; cin>>N;
    string s; cin>>s;
    s=' '+s;

    using mint=modint<1000000007>;
    vector<vector<mint>> dp(N+1,vector<mint>(N));
    for(int i=1;i<=N;i++) dp[1][N-i]=1;
    // O(N^3)->O(N^2)
    for(int i=1;i<N;i++){
        vector<mint> add(N);
        if(s[i]=='<'){
            for(int j=1;j<=N-i;j++){
                // for(int k=1;k<=j;k++) dp[i+1][j-k]+=dp[i][j];
                add[0]+=dp[i][j];
                add[j]-=dp[i][j];
            }
        }else{
            for(int j=0;j<N-i;j++){
                // for(int k=1;k<=N-i-j;k++) dp[i+1][N-i-k]+=dp[i][j];
                add[j]+=dp[i][j];
                add[N-i]-=dp[i][j];
            }
        }
        for(int j=0;j<N-1;j++) add[j+1]+=add[j];
        for(int j=0;j<N;j++) dp[i+1][j]+=add[j];
    }
    cout<<dp[N][0].value()<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,c,d;
	string ans="Balanced";
	cin>>a>>b>>c>>d;
	if(a+b>c+d)ans="Left";
	if(a+b<c+d)ans="Right";
	cout<<ans<<endl;
}


Measured memory_bytes: 256