akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct{
	int no;
	int cnt;
}DATA;
 
int cmp( const void *p, const void *q ) {
    return ((DATA*)q)->cnt - ((DATA*)p)->cnt;
}
 
int main(void){
	
	int i, n, tmp, cnt, ans;
	
	scanf("%d", &n);
	
	int v_odd[n / 2], v_even[n / 2];
	DATA cnt_odd[100000], cnt_even[100000];
	for(i = 0; i < 100000; i++){
		cnt_odd[i].no = i + 1;
		cnt_odd[i].cnt = 0;
		cnt_even[i].no = i + 1;
		cnt_even[i].cnt = 0;
	}
	
	for(i = 0; i < n; i++){
		if(i % 2 == 0){
			scanf("%d", &v_even[i / 2]);
			cnt_even[v_even[i / 2] - 1].cnt++;
		}else{
			scanf("%d", &v_odd[i / 2]);
			cnt_odd[v_odd[i / 2] - 1].cnt++;
		}
	}
	
	
	
	qsort(cnt_even, 100000, sizeof(DATA), cmp);
	qsort(cnt_odd, 100000, sizeof(DATA), cmp);
	
	
	
	
	// printf("odd1 : %d (%d)\nodd2 : %d (%d)\neven1 : %d (%d)\neven2 : %d (%d)\n", cnt_odd[0].no, cnt_odd[0].cnt, cnt_odd[1].no, cnt_odd[1].cnt, cnt_even[0].no, cnt_even[0].cnt, cnt_even[1].no, cnt_even[1].cnt);
	
	if(cnt_odd[0].no == cnt_even[0].no){
		int a[2];
		a[0] = (n / 2 - cnt_odd[1].cnt) + (n / 2 - cnt_even[0].cnt);
		a[1] = (n / 2 - cnt_odd[0].cnt) + (n / 2 - cnt_even[1].cnt);
		if(a[0] < a[1]){
			ans = a[0];
		}else{
			ans = a[1];
		}
	}else{
		ans = (n / 2 - cnt_odd[0].cnt) + (n / 2 - cnt_even[0].cnt);
	}
	
	printf("%d", ans);
	
	
	return 0;
}

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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int K;
  cin >> K;
  set<int> s;
  int c = 7;
  int cnt = 1;
  while(1) {
    c %= K;
    if (c == 0) {
      cout << cnt << endl;
      break;
    }
    else if (s.find(c) != s.end()) {
      cout << "-1" << endl;
      break;
    }
    else {
      s.insert(c);
      cnt++;
      c = c*10+7;
    }
  }
}


Measured memory_bytes: 50536
def task(num):
  num = int(num)
  lst = []

  if num < 2:
    return lst

  if num >= 2:
    lst.append(2)

  for i in range(3, num + 1):       
    if i % 2 == 1:
      switch = True
      for n in range(3, int(i ** 0.5) + 1, 2):
        if i % n == 0:
          switch = False  
          break        
      if switch:
        lst.append(i)
  return lst + [100003]

num=int(input())
lst = task(10**5)
ans = [e for e in lst if e >= num]
print(ans[0])


Measured memory_bytes: 3408
import sys
lst=[]
ans=0
for i in range(5):
  a=int(input())
  if a%10==0:
    ans+=a
  else:
    lst.append(a)
if len(lst)!=0:
  C=[[] for _ in range(len(lst))]   
  for i in range(len(lst)):
    v=lst[i]
    c=v%10
    C[i]=[-c,v]
  C=sorted(C)
  for i in range(len(lst)-1):
    v=C[i][1]
    c=-C[i][0]
    ans+=(v+(10-c))
  print(ans+C[-1][1])
else:
  print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll INF = LLONG_MAX / 10;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

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

int main() {
	int m = 1;
	int N; cin >> N;
	while (N--) {
		int a; cin >> a;
		m = lcm(m, a);
	}
	cout << m << endl;
}

Measured memory_bytes: 3096
a,b,c,k = map(int,input().split())
sum=0
if(k==0):
  print(sum)
  exit()
if(a>=k):
  sum+=k
  print(sum)
  exit()
else:
  sum+=a
  k=k-a
  if(b>=k):
    print(sum)
    exit()
  else:
    k = k-b
    if(c>=k):
      sum-=k
      print(sum)
    else:
      sum-=c
      print(sum)


Measured memory_bytes: 9200
# coding: utf-8

def main():
    k, n = map(int, input().split())
    A_array = list(map(int, input().split()))
    A_array.sort()
    # print(A_array, A_array[-1])
    
    
    ans = float("inf")
    for i in range(n):
        if i == 0:
            d_r = A_array[-1] - A_array[0]
            d_l = k - (A_array[1] - A_array[0])
            d = min(d_r, d_l)
        elif i == n - 1:
            d_r = k - (A_array[-1] - A_array[-2])
            d_l = A_array[-1] - A_array[0]
            d = min(d_r, d_l)
        else:
            d_r = k - (A_array[i] - A_array[i-1])
            d_l = A_array[i] + (k - A_array[i+1])
            d = min(d_l, d_r)
        # print(d)
        ans = min(ans, d)
    print(ans)
main()

Measured memory_bytes: 33672
import sys
from math import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
def calc(i,k):
    ct = 0
    while i < k:
        i *= 2
        ct += 1
    return ct

s = 0
for i in range(1,n+1):
    s += pow(1/2,calc(i,k))
print((1/n) * s)

Measured memory_bytes: 3064
#include <stdio.h>

#define STEP(X) \
  ( (X) < 0 ? 0 : (X) )
#define RANGE(X,L,U) \
  ( (X) < (L) ? 0 \
  : (X) > (U) ? (U) - (L) \
  :             (X) - (L) )

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int w;

    scanf ( "%d", &w );
    if ( w == -1 )  break ;

    printf ( "%d\n"
           , 4280 - 1150
                  - 125 * RANGE( w, 10, 20 )
                  - 140 * RANGE( w, 20, 30 )
                  - 160 * STEP( w - 30 ) );
  }

  return ( 0 );
}

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

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

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}

template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

template <typename A>
string to_string(A x[], signed n) {
    string result = "{";
    for (signed i=0; i<n; ++i) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n;
    cin >> n;
    pair<int,int> coords[n];
    REP(i, n) {
        int x,y;
        cin >> x >> y;
        coords[i] = {x, y};
    }
    sort(coords, coords+n);

    if (n == 1) {
        cout << 1;
        return 0;
    }

    int best = -1;
    for (auto a : coords) {
        for (auto b : coords) {
            if (a == b) continue;
            int p = a.first-b.first, q=a.second-b.second;
            int saved = 0;
            for (auto x : coords) {
                for (auto y : coords) {
                    if (y.first-x.first == p && y.second-x.second == q) {
                        ++saved;
                    }
                }
            }
            if (best == -1 || n-saved < best) best = n-saved;
        }
    }
    cout << best;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b,c=0,d=1,e,f,g,h,n,m,mx=0,x,y;
  cin>>n>>m;
  if(n%2==0 || m%2==0) co("Even");
  else co("Odd");
    
  return 0;
}

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

int main() {
    string word;
    string s;
    cin >> word >> s;

    int count = 0;
    while (s != "END_OF_TEXT") {
        transform(s.begin(), s.end(), s.begin(), ::tolower);
        if (s == word)
            count++;
        cin >> s;
    }
     
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
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; }
using namespace std;

int n;
char c[510][510];

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    bool black=false;
    rep(i,n)rep(j,n){
        cin>>c[i][j];
        if(c[i][j]=='#')black=true;
    }
    if(!black){
        cout<<-1<<endl;
        return 0;
    }
    
    int white=0;
    rep(i,n){
        bool b=false;
        rep(j,n)if(c[j][i]=='.')b=true;
        if(b)white++;
    }
    
    int ans=INF;
    rep(i,n){
        bool b=false;
        int cnt=0;
        rep(j,n){
            if(c[j][i]=='#')b=true;
            if(c[i][j]=='.')cnt++;
        }
        if(!b)cnt++;
        chmin(ans, cnt+white);
    }
    
    cout<<ans<<endl;
    return 0;
    
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;

  vector<ll> A(N);
  vector<ll> B(N);

  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  
  vector<ll> pos;
  ll sum_neg = 0;
  int cnt_neg = 0;
  ll a, b;
  rep(i, N){
    
    a = A[i];
    b = B[i];
    if(a > b){
      pos.push_back(a-b);
    }else if(b > a){
      sum_neg += (b-a);
      cnt_neg++;
    }
  }

  int cnt = cnt_neg;
  sort(pos.rbegin(), pos.rend());

  rep(i, pos.size()){
    if(sum_neg <= 0){
      cout << cnt << endl;
      return 0;
    }

    sum_neg -= pos[i];
    cnt++;

  }

  if(sum_neg <= 0){
    cout << cnt << endl;
  }else{
    cout << -1 << endl;
  }


  return 0;
}


Measured memory_bytes: 2428
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    A, B, C = map(int, readline().split())
    a = min(A,B,C)
    c = max(A,B,C)
    b = (A+B+C)-(a+c)
    if a==b:
        ans = c-a
    else:
        ans = (b-a)//2
        a += ((b-a)//2)*2
        ans += c-a
        b += c - a
        a = c
        if a!=b:
            ans += 1
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	int n;
	cin >> n;
	map<int,int> mp1,mp2;
	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		if(i%2==0){
			mp1[x]++;
		}else{
			mp2[x]++;
		}
	}
	
	int mx1=-1;
	int pre1=-1;
	vector<int> v1(n/2,0);
	for(auto itr=mp1.begin();itr!=mp1.end();itr++){
		if(itr->second>=pre1){
			mx1=itr->first;
			pre1=itr->second;
		}
		v1.push_back(itr->second);
		//pre1=itr->second;
	}
	sort(v1.begin(),v1.end(),greater<int>());

	int mx2=-1;
	int pre2=-1;	
	vector<int> v2(n/2,0);
	for(auto itr=mp2.begin();itr!=mp2.end();itr++){
		if(itr->second>=pre2){
			mx2=itr->first;
			pre2=itr->second;
		}
		v2.push_back(itr->second);
		//pre2=itr->second;
	}
	sort(v2.begin(),v2.end(),greater<int>());
	
	//cout << mx1 << " " << mx2 << endl;
	
	int ans;
	if(mx1==mx2){
		ans=n-max((v1[0]+v2[1]),(v1[1]+v2[0]));
	}else{
		ans=n-(v1[0]+v2[0]);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define rep(i,n) for (int i=1; i<=(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
int gcd(int a, int b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

int main(){
    int k;
    cin >>k;
    int ans = 0;
    rep(s,k){
        rep(t,k){
            rep(u,k){
                int gcd_k = gcd(s,gcd(t,u));
                ans += gcd_k;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>


using namespace std;

int data[11],N;
int a[11],b[11];
int na,nb;

bool dfs(int a[],int b[],int k)
{
	if(k==11)
	  return true;
	if(data[k]>a[na])
	{
		na++;
		a[na] = data[k];
		
		if(dfs(a,b,k+1))
		 return true;
		a[na] = 0;
		na--;
	}
	if(data[k]>b[nb])
	{
		nb++;
		b[nb] = data[k];
	    if(dfs(a,b,k+1))
	     return true;
		b[nb]=0;
		nb--;
	}
	
	return false;
	
}
int main()
{
	cin>>N;
	int time=1;
	while(time++<=N)
	{
		for(int i=1;i<=10;i++)
		{
		cin>>data[i];
		a[i]=0;
		b[i]=0;
		}
		na = nb = 0;
		
		if(dfs(a,b,1)==true)
		cout<<"YES"<<endl;
		else
		 cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 3072
#include<vector>
#include<algorithm>
#include<stack>
#include<iostream>

using namespace std;

int main(void){
	
	stack<int>st;
	int a;
	
	while(cin >> a){
		if(a==0){
			cout << st.top() << endl;
			st.pop();
		}
		else{
			st.push(a);
		}
	}
	
return 0;
}

Measured memory_bytes: 1200
import math

DEBUG = False

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

if DEBUG:
    ans = 0
    for x in range(1, N+1):
        term1 = math.floor(A*x/B)
        term2 = A * math.floor(x/B)
        temp = term1 - term2
        print("x: {}, temp: {}, term1: {}, term2: {}".format(x, temp, term1, term2))
        ans = max(ans, temp)
    print(ans)

print(math.floor(A*min(B-1, N)/B)-A*math.floor(min(B-1, N)/B))


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> c(n - 1), s(n - 1), f(n - 1);
	for(int i = 0; i < n - 1; ++i){
		cin >> c[i] >> s[i] >> f[i];
	}
	for(int i = 0; i < n; ++i){
		int t = 0;
		for(int j = i; j < n - 1; ++j){
			if(t < s[j]){ t = s[j]; }
			if(t % f[j] != 0){ t += (f[j] - t % f[j]); }
			t += c[j];
		}
		cout << t << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back

using namespace std;
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  vector<ll> F;
  REP(i, N) {
    ll num = 0;
    REP(j, 10) {
      ll f; cin >> f;
      num *= 2;
      num += f;
    }
    F.PB(num);
  }
  vector<vector<ll>> P(N, vector<ll>(11));
  REP(i, N) REP(j, 11) cin >> P[i][j];

  ll ans = -1000000000000;
  for (int b = 1; b < (1 << 10); b++) {
    ll benefit = 0;
    REP(i, N) {
      ll num = b & F[i];
      ll c = 0;
      REP(j, 10) c += (num >> j) & 1;
      benefit += P[i][c];
    }
    ans = max(ans, benefit);
  }
  cout << ans << endl;

  return 0;
}

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

int main()
{
	int X, A;
	cin >> X;
	cin >> A;
	if (X<A)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << 10 << endl;
	}
	return 0;
}

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

int main() {
  int N, tmp, cnt = 0;
  cin >> N;
  
  vector<int> d(N);
  
  for(int i = 0; i < N ; i++) {
     cin >> d.at(i);
  }
  
  for(int i = 0; i < N ; i++) {
    for(int j = 0; j < N-1; j++) {
      if(d.at(j)>d.at(j+1)) {
        tmp = d.at(j);
        d.at(j) = d.at(j+1);
        d.at(j+1) = tmp;
      }
    }
  }
  for(int i = 0; i < N-1 ; i++) {
    if(d.at(i) != d.at(i+1)) {
      cnt++;
    }
  }
  cout << cnt+1 << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
template <typename T>
struct binary_indexed_tree{
	int N;
	vector<T> BIT;
	binary_indexed_tree(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		BIT = vector<T>(N + 1, 0);
	}
	void add(int i, T x){
		i++;
		while (i <= N){
			BIT[i] += x;
			BIT[i] %= MOD;
			i += i & -i;
		}
	}
	T sum(int i){
		T ans = 0;
		while (i > 0){
			ans += BIT[i];
			ans %= MOD;
			i -= i & -i;
		}
		return ans;
	}
	T query(int L, int R){
		return (sum(min(R, N)) + MOD - sum(max(L, 0))) % MOD;
	}
	T all(){
		return BIT[0];
	}
};
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (int i = 0; i < K; i++){
    cin >> L[i] >> R[i];
    R[i]++;
  }
  binary_indexed_tree<long long> dp(N);
  dp.add(0, 1);
  for (int i = 1; i < N; i++){
    for (int j = 0; j < K; j++){
      dp.add(i, dp.query(i - R[j] + 1, i - L[j] + 1));
    }
  }
  cout << dp.query(N - 1, N) << endl;
}

Measured memory_bytes: 5368
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int MIN1 = 100000;
	int MIN2 = 100000;
	int a;

	for (int i = 0; i < 3; i++) {
		cin >> a;
		MIN1 = min(MIN1, a);
	}

	for (int i = 0; i < 2; i++) {
		cin >> a;
		MIN2 = min(MIN2, a);
	}

	cout << MIN1+MIN2-50 << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <forward_list>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

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

int gcd(int n, int m) { return n ? gcd(m % n, n) : m; }

struct edge {
    int src;
    int dst;
    int cap;
    int flow;
};

typedef vector<vector<reference_wrapper<edge>>> graph;

void add_edge(graph& g, forward_list<edge>& edges, edge e)
{
    edges.push_front(e);
    g[e.src].push_back(edges.front());
    g[e.dst].push_back(edges.front());
}

inline int opposite(const edge& e, int v) { return (e.dst == v) ? e.src : e.dst; }
inline int residue(const edge& e, int dst) { return (e.dst == dst) ? e.cap - e.flow : e.flow; }
inline void augment(edge& e, int dst, int delta) { e.flow += (e.dst == dst) ? delta : -delta; }

int max_flow(graph& g, int src, int sink)
{
    edge dummy = { 0, 0, 0, 0 };
    int f = 0;
    for (;;) {
        vector<edge*> prev(g.size(), nullptr);
        vector<int> stack;
        stack.push_back(src);
        prev[src] = &dummy;
        while (!stack.empty()) {
            int v = stack.back(); stack.pop_back();
            if (v == sink)
                break;
            for (edge& e : g[v]) {
                int w = opposite(e, v);
                if (residue(e, w) > 0 && prev[w] == nullptr) {
                    prev[w] = &e;
                    stack.push_back(w);
                }
            }
        }
        if (prev[sink] == nullptr)
            return f;
        int delta = 1e9;
        for (int v = sink; prev[v] != &dummy; v = opposite(*prev[v], v))
            delta = min(delta, residue(*prev[v], v));
        for (int v = sink; prev[v] != &dummy; v = opposite(*prev[v], v))
            augment(*prev[v], v, delta);
        f += delta;
    }
}

int main()
{
    ios::sync_with_stdio(false);

    int m, n;
    while (cin >> m >> n, m) {
        vector<int> bs(m), rs(n);
        rep(i, m) cin >> bs[i];
        rep(i, n) cin >> rs[i];

        forward_list<edge> edges;
        graph g(n + m + 2);
        rep(i, m) rep(j, n) {
            if (gcd(bs[i], rs[j]) > 1) {
                add_edge(g, edges, { i, m + j, 1, 0 });
            }
        }
        rep(i, m) add_edge(g, edges, { m + n, i, 1, 0 });
        rep(j, n) add_edge(g, edges, { m + j, m + n + 1, 1, 0 });

        int f = max_flow(g, m + n, m + n + 1);
        cout << f << endl;
    }
}

Measured memory_bytes: 7792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

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

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n,T,mn = 1500;
    cin >> n >> T;
    vector<int> c(n),t(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i] >> t[i];
        if(t[i] <= T) mn = min(mn,c[i]);
    }
    if(mn == 1500) cout << "TLE" << endl;
    else cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

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

    return (0);
}


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

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var buffer = Console.ReadLine().Split(' ');
            int N = int.Parse(buffer[0]);
            int K = int.Parse(buffer[1]);

            int cnt = 0;
            while (N > 0)
            {
                N /= K;
                cnt++;
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 17708
n = int(input())
aa = list(map(int,input().split()))

left = [0]*(n+1)
right = [0]*(n+1)

for i in range(n):
  left[i+1] = left[i] + aa[i]
  right[i+1]= right[i] +aa[-i-1]

ans = 10**10
for i in range(1,n):
  ans = min(ans,abs(left[i] - right[-i-1]))
  
print(ans)  

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

int main() {
    int N, i; cin >> N >> i;
    cout << N - i + 1 << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ld w,h;
ld x,y;
ll ans;

int main(){
  cin >> w >> h;
  cin >> x >> y;
  cout << setprecision(17);

  cout << w*h/2 << " ";
  if(x*2 == w && y*2 == h) cout << 1 << endl;
  else cout << 0 << endl;

}


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

int main(){
  char alpha[1];
  cin >> alpha[0];
  if(isupper(alpha[0])){
    cout << "A" << endl;
  }else{
    cout << "a" << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
import heapq

x, y, z, k = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

# A+B+Cが大きい順になるようにリストに入れていく
ABC = []

# heapqに任意の値が入っているか確認する
from collections import defaultdict
d = defaultdict(int)

que = []

def HeapPush(a, b, c):
    if d[(a, b, c)] == 0:
        heapq.heappush(que, ((A[a] + B[b] + C[c])*-1, a, b, c))  # -1を掛ける
        d[(a, b, c)] += 1


HeapPush(0, 0, 0)

while len(ABC) < k:
    
    abc, a, b, c = heapq.heappop(que)
    ABC.append(abc*-1)  # -1を掛け直す
    
    if a + 1 < x:
        HeapPush(a+1, b, c)
    if b + 1 < y:
        HeapPush(a, b+1, c)
    if c + 1 < z:
        HeapPush(a, b, c+1)
   

for abc in ABC:
    print(abc)

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

public class Main {
	public static void main(String[] args) {
		try {
			String input = new BufferedReader(new InputStreamReader(System.in)).readLine();
			int pre = Integer.parseInt(input.substring(0, 2));
			int pro = Integer.parseInt(input.substring(2));
			boolean preIn12 = (0 < pre && pre <= 12);
			boolean proIn12 = (0 < pro && pro <= 12);

			String ret = (preIn12 && proIn12 ? "AMBIGUOUS"
								  : (proIn12 ? "YYMM"
								  : (preIn12 ? "MMYY"
								  : "NA")));
			System.out.println(ret);
		} catch (IOException e1) {
		}
	}
}


Measured memory_bytes: 22228
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int N, K;

int main(int argc, char const *argv[]) {
	cin >> N >> K;
	int a;
	vector<int> v;
	for (int i = 0; i < K; i++) {
		cin >> a;
		v.push_back(a);
	}

	string sx;
	for (int x = N; x < 10 * N; x++) {
		sx = to_string(x);
		bool flag = false;
		for (int i = 0; i < sx.size(); i++) {
			for (int j = 0; j < v.size(); j++)
				if (sx[i]-'0' == v[j]) flag = true;
		}
		if (!flag) {
			cout << x << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {
	static int x;
	static int minI;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] l = new int[n * 2];

		for (int i = 0; i < l.length; i++) {
			l[i] = sc.nextInt();
		}

		Arrays.sort(l);

		int sum = 0;
		for (int i = 0; i < l.length; i += 2) {
			sum += l[i];
		}

		System.out.println(sum);

		sc.close();
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  bool flag = true;
  rep(i, n-1){
    if (a[i] == a[i+1])
      flag = false;
  }
  if (flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#ifndef BZ
#pragma GCC optimize "-Ofast"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;

using namespace std;

const int MX = 307;

ld f[MX + 5][MX + 5][MX + 5];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n;
    int c[4]={0};
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        c[x]++;
    }

    for (int k = 0; k < MX; k++) {
        for (int j = 0; j + k < MX; j++) {
            for (int i = 0; i + j + k < MX; i++) {
                if (i == 0 && j == 0 && k == 0) {
                    continue;
                }
                if (i + j + k > MX) {
                    continue;
                }
                ld wait = 1.0 * n / (i + j + k);
                ld pi = 1.0 * i / (i + j + k);
                ld pj = 1.0 * j / (i + j + k);
                ld pk = 1.0 * k / (i + j + k);

                if (i) {
                    f[i][j][k] += pi * f[i - 1][j][k];
                }
                if (j) {
                    f[i][j][k] += pj * f[i + 1][j - 1][k];
                }
                if (k) {
                    f[i][j][k] += pk * f[i][j + 1][k - 1];
                }
                f[i][j][k] += wait;
            }
        }
    }

    cout.precision(10);
    cout << fixed << f[c[1]][c[2]][c[3]] << "\n";
    return 0;
}



Measured memory_bytes: 233728
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll oo = 1e18;
const ll mod = 998244353,maxn = 3030;
const double PI = acos(-1);


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, less = 0, sum = 0;
    cin >> n >> m;

    vector<int> v(n);

    for (auto &x: v) cin >> x, sum += x;
    less = sum/(4*m);
    if (sum%(4*m)) less++;
    int cnt = 0;

    for (int i=0; i<n; i++){
        if (v[i] >= less) cnt++;
    }

    if (cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

static const int HMAX=1001;
static const int WMAX=1001;

char S[HMAX][WMAX];
int ans[HMAX][WMAX];



int main(){
    int H,W;
    cin >> H >> W;
    int Ch, Cw;
    cin >> Ch >> Cw;
    int Dh, Dw;
    cin >> Dh >> Dw;

    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            cin >> S[i][j];
            ans[i][j] = -1;
        }
    }

    queue<pair<int,int> > que;
    queue<pair<int,int> > que2;

    que.push(make_pair(Ch,Cw));

    ans[Ch][Cw] = 0;

    while( (!que.empty()) || (!que2.empty()) ){

    while(!que.empty()){
        int i=que.front().first;
        int j=que.front().second;

        que2.push(make_pair(i,j));
        que.pop();

        for(int ii=i-1; ii<=i+1; ii=ii+2){
            if(ii<=H && ii > 0){
                if(S[ii][j]=='.'){
                    if( ans[ii][j]<=ans[i][j] && ans[ii][j]!=-1 ) continue;
                    que.push(make_pair(ii,j));
                    ans[ii][j]=ans[i][j];
                }
            }
        }
        for(int jj=j-1; jj<=j+1; jj=jj+2){
            if(jj<=W && jj > 0){
                if(S[i][jj]=='.'){
                    if( ans[i][jj]<=ans[i][j] && ans[i][jj]!=-1 ) continue;
                    que.push(make_pair(i,jj));
                    ans[i][jj]=ans[i][j];
                }
            }
        }
        //cout << "que1: i j ans[i][j] " << i << " " << j << " " << ans[i][j] << endl;
    }

    while(!que2.empty()){

        int i=que2.front().first;
        int j=que2.front().second;

        que2.pop();

        for(int ii=i-2; ii<=i+2; ii++){
            for(int jj=j-2; jj<=j+2; jj++){
                if(ii<=H && jj<=W && ii>0 && jj>0){
                    if(S[ii][jj]=='.'){
                        if( ans[ii][jj]>ans[i][j]+1 || ans[ii][jj]==-1 ){
                            ans[ii][jj] = ans[i][j]+1;
                            que.push(make_pair(ii,jj));
                        }
                    }
                }                
            }            
        }

        //cout << "que2: i j ans[i][j] " << i << " " << j << " " << ans[i][j] << endl;

    }

    }

    cout << ans[Dh][Dw] << endl;

    return 0;
}

Measured memory_bytes: 8572
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
  string line;
  int a,b,c;
  getline (cin,line);
  stringstream(line) >> a >> b >> c;
  if ( a < b && b < c )
  { cout << "Yes\n"; }
  else
  { cout << "No\n"; }
  return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string a, b; cin >> a >> b;
  int an = a.size(), bn = b.size();
  string ans = "EQUAL";
  if (an > bn) {
    ans = "GREATER";
  } else if (an < bn) {
    ans = "LESS";
  } else if (an == bn) {
    if (a > b) ans = "GREATER";
    else if (a < b) ans = "LESS";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>

int main() {
	int n;
	int a[4] = {};

	while (std::cin >> n) {
		if (n == 0000)
			break;

		if (n % 1111 == 0) {
			std::cout << "NA" << std::endl;
			continue;
		}

		int count = 0;
		while (n != 6174) {
			a[0] = n / 1000, n %= 1000;
			a[1] = n / 100, n %= 100;
			a[2] = n / 10, n %= 10;
			a[3] = n;

			std::sort(a, a + 4);

			n = 0;
			n += (a[3] - a[0]) * 1000;
			n += (a[2] - a[1]) * 100;
			n += (a[1] - a[2]) * 10;
			n += a[0] - a[3];

			++count;
		}

		std::cout << count << std::endl;
	}
	return 0;
}

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

int main(){
	long long n, in;
	map<long long, long long> cnt;
	vector<long long> edge;
	cin >> n;
	
	for(long long i = 0 ; i < n ; i++){
		cin >> in;
		cnt[in]++;
		if(cnt[in] == 2){
			edge.push_back(in);
			cnt[in] = 0;
		}
	}
	
	sort(edge.begin(), edge.end(), greater<long long>());
	
	if(edge.size() < 2) cout << "0" << endl;
	else cout << (long long)edge[0]*edge[1] << endl;
	
	return 0;
}


Measured memory_bytes: 6528
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

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

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

	int ans;

	ans = min(a + b, b + c);
	ans = min(ans, a + c);

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

int main() {
	deque<char> deq;
	string s; cin >> s;
	for (auto c : s) deq.push_back(c);
	int q; cin >> q;
	int flag = 0;
	while (q--) {
		int t; cin >> t;
		if (t == 1) {
			flag = 1 - flag;
		} else {
			int f; cin >> f;
			char c;  cin >> c;
			if (f == 1) {
				if (flag) deq.push_back(c);
				else deq.push_front(c);
			} else {
				if (flag) deq.push_front(c);
				else deq.push_back(c);
			}
		}
	}
	if (flag) reverse(deq.begin(), deq.end());
	for (auto it = deq.begin(); it != deq.end(); it++)
		cout << *it;
	cout << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cout << (n<1200 ? "ABC" : "ARC") << endl;
}

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

using namespace std;

const int maxn = 111111;
int arr[maxn], dp[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	dp[1] = 0;
	dp[2] = abs(arr[2] - arr[1]);
	for (int i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]), dp[i - 2] + abs(arr[i] - arr[i - 2]));
	}
	cout << dp[n] << '\n';
	return 0;
}


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

using namespace std;

void Main() {
    int H, A;
    cin >> H >> A;

    int ans = H / A;
    if (H % A > 0) {
        ++ans;
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

int cnt[100005];

signed main() {
	int n;
	cin >> n;
	int d[100005], ma = 0, ans = 1;
	rep(i, n) {
		cin >> d[i];
		cnt[d[i]]++;
		ma = max(ma, d[i]);
	}
	if (d[0] != 0 || cnt[0] != 1) {
		cout << 0 << endl;
		return 0;
	}
	rep(i, ma) {
		ans *= mod_pow(cnt[i], cnt[i + 1], 998244353);
		ans %= 998244353;
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

sx, sy, tx, ty = MAP()
X = tx - sx
Y = ty - sy

way1 = "R"*X + "U"*Y
way2 = "L"*X + "D"*Y
way3 = "L" + "U"*(Y+1) + "R"*(X+1) + "D"
way4 = "R" + "D"*(Y+1) + "L"*(X+1) + "U"

print(way1+way2+way3+way4)

Measured memory_bytes: 5204
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	ll a,b,c;
	in(a);
	in(b);
        if(a==b){
            outn(a+b);
        }
        else{
            c=max(a,b);
            outn(c+c-1);
        }
	return 0;

}


Measured memory_bytes: 256
def f a, b, c
	count = 0
	loop do
		return count if [a, b, c].any?(&:odd?)
		return -1 if a==b and a==c
		a, b, c = (b+c)/2, (c+a)/2, (a+b)/2
		count += 1
	end
end

puts f(*gets.split.map(&:to_i))

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

using namespace std;


void solve(long long N, long long M, std::vector<long long> s, std::vector<long long> c){

    std::vector<long long> num(N);
    long long ans;

    for( int n=0; n < N; n++){
        num[n] = 10;
    }

    for( int m=0; m < M; m++){
        if(num[N-s[m]] != 10 && num[N-s[m]] != c[m]){
            ans = -1;
            cout << ans << endl;
            return;
        }
        num[N-s[m]] = c[m];
    }

    for( int n=0; n < N; n++){
        //cout << num[n] << endl;
    }

    if(num[N-1] == 0 && N > 1){
        ans = -1;
        cout << ans << endl;
        return;
    }

    ans = 0;
    for( int n=0; n < N; n++){
        
        if(num[n] == 10){
            if(n == N-1 && N != 1){
                num[n]=1;
            }else{
                num[n] = 0;
            }
        }
        ans += num[n] * std::pow(10, n);

    }
    cout << ans << endl;

    

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> s(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&s[i]);
        scanf("%lld",&c[i]);
    }
    solve(N, M, std::move(s), std::move(c));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


int main(){
    int A,B;
    cin >> A >> B;
    int ans = A*B -(A+B) + 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int n, m[100][100] = { 0 }, d[100] = { 0 }, t = 0, nt[100] = { 0 }, f[100] = { 0 };
int color[100] = { WHITE };

int next(int u) {
	FOR(i, nt[u], n) {
		nt[u] = i + 1;
		if (m[u][i]==1){ return i; }
	}
	return -1;
}

int dfs(int r) {
	stack<int>S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++t;

	while (!S.empty()) {
		int u=S.top();
		int v = next(u); //cout << v << endl;
		if (v != -1) {
			if (color[v]==WHITE)
			{
				S.push(v);
				color[v] = GRAY;
				d[v] = ++t;
			}
		}
		else {
			S.pop();
			color[v] = BLACK;
			f[u] = ++t;
		//	cout << f[v]<<endl;
		}
	}
	return 0;
}
int main()
{
	 cin >> n;
	REP(i, n) {
		int u, k; cin >>u >> k; u--;//
		REP(j, k) {
			int muki; cin >> muki; muki--;//
			m[u][muki] = 1;
			//printf("%d aa%d\n", u, muki);
		}
	}
	REP(i, n) {
		if (color[i] == WHITE) {
			dfs(i);// cout << i << endl;
		}
	}
	REP(i, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
import java.util.Scanner;

/**
 * Created by enpingkuang on 2020/9/10 10:54 下午
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int t = scanner.nextInt();
        int flag = n % x == 0?0:1;
        System.out.println((n/x + flag)*t);
    }
}


Measured memory_bytes: 35664
#include<bits/stdc++.h>
using namespace std;
int n,ma,mb;
int a[50],b[50],c[50];
int ms1[500][500];
int ms2[500][500];
vector<pair<pair<int,int>,int> > aa,bb;
void dfs(int cur,int x,int y,int z,int lst,vector<pair<pair<int,int>,int> > &ok){
	if(cur>=lst+1)
	{
		ok.push_back(make_pair(make_pair(x,y),z));
		return;
	}
	else
	{
		dfs(cur+1,x,y,z,lst,ok);
		dfs(cur+1,x+a[cur],y+b[cur],z+c[cur],lst,ok);
	}
}
int main(){
	int i,j,k,l,ans=1e9;
	cin>>n>>ma>>mb;
	for(i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	memset(ms1,63,sizeof(ms1));
	memset(ms2,63,sizeof(ms2));
	dfs(1,0,0,0,n/2,aa);
	dfs(n/2+1,0,0,0,n,bb);
	for(i=0;i<aa.size();i++)
	{
		ms1[aa[i].first.first][aa[i].first.second]=min(ms1[aa[i].first.first][aa[i].first.second],aa[i].second);
	}
	for(i=0;i<bb.size();i++)
	{
		ms2[bb[i].first.first][bb[i].first.second]=min(ms2[bb[i].first.first][bb[i].first.second],bb[i].second);
	}
	for(i=ma;i<=400;i+=ma)
	{
		j=i/ma*mb;
		if(j>400)
			continue;
		for(k=0;k<=i;k++)
		{
			for(l=0;l<=j;l++)
			{
				ans=min(ans,ms1[k][l]+ms2[i-k][j-l]);
			}
		}
	}
	if(ans==1e9)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 34792